Skip to content
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

decode 'months since' for 360_day calendars #68

Closed
rabernat opened this issue Sep 28, 2018 · 4 comments
Closed

decode 'months since' for 360_day calendars #68

rabernat opened this issue Sep 28, 2018 · 4 comments

Comments

@rabernat
Copy link

rabernat commented Sep 28, 2018

The IRI Data Library contains tons of datasets with the following time attributes:

	float32 T(T) ;
		T:standard_name = time ;
		T:pointwidth = 1.0 ;
		T:long_name = Time ;
		T:calendar = 360 ;
		T:expires = 1538524800 ;
		T:gridtype = 0 ;
		T:units = months since 1960-01-01 ;

(edited to correct typo in original post)

(example dataset)

I would like to be able to open and decode these datasets in xarray, with time decoding handled by cftime.

There are two problems:

  1. The calendar is not a valid CF calendar. It should be 360_day. But that is easy to fix by rewriting the calendar attribute.
  2. Even with calendar = 360_day, months is not considered a valid time unit

However, in a 360-day calendar month==30 days, so this should be valid.

This was discussed over in Unidata/netcdf4-python#434 (comment), where @jswhit commented:

A pull request allowing months since when calendar is 360_day would be welcome

@rabernat
Copy link
Author

To clarify, currently in cftime, I get the following:

cftime.num2date(0, 'months since 1960-01-01', '360_day')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-65-4a67652d64b1> in <module>()
----> 1 cftime.num2date(0, 'months since 1960-01-01', '360_day')

cftime/_cftime.pyx in cftime._cftime.num2date()

cftime/_cftime.pyx in cftime._cftime.utime.__init__()

cftime/_cftime.pyx in cftime._cftime._parse_date_and_units()

ValueError: units must be one of 'seconds', 'minutes', 'hours' or 'days' (or singular version of these), got 'months'

@jswhit
Copy link
Collaborator

jswhit commented Oct 26, 2018

Created a new pull request #75 which includes both the date2num and num2date implementations, and works with the latest updates to master.

jswhit added a commit that referenced this issue Oct 27, 2018
allow 'months_since' for '360_day' calendar (issue #68)
@jswhit
Copy link
Collaborator

jswhit commented Oct 27, 2018

merged pull request #75

@jswhit jswhit closed this as completed Oct 27, 2018
@davidhassell
Copy link
Contributor

Sorry, I've not been able to look at this for a few days - does this mean that "months since ..." are always decoded as 30 day months when the calendar is "360_day"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants