Unidata / netcdf4-python

netcdf4-python: python/numpy interface to the netCDF C library
http://unidata.github.io/netcdf4-python
MIT License
752 stars 262 forks source link

num2date returns 01:00:00 or 00:59:59 depending on calendar #810

Open demorym opened 6 years ago

demorym commented 6 years ago

Good afternoon,

You may already be aware of this problem, but I didn't find how to solve it. I have an output with hourly intervals written in days since 1979-01-01 00:00:00. The first time step is 0. The second is 0.041666666667. I have noticed that num2date does not give the same results when reading the second time step depending on the calendar used. It sometimes give 1979-01-01 01:00:00 (which is what we want), and sometimes 1979-01-01 00:59:59 (see below). How can we fix it so num2date would give the correct result (01:00:00. 02:00:00, etc.) whatever calendar is used?

Thank you for your help, Marie-Estelle

time_in1=0.041666666667 print(time_in_units) days since 1979-01-01 00:00:00 dt_in1 = num2date(time_in1,time_in_units,calendar='standard') str(dt_in1) '1979-01-01 01:00:00' dt_in1 = num2date(time_in1,time_in_units,calendar='gregorian') str(dt_in1) '1979-01-01 01:00:00' dt_in1 = num2date(time_in1,time_in_units,calendar='proleptic_gregorian') str(dt_in1) '1979-01-01 01:00:00' dt_in1 = num2date(time_in1,time_in_units,calendar='noleap') str(dt_in1) '1979-01-01 00:59:59' dt_in1 = num2date(time_in1,time_in_units,calendar='365_day') str(dt_in1) '1979-01-01 00:59:59' dt_in1 = num2date(time_in1,time_in_units,calendar='360_day') str(dt_in1) '1979-01-01 00:59:59' dt_in1 = num2date(time_in1,time_in_units,calendar='julian') str(dt_in1) '1979-01-01 01:00:00' dt_in1 = num2date(time_in1,time_in_units,calendar='all_leap') str(dt_in1) '1979-01-01 00:59:59' dt_in1 = num2date(time_in1,time_in_units,calendar='366_day') str(dt_in1) '1979-01-01 00:59:59'

fmaussion commented 6 years ago

@demorym maybe you can open this issue on https://github.com/Unidata/cftime as well, which is where time functionalities is handled now.

demorym commented 6 years ago

Will do that, thank you!