netcdf4-python icon indicating copy to clipboard operation
netcdf4-python copied to clipboard

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

Open demorym opened this issue 7 years ago • 2 comments

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'

demorym avatar Jun 22 '18 13:06 demorym

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

fmaussion avatar Jul 06 '18 09:07 fmaussion

Will do that, thank you!

demorym avatar Jul 10 '18 13:07 demorym