earthkit.climate.atmos.precipitation.standardized_precipitation_index

earthkit.climate.atmos.precipitation.standardized_precipitation_index(pr: xarray.DataArray | str = 'pr', ds: xarray.Dataset | Any = None, *, freq: str | None = 'MS', window: int = 1, dist: str | Any = 'gamma', method: str = 'ML', fitkwargs: dict | None = None, cal_start: str | None = None, cal_end: str | None = None, params: Any | None = None, prob_zero_interpolation: str | float = 'upper', plotting_position_zero: str | tuple[float, float] = 'ecdf', **kwargs: Any) Any

Standardized precipitation index (spi).

Precipitation over a moving window, normalized such that SPI averages to 0 for the calibration data. The window unit X is the minimal time period defined by the resampling frequency.

Units:

  • spi: dimensionless

This function wraps xclim.indicators.atmos.standardized_precipitation_index.

Parameters:
  • pr (xarray.DataArray | str) – Daily precipitation.

  • freq (str | None) – Resampling frequency. A monthly or daily frequency is expected. Option None assumes that the desired resampling has already been applied input dataset and will skip the resampling step.

  • window (int) – Averaging window length relative to the resampling frequency. For example, if freq=”MS”, i.e. a monthly resampling, the window is an integer number of months.

  • dist (str | Any) – Name of the univariate distribution, or a callable rv_continuous (see scipy.stats).

  • method (str) – Name of the fitting method, such as ML (maximum likelihood), APP (approximate). The approximate method uses a deterministic function that does not involve any optimization, which can be sensitive to noise. PWM should be used with a lmoments3 distribution.

  • fitkwargs (dict | None) – Kwargs passed to xclim.indices.stats.fit used to impose values of certains parameters (floc, fscale). If method is PWM, fitkwargs should be empty, except for floc with dist`=`gamma which is allowed.

  • cal_start (str | None) – Start date of the calibration period. A DateStr is expected, that is a str in format “YYYY-MM-DD”. Default option None means that the calibration period begins at the start of the input dataset.

  • cal_end (str | None) – End date of the calibration period. A DateStr is expected, that is a str in format “YYYY-MM-DD”. Default option None means that the calibration period finishes at the end of the input dataset.

  • params (Any | None) – Fit parameters. The params can be computed using xclim.indices.stats.standardized_index_fit_params in advance. The output can be given here as input, and it overrides other options.

  • prob_zero_interpolation (str | float) – Interpolation method used to assign a probability to zero values (only used if zero_inflated is True). When the data contain multiple zeros, the admissible plotting position interval spans from the first zero rank to the last zero rank. This parameter selects a representative probability within that interval. The default method “upper” assigns the upper bound of the zero-rank interval. The “center” method assigns the midpoint of the zero-rank interval. If a float in [0, 1] is provided, it is used as a linear interpolation factor between the lower (0) and upper (1) zero-rank plotting positions.

  • plotting_position_zero (str | tuple[float, float]) – Method used to assign a probability to a rank for the zeros (only used if zero_inflated is True). “ecdf” (default option) is the empirical cumulative distribution and divides the number or zeros by the total number of observations. “weibull” implements the unbiased version, dividing by the total number of observation plus one. A tuple consisting of two coefficients in [0,1] to relate the number of zeros and the total number of observations. “ecdf” corresponds to (0,1) and “weibull” to (0,0). See scipy.stats.mstats.plotting_positions()

  • ds (xarray.Dataset | Any) – Input dataset.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

The computed index.

Return type:

Any