-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v1.1.8 'days since 0000-01-01 00:00:00' ValueError: year is out of range #442
Comments
There is no year 0 in the Gregorian or Julian calendars. I don't think we should try to support this by treating year 0 the same as year 1 as udunits does. |
Yeah, that makes sense. Perhaps making a more descriptive ValueError for this would be useful? There are datasets floating around with this time units convention floating around... |
I just encountered this error myself and then found it was already documented here. 'days since 0000-01-01 00:00:00' is the unit for time in the CCSM POP ocean model. It will be problematic if it is not supported by netCDF4, since there is lots of pre-existing output that uses this convention. What would be the best work-around, short of modifying petabytes of existing model output? |
I've just been using a method where I shift the year to something allowable, use num2date, and then shift it back. Saves me from having to alter the netcdf files....
|
I agree with @jswhit that netcdf4-python should not support this. But some CDMs, like iris, can handle this for you. Iris uses cf_units which obey UDUNITS rules: import cf_units
from datetime import datetime
units = "days since 0000-01-01 00:00:00"
cf_units.date2num(datetime(1, 1, 1), units, cf_units.CALENDAR_NO_LEAP)
365.0
cf_units.num2date(365, units, cf_units.CALENDAR_STANDARD)
-1-12-31 00:00:00 # (!)
cf_units.num2date(366, units, cf_units.CALENDAR_STANDARD)
1-01-01 00:00:00 A little odd, but works! |
pull request #447 adds a more informative error message if year 0 (or negative year) used in a time units string. |
raise ValueError if year 0 used in time units (issue #442)
Hi, I see that zero is not allowed for other calendars, too:
The CF conventions says "Year 0 may be a valid year in non-real-world calendars, and therefore cannot be used to signal climatological time in such cases.", so it ought to be ok in the non-real-world cases. What do you think? All the best, David |
I agree. Pull request #470 fixes this (allows non-positive reference years in non-real-world calendars). |
Pull request #470 has been merged. |
That's great - thanks. |
I got a strange error when working with some data today and it was related to the time variable's units.
When code attempted to translate the time data into datetime objects I would get the following error:
After digging around a bit, it was apparent that the limit for gregorian calendar (which is what 'noleap' translates to?) is the year 0001 CE. However, I was looking at some documentation in netcdftime/netcdftime.py and this section (line 612)
This makes it seem like 'days since 0000-01-01 00:00:00' should work and be interpreted as the year 0001. I also have a colleague who was running the same code (not sure of the version for his netcdf4 library) without the ValueError.
I switched the units to use the year 0001 and it ended up working fine, but the data is now of course pushed 1 year forward. I figured I'd throw this on here just incase it is a bug, and not an intended feature.
I'm using Python v2.7.10 with the Anaconda distr. v2.2.0 and netCDF4 v1.1.8.
The text was updated successfully, but these errors were encountered: