Skip to content

Commit

Permalink
Fix code style issues with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
lint-action committed Jun 19, 2024
1 parent 1a01bfa commit 615e9d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
20 changes: 13 additions & 7 deletions data/scenario_files/GCIL_plus_NW/calculate_combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@
elif crop == "Maize":
xia_naming = "corn"
print("Reading data for nuclear winter")
nw = pd.read_csv(f"data{os.sep}scenario_files{os.sep}nuclear_winter{os.sep}xia_37tg_y3_{xia_naming}.csv", index_col=0)
nw = pd.read_csv(
f"data{os.sep}scenario_files{os.sep}nuclear_winter{os.sep}xia_37tg_y3_{xia_naming}.csv",
index_col=0,
)

# Then read the data from the global catastrophic infrastructure loss scenario
if crop == "Maize":
crop_name = "Corn"
else:
crop_name = crop
print("Reading data for global catastrophic infrastructure loss")
gcil = pd.read_csv(f"data{os.sep}scenario_files{os.sep}losing_industry{os.sep}{crop_name}2mean_values.csv", index_col=0)
gcil = pd.read_csv(
f"data{os.sep}scenario_files{os.sep}losing_industry{os.sep}{crop_name}2mean_values.csv",
index_col=0,
)

# Change to fractions
nw = nw / 100 + 1
Expand All @@ -38,9 +44,7 @@
# Multiply the two dataframes together, but first make sure that the country names are unified
cc = coco.CountryConverter()
print("Converting country names for nuclear winter")
nw.index = cc.pandas_convert(
pd.Series(nw.index), to="name_short", not_found=None
)
nw.index = cc.pandas_convert(pd.Series(nw.index), to="name_short", not_found=None)
print("Converting country names for global catastrophic infrastructure loss")
gcil.index = cc.pandas_convert(
pd.Series(gcil.index), to="name_short", not_found=None
Expand All @@ -54,12 +58,14 @@
combined = combined.dropna()
nw = nw.loc[combined.index]
gcil = gcil.loc[combined.index]

combined = nw["37tg"] * gcil["mean_value"]

# Change back to percentages
combined = (combined - 1) * 100

# Save the combined data
print("Saving the combined data")
combined.to_csv(f"data{os.sep}scenario_files{os.sep}GCIL_plus_NW{os.sep}combined_{crop}.csv")
combined.to_csv(
f"data{os.sep}scenario_files{os.sep}GCIL_plus_NW{os.sep}combined_{crop}.csv"
)
24 changes: 16 additions & 8 deletions src/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,9 @@ def plot_roles(
# Check if both lists contain the same countries
assert set(countries_z) == set(countries_p)
sorted_values_z = [self.zscores[idx][country] for country in countries_p]
sorted_values_p = [self.participation[idx][country] for country in countries_p]
sorted_values_p = [
self.participation[idx][country] for country in countries_p
]
# Scatter plot
ax.scatter(
sorted_values_p,
Expand All @@ -1355,15 +1357,21 @@ def plot_roles(
try:
ax.annotate(
country,
xy=(self.participation[idx][country], self.zscores[idx][country]),
xytext=(self.participation[idx][country] + offset_x, self.zscores[idx][country] + offset_y),
xy=(
self.participation[idx][country],
self.zscores[idx][country],
),
xytext=(
self.participation[idx][country] + offset_x,
self.zscores[idx][country] + offset_y,
),
clip_on=True,
bbox={
'facecolor': 'white',
'clip_on': True,
'alpha': 0.85,
'pad': 1,
'edgecolor': 'none'
"facecolor": "white",
"clip_on": True,
"alpha": 0.85,
"pad": 1,
"edgecolor": "none",
},
fontsize=fontsize,
zorder=10,
Expand Down

0 comments on commit 615e9d4

Please sign in to comment.