Skip to content

Commit

Permalink
minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
Schmid Timo committed Oct 24, 2023
1 parent acef2f5 commit 95ddac9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions climada/util/calibrate/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,16 @@ def plot_impf_variability(
plot_haz: bool = True,
**plot_kwargs
):
"""Plot impact function variability with parameter combinations of almost equal
cost function values

"""Plot impact function variability with parameter combinations of
almost equal cost function values
Args:
cost_func_diff (float, optional): Max deviation from optimal cost function value
(as fraction). Defaults to 0.1 (i.e. 10%).
cost_func_diff (float, optional): Max deviation from optimal cost
function value (as fraction). Defaults to 0.1 (i.e. 10%).
p_space_df (pd.DataFrame, optional): parameter space. Defaults to None.
plot_haz (bool, optional): Whether or not to plot hazard intensity distibution.
Defaults to False.
haz_vals (np.array, optional): Hazard values at exposure points (if
pre-calculated). Defaults to None.
plot_haz (bool, optional): Whether or not to plot hazard intensity
distibution. Defaults to False.
"""

haz_type = self.input.hazard.haz_type
Expand All @@ -194,16 +193,16 @@ def plot_impf_variability(
# Retrieve parameters of impact functions with cost function values
# within 'cost_func_diff' % of the best estimate
max_cost_func_val = p_space_df['Cost Function'].min()*(1+cost_func_diff)
params_within_range = p_space_df.loc[p_space_df['Cost Function']<=max_cost_func_val,
params]
params_within_range = p_space_df.loc[p_space_df['Cost Function'] <=
max_cost_func_val,params]

# Initialize figure
fig,ax = plt.subplots()

#Plot best-fit impact function
best_impf = self.impf_set.get_func(haz_type=haz_type)[0]
ax.plot(best_impf.intensity,best_impf.mdd*best_impf.paa*100,color='tab:blue',
lw=2,zorder=3,label='best fit')
ax.plot(best_impf.intensity,best_impf.mdd*best_impf.paa*100,
color='tab:blue',lw=2,zorder=3,label='best fit',**plot_kwargs)

#Plot all impact functions within 'cost_func_diff' % of best estimate
for row in range(params_within_range.shape[0]):
Expand All @@ -213,8 +212,8 @@ def plot_impf_variability(
temp_impf_set = self.input.impact_func_creator(**sel_params)
temp_impf = temp_impf_set.get_func(haz_type=haz_type)[0]

ax.plot(temp_impf.intensity,temp_impf.mdd*temp_impf.paa*100,color='grey',
alpha=0.4,label=label)
ax.plot(temp_impf.intensity,temp_impf.mdd*temp_impf.paa*100,
color='grey',alpha=0.4,label=label)

# Plot hazard intensity value distributions
if plot_haz:
Expand All @@ -224,7 +223,8 @@ def plot_impf_variability(
ax2.hist(haz_vals.data,bins=40,color='tab:orange',
alpha=0.3,label='Hazard intensity\noccurence')
ax2.set(ylabel='Hazard intensity occurence (#Exposure points)')
ax.axvline(x=haz_vals.max(),label='Maximum hazard value',color='tab:orange')
ax.axvline(x=haz_vals.max(),label='Maximum hazard value',
color='tab:orange')
ax2.legend(loc='lower right')

ax.set(xlabel=f"Intensity ({self.input.hazard.units})",
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial/climada_util_calibrate.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 35,
"metadata": {},
"outputs": [
{
Expand All @@ -2512,7 +2512,7 @@
"<Axes: xlabel='Intensity (m/s)', ylabel='Mean Damage Ratio (MDR) in %'>"
]
},
"execution_count": 34,
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
},
Expand Down

0 comments on commit 95ddac9

Please sign in to comment.