xcdat
xcdat copied to clipboard
[Feature]: Retain bounds and compute time point for group averaging operations
Is your feature request related to a problem?
Time bounds are dropped when computing group averages and the time point is set to the beginning of the averaging period.
Note that time values exist in the initial dataset:
# import xcdat
import xcdat as xc
# open dataset
dpath = '/p/user_pub/work/CMIP6/CMIP/E3SM-Project/E3SM-2-0/historical/r1i1p1f1/Amon/ts/gr/v20220830/'
ds = xc.open_mfdataset(dpath)
# show time bounds present
ds.time_bnds
<xarray.DataArray 'time_bnds' (time: 1980, bnds: 2)> dask.array<concatenate, shape=(1980, 2), dtype=object, chunksize=(600, 2), chunktype=numpy.ndarray> Coordinates:
- time (time) object 1850-01-16 12:00:00 ... 2014-12-16 12:00:00 Dimensions without coordinates: bnds
But the bounds disappear for the group average values:
# compute annual averages
ds = ds.temporal.group_average('ts', freq='year')
# extract time_bnds
ds.time_bnds
AttributeError: 'Dataset' object has no attribute 'time_bnds'
And the time point for each group average is at the beginning of the period:
# inspect time values
ds.time.values
array([cftime.DatetimeNoLeap(1850, 1, 1, 0, 0, 0, 0, has_year_zero=True), cftime.DatetimeNoLeap(1851, 1, 1, 0, 0, 0, 0, has_year_zero=True), cftime.DatetimeNoLeap(1852, 1, 1, 0, 0, 0, 0, has_year_zero=True), ...
Describe the solution you'd like
-
Ideally we could return
time_bnds
with group averaging calculations. I think the returned bounds could be the lower most and upper most bound for the averaged data. -
The returned time points could then be the mean of these returned time bounds, which would be more representative than a time point in the beginning of the averaged period.
Describe alternatives you've considered
No response
Additional context
No response