rex.utilities.bc_utils.QuantileDeltaMapping

class QuantileDeltaMapping(params_oh, params_mh, params_mf, dist='empirical', relative=True, sampling='linear', log_base=10, delta_denom_min=None, delta_denom_zero=None, delta_range=None)[source]

Bases: object

Class for quantile delta mapping based on the method from Cannon et al., 2015

Note that this is a utility class for implementing QDM and should not be requested directly as a method in the reV/rex bias correction table input

Cannon, A. J., Sobie, S. R. & Murdock, T. Q. Bias Correction of GCM Precipitation by Quantile Mapping: How Well Do Methods Preserve Changes in Quantiles and Extremes? Journal of Climate 28, 6938–6959 (2015).

Parameters:
  • params_oh (np.ndarray) – 2D array of observed historical distribution parameters created from a multi-year set of data where the shape is (space, N). This can be the output of a parametric distribution fit like scipy.stats.weibull_min.fit() where N is the number of parameters for that distribution, or this can define the x-values of N points from an empirical CDF that will be linearly interpolated between. If this is an empirical CDF, this must include the 0th and 100th percentile values and have even percentile spacing between values.

  • params_mh (np.ndarray) – Same requirements as params_oh. This input arg is for the modeled historical distribution.

  • params_mf (np.ndarray | None) – Same requirements as params_oh. This input arg is for the modeled future distribution. If this is None, this defaults to params_mh (no future data, just corrected to modeled historical distribution)

  • dist (str | np.ndarray) – Probability distribution name to use to model the data which determines how the param args are used. This can “empirical” or any continuous distribution name from scipy.stats. Can also be a 1D array of dist inputs if being used from reV, but they must all be the same option.

  • relative (bool | np.ndarray) – Flag to preserve relative rather than absolute changes in quantiles. relative=False (default) will multiply by the change in quantiles while relative=True will add. See Equations 4-6 from Cannon et al., 2015 for more details. Can also be a 1D array of dist inputs if being used from reV, but they must all be the same option.

  • sampling (str | np.ndarray) – If dist=”empirical”, this is an option for how the quantiles were sampled to produce the params inputs, e.g., how to sample the y-axis of the distribution (see sampling functions in rex.utilities.bc_utils). “linear” will do even spacing, “log” will concentrate samples near quantile=0, and “invlog” will concentrate samples near quantile=1. Can also be a 1D array of dist inputs if being used from reV, but they must all be the same option.

  • log_base (int | float | np.ndarray) – Log base value if sampling is “log” or “invlog”. A higher value will concentrate more samples at the extreme sides of the distribution. Can also be a 1D array of dist inputs if being used from reV, but they must all be the same option.

  • delta_denom_min (float | None) – Option to specify a minimum value for the denominator term in the calculation of a relative delta value. This prevents division by a very small number making delta blow up and resulting in very large output bias corrected values. See equation 4 of Cannon et al., 2015 for the delta term.

  • delta_denom_zero (float | None) – Option to specify a value to replace zeros in the denominator term in the calculation of a relative delta value. This prevents division by a very small number making delta blow up and resulting in very large output bias corrected values. See equation 4 of Cannon et al., 2015 for the delta term.

  • delta_range (tuple | None) – Option to set a (min, max) on the delta term in QDM. This can help prevent QDM from making non-realistic increases/decreases in otherwise physical values. See equation 4 of Cannon et al., 2015 for the delta term.

Methods

cdf(x, params, scipy_dist, sampling, log_base)

Run the CDF function e.g., convert physical variable to quantile

ppf(p, params, scipy_dist, sampling, log_base)

Run the inverse CDF function (percent point function) e.g., convert quantile to physical variable

run_qdm(arr, params_oh, params_mh, ...)

Run the actual QDM operation from args without initializing the QuantileDeltaMapping object

classmethod cdf(x, params, scipy_dist, sampling, log_base)[source]

Run the CDF function e.g., convert physical variable to quantile

classmethod ppf(p, params, scipy_dist, sampling, log_base)[source]

Run the inverse CDF function (percent point function) e.g., convert quantile to physical variable

classmethod run_qdm(arr, params_oh, params_mh, params_mf, scipy_dist, relative, sampling, log_base, delta_denom_min, delta_denom_zero, delta_range)[source]

Run the actual QDM operation from args without initializing the QuantileDeltaMapping object

Parameters:
  • arr (np.ndarray) – 2D array of values in shape (time, space)

  • params_oh (np.ndarray) – 2D array of observed historical distribution parameters created from a multi-year set of data where the shape is (space, N). This can be the output of a parametric distribution fit like scipy.stats.weibull_min.fit() where N is the number of parameters for that distribution, or this can define the x-values of N points from an empirical CDF that will be linearly interpolated between. If this is an empirical CDF, this must include the 0th and 100th percentile values and have even percentile spacing between values.

  • params_mh (np.ndarray) – Same requirements as params_oh. This input arg is for the modeled historical distribution.

  • params_mf (np.ndarray) – Same requirements as params_oh. This input arg is for the modeled future distribution.

  • scipy_dist (scipy.stats.rv_continuous | None) – Any continuous distribution class from scipy.stats or None if using an empirical distribution (taken from attribute QuantileDeltaMapping.scipy_dist)

  • relative (bool | np.ndarray) – Flag to preserve relative rather than absolute changes in quantiles. relative=False (default) will multiply by the change in quantiles while relative=True will add. See Equations 4-6 from Cannon et al., 2015 for more details. Can also be a 1D array of dist inputs if being used from reV, but they must all be the same option.

  • sampling (str | np.ndarray) – If dist=”empirical”, this is an option for how the quantiles were sampled to produce the params inputs, e.g., how to sample the y-axis of the distribution (see sampling functions in rex.utilities.bc_utils). “linear” will do even spacing, “log” will concentrate samples near quantile=0, and “invlog” will concentrate samples near quantile=1. Can also be a 1D array of dist inputs if being used from reV, but they must all be the same option.

  • log_base (int | float | np.ndarray) – Log base value if sampling is “log” or “invlog”. A higher value will concentrate more samples at the extreme sides of the distribution. Can also be a 1D array of dist inputs if being used from reV, but they must all be the same option.

  • delta_denom_min (float | None) – Option to specify a minimum value for the denominator term in the calculation of a relative delta value. This prevents division by a very small number making delta blow up and resulting in very large output bias corrected values. See equation 4 of Cannon et al., 2015 for the delta term.

  • delta_denom_zero (float | None) – Option to specify a value to replace zeros in the denominator term in the calculation of a relative delta value. This prevents division by a very small number making delta blow up and resulting in very large output bias corrected values. See equation 4 of Cannon et al., 2015 for the delta term.

  • delta_range (tuple | None) – Option to set a (min, max) on the delta term in QDM. This can help prevent QDM from making non-realistic increases/decreases in otherwise physical values. See equation 4 of Cannon et al., 2015 for the delta term.

Returns:

arr (np.ndarray) – Bias corrected copy of the input array with same shape.

__call__(arr, max_workers=1)[source]

Run the QDM function to bias correct an array

Parameters:
  • arr (np.ndarray) – 2D array of values in shape (time, space)

  • max_workers (int, None) – Number of parallel workers to use in QDM bias correction. 1 will run in serial (default), None will use all available cores.

Returns:

arr (np.ndarray) – Bias corrected copy of the input array with same shape.