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

Refactor methods to operate on and return DataArrays #7

Open
jgerardsimcock opened this issue Oct 10, 2017 · 0 comments
Open

Refactor methods to operate on and return DataArrays #7

jgerardsimcock opened this issue Oct 10, 2017 · 0 comments

Comments

@jgerardsimcock
Copy link
Contributor

jgerardsimcock commented Oct 10, 2017

  • climate_toolbox version:
  • Python version:
  • Operating System:

Description

Right now methods for projecting from gridded to iso/hierid operate on datasets. This is kind of a problem when we have multiple climate variables in the same dataset (spline-tas, degree-days) or something like below.

Dimensions:  (lat: 720, lon: 1440, time: 365)
Coordinates:
  * time     (time) datetime64[ns] 2006-01-01T12:00:00 2006-01-02T12:00:00 ...
  * lat      (lat) float32 -89.875 -89.625 -89.375 -89.125 -88.875 -88.625 ...
  * lon      (lon) float32 0.125 0.375 0.625 0.875 1.125 1.375 1.625 1.875 ...
Data variables:
    tas      (time, lat, lon) float32 271.728 271.744 271.745 271.733 ...
    tas_2    (time, lat, lon) float32 73836.0 73844.9 73845.5 73838.8 ...
    tas_3    (time, lat, lon) float32 2.00633e+07 2.00669e+07 2.00672e+07 ...

I am uncomfortable with the current implementation where, in order to project to hierid, we would have to iterate over each variable like the following:

for var in ds.data_vars.keys():
            ds = weighted_aggregate_grid_to_regions(
                ds, var, aggwt, agglev, weights=weights)

The assignment and reassingment of datasets in xarray makes me uncomfortable.

One possible implementation:

xformd_das = []
vars = []
for var in ds.data_vars.keys():
        da = ds[var]
        da = weighted_aggregate_grid_to_regions(da, aggwt, agglev, weights
        xformd.append(da)
        vars.append(var)

da = xr.concat(xformd_das, pd.Index(vars))
...

da.to_netcdf(...)
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

1 participant