sup3r.bias.bias_transforms.local_qdm_bc

local_qdm_bc(data: ndarray, lat_lon: ndarray, base_dset: str, feature_name: str, bias_fp, time_index: DatetimeIndex, lr_padded_slice=None, threshold=0.1, relative=True, no_trend=False)[source]

Bias correction using QDM

Apply QDM to correct bias on the given data. It assumes that the required statistical distributions were previously estimated and saved in bias_fp.

Assume CDF for the nearest day of year (doy) is representative.

Parameters:
  • data (np.ndarray) – Sup3r input data to be bias corrected, assumed to be 3D with shape (spatial, spatial, temporal) for a single feature.

  • lat_lon (np.ndarray) – Array of latitudes and longitudes for the domain to bias correct (n_lats, n_lons, 2)

  • base_dset – Name of feature that is used as (historical) reference. Dataset with names “base_{base_dset}_params” will be retrieved.

  • feature_name (str) – Name of feature that is being corrected. Datasets with names “bias_{feature_name}_params” and “bias_fut_{feature_name}_params” will be retrieved.

  • time_index (pd.DatetimeIndex) – DatetimeIndex object associated with the input data temporal axis (assumed 3rd axis e.g. axis=2). Note that if this method is called as part of a sup3r resolution forward pass, the time_index will be included automatically for the current chunk.

  • bias_fp (str) – Filepath to statistical distributions file from the bias calc module. Must have datasets “bias_{feature_name}_params”, “bias_fut_{feature_name}_params”, and “base_{base_dset}_params” that are the parameters to define the statistical distributions to be used to correct the given data.

  • lr_padded_slice (tuple | None) – Tuple of length four that slices (spatial_1, spatial_2, temporal, features) where each tuple entry is a slice object for that axes. Note that if this method is called as part of a sup3r forward pass, the lr_padded_slice will be included automatically in the kwargs for the active chunk. If this is None, no slicing will be done and the full bias correction source shape will be used.

  • no_trend (bool, default=False) – An option to ignore the trend component of the correction, thus resulting in an ordinary Quantile Mapping, i.e. corrects the bias by comparing the distributions of the biased dataset with a reference datasets. See params_mf of rex.utilities.bc_utils.QuantileDeltaMapping. Note that this assumes that params_mh is the data distribution representative for the target data.

Returns:

out (np.ndarray) – The input data corrected by QDM. Its shape is the same of the input (spatial, spatial, time_window, temporal). The dimension time_window aligns with the number of time windows defined in a year, while temporal aligns with the time of the data.

See also

sup3r.bias.qdm.QuantileDeltaMappingCorrection

Estimate probability distributions required by QDM method

Notes

Be careful selecting bias_fp. Usually, the input data used here would be related to the dataset used to estimate “bias_fut_{feature_name}_params”.

Keeping arguments as consistent as possible with local_linear_bc(), thus a 4D data (spatial, spatial, time_window, temporal), and lat_lon (n_lats, n_lons, [lat, lon]). But QuantileDeltaMapping(), from rex library, expects an array, (time, space), thus we need to re-organize our input to match that, and in the end bring it back to (spatial, spatial, time_window, temporal). This is still better than maintaining the same functionality consistent in two libraries.

Also, rex.utilities.bc_utils.QuantileDeltaMapping expects params to be 2D (space, N-params).

See also

rex.utilities.bc_utils.QuantileDeltaMapping

Core QDM transformation.

Examples

>>> unbiased = local_qdm_bc(biased_array, lat_lon_array, "ghi", "rsds",
...                         "./dist_params.hdf")