Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dscim/menu/simple_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ def gdppc(self):
def adding_up_damages(self):
"""This property calls pre-calculated adding-up IR-level 'mean' over batches."""

mean_cc = f"{self.ce_path}/adding_up_cc.zarr"
mean_no_cc = f"{self.ce_path}/adding_up_no_cc.zarr"
mean_cc = f"{self.ce_path}/adding_up_cc_eta{self.eta}.zarr"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting for the future that we should go ahead and make the whole filepath an arg in self so that these sorts of code changes aren't necessary.

mean_no_cc = f"{self.ce_path}/adding_up_no_cc_eta{self.eta}.zarr"

if os.path.exists(mean_cc) and os.path.exists(mean_no_cc):
self.logger.info(
Expand Down
20 changes: 19 additions & 1 deletion src/dscim/preprocessing/input_damages.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ def prep_mortality_damages(
outpath,
mortality_version,
path_econ,
etas,
):
ec = EconVars(path_econ=path_econ)

Expand All @@ -744,6 +745,10 @@ def prep_mortality_damages(
scaling_deaths = "epa_row"
scaling_costs = "epa_scaled"
valuation = "vsl"
elif mortality_version == 9:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mortality version 9 is a new one to me. Need to add this to our documentation. Also, we need to add brief comments in here about what each version means (or at least what the string values mean).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The theory behind the naming scheme is that versions 1-5 use VSL valuation and 6-10 use the same scaling deaths and costs, but with VLY instead. Version 9 has an extra wrench thrown in, which is that it uses a $2 million VSL in 2025 (2025 USD). This was an MG request for his book spec of the regional SCCs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @JMGilbert! Is that theory on versioning documented anywhere else?

scaling_deaths = "epa_popavg"
scaling_costs = "epa_scaled"
valuation = "vly"
else:
raise ValueError("Mortality version not valid: ", str(mortality_version))

Expand Down Expand Up @@ -776,7 +781,19 @@ def prep(
valuation=valuation,
).drop(["gcm", "valuation"])

data = xr.open_mfdataset(paths, preprocess=prep, parallel=True, engine="zarr")
d_ls = []
for eta in etas:
paths_ls = [paths.format(i, eta) for i in range(15)]
Comment thread
kemccusker marked this conversation as resolved.
data = (
xr.open_mfdataset(
paths_ls, preprocess=prep, parallel=True, engine="zarr"
)
.assign_coords({"eta": eta})
.expand_dims("eta")
)
d_ls.append(data)

data = xr.merge(d_ls)

damages = xr.Dataset(
{
Expand All @@ -798,6 +815,7 @@ def prep(
damages = damages.chunk(
{
"batch": 15,
"eta": 1,
"ssp": 1,
"model": 1,
"rcp": 1,
Expand Down
14 changes: 6 additions & 8 deletions src/dscim/preprocessing/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ def reduce_damages(
bottom_coding_gdppc=39.39265060424805,
zero=False,
):
if recipe == "adding_up":
assert (
eta is None
), "Adding up does not take an eta argument. Please set to None."
# client = Client(n_workers=35, memory_limit="9G", threads_per_worker=1)

with open(config) as stream:
c = yaml.safe_load(stream)
params = c["sectors"][sector]
Expand Down Expand Up @@ -114,7 +108,9 @@ def reduce_damages(
}

ce_batch_dims = [i for i in gdppc.dims] + [
i for i in ds.dims if i not in gdppc.dims and i != "batch"
i
Comment thread
kemccusker marked this conversation as resolved.
Outdated
for i in ds.dims
if i not in gdppc.dims and i != "batch" and i != "eta"
]
ce_batch_coords = {c: ds[c].values for c in ce_batch_dims}
ce_batch_coords["region"] = [
Expand All @@ -129,6 +125,8 @@ def reduce_damages(
).chunk(chunkies)

other = xr.open_zarr(damages).chunk(chunkies)
if "eta" in other.coords:
other = other.sel(eta=eta, drop=True)

out = other.map_blocks(
ce_from_chunk,
Expand All @@ -155,7 +153,7 @@ def reduce_damages(

if recipe == "adding_up":
out.to_zarr(
f"{outpath}/{recipe}_{reduction}.zarr",
f"{outpath}/{recipe}_{reduction}_eta{eta}.zarr",
consolidated=True,
mode="w",
)
Expand Down
19 changes: 5 additions & 14 deletions tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ def test_subset_USA_reduced_damages(tmp_path, recipe):

d = tmp_path / "USA_econ"
d.mkdir()
if recipe == "adding_up":
infile = d / f"{sector}/{recipe}_{reduction}.zarr"
outfile = d / f"{sector}_USA/{recipe}_{reduction}.zarr"
else:
infile = d / f"{sector}/{recipe}_{reduction}_eta{eta}.zarr"
outfile = d / f"{sector}_USA/{recipe}_{reduction}_eta{eta}.zarr"
infile = d / f"{sector}/{recipe}_{reduction}_eta{eta}.zarr"
outfile = d / f"{sector}_USA/{recipe}_{reduction}_eta{eta}.zarr"

ds_in = xr.Dataset(
{
Expand Down Expand Up @@ -404,14 +400,9 @@ def test_reduce_damages(tmp_path, recipe, eta):
+ 38.39265060424805 # Since the dummy data gets set to less than the bottom code, set the expected output equal to the bottom code
)

if recipe == "adding_up":
damages_reduced_actual_path = (
f"{reduced_damages_out}/dummy_sector1/{recipe}_cc.zarr"
)
else:
damages_reduced_actual_path = (
f"{reduced_damages_out}/dummy_sector1/{recipe}_cc_eta{eta}.zarr"
)
damages_reduced_actual_path = (
f"{reduced_damages_out}/dummy_sector1/{recipe}_cc_eta{eta}.zarr"
)

xr.testing.assert_equal(
xr.open_zarr(damages_reduced_actual_path), damages_reduced_out_expected
Expand Down
Loading