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

Rounding in netCDF4.num2date

Open wcarthur opened this issue 8 years ago • 1 comments

I'm using netCDF4.num2date to read in some (randomly generated) datetime information from a netCDF4 file.

Below are three calls to netCDF4.num2date with the input value changing by +/- 00000001. The second line shows the unexpected behaviour. The returned netcdftime._netcdftime.DatetimeJulian increments the day attribute, but the minutes and seconds do not, so the datetime is incorrect (it should match the result of the third function call)

>>> import netCDF4
>>> netCDF4.__version__
'1.2.8'

>>> netCDF4.num2date(57172751.99999999, 'hours since 1900-01-01 00:00', 'julian')
netcdftime._netcdftime.DatetimeJulian(8422, 2, 6, 23, 59, 59, 963939, -1, 1)

>>> netCDF4.num2date(57172752.0, 'hours since 1900-01-01 00:00', 'julian')
netcdftime._netcdftime.DatetimeJulian(8422, 2, 7, 23, 59, 59, 999907, -1, 1)

>>> netCDF4.num2date(57172752.00000001, 'hours since 1900-01-01 00:00', 'julian')
netcdftime._netcdftime.DatetimeJulian(8422, 2, 7, 0, 0, 0, 0, -1, 1)

I've not delved into the inner workings of the function, so can't suggest any starting point for resolution.

wcarthur avatar Nov 15 '17 02:11 wcarthur

Hi - There was some discussion on this sort of thing in issue #590

davidhassell avatar Nov 15 '17 08:11 davidhassell