Skip to content

Commit f169522

Browse files
authored
Merge pull request #44 from ClimateImpactLab/fix_mutedefaults
Remove mutable argument defaults
2 parents 5aa2b70 + 8842e87 commit f169522

File tree

15 files changed

+202
-133
lines changed

15 files changed

+202
-133
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88
### Changed
9+
- Remove mutable argument defaults to avoid gotchas. ([PR #44](https://github.com/ClimateImpactLab/dscim/pull/44), [@brews](https://github.com/brews))
910
- Quiet unused(?), common, logging messages to terminal. ([PR #14](https://github.com/ClimateImpactLab/dscim/pull/14), [@brews](https://github.com/brews))
1011
### Fixed
1112
- Add missing `self` arg to `global_consumption_calculation` abstract method. ([PR #43](https://github.com/ClimateImpactLab/dscim/pull/43), [@brews](https://github.com/brews))

src/dscim/diagnostics/batch_maps.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,26 @@ def batch_maps(
7474
ECON_ZARR,
7575
eta,
7676
maxmin=True,
77-
selection=dict(year=2097, ssp=["SSP2", "SSP3", "SSP4"], batch="batch0"),
77+
selection=None,
7878
location=(0.35, -0.2),
7979
gcm="mean",
8080
prefix=None,
81-
variables=[
81+
variables=(
8282
"rp_inc_share",
8383
"rp_damage_share",
8484
"rp_cons_share",
8585
"rp",
8686
"cons",
8787
"cons_ce",
88-
],
89-
maxes=[None, None, None, None, None, None],
90-
mins=[None, None, None, None, None, None],
88+
),
89+
maxes=(None, None, None, None, None, None),
90+
mins=(None, None, None, None, None, None),
9191
year=2097,
9292
plot=True,
9393
save_path=None,
9494
):
95+
if selection is None:
96+
selection = dict(year=2097, ssp=["SSP2", "SSP3", "SSP4"], batch="batch0")
9597

9698
assert len(maxes) == len(
9799
variables

src/dscim/diagnostics/compare_sccs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def compare_sccs(
7-
rootdict, recipe, disc, eta, rho, quantiles=[0, 0.05, 0.5, 0.95, 1], wp="0.5"
7+
rootdict, recipe, disc, eta, rho, quantiles=(0, 0.05, 0.5, 0.95, 1), wp="0.5"
88
):
99

1010
this_list = []

src/dscim/diagnostics/damage_function.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def damage_function(
7070
rho,
7171
year=2097,
7272
hue_vars="ssp",
73-
recipes=["adding_up", "risk_aversion", "equity"],
73+
recipes=("adding_up", "risk_aversion", "equity"),
7474
scale=10**12,
7575
x_lim=(-np.inf, np.inf),
7676
y_lim=(-np.inf, np.inf),
@@ -97,7 +97,7 @@ def damage_function(
9797
Type of discounting. Can be 'constant', 'ramsey', or 'wr'.
9898
year: int
9999
Year of damage function to be plotted.
100-
recipes : list of str
100+
recipes : sequence of str
101101
Recipe types to be plotted. Can be 'adding_up', 'risk_aversion', 'equity'
102102
scale : int
103103
Units of dollars for axis. ie., if 10**12 is passed, y axis will be in trillions.
@@ -269,8 +269,8 @@ def damage_function_w_consumption(
269269
output,
270270
eta,
271271
rho,
272-
years=[2050, 2099],
273-
recipes=["equity"],
272+
years=(2050, 2099),
273+
recipes=("equity",),
274274
disc="constant",
275275
model="IIASA GDP",
276276
ssp="SSP3",

src/dscim/diagnostics/discount_rates.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ def plot_implicit_rates(
1212
eta,
1313
rho,
1414
fair_aggregation="ce",
15-
ssp=["SSP3"],
16-
model=["IIASA GDP"],
17-
rcp=["ssp585", "ssp245", "ssp460", "ssp370", "Naive Ramsey"],
18-
weitzman_parameter=["0.001", "0.1", "1.0"],
15+
ssp=("SSP3",),
16+
model=("IIASA GDP",),
17+
rcp=("ssp585", "ssp245", "ssp460", "ssp370", "Naive Ramsey"),
18+
weitzman_parameter=("0.001", "0.1", "1.0"),
1919
pulse_year=2020,
20-
recipes=["risk_aversion", "equity"],
21-
discounting=["ramsey", "gwr"],
20+
recipes=("risk_aversion", "equity"),
21+
discounting=("ramsey", "gwr"),
2222
aspect=0.4,
2323
save_path=None,
2424
csv=True,

src/dscim/diagnostics/equity_risk_premiums.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,23 @@ def mumbai_plots(
2222
eta,
2323
title=True,
2424
aspect=1,
25-
selection=dict(year=2097),
26-
region_dict={
27-
"IND.21.317.1249": "Mumbai, IND",
28-
"CAN.2.33.913": "Vancouver, CAN",
29-
"USA.14.608": "Chicago, USA",
30-
"EGY.11": "Cairo, EGY",
31-
"SDN.4.11.50.164": "Khartoum, SDN",
32-
"NGA.25.510": "Lagos, NGA",
33-
"SAU.7": "Riyadh, SAU",
34-
"RUS.16.430.430": "St Petersburg, RUS",
35-
},
25+
selection=None,
26+
region_dict=None,
3627
):
28+
if selection is None:
29+
selection = dict(year=2097)
30+
31+
if region_dict is None:
32+
region_dict = {
33+
"IND.21.317.1249": "Mumbai, IND",
34+
"CAN.2.33.913": "Vancouver, CAN",
35+
"USA.14.608": "Chicago, USA",
36+
"EGY.11": "Cairo, EGY",
37+
"SDN.4.11.50.164": "Khartoum, SDN",
38+
"NGA.25.510": "Lagos, NGA",
39+
"SAU.7": "Riyadh, SAU",
40+
"RUS.16.430.430": "St Petersburg, RUS",
41+
}
3742

3843
assert premium in [
3944
"risk_aversion",

src/dscim/diagnostics/fair_step.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def marginal_damages(
2121
sector,
2222
sector_path,
2323
discounting,
24-
recipes=["risk_aversion", "equity"],
24+
recipes=("risk_aversion", "equity"),
2525
save_path=None,
2626
):
2727

@@ -98,7 +98,7 @@ def global_consumption(
9898
sector,
9999
sector_path,
100100
discounting,
101-
recipes=["risk_aversion", "equity"],
101+
recipes=("risk_aversion", "equity"),
102102
save_path=None,
103103
scale=10**12,
104104
):
@@ -153,20 +153,20 @@ def output_scc(
153153
sector_path,
154154
eta,
155155
rho,
156-
recipes=["adding_up", "risk_aversion", "equity", "local"],
157-
discounting=["constant_model_collapsed", "constant", "euler_ramsey", "euler_gwr"],
156+
recipes=("adding_up", "risk_aversion", "equity", "local"),
157+
discounting=("constant_model_collapsed", "constant", "euler_ramsey", "euler_gwr"),
158158
save_path=None,
159159
file=None,
160160
subset_dict=None,
161-
index=[
161+
index=(
162162
"discount_type",
163163
"discrate",
164164
"weitzman_parameter",
165165
"model",
166166
"ssp",
167167
"rcp",
168168
"gas",
169-
],
169+
),
170170
):
171171

172172
final_dfs = []
@@ -230,14 +230,19 @@ def plot_implicit_rates(
230230
sector,
231231
path,
232232
fair_aggregation="ce",
233-
ssp=["SSP3"],
234-
model=["IIASA GDP"],
233+
ssp=None,
234+
model=None,
235235
pulse_year=2020,
236-
recipes=["risk_aversion", "equity"],
237-
discounting=["ramsey", "gwr"],
236+
recipes=("risk_aversion", "equity"),
237+
discounting=("ramsey", "gwr"),
238238
save_path=None,
239239
csv=True,
240240
):
241+
if ssp is None:
242+
ssp = ["SSP3"]
243+
244+
if model is None:
245+
model = ["IIASA GDP"]
241246

242247
for recipe in recipes:
243248

src/dscim/diagnostics/maps.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,26 @@ def maps(
7474
ECON_ZARR,
7575
eta,
7676
maxmin=True,
77-
selection=dict(year=2097, ssp=["SSP2", "SSP3", "SSP4"]),
77+
selection=None,
7878
location=(0.35, -0.2),
7979
gcm="mean",
8080
prefix=None,
81-
variables=[
81+
variables=(
8282
"rp_inc_share",
8383
"rp_damage_share",
8484
"rp_cons_share",
8585
"rp",
8686
"cons",
8787
"cons_ce",
88-
],
89-
maxes=[None, None, None, None, None, None],
90-
mins=[None, None, None, None, None, None],
88+
),
89+
maxes=(None, None, None, None, None, None),
90+
mins=(None, None, None, None, None, None),
9191
year=2097,
9292
plot=True,
9393
save_path=None,
9494
):
95+
if selection is None:
96+
selection = dict(year=2097, ssp=["SSP2", "SSP3", "SSP4"])
9597

9698
assert len(maxes) == len(
9799
variables

src/dscim/diagnostics/stacked_damage_function.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ def plot_stacked(
1515
eta=2.0,
1616
rho=0.0,
1717
xlim=(-1, 8),
18-
years=[2020, 2050, 2090, 2100, 2200, 2300],
18+
years=None,
1919
sharey=False,
2020
rff=True,
2121
):
22+
if years is None:
23+
years = [2020, 2050, 2090, 2100, 2200, 2300]
2224

2325
root_rff = f"/shares/gcp/integration_replication/results/rff/{sector}/2020/"
2426
root_ssp = f"/shares/gcp/integration_replication/results/AR6_ssp/{sector}/2020/"

0 commit comments

Comments
 (0)