Hello i have a neetcdf4 file with monthly precipitation data for over 10 years. what i am trying to do is :
dataset = Dataset('test.nc','r',format='NETCDF4') lons = dataset.variables['lon'][:] lats = dataset.variables['lat'][:] times = dataset.variables['time'][:] times_units = dataset.variables['time'].units prep_solide = dataset.variables['PREC'][:,:,:] prec_units =dataset.variables['PREC'].units dates = num2date(times[:],' months since 1801-01-01 00:00:00')
The error i keep getting is
ValueError: unsupported time units
is there any other way to fix this error ?
As you already noticed "months" is not supported by num2date function. To be honest, what is the meaning of 2 months since 1800-01-01 00:00:00 anyway? Is it 1800-03-01 00:00:00 or something else (1 month = 365.25/12 days and hence 1800-03-02 02:21:00)?
In any case, I would make the dates with my own function. For example, in your case:
dates = [datetime.datetime(1800,1,1)+datetime.timedelta(seconds = 365.25/12*24.0*3600.0*float(val)) for val in times]
As I do not know what is the value of 1 month in seconds in your data, I used 365.25/12.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With