convert_calendar 360_day with offset start and end dates. #7407
Unanswered
ollie-bell
asked this question in
Q&A
Replies: 1 comment 2 replies
-
my knowledge of calendar conversions is pretty minimal, but I'm guessing that this is the expected behavior of In [1]: import xarray as xr
In [2]: times = xr.date_range("1980-12-01", "1990-11-30")
...: ds = xr.Dataset(coords={"time": times})
...: ds.time
Out[2]:
<xarray.DataArray 'time' (time: 3652)>
array(['1980-12-01T00:00:00.000000000', '1980-12-02T00:00:00.000000000',
'1980-12-03T00:00:00.000000000', ..., '1990-11-28T00:00:00.000000000',
'1990-11-29T00:00:00.000000000', '1990-11-30T00:00:00.000000000'],
dtype='datetime64[ns]')
Coordinates:
* time (time) datetime64[ns] 1980-12-01 1980-12-02 ... 1990-11-30
In [3]: ds.convert_calendar("360_day", align_on="year").time
Out[3]:
<xarray.DataArray 'time' (time: 3600)>
array([cftime.Datetime360Day(1980, 11, 30, 0, 0, 0, 0, has_year_zero=True),
cftime.Datetime360Day(1980, 12, 1, 0, 0, 0, 0, has_year_zero=True),
cftime.Datetime360Day(1980, 12, 2, 0, 0, 0, 0, has_year_zero=True), ...,
cftime.Datetime360Day(1990, 11, 27, 0, 0, 0, 0, has_year_zero=True),
cftime.Datetime360Day(1990, 11, 28, 0, 0, 0, 0, has_year_zero=True),
cftime.Datetime360Day(1990, 11, 29, 0, 0, 0, 0, has_year_zero=True)],
dtype=object)
Coordinates:
* time (time) object 1980-11-30 00:00:00 ... 1990-11-29 00:00:00
In [4]: ds.convert_calendar("360_day", align_on="date").time
Out[4]:
<xarray.DataArray 'time' (time: 3582)>
array([cftime.Datetime360Day(1980, 12, 1, 0, 0, 0, 0, has_year_zero=True),
cftime.Datetime360Day(1980, 12, 2, 0, 0, 0, 0, has_year_zero=True),
cftime.Datetime360Day(1980, 12, 3, 0, 0, 0, 0, has_year_zero=True), ...,
cftime.Datetime360Day(1990, 11, 28, 0, 0, 0, 0, has_year_zero=True),
cftime.Datetime360Day(1990, 11, 29, 0, 0, 0, 0, has_year_zero=True),
cftime.Datetime360Day(1990, 11, 30, 0, 0, 0, 0, has_year_zero=True)],
dtype=object)
Coordinates:
* time (time) object 1980-12-01 00:00:00 ... 1990-11-30 00:00:00 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an observational dataset on standard 365/366 day calendar, and a modelled dataset on the same spatial grid but with a 360 day calendar. Both datasets are daily frequency. I need to convert the observational dataset calendar to 360_day in order to do bias adjustment on the modelled dataset.
The modelled data has a start date of 1980-12-01 and end date of 2080-11-30, and when dealing with temporal subsets the processing I am doing makes sense to keep 12-01 and 11-30 start and end dates for both the observational and modelled datasets, e.g. 1980-12-01 to 1990-11-30:
However, when converting the observational dataset calendar to
360_day
usingconvert_calendar
with these start and end dates, it returns a time coordinate over 1980-11-30 to 1990-11-29 (instead of the desired 1980-12-01 to 1990-11-30).If this is indeed expected behaviour and isn't a bug in
convert_calendar
, then what is an appropriate way to deal with this?e.g. I could take a hacky approach and just increment the resulting time coordinate by 1 day?
Beta Was this translation helpful? Give feedback.
All reactions