Skip to content

Commit 152ae4f

Browse files
authored
Merge pull request #68 from ClimateImpactLab/input_damages_pytests
Add pytests for preprocessing spatial innput damages
2 parents 802f129 + 8bdc1ee commit 152ae4f

File tree

3 files changed

+1308
-11
lines changed

3 files changed

+1308
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [0.4.0] - Unreleased
88
### Added
9+
- New unit tests for [dscim/utils/input_damages.py](https://github.com/ClimateImpactLab/dscim/blob/main/src/dscim/preprocessing/input_damages.py). ([PR #68](https://github.com/ClimateImpactLab/dscim/pull/68), [@davidrzhdu](https://github.com/davidrzhdu))
910
- New unit tests for [dscim/utils/rff.py](https://github.com/ClimateImpactLab/dscim/blob/main/src/dscim/utils/rff.py). ([PR #73](https://github.com/ClimateImpactLab/dscim/pull/73), [@JMGilbert](https://github.com/JMGilbert))
1011
- New unit tests for [dscim/dscim/preprocessing.py](https://github.com/ClimateImpactLab/dscim/blob/main/src/dscim/preprocessing/preprocessing.py). ([PR #67](https://github.com/ClimateImpactLab/dscim/pull/67), [@JMGilbert](https://github.com/JMGilbert))
11-
- Add functions used for producing RFF weights. ([PR #66](https://github.com/ClimateImpactLab/dscim/pull/66), [@davidrzhdu](https://github.com/davidrzhdu))
12+
- Functions used for producing RFF weights. ([PR #66](https://github.com/ClimateImpactLab/dscim/pull/66), [@davidrzhdu](https://github.com/davidrzhdu))
1213
### Changed
13-
- Changed `prep_mortality_damages` function to work with new format mortality outputs. ([PR #74](https://github.com/ClimateImpactLab/dscim/pull/65), [@JMGilbert](https://github.com/JMGilbert))
14+
- Changed `coastal_inputs` function to work with new version of coastal outputs. ([PR #75](https://github.com/ClimateImpactLab/dscim/pull/75), [@davidrzhdu](https://github.com/davidrzhdu))
15+
- Changed `prep_mortality_damages` function to work with new format mortality outputs. ([PR #74](https://github.com/ClimateImpactLab/dscim/pull/74) and [PR #68](https://github.com/ClimateImpactLab/dscim/pull/68), [@JMGilbert](https://github.com/JMGilbert))
1416
- Included US territories in damages and economic variable subsetting. ([PR #78](https://github.com/ClimateImpactLab/dscim/pull/78), [@JMGilbert](https://github.com/JMGilbert))
1517
- Changed format of `eta_rhos` to allow for multiple values of `rho` for the same `eta`. ([PR #65](https://github.com/ClimateImpactLab/dscim/pull/65), [@JMGilbert](https://github.com/JMGilbert))
1618
- Removed incomplete "time_trend" extrapolation option from `dscim.utils.utils.model_outputs()`, along with unused function arguments. This is a breaking change. ([PR #53](https://github.com/ClimateImpactLab/dscim/pull/53), [@brews](https://github.com/brews))
@@ -21,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2123
- Remove old/unnecessary files. ([PR #57](https://github.com/ClimateImpactLab/dscim/pull/57), [@JMGilbert](https://github.com/JMGilbert))
2224
- Remove unused “save_path” and “ec_cls” from `read_energy_files_parallel()`. ([PR #56](https://github.com/ClimateImpactLab/dscim/pull/56), [@davidrzhdu](https://github.com/davidrzhdu))
2325
### Fixed
26+
- Add `.load()` to every loading of population data from EconVars. ([PR #82](https://github.com/ClimateImpactLab/dscim/pull/82), [@davidrzhdu](https://github.com/davidrzhdu))
27+
- Make `compute_ag_damages` function correctly save outputs in float32. ([PR #72](https://github.com/ClimateImpactLab/dscim/pull/72) and [PR #82](https://github.com/ClimateImpactLab/dscim/pull/82), [@davidrzhdu](https://github.com/davidrzhdu))
2428
- Make rff damage functions read in and save out in the proper filepath structure. ([PR #79](https://github.com/ClimateImpactLab/dscim/pull/79), [@JMGilbert](https://github.com/JMGilbert))
2529
- Enter the proper functional form of isoelastic utility when `eta = 1`. ([PR #65](https://github.com/ClimateImpactLab/dscim/pull/65), [@JMGilbert](https://github.com/JMGilbert))
2630
- Pin numpy version to stop tests failing. ([PR #60](https://github.com/ClimateImpactLab/dscim/pull/60), [@JMGilbert](https://github.com/JMGilbert))

src/dscim/preprocessing/input_damages.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ def process_batch(g):
368368
batches = p_map(
369369
process_batch, [g for i, g in paths.groupby("batch")], num_cpus=num_cpus
370370
)
371+
batches = [ds for ds in batches if ds is not None]
371372
chunkies = {
372373
"rcp": 1,
373374
"region": 24378,
@@ -704,11 +705,18 @@ def prep(
704705
scaling_costs=scaling_costs,
705706
valuation=valuation,
706707
):
707-
return ds.sel(
708-
gcm=gcm,
709-
scaling=[scaling_deaths, scaling_costs],
710-
valuation=valuation,
711-
).drop(["gcm", "valuation"])
708+
if scaling_deaths == scaling_costs:
709+
return ds.sel(
710+
gcm=gcm,
711+
scaling=[scaling_deaths],
712+
valuation=valuation,
713+
).drop(["gcm", "valuation"])
714+
else:
715+
return ds.sel(
716+
gcm=gcm,
717+
scaling=[scaling_deaths, scaling_costs],
718+
valuation=valuation,
719+
).drop(["gcm", "valuation"])
712720

713721
data = xr.open_mfdataset(paths, preprocess=prep, parallel=True, engine="zarr")
714722

@@ -747,15 +755,13 @@ def prep(
747755

748756
if i == 0:
749757
damages.to_zarr(
750-
outpath
751-
/ f"impacts-darwin-montecarlo-damages-v{mortality_version}.zarr",
758+
f"{outpath}/impacts-darwin-montecarlo-damages-v{mortality_version}.zarr",
752759
consolidated=True,
753760
mode="w",
754761
)
755762
else:
756763
damages.to_zarr(
757-
outpath
758-
/ f"impacts-darwin-montecarlo-damages-v{mortality_version}.zarr",
764+
f"{outpath}/impacts-darwin-montecarlo-damages-v{mortality_version}.zarr",
759765
consolidated=True,
760766
append_dim="gcm",
761767
)

0 commit comments

Comments
 (0)