Skip to content

Commit

Permalink
fixed docstrings and delete old files
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinGebhart committed Aug 23, 2024
1 parent b2c85ad commit b62af52
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 503 deletions.
31 changes: 16 additions & 15 deletions climada/engine/impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,9 @@ def local_exceedance_impact(
self,
return_periods=(25, 50, 100, 250),
method = 'interpolate',
impact_cutoff=0,
log_frequency=True,
log_impact=True,
impact_cutoff=0,
extrapolation = True
):
"""Compute local exceedance impact for given return periods. The default method
Expand All @@ -490,21 +490,22 @@ def local_exceedance_impact(
method : str
Method to interpolate to new return periods. Currently available are "interpolate" and

Check warning on line 491 in climada/engine/impact.py

View check run for this annotation

Jenkins - WCR / Pylint

trailing-whitespace

LOW: Trailing whitespace
Raw output
Used when there is whitespace between the end of a line and the newline.
"stepfunction". Defauls to "interpolate".
frequency_scale : str
If set to "log", frequency will be converted to log scale in interpolation.
Defaults to "log".
impact_scale : str
If set to "log", intensity will be converted to log scale in interpolation.
Defaults to "log".
impact_cutoff : float, None
impact_cutoff : float, optional
Minimal threshold to filter the impact. Defaults to 0.
fill_value : tuple, float, str
fill values to use when return_periods outside of seen return period range.
If set to "extrapolate", values will be extrapolated. If set to a float, value will
be used on both sides. If set to tuple, left value will be used for left side and
right value will be used for right side. If tuple and left value is "maximum",
the maximum of the cummulative frequencies will be used to compute exceedance
impacts on the left. Defaults to "extrapolate"
log_frequency : bool, optional
This parameter is only used if method is set to "interpolate". If set to True,
(cummulative) frequency values are converted to log scale before inter- and
extrapolation. Defaults to True.
log_impact : bool, optional
This parameter is only used if method is set to "interpolate". If set to True,
impact values are converted to log scale before inter- and extrapolation.
Defaults to True.
extrapolation : bool, optional
This parameter is only used if method is set to "interpolate". If set to True, local
exceedance impacts will be extrapolated. If set to False, return periods larger than
the Impact object's observed local return periods will be assigned the largest
local impact, and return periods smaller than the Impact object's observed local
return periods will be assigned 0. Defaults to True.
Returns
-------
Expand Down
72 changes: 42 additions & 30 deletions climada/hazard/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ def local_exceedance_intensity(
self,
return_periods=(25, 50, 100, 250),
method='interpolate',
intensity_cutoff=None,
log_frequeny=True,
log_intensity=True,
intensity_cutoff=None,
extrapolation=True
):
"""Compute local exceedance intensity for given return periods. The default method
Expand All @@ -469,20 +469,23 @@ def local_exceedance_intensity(
method : str
Method to interpolate to new return periods. Currently available are "interpolate" and

Check warning on line 470 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Pylint

trailing-whitespace

LOW: Trailing whitespace
Raw output
Used when there is whitespace between the end of a line and the newline.
"stepfunction". Defauls to "interpolate".
frequency_scale : str
If set to "log", frequency will be converted to log scale in interpolation. Defaults to "log".
intensity_scale : str
If set to "log", intensity will be converted to log scale in interpolation. Defaults to "log".
intensity_cutoff : float, None
Minimal threshold to filter the hazard intensity. If set to None, self.intensity_thres will be
used. Defaults to None.
fill_value : tuple, float, str
fill values to use when return_periods outside of seen return period range.
If set to "extrapolate", values will be extrapolated. If set to a float, value will
be used on both sides. If set to tuple, left value will be used for left side and
right value will be used for right side. If tuple and left value is "maximum", the maximum
of the cummulative frequencies will be used to compute exceedance intensities on the left.
Defaults to "extrapolate"
intensity_cutoff : float, optional
Minimal threshold to filter the hazard intensity. If set to None, self.intensity_thres
will be used. Defaults to None.
log_frequency : bool, optional
This parameter is only used if method is set to "interpolate". If set to True,
(cummulative) frequency values are converted to log scale before inter- and
extrapolation. Defaults to True.
log_intensity : bool, optional
This parameter is only used if method is set to "interpolate". If set to True,
intensity values are converted to log scale before inter- and extrapolation.
Defaults to True.
extrapolation : bool, optional
This parameter is only used if method is set to "interpolate". If set to True, local
exceedance intensities will be extrapolated. If set to False, return periods larger than
the Hazard object's observed local return periods will be assigned the largest
local intensity, and return periods smaller than the Impact object's observed local
return periods will be assigned 0. Defaults to True.
Returns
-------
Expand Down Expand Up @@ -567,9 +570,10 @@ def local_return_period(
self,
threshold_intensities=(10., 20.),
method='interpolate',
intensity_cutoff = None,
extrapolation=False,
log_frequency=True,
log_intensity=True,
extrapolation=False
log_intensity=True
):
"""Compute local return periods for given hazard intensities. The default method
is fitting the ordered intensitites per centroid to the corresponding cummulated
Expand All @@ -583,17 +587,23 @@ def local_return_period(
method : str
Method to interpolate to new intensity values. Currently available are "interpolate" and

Check warning on line 588 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Pylint

trailing-whitespace

LOW: Trailing whitespace
Raw output
Used when there is whitespace between the end of a line and the newline.
"stepfunction". Defauls to "interpolate".
frequency_scale : str
If set to "log", frequency will be converted to log scale in interpolation. Defaults to "log".
intensity_scale : str
If set to "log", intensity will be converted to log scale in interpolation. Defaults to "log".
fill_value : tuple, float, str
fill values to use when threshold_intensity outside of seen intensity range.
If set to "extrapolate", values will be extrapolated. If set to a float, value will
be used on both sides. If set to tuple, left value will be used for left side and
right value will be used for right side. If tuple and left value is "maximum", the maximum
of the cummulative frequencies will be used to compute return periods on the left.
Defaults to ('maximum', np.nan)
intensity_cutoff : float, optional
Minimal threshold to filter the hazard intensity. If set to None, self.intensity_thres
will be used. Defaults to None.
log_frequency : bool, optional
This parameter is only used if method is set to "interpolate". If set to True,
(cummulative) frequency values are converted to log scale before inter- and
extrapolation. Defaults to True.
log_intensity : bool, optional
This parameter is only used if method is set to "interpolate". If set to True,
intensity values are converted to log scale before inter- and extrapolation.
Defaults to True.
extrapolation : bool, optional
This parameter is only used if method is set to "interpolate". If set to True, local
return periods will be extrapolated. If set to False, threshold intensities larger than
the Hazard object's local intensities will be assigned NaN, and threshold intensities
smaller than the Hazard object's local intensities will be assigned the smallest
observed local return period. Defaults to False.
Returns
-------
Expand All @@ -607,6 +617,8 @@ def local_return_period(
column_label : function
Column-label-generating function, for reporting and plotting
"""
if not intensity_cutoff and intensity_cutoff != 0:
intensity_cutoff = self.intensity_thres
#check frequency unit
if self.frequency_unit in ['1/year', 'annual', '1/y', '1/a']:
return_period_unit = 'Years'
Expand Down Expand Up @@ -640,11 +652,11 @@ def local_return_period(
if method == 'interpolate':
return_periods[:,i] = u_interp.interpolate_ev(
threshold_intensities, intensity, frequency, logx=log_intensity,
logy=log_frequency, x_threshold=0, extrapolation=extrapolation, y_asymptotic=np.nan
logy=log_frequency, x_threshold=intensity_cutoff, extrapolation=extrapolation, y_asymptotic=np.nan

Check warning on line 655 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (118/100)
Raw output
Used when a line is longer than a given number of characters.
)
elif method == 'stepfunction':
return_periods[:,i] = u_interp.stepfunction_ev(
threshold_intensities, intensity, frequency, x_threshold=0
threshold_intensities, intensity, frequency, x_threshold=intensity_cutoff
)
else:
raise ValueError(f"Unknown method: {method}")

Check warning on line 662 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Code Coverage

Not covered lines

Lines 657-662 are not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion climada/hazard/test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def test_local_return_period(self):
# second centroid has intensities 2, 4 with cum frequencies 2, 1
# third centroid has intensities 1 with cum frequencies 1 (0 intensity is neglected)
# testing at intensities 1, 2, 3
return_stats, _, _ = haz.local_return_period(threshold_intensities, log_frequency=False, log_intensity=False)
return_stats, _, _ = haz.local_return_period(threshold_intensities, log_frequency=False, log_intensity=False, intensity_cutoff=0)
np.testing.assert_allclose(
return_stats[return_stats.columns[1:]].values,
np.array([
Expand Down
Loading

0 comments on commit b62af52

Please sign in to comment.