Skip to content

Commit 3fa1380

Browse files
make binning possible for all methods
1 parent 4efbc16 commit 3fa1380

File tree

3 files changed

+60
-41
lines changed

3 files changed

+60
-41
lines changed

climada/engine/impact.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,9 @@ def local_exceedance_impact(
530530
If set to True, impact values are converted to log scale before
531531
inter- and extrapolation. Defaults to True.
532532
bin_decimals : int, optional
533-
This parameter is only used if method is set to "extrapolate". Number of decimals
534-
for the binning of the impact values, see Notes. If None,
535-
impact values are not binned. Defaults to None.
536-
533+
Number of decimals to group and bin impact values. Binning results in smoother (and
534+
coarser) interpolation and more stable extrapolation. For more details and sensible
535+
values for bin_decimals, see Notes. If None, values are not binned. Defaults to None.
537536
Returns
538537
-------
539538
gdf : gpd.GeoDataFrame
@@ -553,11 +552,15 @@ def local_exceedance_impact(
553552
554553
Notes
555554
-------
556-
If method = "extrapolate" and an integer bin_decimals is provided, impacts are binned
557-
according to their bin_decimals decimal places. This results in a smoother (and coarser)
558-
interpolation, and a more stable extrapolation. The default bin_decimals=None results in
559-
not binning the values. For more information about the binning, see
560-
climada.util.interpolation.preprocess_and_interpolate_ev().
555+
If an integer bin_decimals is given, the impact values are binned according to their
556+
bin_decimals decimals, and their corresponding frequencies are summed. This binning leads
557+
to a smoother (and coarser) interpolation, and a more stable extrapolation. For instance,
558+
if bin_decimals=1, the two values 12.01 and 11.97 with corresponding frequencies 0.1 and
559+
0.2 are combined to a value 12.0 with frequency 0.3. The default bin_decimals=None results
560+
in not binning the values.
561+
E.g., if your impact range from 1 to 100, you could use bin_decimals=1, if your
562+
impact range from 1e6 to 1e9, you could use bin_decimals=-5, if your impact
563+
range from 0.0001 to .01, you could use bin_decimals=5.
561564
"""
562565
LOGGER.info(
563566
"Computing exceedance impact map for return periods: %s", return_periods
@@ -683,9 +686,9 @@ def local_return_period(
683686
If set to True, impact values are converted to log scale before
684687
inter- and extrapolation. Defaults to True.
685688
bin_decimals : int, optional
686-
This parameter is only used if method is set to "extrapolate". Number of decimals
687-
for the binning of the impact values, see Notes. If None,
688-
impact values are not binned. Defaults to None.
689+
Number of decimals to group and bin impact values. Binning results in smoother (and
690+
coarser) interpolation and more stable extrapolation. For more details and sensible
691+
values for bin_decimals, see Notes. If None, values are not binned. Defaults to None.
689692
690693
Returns
691694
-------
@@ -706,11 +709,15 @@ def local_return_period(
706709
707710
Notes
708711
-------
709-
If method = "extrapolate" and an integer bin_decimals is provided, impacts are binned
710-
according to their bin_decimals decimal places. This results in a smoother (and coarser)
711-
interpolation, and a more stable extrapolation. The default bin_decimals=None results in
712-
not binning the values. For more information about the binning, see
713-
climada.util.interpolation.preprocess_and_interpolate_ev().
712+
If an integer bin_decimals is given, the impact values are binned according to their
713+
bin_decimals decimals, and their corresponding frequencies are summed. This binning leads
714+
to a smoother (and coarser) interpolation, and a more stable extrapolation. For instance,
715+
if bin_decimals=1, the two values 12.01 and 11.97 with corresponding frequencies 0.1 and
716+
0.2 are combined to a value 12.0 with frequency 0.3. The default bin_decimals=None results
717+
in not binning the values.
718+
E.g., if your impact range from 1 to 100, you could use bin_decimals=1, if your
719+
impact range from 1e6 to 1e9, you could use bin_decimals=-5, if your impact
720+
range from 0.0001 to .01, you could use bin_decimals=5.
714721
"""
715722

716723
LOGGER.info("Computing return period map for impacts: %s", threshold_impact)

climada/hazard/base.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,9 @@ def local_exceedance_intensity(
521521
If set to True, intensity values are converted to log scale before
522522
inter- and extrapolation. Defaults to True.
523523
bin_decimals : int, optional
524-
This parameter is only used if method is set to "extrapolate". Number of decimals
525-
for the binning of the intensity values, see Notes. If None,
526-
intensity values are not binned. Defaults to None.
524+
Number of decimals to group and bin intensity values. Binning results in smoother (and
525+
coarser) interpolation and more stable extrapolation. For more details and sensible
526+
values for bin_decimals, see Notes. If None, values are not binned. Defaults to None.
527527
528528
Returns
529529
-------
@@ -544,11 +544,15 @@ def local_exceedance_intensity(
544544
545545
Notes
546546
-------
547-
If method = "extrapolate" and an integer bin_decimals is provided, intensites are binned
548-
according to their bin_decimals decimal places. This results in a smoother (and coarser)
549-
interpolation, and a more stable extrapolation. The default bin_decimals=None results in
550-
not binning the values. For more information about the binning, see
551-
climada.util.interpolation.preprocess_and_interpolate_ev().
547+
If an integer bin_decimals is given, the intensity values are binned according to their
548+
bin_decimals decimals, and their corresponding frequencies are summed. This binning leads
549+
to a smoother (and coarser) interpolation, and a more stable extrapolation. For instance,
550+
if bin_decimals=1, the two values 12.01 and 11.97 with corresponding frequencies 0.1 and
551+
0.2 are combined to a value 12.0 with frequency 0.3. The default bin_decimals=None results
552+
in not binning the values.
553+
E.g., if your intensities range from 1 to 100, you could use bin_decimals=1, if your
554+
intensities range from 1e6 to 1e9, you could use bin_decimals=-5, if your intensities
555+
range from 0.0001 to .01, you could use bin_decimals=5.
552556
"""
553557
if not min_intensity and min_intensity != 0:
554558
min_intensity = self.intensity_thres
@@ -672,9 +676,9 @@ def local_return_period(
672676
If set to True, intensity values are converted to log scale before
673677
inter- and extrapolation. Defaults to True.
674678
bin_decimals : int, optional
675-
This parameter is only used if method is set to "extrapolate". Number of decimals
676-
for the binning of the intensity values, see Notes. If None,
677-
intensity values are not binned. Defaults to None.
679+
Number of decimals to group and bin intensity values. Binning results in smoother (and
680+
coarser) interpolation and more stable extrapolation. For more details and sensible
681+
values for bin_decimals, see Notes. If None, values are not binned. Defaults to None.
678682
679683
680684
Returns
@@ -696,11 +700,15 @@ def local_return_period(
696700
697701
Notes
698702
-------
699-
If method = "extrapolate" and an integer bin_decimals is provided, intensites are binned
700-
according to their bin_decimals decimal places. This results in a smoother (and coarser)
701-
interpolation, and a more stable extrapolation. The default bin_decimals=None results in
702-
not binning the values. For more information about the binning, see
703-
climada.util.interpolation.preprocess_and_interpolate_ev().
703+
If an integer bin_decimals is given, the intensity values are binned according to their
704+
bin_decimals decimals, and their corresponding frequencies are summed. This binning leads
705+
to a smoother (and coarser) interpolation, and a more stable extrapolation. For instance,
706+
if bin_decimals=1, the two values 12.01 and 11.97 with corresponding frequencies 0.1 and
707+
0.2 are combined to a value 12.0 with frequency 0.3. The default bin_decimals=None results
708+
in not binning the values.
709+
E.g., if your intensities range from 1 to 100, you could use bin_decimals=1, if your
710+
intensities range from 1e6 to 1e9, you could use bin_decimals=-5, if your intensities
711+
range from 0.0001 to .01, you could use bin_decimals=5.
704712
"""
705713
if not min_intensity and min_intensity != 0:
706714
min_intensity = self.intensity_thres

climada/util/interpolation.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ def preprocess_and_interpolate_ev(
7777
Has no effect if method is "interpolate". Else, provides return value and if
7878
for test x values larger than given x values, if size < 2 or if method is set
7979
to "extrapolate_constant" or "stepfunction". Defaults to np.nan.
80-
bin_decimals : int or None, optional
81-
Number of decimals to group and bin the values, see Notes. If None, values are not binned.
82-
Defaults to None.
80+
bin_decimals : int, optional
81+
Number of decimals to group and bin the values. Binning results in smoother (and coarser)
82+
interpolation and more stable extrapolation. For more details and sensible values for
83+
bin_decimals, see Notes. If None, values are not binned. Defaults to None.
8384
8485
Returns
8586
-------
@@ -94,12 +95,15 @@ def preprocess_and_interpolate_ev(
9495
9596
Notes
9697
-----
97-
Before extrapolation, if an integer bin_decimals is given, the values are binned according to
98-
their bin_decimals decimals, and their corresponding frequencies are summed. For instance, if
98+
If an integer bin_decimals is given, the values are binned according to their
99+
bin_decimals decimals, and their corresponding frequencies are summed. This binning leads to
100+
a smoother (and coarser) interpolation, and a more stable extrapolation. For instance, if
99101
bin_decimals=1, the two values 12.01 and 11.97 with corresponding frequencies 0.1 and 0.2 are
100-
combined to a value 12.0 with frequency 0.3. This binning leads to a smoother (and coarser)
101-
interpolation, and a more stable extrapolation. The default bin_decimals=None results in not
102+
combined to a value 12.0 with frequency 0.3. The default bin_decimals=None results in not
102103
binning the values.
104+
E.g., if your values range from 1 to 100, you could use bin_decimals=1, if your values range
105+
from 1e6 to 1e9, you could use bin_decimals=-5, if your values range from 0.0001 to .01, you
106+
could use bin_decimals=5.
103107
"""
104108

105109
# check that only test frequencies or only test values are given
@@ -117,7 +121,7 @@ def preprocess_and_interpolate_ev(
117121
frequency = frequency[sorted_idxs]
118122

119123
# group similar values together
120-
if method == "extrapolate" and isinstance(bin_decimals, int):
124+
if isinstance(bin_decimals, int):
121125
frequency, values = _group_frequency(frequency, values, bin_decimals)
122126

123127
# transform frequencies to cummulative frequencies

0 commit comments

Comments
 (0)