sup3r.bias.bias_transforms.local_presrat_bc

sup3r.bias.bias_transforms.local_presrat_bc#

local_presrat_bc(data: ndarray, lat_lon: ndarray, base_dset: str, feature_name: str, bias_fp, date_range_kwargs: dict, lr_padded_slice=None, threshold=0.1, relative=True, no_trend=False, delta_denom_min=None, delta_range=None, k_range=None, out_range=None, max_workers=1)[source]#

Bias correction using PresRat

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.

  • 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.

  • date_range_kwargs (dict) – Keyword args for pd.date_range to produce a 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 date_range_kwargs will be included automatically for the current chunk.

  • 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.

  • threshold (float) – Nearest neighbor euclidean distance threshold. If the coordinates are more than this value away from the bias correction lat/lon, an error is raised.

  • relative (bool) – Apply QDM correction as a relative factor (product), otherwise, it is applied as an offset (sum).

  • 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, without reinforcing the zero rate or applying the k-factor. 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.

  • 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. If this is not set, the zero_rate_threshold calculated as part of the presrat bias calculation will be used

  • 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.

  • k_range (tuple | None) – Option to set a (min, max) value for the k-factor multiplier

  • out_range (None | tuple) – Option to set floor/ceiling values on the output data.

  • max_workers (int | None) – Max number of workers to use for QDM process pool