netcdf4-python
netcdf4-python copied to clipboard
Rounding in netCDF4.num2date
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.
Hi - There was some discussion on this sort of thing in issue #590