Skip to content

Commit

Permalink
Merge branch 'main' into fix_xarray_deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
brews authored Sep 29, 2022
2 parents a53c5e5 + 6fc7714 commit 5b223b0
Show file tree
Hide file tree
Showing 4 changed files with 525 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- New unit tests. ([PR #50](https://github.com/ClimateImpactLab/dscim/pull/50), [@brews](https://github.com/brews))
- New unit tests. ([PR #50](https://github.com/ClimateImpactLab/dscim/pull/50), [PR #52](https://github.com/ClimateImpactLab/dscim/pull/52), [@brews](https://github.com/brews))
### Changed
- Updated README with additional technical details. ([PR #49](https://github.com/ClimateImpactLab/dscim/pull/49), [@brews](https://github.com/brews))
### Fixed
- Minor fixes to docstrs. ([PR #50](https://github.com/ClimateImpactLab/dscim/pull/50), [@brews](https://github.com/brews))
- Fix xarray `.drop()` deprecation. ([PR #54](https://github.com/ClimateImpactLab/dscim/pull/54), [@brews](https://github.com/brews))
- Fix pathlib.Path/str `TypeError` in `preprocessing.clip_damages()`. ([PR #55](https://github.com/ClimateImpactLab/dscim/pull/55), [@brews](https://github.com/brews))
- Minor fixes to docstrs. ([PR #50](https://github.com/ClimateImpactLab/dscim/pull/50), [PR #52](https://github.com/ClimateImpactLab/dscim/pull/52), [@brews](https://github.com/brews))


## [0.2.1] - 2022-09-22
Expand Down
10 changes: 10 additions & 0 deletions src/dscim/menu/simple_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ class StackedDamages:
A dictionary with coordinate values to filter data.
eta : int
Curvature parameter of the CRRA utility function.
gdppc_bottom_code : int or float
Minimum values allowed for per-capita GDP in ``self.gdppc``.
ce_path : str, optional
Path to directory containing certainty equivalent reduced damages and
risk aversion data. This directory can contain `adding_up_cc.zarr` and
`adding_up_no_cc.zarr` which have reduced damages due to climate in
dollars (by impact region, year, etc.) for the `adding_up` recipe with
climate change (cc) and without climate change (no cc).
This directory should also contain `risk_aversion_{ce_type}_eta{eta}.zarr`
as used for risk aversion calculations.
"""

NAME = ""
Expand Down
14 changes: 9 additions & 5 deletions src/dscim/preprocessing/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,11 @@ def clip_damages(
params = loaded_config["sectors"][sector]

# get sector paths and variable names
path = Path(params["sector_path"])
sector_path = Path(params["sector_path"])
histclim = params["histclim"]
delta = params["delta"]

with xr.open_zarr(path, chunks=None)[delta] as ds:
with xr.open_zarr(sector_path, chunks=None)[delta] as ds:
with xr.open_zarr(econ_path, chunks=None) as gdppc:

ce_batch_dims = [i for i in ds.dims]
Expand All @@ -343,7 +343,7 @@ def clip_damages(
i for i in ds.region.values if i in gdppc.region.values
]
ce_shapes = [len(ce_batch_coords[c]) for c in ce_batch_dims]
ce_chunks = [xr.open_zarr(path).chunks[c][0] for c in ce_batch_dims]
ce_chunks = [xr.open_zarr(sector_path).chunks[c][0] for c in ce_batch_dims]
print(ce_chunks)

template = xr.DataArray(
Expand Down Expand Up @@ -394,11 +394,15 @@ def chunk_func(

return damages

data = xr.open_zarr(path)
data = xr.open_zarr(sector_path)

for var in [delta, histclim]:
out = (
data[var].map_blocks(chunk_func, template=template).rename(var).to_dataset()
)
outpath = path.replace(".zarr", "_clipped.zarr")

parent, name = sector_path.parent, sector_path.name
clipped_name = name.replace(".zarr", "_clipped.zarr")
outpath = Path(parent).joinpath(clipped_name)

out.to_zarr(outpath, mode="a", consolidated=True)
Loading

0 comments on commit 5b223b0

Please sign in to comment.