Skip to content

Commit 83dab9b

Browse files
author
Kit Schwarz
committed
more fixes and blacking
1 parent 8344a76 commit 83dab9b

File tree

16 files changed

+67
-57
lines changed

16 files changed

+67
-57
lines changed

dscim/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ def menu_factory(self, menu_key, sector, kwargs=None):
201201
climate_options.update(**climate_kwargs)
202202

203203
# Set up
204-
dir_name = os.path.dirname(os.path.abspath(__file__))
205204
sector_config = self.param_dict["sectors"].get(sector)
206205
sector_config.update({k: v for k, v in global_options.items()})
207206
sector_config.update(

dscim/cli.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def cli(config_file, menu_order, log_level, local, pro=False):
7878
path_to_scheduler = os.path.join(os.getenv("SCRATCH"), "scheduler.json")
7979
client = Client(scheduler_file=path_to_scheduler)
8080

81+
print(logger, client)
82+
8183
if menu_order == "":
8284
waiter.execute_order()
8385
else:
@@ -86,12 +88,9 @@ def cli(config_file, menu_order, log_level, local, pro=False):
8688

8789
menus = global_parameters["menu_type"]
8890
discounts = global_parameters["discounting_type"]
89-
course = global_parameters["course"]
9091
pulse_year = waiter.param_dict["climate"]["pulse_year"]
9192

92-
for menu, discount, sector, level in itertools.product(
93-
menus, discounts, sectors, levels
94-
):
93+
for menu, discount, sector in itertools.product(menus, discounts, sectors):
9594
obj = waiter.menu_factory(
9695
menu_key=menu,
9796
sector=sector,

dscim/diagnostics/batch_maps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def batch_maps(
119119
if gcm == "mean":
120120
damages = damages.weighted(weights).mean(dim="gcm")
121121
elif gcm == "ce":
122-
damages = c_equivalence(risk.damages, dims=["gcm"])
122+
damages = c_equivalence(damages, dims=["gcm"])
123123
else:
124124
damages = damages.sel({"gcm": gcm})
125125

dscim/diagnostics/crayola_plots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,4 @@ def crayola_plots(
180180
title = f"{var}_{recipe.discounting_type}_{recipe.NAME}_{recipe.sector}_{ssp}.png"
181181
g.savefig(os.path.join(save_plot_path, title))
182182

183-
return (global_damages, global_consumption)
183+
return (global_damages, recipe.global_consumption)

dscim/diagnostics/damage_inc_share_boxplots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def income_boxplot(
106106
}
107107
)
108108

109-
bxp = ax.bxp(stats, showmeans=True, meanline=False)
109+
ax.bxp(stats, showmeans=True, meanline=False)
110110
ax.set_ylabel(f"{year} damages as a share of present-day GDP")
111111
ax.set_xlabel("Decile of present-day GDP per capita")
112112
ax.spines["top"].set_visible(False)

dscim/diagnostics/fair_step.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
logger = logging.getLogger(__name__)
1212
import matplotlib.pyplot as plt
1313
import seaborn as sns
14-
from dscim.utils.dicts import *
1514
from functools import reduce
1615

1716
sns.set_style("darkgrid")
@@ -42,7 +41,6 @@ def marginal_damages(
4241
marginal_damages[recipe]["ssp-model"] = (
4342
marginal_damages[recipe].ssp + "-" + marginal_damages[recipe].model
4443
)
45-
len_ssps = len(marginal_damages[recipe].reset_index().ssp.unique())
4644
marginal_damages[recipe] = marginal_damages[recipe].sort_values(["ssp-model"])
4745

4846
# to avoid errors when plotting by hue and style

dscim/diagnostics/maps.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ def make_map(
2828
maxmin=True,
2929
):
3030

31-
font = {
32-
"family": "serif",
33-
"color": "black",
34-
"weight": "normal",
35-
"size": 14,
36-
}
37-
3831
# create figure
3932
fig, ax = plt.subplots(figsize=figsize, facecolor="white")
4033

@@ -147,7 +140,7 @@ def maps(
147140
elif gcm == "mean":
148141
damages = damages.weighted(weights).mean(dim="gcm")
149142
elif gcm == "ce":
150-
damages = c_equivalence(risk.damages, dims=["gcm"])
143+
damages = c_equivalence(damages, dims=["gcm"])
151144
else:
152145
damages = damages.sel({"gcm": gcm})
153146

dscim/menu/decorators.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,14 @@ def save_wrap(self, *args, **kwargs):
3535
filename_path = os.path.join(self.save_path, filename)
3636

3737
if isinstance(save, xr.DataArray):
38-
try:
39-
save = save.to_dataset()
40-
except:
41-
save = save.rename(name).to_dataset()
42-
save.attrs = self.output_attrs
43-
44-
# change `None` object to str(None)
45-
for att in save.attrs:
46-
if save.attrs[att] is None:
47-
save.attrs.update({att: "None"})
38+
39+
save = save.rename(name).to_dataset()
40+
save.attrs = self.output_attrs
41+
42+
# change `None` object to str(None)
43+
for att in save.attrs:
44+
if save.attrs[att] is None:
45+
save.attrs.update({att: "None"})
4846

4947
self.logger.info(f"Saving {filename_path}.nc4")
5048
save.to_netcdf(f"{filename_path}.nc4")

dscim/menu/main_recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def damage_function():
278278
self.damage_function_coefficients
279279
try:
280280
self.damage_function_fit
281-
except:
281+
except FileNotFoundError:
282282
pass
283283

284284
def scc():

dscim/menu/simple_storage.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ def gmst(self):
8181
@property
8282
def gmsl(self):
8383
"""Cached GMSL anomalies"""
84-
gmsl = xr.open_dataset(self.gmsl_path, engine = "zarr").gmsl.to_dataframe().reset_index()
84+
gmsl = (
85+
xr.open_dataset(self.gmsl_path, engine="zarr")
86+
.gmsl.to_dataframe()
87+
.reset_index()
88+
)
8589

8690
return gmsl
8791

@@ -273,7 +277,7 @@ def __init__(self, path_econ):
273277
def econ_vars(self):
274278
"""Economic variables"""
275279
if self.path[-3:] == "arr":
276-
raw = xr.open_dataset(self.path, engine = "zarr", consolidated=True)
280+
raw = xr.open_dataset(self.path, engine="zarr", consolidated=True)
277281
else:
278282
raw = xr.open_dataset(self.path)
279283
return raw[["gdp", "pop"]]
@@ -400,7 +404,11 @@ def adding_up_damages(self):
400404
f"Adding up aggregated damages found at {mean_cc}, {mean_no_cc}. These are being loaded..."
401405
)
402406
damages = (
403-
(xr.open_dataset(mean_no_cc, engine = "zarr").no_cc - xr.open_dataset(mean_cc, engine = "zarr").cc) * self.pop
407+
(
408+
xr.open_dataset(mean_no_cc, engine="zarr").no_cc
409+
- xr.open_dataset(mean_cc, engine="zarr").cc
410+
)
411+
* self.pop
404412
).sum("region")
405413
else:
406414
raise NotImplementedError(
@@ -429,4 +437,4 @@ def risk_aversion_damages(self, ce_type):
429437
raise NotImplementedError(
430438
"Risk-aversion CEs not found. Please run CE_calculation.ipynb for `risk_aversion`."
431439
)
432-
return self.cut(xr.open_dataset(file, engine = "zarr"))
440+
return self.cut(xr.open_dataset(file, engine="zarr"))

0 commit comments

Comments
 (0)