Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
agstephens opened this issue Jan 14, 2022 · 0 comments
Open
Assignees

Comments

@agstephens
Copy link
Collaborator

agstephens commented Jan 14, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants