I have a time series that I have pulled from a netCDF file and I\'m trying to convert them to a datetime format. The format of the time series is in \'days since 1990-01-01 00:0
netCDF num2date is the correct function to use here:
import netCDF4
ncfile = netCDF4.Dataset('./foo.nc', 'r')
time = ncfile.variables['time'] # do not cast to numpy array yet
time_convert = netCDF4.num2date(time[:], time.units, time.calendar)
This will convert number of days since 1900-01-01 (i.e. the units
of time
) to python datetime objects. If time
does not have a calendar
attribute, you'll need to specify the calendar, or use the default of standard.