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

Add a datetime_to_365day method #6

Open
delgadom opened this issue Aug 11, 2017 · 0 comments
Open

Add a datetime_to_365day method #6

delgadom opened this issue Aug 11, 2017 · 0 comments

Comments

@delgadom
Copy link
Member

delgadom commented Aug 11, 2017

Every climate transformation I do requires changing the time (datetime64[ns]) dimension into a YYYYDDD 365-day calendar time (int64) dimension. This seems like a good candidate for admission into the toolbox.

Proposed API

The function should accept as inputs:

  • a dataset indexed by some time dimension and any other dimensions, with an arbitrary number of data variables, which may or may not be indexed by the time dimension.
  • the name of the time dimension, which should be a datetime-like object, and which may have leap-years and may be less than or greater than a full year
  • an inplace argument (default False)

The function should return:

  • a dataset indexed by some integer 365-day YYYYDDD time dimension with the same dimension name. * If inplace=True, the data should be modified in-place, and the function should return None

Suggested Code

def datetime_to_365_day(ds, dim='time', inplace=False):

    if inplace:
        result = ds
    else:
        result = ds.copy()

    result = result.loc[{
        'time': ~((result['time.month'] == 2) & (result['time.day'] == 29))}]

    # this needs to be changed!
    # currently, this only works for datasets with 1 year or less of data. If there is more
    # than one year of daily data, this method will fail.
    # note that the tricky part here is we want March 1 to become YYYY060 regardless
    # of whether it is a leap year.
    # result.coords[dim] = result[str(dim)+'.year']*1000 + np.arange(1, len(result[dim])+1)
    raise NotImplementedError

    if not inplace:
        return result
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

1 participant