Skip to content

Prototype adding time bounds to Datasets returned by time averaging #214

@agstephens

Description

@agstephens

Let's see if we can add time bounds into the outputs from time_average(...):

https://github.com/roocs/clisops/blob/average_time/clisops/core/average.py#L275-L279

I did some playing with xarray and it might be relatively simple to do this...

import xarray as xr


ds = xr.open_dataset("/home/users/astephen/tas_Amon_EC-Earth3_dcppA-hindcast_s198611-r1i1p1f1_gr_198611-198710.nc",
         use_cftime=True)

d = ds.resample(indexer={ds.time.name: '1MS'}).mean(
       dim=ds.time.name, skipna=True, keep_attrs=True)

time_0 = d.time.values[0]
dt_cls = time_0.__class__

freq = "month"
if freq == "month":
    time_bounds = [
        [dt_cls(tm.year, tm.month, tm.day), dt_cls(tm.year, tm.month, tm.daysinmonth)]
            for tm in d.time.values
    ]

print(time_bounds)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions