Skip to content

Commit

Permalink
Lukas review
Browse files Browse the repository at this point in the history
  • Loading branch information
Schmid Timo committed Oct 24, 2023
1 parent 95ddac9 commit fb51621
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 39 deletions.
86 changes: 51 additions & 35 deletions climada/util/calibrate/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def plot_impf_variability(
cost_func_diff: float = 0.1,
p_space_df: Optional[pd.DataFrame] = None,
plot_haz: bool = True,
**plot_kwargs
plot_impf_kws : dict = {},
plot_hist_kws : dict = {},
):

"""Plot impact function variability with parameter combinations of
Expand Down Expand Up @@ -197,40 +198,55 @@ def plot_impf_variability(
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',**plot_kwargs)

#Plot all impact functions within 'cost_func_diff' % of best estimate
for row in range(params_within_range.shape[0]):
label = f'within {int(cost_func_diff*100)} percent of best fit' if row==0 else None

sel_params = params_within_range.iloc[row,:].to_dict()
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)

# Plot hazard intensity value distributions
if plot_haz:
haz_vals = self.input.hazard.intensity[:,self.input.exposure.gdf[f"centr_{haz_type}"]]

ax2 = ax.twinx()
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')
ax2.legend(loc='lower right')

ax.set(xlabel=f"Intensity ({self.input.hazard.units})",
ylabel="Mean Damage Ratio (MDR) in %",
xlim=(min(best_impf.intensity),max(best_impf.intensity)))
ax.legend()
_,ax = plt.subplots()

Check warning on line 201 in climada/util/calibrate/base.py

View check run for this annotation

Jenkins - WCR / Pylint

invalid-name

LOW: Variable name "ax" doesn't conform to '(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$' pattern
Raw output
Used when the name doesn't match the regular expression associated to its type(constant, variable, class...).

# Plot defaults
color = plot_impf_kws.pop('color','tab:blue')
lw = plot_impf_kws.pop('lw',2)

Check warning on line 205 in climada/util/calibrate/base.py

View check run for this annotation

Jenkins - WCR / Pylint

invalid-name

LOW: Variable name "lw" doesn't conform to '(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$' pattern
Raw output
Used when the name doesn't match the regular expression associated to its type(constant, variable, class...).
zorder = plot_impf_kws.pop('zorder',3)
label = plot_impf_kws.pop('label','best fit')

#get number of impact functions and create a plot for each
n_impf = len(self.impf_set.get_func(haz_type=haz_type))
for impf_idx in range(n_impf):

#Plot best-fit impact function
best_impf = self.impf_set.get_func(haz_type=haz_type)[impf_idx]
ax.plot(best_impf.intensity,best_impf.mdd*best_impf.paa*100,
color=color,lw=lw,zorder=zorder,label=label,**plot_impf_kws)

#Plot all impact functions within 'cost_func_diff' % of best estimate
for row in range(params_within_range.shape[0]):
label_temp = f'within {int(cost_func_diff*100)} percent of best fit' if row==0 else None

Check warning on line 220 in climada/util/calibrate/base.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (104/100)
Raw output
Used when a line is longer than a given number of characters.

sel_params = params_within_range.iloc[row,:].to_dict()
temp_impf_set = self.input.impact_func_creator(**sel_params)
temp_impf = temp_impf_set.get_func(haz_type=haz_type)[impf_idx]

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

# Plot hazard intensity value distributions
if plot_haz:
haz_vals = self.input.hazard.intensity[:,self.input.exposure.gdf[f"centr_{haz_type}"]]

Check warning on line 231 in climada/util/calibrate/base.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (102/100)
Raw output
Used when a line is longer than a given number of characters.

#Plot defaults
color_hist = plot_hist_kws.pop('color','tab:orange')
alpha_hist = plot_hist_kws.pop('alpha',0.3)

ax2 = ax.twinx()
ax2.hist(haz_vals.data,bins=40,color=color_hist,
alpha=alpha_hist,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')
ax2.legend(loc='lower right')

ax.set(xlabel=f"Intensity ({self.input.hazard.units})",
ylabel="Mean Damage Ratio (MDR) in %",
xlim=(min(best_impf.intensity),max(best_impf.intensity)))
ax.legend()

return ax


Expand Down
29 changes: 25 additions & 4 deletions doc/tutorial/climada_util_calibrate.ipynb

Large diffs are not rendered by default.

0 comments on commit fb51621

Please sign in to comment.