Skip to content

Commit a60e877

Browse files
Extended the description of quantile mapping with text and images (#20)
1 parent 1a809d4 commit a60e877

File tree

7 files changed

+82
-23
lines changed

7 files changed

+82
-23
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
This Python module serves as a collection of different scale- and distribution-based bias correction techniques for climatic research
2222

23-
The documentation is available at: [https://python-kraken-sdk.readthedocs.io/en/stable/](https://python-kraken-sdk.readthedocs.io/en/stable/)
23+
The documentation is available at: [https://python-cmethods.readthedocs.io/en/stable/](https://python-cmethods.readthedocs.io/en/stable/)
2424

2525
> ⚠️ For the application of bias corrections on _lage data sets_ it is recomanded to use the command-line tool [BiasAdjustCXX](https://github.com/btschwertfeger/BiasAdjustCXX) since bias corrections are complex statistical transformation which are very slow in Python compared to the C++ implementation.
2626
@@ -78,6 +78,17 @@ All methods except the `adjust_3d` function requires that the input data sets on
7878
| `quantile_delta_mapping` | Quantile Delta Mapping (additive and multiplicative) |
7979
| `adjust_3d` | requires a method name and the respective parameters to adjust all time series of a 3-dimensional data set |
8080

81+
Except for the variance scaling, all methods can be applied on stochastic and non-stochastic
82+
climate variables. Variance scaling can only be applied on non-stochastic climate variables.
83+
84+
- Stochastic climate variables are those that are subject to random fluctuations
85+
and are not predictable. They have no predictable trend or pattern. Examples of
86+
stochastic climate variables include precipitation, air temperature, and humidity.
87+
88+
- Non-stochastic climate variables, on the other hand, have clear trend and pattern histories
89+
and can be readily predicted. They are often referred to as climate elements and include
90+
variables such as water temperature and air pressure.
91+
8192
---
8293

8394
<a name="installation"></a>
@@ -119,7 +130,7 @@ qdm_result = cm.adjust_3d( # 3d = 2 spatial and 1 time dimension
119130
)
120131
# to calculate the relative rather than the absolute change,
121132
# '*' can be used instead of '+' (this is prefered when adjusting
122-
# ratio based variables like precipitation)
133+
# stochastic variables like precipitation)
123134
```
124135

125136
Notes:

cmethods/__init__.py

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,16 @@ class CMethods:
6060
* Quantile Mapping :func:`cmethods.CMethods.quantile_mapping`
6161
* Quantile Delta Mapping :func:`cmethods.CMethods.quantile_delta_mapping`
6262
63-
Except for the Variance Scaling all methods can be applied on both, interval- and ratio- based
64-
variables. The Variance Scaling can only be applied on interval-based variables.
63+
Except for the Variance Scaling all methods can be applied on both, stochastic and non-stochastic
64+
variables. The Variance Scaling can only be applied on stochastic climate variables.
65+
66+
Stochastic climate variables are those that are subject to random fluctuations
67+
and are not predictable. They have no predictable trend or pattern. Examples of
68+
stochastic climate variables include precipitation, air temperature, and humidity.
69+
70+
Non-stochastic climate variables, on the other hand, have clear trend and pattern histories
71+
and can be readily predicted. They are often referred to as climate elements and include
72+
variables such as water temperature and air pressure.
6573
"""
6674

6775
SCALING_METHODS = ["linear_scaling", "variance_scaling", "delta_method"]
@@ -362,8 +370,8 @@ def linear_scaling(
362370
**kwargs,
363371
) -> np.array:
364372
r"""
365-
The Linear Scaling bias correction technique can be applied on interval- and
366-
ratio-based climate variables to minimize deviations in the mean values
373+
The Linear Scaling bias correction technique can be applied on stochastic and
374+
non-stochastic climate variables to minimize deviations in the mean values
367375
between predicted and observed time-series of past and future time periods.
368376
369377
Since the multiplicative scaling can result in very high scaling factors,
@@ -412,8 +420,8 @@ def linear_scaling(
412420
:type simp: xr.core.dataarray.DataArray
413421
:param group: The grouping defines the basis of the mean, defaults to ``time.month``
414422
:type group: Union[str, None], optional
415-
:param kind: The kind of the correction, additive for interval- and multiplicative
416-
for ratio-based variables, defaults to ``+``
423+
:param kind: The kind of the correction, additive for non-stochastic and multiplicative
424+
for stochastic climate variables, defaults to ``+``
417425
:type kind: str, optional
418426
:raises NotImplementedError: If the kind is not in (``+``, ``*``, ``add``, ``mult``)
419427
:return: The bias-corrected time series
@@ -474,7 +482,7 @@ def variance_scaling(
474482
**kwargs,
475483
) -> np.array:
476484
r"""
477-
The Variance Scaling bias correction technique can be applied on interval-based
485+
The Variance Scaling bias correction technique can be applied only on non-stochastic
478486
climate variables to minimize deviations in the mean and variance
479487
between predicted and observed time-series of past and future time periods.
480488
@@ -532,7 +540,7 @@ def variance_scaling(
532540
:type simp: xr.core.dataarray.DataArray
533541
:param group: The grouping defines the basis of the mean, defaults to ``time.month``
534542
:type group: Union[str, None], optional
535-
:param kind: The kind of the correction, additive for interval-based variables,
543+
:param kind: The kind of the correction, additive for non-stochastic climate variables
536544
no other kind is available so far, defaults to ``+``
537545
:type kind: str, optional
538546
:raises NotImplementedError: If the kind is not in (``+``, ``add``)
@@ -600,8 +608,8 @@ def delta_method(
600608
**kwargs,
601609
) -> np.array:
602610
r"""
603-
The Delta Method bias correction technique can be applied on interval- and
604-
ratio-based climate variables to minimize deviations in the mean values
611+
The Delta Method bias correction technique can be applied on stochastic and
612+
non-stochastic climate variables to minimize deviations in the mean values
605613
between predicted and observed time-series of past and future time periods.
606614
607615
Since the multiplicative scaling can result in very high scaling factors,
@@ -651,8 +659,8 @@ def delta_method(
651659
:type simp: xr.core.dataarray.DataArray
652660
:param group: The grouping defines the basis of the mean, defaults to ``time.month``
653661
:type group: Union[str, None], optional
654-
:param kind: The kind of the correction, additive for interval- and multiplicative
655-
for ratio-based variables, defaults to ``+``
662+
:param kind: The kind of the correction, additive for non-stochastic and multiplicative
663+
for stochastic climate variables, defaults to ``+``
656664
:type kind: str, optional
657665
:raises NotImplementedError: If the kind is not in (``+``, ``*``, ``add``, ``mult``)
658666
:return: The bias-corrected time series
@@ -734,14 +742,39 @@ def quantile_mapping(
734742
After the Quantile Mapping was applied, the mean is shifted back. Since it does not make sens
735743
to take the whole mean to rescale the data, the month-dependent long-term mean is used.
736744
737-
In the following the equations of Alex J. Cannon (2015) are shown (without detrending):
745+
In the following the equations of Alex J. Cannon (2015) are shown and explained (without detrending):
738746
739747
**Additive**:
740748
741749
.. math::
742750
743751
X^{*QM}_{sim,p}(i) = F^{-1}_{obs,h} \left\{F_{sim,h}\left[X_{sim,p}(i)\right]\right\}
744752
753+
754+
The additive quantile mapping procedure consists of inserting the value to be
755+
adjusted (:math:`X_{sim,p}(i)`) into the cumulative distribution function
756+
of the modeled data of the control period (:math:`F_{sim,h}`). This determines,
757+
in which quantile the value to be adjusted can be found in the modeled data of the control period
758+
The following images show this by using :math:`T` for temperatures.
759+
760+
.. figure:: ../_static/images/qm-cdf-plot-1.png
761+
:width: 600
762+
:align: center
763+
:alt: Determination of the quantile value
764+
765+
Fig 1: Inserting :math:`X_{sim,p}(i)` into :math:`F_{sim,h}` to determine the quantile value
766+
767+
This value, which of course lies between 0 and 1, is subsequently inserted
768+
into the inverse cumulative distribution function of the reference data of the control period to
769+
determine the bias-corrected value at time step :math:`i`.
770+
771+
.. figure:: ../_static/images/qm-cdf-plot-2.png
772+
:width: 600
773+
:align: center
774+
:alt: Determination of the QM bias-corrected value
775+
776+
Fig 1: Inserting the quantile value into :math:`F^{-1}_{obs,h}` to determine the bias-corrected value for time step :math:`i`
777+
745778
**Multiplicative**:
746779
747780
.. math::
@@ -759,12 +792,16 @@ def quantile_mapping(
759792
:type simp: xr.core.dataarray.DataArray
760793
:param n_quantiles: Number of quantiles to respect/use
761794
:type n_quantiles: int
762-
:param kind: The kind of the correction, additive for interval- and multiplicative
763-
for ratio-based variables, defaults to ``+``
795+
:param kind: The kind of the correction, additive for non-stochastic and multiplicative
796+
for stochastic climate variables, defaults to ``+``
764797
:type kind: str, optional
765798
:param detrended: If the extremes should be respected by applying month-dependent
766799
detrending before and after applying the Quantile Mapping
767800
:type detrended: bool, optional
801+
:param val_min: Lower boundary for interpolation (only if ``kind="*"``, default: ``0``)
802+
:type val_min: float, optional
803+
:param val_max: Upper boundary for interpolation (only if ``kind="*"``, default: ``None``)
804+
:type val_max: float, optional
768805
:raises NotImplementedError: If the kind is not in (``+``, ``*``, ``add``, ``mult``)
769806
:return: The bias-corrected time series
770807
:rtype: np.array
@@ -990,8 +1027,8 @@ def quantile_delta_mapping(
9901027
:type simp: xr.core.dataarray.DataArray
9911028
:param n_quantiles: Number of quantiles to respect/use
9921029
:type n_quantiles: int
993-
:param kind: The kind of the correction, additive for interval- and multiplicative
994-
for ratio-based variables, defaults to ``+``
1030+
:param kind: The kind of the correction, additive for non-stochastic and multiplicative
1031+
for non-stochastic climate variables, defaults to ``+``
9951032
:type kind: str, optional
9961033
:raises NotImplementedError: If the kind is not in (``+``, ``*``, ``add``, ``mult``)
9971034
:return: The bias-corrected time series
@@ -1125,7 +1162,7 @@ def get_inverse_of_cdf(
11251162
xbins: Union[list, np.array],
11261163
) -> np.array:
11271164
r"""
1128-
Returns the inverse cumulative distribution function of with the following
1165+
Returns the inverse cumulative distribution function as:
11291166
:math:`F^{-1}_{x}\left[y\right]` where :math:`x` represents ``base_cdf`` and
11301167
``insert_cdf`` is represented by :math:`y`.
11311168
@@ -1152,7 +1189,7 @@ def get_adjusted_scaling_factor(
11521189
11531190
where:
11541191
- :math:`x` is ``factor``
1155-
- :math:`y` is ``max_scaling_factor``.
1192+
- :math:`y` is ``max_scaling_factor``
11561193
11571194
:param factor: The value to check for
11581195
:type factor: Union[int, float]
File renamed without changes.
File renamed without changes.

docs/_static/images/qm-cdf-plot-1.png

89.3 KB
Loading

docs/_static/images/qm-cdf-plot-2.png

94.2 KB
Loading

docs/src/introduction.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ time periods. Data from past periods are used to adjust variables
1616
from current and future time series so that their distributional
1717
properties approximate possible actual values.
1818

19-
.. figure:: ../images/biasCdiagram.png
19+
.. figure:: ../_static/images/biasCdiagram.png
2020
:width: 600
2121
:align: center
2222
:alt: Schematic representation of a bias adjustment procedure
@@ -31,7 +31,7 @@ It is directly visible that the delta adjusted time series
3131
(:math:`T^{*DM}_{sim,p}`) are much more similar to the observed data (:math:`T_{obs,p}`)
3232
than the raw modeled data (:math:`T_{sim,p}`).
3333

34-
.. figure:: ../images/dm-doy-plot.png
34+
.. figure:: ../_static/images/dm-doy-plot.png
3535
:width: 600
3636
:align: center
3737
:alt: Temperature per day of year in modeled, observed and bias-adjusted climate data
@@ -56,6 +56,17 @@ All of these methods are intended to be applied on 1-dimensional time-series cli
5656
This module also provides the function :func:`cmethods.CMethods.adjust_3d` that enables
5757
the application of the desired bias correction method on 3-dimensinoal data sets.
5858

59+
Except for the variance scaling, all methods can be applied on stochastic and non-stochastic
60+
climate variables. Variance scaling can only be applied on non-stochastic climate variables.
61+
62+
- Stochastic climate variables are those that are subject to random fluctuations
63+
and are not predictable. They have no predictable trend or pattern. Examples of
64+
stochastic climate variables include precipitation, air temperature, and humidity.
65+
66+
- Non-stochastic climate variables, on the other hand, have clear trend and pattern histories
67+
and can be readily predicted. They are often referred to as climate elements and include
68+
variables such as water temperature and air pressure.
69+
5970
Examples can be found in the `python-cmethods`_ repository and of course
6071
within this documentation.
6172

0 commit comments

Comments
 (0)