-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
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
inplaceargument (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 resultMetadata
Metadata
Assignees
Labels
No labels