I am working with an nc file.The file has an array of dimensions time, number, latitude, longitude. I was trying to convert time from number to date via the num2date method.
time_unit = nc.variables["time"].getncattr('units') # first read the 'units' attributes from the variable time
print(time_unit)
time_cal = nc.variables["time"].getncattr('calendar') # read calendar type
local_time = nc.num2date(t, units=time_unit, calendar=time_cal) # convert time
print("Original time %s is now converted as %s" % (time[0], local_time[0]))
But i am facing the following error.
AttributeError Traceback (most recent call last)
<ipython-input-124-d9912be48299> in <module>()
2 print(time_unit)
3 time_cal = nc.variables["time"].getncattr('calendar') # read
calendar type
----> 4 local_time = nc.num2date(t, units=time_unit, calendar=time_cal) #
convert time
5 print("Original time %s is now converted as %s" % (time[0],
local_time[0]))
netCDF4\_netCDF4.pyx in netCDF4._netCDF4.Dataset.__getattr__
(netCDF4\_netCDF4.c:20474)()
netCDF4\_netCDF4.pyx in netCDF4._netCDF4.Dataset.getncattr
(netCDF4\_netCDF4.c:19433)()
netCDF4\_netCDF4.pyx in netCDF4._netCDF4._get_att (netCDF4\_netCDF4.c:4451()
AttributeError: NetCDF: Attribute not found
Any solutions?