Closed matt-long closed 5 years ago
@matt-long, with #133, I added a new optional argument, method
to allow users to control how they want the time values to be computed:
By default, midpoint values are computed:
dsm = esmlab.resample(ds, freq='mon')
dsm.time
<xarray.DataArray 'time' (time: 12)>
array([cftime.DatetimeNoLeap(2000, 1, 16, 12, 0, 0, 0, 6, 16),
cftime.DatetimeNoLeap(2000, 2, 15, 0, 0, 0, 0, 1, 46),
cftime.DatetimeNoLeap(2000, 3, 16, 12, 0, 0, 0, 2, 75),
cftime.DatetimeNoLeap(2000, 4, 16, 0, 0, 0, 0, 5, 106),
cftime.DatetimeNoLeap(2000, 5, 16, 12, 0, 0, 0, 0, 136),
cftime.DatetimeNoLeap(2000, 6, 16, 0, 0, 0, 0, 3, 167),
cftime.DatetimeNoLeap(2000, 7, 16, 12, 0, 0, 0, 5, 197),
cftime.DatetimeNoLeap(2000, 8, 16, 12, 0, 0, 0, 1, 228),
cftime.DatetimeNoLeap(2000, 9, 16, 0, 0, 0, 0, 4, 259),
cftime.DatetimeNoLeap(2000, 10, 16, 12, 0, 0, 0, 6, 289),
cftime.DatetimeNoLeap(2000, 11, 16, 0, 0, 0, 0, 2, 320),
cftime.DatetimeNoLeap(2000, 12, 16, 12, 0, 0, 0, 4, 350)], dtype=object)
Coordinates:
* time (time) object 2000-01-16 12:00:00 ... 2000-12-16 12:00:00
Attributes:
bounds: time_bnds
dsm = esmlab.resample(ds, freq='mon', method='left')
dsm.time
<xarray.DataArray 'time' (time: 12)>
array([cftime.DatetimeNoLeap(2000, 1, 1, 12, 0, 0, 0, 5, 1),
cftime.DatetimeNoLeap(2000, 2, 1, 12, 0, 0, 0, 1, 32),
cftime.DatetimeNoLeap(2000, 3, 1, 12, 0, 0, 0, 1, 60),
cftime.DatetimeNoLeap(2000, 4, 1, 12, 0, 0, 0, 4, 91),
cftime.DatetimeNoLeap(2000, 5, 1, 12, 0, 0, 0, 6, 121),
cftime.DatetimeNoLeap(2000, 6, 1, 12, 0, 0, 0, 2, 152),
cftime.DatetimeNoLeap(2000, 7, 1, 12, 0, 0, 0, 4, 182),
cftime.DatetimeNoLeap(2000, 8, 1, 12, 0, 0, 0, 0, 213),
cftime.DatetimeNoLeap(2000, 9, 1, 12, 0, 0, 0, 3, 244),
cftime.DatetimeNoLeap(2000, 10, 1, 12, 0, 0, 0, 5, 274),
cftime.DatetimeNoLeap(2000, 11, 1, 12, 0, 0, 0, 1, 305),
cftime.DatetimeNoLeap(2000, 12, 1, 12, 0, 0, 0, 3, 335)], dtype=object)
Coordinates:
* time (time) object 2000-01-01 12:00:00 ... 2000-12-01 12:00:00
Attributes:
bounds: time_bnds
dsm = esmlab.resample(ds, freq='mon', method='right')
dsm.time
<xarray.DataArray 'time' (time: 12)>
array([cftime.DatetimeNoLeap(2000, 1, 31, 12, 0, 0, 0, 0, 31),
cftime.DatetimeNoLeap(2000, 2, 28, 12, 0, 0, 0, 0, 59),
cftime.DatetimeNoLeap(2000, 3, 31, 12, 0, 0, 0, 3, 90),
cftime.DatetimeNoLeap(2000, 4, 30, 12, 0, 0, 0, 5, 120),
cftime.DatetimeNoLeap(2000, 5, 31, 12, 0, 0, 0, 1, 151),
cftime.DatetimeNoLeap(2000, 6, 30, 12, 0, 0, 0, 3, 181),
cftime.DatetimeNoLeap(2000, 7, 31, 12, 0, 0, 0, 6, 212),
cftime.DatetimeNoLeap(2000, 8, 31, 12, 0, 0, 0, 2, 243),
cftime.DatetimeNoLeap(2000, 9, 30, 12, 0, 0, 0, 4, 273),
cftime.DatetimeNoLeap(2000, 10, 31, 12, 0, 0, 0, 0, 304),
cftime.DatetimeNoLeap(2000, 11, 30, 12, 0, 0, 0, 2, 334),
cftime.DatetimeNoLeap(2000, 12, 31, 12, 0, 0, 0, 5, 365)], dtype=object)
Coordinates:
* time (time) object 2000-01-31 12:00:00 ... 2000-12-31 12:00:00
Attributes:
bounds: time_bnds
Resampling daily to monthly data using
resample
returns an erroneous time axis and time_bounds.For instance:
The original dataset was a year of daily data
The monthly dataset mysteriously begins on Jan 2 1850 and appears to be daily data, but is in fact monthly.
Even worse,
time_bnds
: