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

Units in date2num / num2date #434

Closed
dpl opened this issue Jul 3, 2015 · 10 comments
Closed

Units in date2num / num2date #434

dpl opened this issue Jul 3, 2015 · 10 comments

Comments

@dpl
Copy link

dpl commented Jul 3, 2015

In the documentation for num2date and date2num, it says that "units" in the arguments list should be: "a string of the form 'time units since reference time' describing the time units. time units can be days, hours, minutes, seconds, milliseconds or microseconds." Now I on several occasions encountered data where the time unit is set as, e.g., "months since yyyy-mm-dd hh:mm:ss". Is there any way or planned implementation to deal with such longer-timestep units as well?

@mdecker
Copy link

mdecker commented Jul 3, 2015

The problem with time units such as "months" is that they are not well defined. In contrast to days, hours, etc. the length of a month depends on the calendar used and even varies between different months.
The alternative is to define a month exactly as 1/12th of a year as udunits does. This "solution" is not very intuitive to the user will will likely lead to misunderstandings.

A few words about this issue can be found in the CF conventions: http://cfconventions.org/Data/cf-conventions/cf-conventions-1.6/build/cf-conventions.html#time-coordinate

We recommend that the unit year be used with caution. The Udunits package defines a
year to be exactly 365.242198781 days (the interval between 2 successive passages of
the sun through vernal equinox). It is not a calendar year. Udunits includes the following
definitions for years: a common_year is 365 days, a leap_year is 366 days, a Julian_year
is 365.25 days, and a Gregorian_year is 365.2425 days.

For similar reasons the unit month , which is defined in udunits.dat to be exactly year/12,
should also be used with caution. 

@jswhit
Copy link
Collaborator

jswhit commented Jul 3, 2015

We could convert "months since" to "seconds since" using 1 month = year/12 = 2629743.831225 seconds. Same for "weeks since" and "years since". This is how netcdf-java does it (http://www.unidata.ucar.edu/software/thredds/current/netcdf-java/CDM/CalendarDateTime.html). It may lead to confusion though, and cause more problems than it solves.

@shoyer
Copy link
Contributor

shoyer commented Jul 3, 2015

My two cents is that it's better to give an error and force users to convert such ill-defined units explicitly.

@davidhassell
Copy link

I would agree. The Udunits definition of "month" is practically never what is meant by encoders of "months since ...", so giving an error would be safe and clear.

@jswhit
Copy link
Collaborator

jswhit commented Jul 6, 2015

We already do throw an error, so it seems like no change in the current behavior is needed. Closing now...

@jswhit jswhit closed this as completed Jul 6, 2015
@dpl
Copy link
Author

dpl commented Jul 6, 2015

Thanks for all replies - by the way, is there something like a users mailing list?

@jswhit
Copy link
Collaborator

jswhit commented Jul 6, 2015

There's no mailing list right now. Wish github had a better mechanism for discussions.

@bennoblumenthal
Copy link

While the udunits definition of month is not what is ever meant, that is a udunits flaw, not a flaw in the standard.

units of months since with a calendar of 360_day is perfectly well defined and there is no reason why this cannot be properly coded.

@jswhit
Copy link
Collaborator

jswhit commented Aug 20, 2015

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

@rabernat
Copy link

👍 to @bennoblumenthal's comment.

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

No branches or pull requests

7 participants