Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 12 additions & 5 deletions src/dscim/menu/main_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Parameters
----------
discounting_type : str
Choice of discounting: ``euler_gwr``, ``euler_ramsey``, ``constant``, ``naive_ramsey``,
Choice of discounting: ``euler_gwr``, ``euler_ramsey``, ``constant``, ``constant_gwr``, ``naive_ramsey``,
``naive_gwr``, ``gwr_gwr``.
discrete_discounting: boolean
Discounting is discrete if ``True``, else continuous (default is ``False``).
Expand All @@ -52,6 +52,7 @@
DISCOUNT_TYPES = [
"constant",
"constant_model_collapsed",
"constant_gwr",
"naive_ramsey",
"euler_ramsey",
"naive_gwr",
Expand Down Expand Up @@ -253,7 +254,11 @@
# 'constant_model_collapsed' should be here except that we allow
# for a collapsed-model Ramsey rate to be calculated (for labour
# and energy purposes)
if self.discounting_type in ["constant", "constant_model_collapsed"]:
if self.discounting_type in [
"constant",
"constant_model_collapsed",
"constant_gwr",
]:
self.stream_discount_factors = None

# assert formulas for which clip_gmsl is implemented
Expand Down Expand Up @@ -318,8 +323,10 @@
self.logger.info("Processing SCC calculation ...")
if self.fit_type == "quantreg":
self.full_uncertainty_iqr
self.calculate_scc
self.stat_uncertainty_iqr
# stat_uncertainty_iqr function expects collapsed SCCs, so a fair aggregation is required
if len(self.fair_aggregation) > 0:
self.calculate_scc
self.stat_uncertainty_iqr

Check warning on line 329 in src/dscim/menu/main_recipe.py

View check run for this annotation

Codecov / codecov/patch

src/dscim/menu/main_recipe.py#L327-L329

Added lines #L327 - L329 were not covered by tests
else:
if len(self.fair_aggregation) > 0:
self.stream_discount_factors
Expand Down Expand Up @@ -1093,7 +1100,7 @@
xr.Dataset
"""

if discrate in ["constant", "constant_model_collapsed"]:
if discrate in ["constant", "constant_model_collapsed", "constant_gwr"]:
if self.discrete_discounting:
discrate_damages = [
damages * (1 / (1 + r)) ** (damages.year - self.climate.pulse_year)
Expand Down
35 changes: 26 additions & 9 deletions src/dscim/preprocessing/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
zero,
socioec,
ce_batch_coords,
quantreg=False,
):
year = chunk.year.values
ssp = chunk.ssp.values
Expand All @@ -44,13 +45,19 @@
raise NotImplementedError("Pass 'cc' or 'no_cc' to reduction.")

if recipe == "adding_up":
result = mean_func(
np.maximum(
if not quantreg:
result = mean_func(
np.maximum(
calculation,
bottom_code,
),
"batch",
)
else:
result = np.maximum(

Check warning on line 57 in src/dscim/preprocessing/preprocessing.py

View check run for this annotation

Codecov / codecov/patch

src/dscim/preprocessing/preprocessing.py#L57

Added line #L57 was not covered by tests
calculation,
bottom_code,
),
"batch",
)
)
elif recipe == "risk_aversion":
result = ce_func(
np.maximum(
Expand All @@ -73,13 +80,17 @@
socioec,
bottom_coding_gdppc=39.39265060424805,
zero=False,
quantreg=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)

if recipe == "risk_aversion":
assert not quantreg, "Quantile regression is not compatible with risk aversion. Please set quantreg to False."

with open(config) as stream:
c = yaml.safe_load(stream)
params = c["sectors"][sector]
Expand Down Expand Up @@ -112,10 +123,15 @@
"model": 1,
"ssp": 1,
}

ce_batch_dims = [i for i in gdppc.dims] + [
i for i in ds.dims if i not in gdppc.dims and i != "batch"
]
if quantreg:
chunkies["batch"] = 1
ce_batch_dims = [i for i in gdppc.dims] + [

Check warning on line 128 in src/dscim/preprocessing/preprocessing.py

View check run for this annotation

Codecov / codecov/patch

src/dscim/preprocessing/preprocessing.py#L127-L128

Added lines #L127 - L128 were not covered by tests
i for i in ds.dims if i not in gdppc.dims
]
else:
ce_batch_dims = [i for i in gdppc.dims] + [
i for i in ds.dims if i not in gdppc.dims and i != "batch"
]
ce_batch_coords = {c: ds[c].values for c in ce_batch_dims}
ce_batch_coords["region"] = [
i for i in gdppc.region.values if i in ce_batch_coords["region"]
Expand Down Expand Up @@ -143,6 +159,7 @@
zero=zero,
socioec=socioec,
ce_batch_coords=ce_batch_coords,
quantreg=quantreg,
),
template=template,
)
Expand Down