Skip to content

Commit 0b1c2a4

Browse files
change extrpolation plot style and add deprecation warning
1 parent 41522a3 commit 0b1c2a4

2 files changed

Lines changed: 37 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Code freeze date: YYYY-MM-DD
2323
- Fixed asset count in impact logging message [#1195](https://github.com/CLIMADA-project/climada_python/pull/1195).
2424

2525
### Deprecated
26+
- `Impact.calc_freq_curve()` should not be given the parameter `return_per`. Use the parameter `return_periods` in `Impact.calc_freq_curve().extrapolate()` instead.
2627

2728
### Removed
2829
- `climada.util.earth_engine.py` Google Earth Engine methods did not facilitate direct use of GEE data in CLIMADA. Code was relocated to [climada-snippets](https://github.com/CLIMADA-project/climada-snippets). [#1109](https://github.com/CLIMADA-project/climada_python/pull/1109)

climada/engine/impact.py

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,12 @@ def calc_freq_curve(self, return_per=None):
786786
ifc_impact = self.at_event[sort_idxs][::-1]
787787

788788
if return_per is not None:
789+
warnings.warn(
790+
"Calculating the frequency curve on user-specified return periods is deprecated. "
791+
"Use ImpactFreqCurve.extrapolate() instead.",
792+
DeprecationWarning,
793+
stacklevel=2,
794+
)
789795
interp_imp = np.interp(return_per, ifc_return_per, ifc_impact)
790796
ifc_return_per = return_per
791797
ifc_impact = interp_imp
@@ -2457,19 +2463,38 @@ def plot_extrapolate(
24572463

24582464
impacts = self.extrapolate(return_periods, **kwargs_interp)
24592465

2460-
axis = self._plot(
2461-
return_periods,
2462-
impacts,
2463-
axis,
2464-
log_frequency,
2465-
self.frequency_unit,
2466-
self.unit,
2467-
self.label,
2468-
**kwargs,
2466+
# check frequency unit
2467+
return_period_unit = u_dt.convert_frequency_unit_to_time_unit(
2468+
self.frequency_unit
24692469
)
24702470

2471-
for rp in [min(self.return_per), max(self.return_per)]:
2472-
axis.axvline(x=1 / rp if log_frequency else rp, linestyle="--", c="gray")
2471+
if not axis:
2472+
_, axis = plt.subplots(1, 1)
2473+
axis.set_title(self.label)
2474+
axis.set_ylabel("Impact (" + self.unit + ")")
2475+
if log_frequency:
2476+
axis.set_xlabel(f"Exceedance frequency ({self.frequency_unit})")
2477+
axis.set_xscale("log")
2478+
x_vals = return_periods**-1
2479+
else:
2480+
axis.set_xlabel(f"Return period ({return_period_unit})")
2481+
x_vals = return_periods
2482+
2483+
# plot extrapolated data as dashed line
2484+
if kwargs_interp["method"] == "interpolate":
2485+
axis.plot(x_vals, impacts, linestyle="-", **kwargs)
2486+
else:
2487+
kwargs_copy = kwargs.copy()
2488+
color = kwargs_copy.pop("color", None)
2489+
min_rp = min(self.return_per)
2490+
max_rp = max(self.return_per)
2491+
mask = (return_periods >= min_rp) & (return_periods <= max_rp)
2492+
2493+
line_data = axis.plot(
2494+
x_vals[mask], impacts[mask], linestyle="-", color=color, **kwargs_copy
2495+
)[0]
2496+
color = line_data.get_color()
2497+
axis.plot(x_vals, impacts, linestyle="--", color=color, **kwargs_copy)
24732498

24742499
return axis
24752500

0 commit comments

Comments
 (0)