Classes and Functions
In past versions of the python-cmethods package (v1.x) there was a “CMethods”
class that implemented the bias correction methods. This class was removed in
version v2.0.0. Since then, the cmethods.adjust
function is used to apply
the implemented techniques except for detrended quantile mapping.
- cmethods.adjust(method: str, obs: XRData, simh: XRData, simp: XRData, **kwargs) XRData
Function to apply a bias correction technique on single and multidimensional data sets. For more information please refer to the method specific requirements and execution examples.
See https://python-cmethods.readthedocs.io/en/latest/methods.html
The time dimension of
obs
,simh
andsimp
must be namedtime
.If the sizes of time dimensions of the input data sets differ, you have to pass the hidden
input_core_dims
parameter, see https://python-cmethods.readthedocs.io/en/latest/getting_started.html#advanced-usage for more information.- Parameters:
method (str) – Technique to apply
obs (XRData) – The reference/observational data set
simh (XRData) – The modeled data of the control period
simp (XRData) – The modeled data of the period to adjust
kwargs (dict) – Any other method-specific parameter (like
n_quantiles
andkind
)
- Returns:
The bias corrected/adjusted data set
- Return type:
XRData
- distribution.detrended_quantile_mapping(simh: DataArray, simp: DataArray, n_quantiles: int, kind: str = '+', **kwargs: Any) NPData
See https://python-cmethods.readthedocs.io/en/latest/methods.html#detrended_quantile_mapping
This function can only be applied to 1-dimensional data.
Some additional methods
- utils.get_pdf(xbins: list | ndarray) ndarray
Compuites and returns the the probability density function \(P(x)\) of
x
based onxbins
.- Parameters:
x (list | np.ndarray) – The vector to get \(P(x)\) from
xbins (list | np.ndarray) – The boundaries/bins of \(P(x)\)
- Returns:
The probability densitiy function of
x
- Return type:
np.ndarray
1>>> from cmethods import CMethods as cm 2 3>>> x = [1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 10] 4>>> xbins = [0, 3, 6, 10] 5>>> print(cm.get_pdf(x=x, xbins=xbins)) 6[2, 5, 5]
- utils.get_cdf(xbins: list | ndarray) ndarray
Computes and returns returns the cumulative distribution function \(F(x)\) of
x
based onxbins
.- Parameters:
x (list | np.ndarray) – Vector to get \(F(x)\) from
xbins (list | np.ndarray) – The boundaries/bins of \(F(x)\)
- Returns:
The cumulative distribution function of
x
- Return type:
np.ndarray
1>>> from cmethods import CMethods as cm 2 3>>> x = [1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 10] 4>>> xbins = [0, 3, 6, 10] 5>>> print(cm.get_cdf(x=x, xbins=xbins)) 6[0, 2, 7, 12]
- utils.get_inverse_of_cdf(insert_cdf: list | ndarray, xbins: list | ndarray) ndarray
Returns the inverse cumulative distribution function as: \(F^{-1}_{x}\left[y\right]\) where \(x\) represents
base_cdf
andinsert_cdf
is represented by \(y\).- Parameters:
base_cdf (list | np.ndarray) – The basis
insert_cdf (list | np.ndarray) – The CDF that gets inserted
xbins (list | np.ndarray) – Probability boundaries
- Returns:
The inverse CDF
- Return type:
np.ndarray