Computing (s2stools.compute)

Data computations.

Functions

s2stools.compute.aggregate_k(data, rule=None)

Aggregate certain k’s to a wavenumber range, corresponding to the sum.

Parameters:
  • data (xr.Dataset or xr.DataArray)

  • rule (dict) – If None, use default aggregation: 0, 1, 2, 3, 4-7, 8-20, 21-inf.

Return type:

xr.Dataset or xr.DataArray

s2stools.compute.css(forecast_anomalies, observation_anomalies, dim)

Calculate the Correlation Skill Score (CSS) between forecast anomalies and observation anomalies.

The Correlation Skill Score (CSS) is a measure of the skill of a forecast model in reproducing the patterns of variability present in the observed data. It is calculated as the correlation coefficient between forecast anomalies and observation anomalies.

Parameters:
  • forecast_anomalies (xarray.DataArray) – An xarray DataArray containing forecast anomalies.

  • observation_anomalies (xarray.DataArray) – An xarray DataArray containing observation anomalies.

  • dim (str) – The dimension along which to calculate the CSS.

Returns:

The Correlation Skill Score (CSS) between forecast anomalies and observation anomalies.

Return type:

xarray.DataArray

s2stools.compute.eddy_flux_spectral(a, b, aggregate_k=None, verify_that_sum_over_k_is_total_flux=False, return_two_profiles_along_dim=False)

Compute spectral covariance, e.g. for eddy heatflux.

Parameters:
  • a (xr.DataArray)

  • b (xr.DataArray)

  • aggregate_k (dict) – rule to combine wavenumbers, e.g., {‘4-7’: slice(4, 7). Defaults to 0, 1, 2, 3, 4-7, 8-20, 21+. If False, don’t combine.}

  • verify_that_sum_over_k_is_total_flux

  • return_two_profiles_along_dim

s2stools.compute.mode(obj, dim)

Compute mode

Parameters:
  • obj ((xr.Dataset | xr.DataArray)) – input data

  • dim (str) – dimension for computing the mode

Returns:

mode – Mode of the input dataset along dimension dim

Return type:

xr.Dataset

See also

scipy.stats.mode()

s2stools.compute.running_mean(dataarray, dim, window_sizes)

Compute running mean (= moving average) of DataArray along a dimension. Use different window sizes and stack the result along a new dimension window_size.

Parameters:
  • dataarray (xr.DataArray) – Input data.

  • dim ('str') – Dimension across which running mean is computed.

  • window_sizes (list) – List of window sizes to use. If only a single value, it probably makes sense to see xarrays xr.DataArray.running().mean() instead.

Returns:

Output data, which has new dimension window_size of length len(window_sizes).

Return type:

xr.DataArray

s2stools.compute.zonal_wavenumber_decomposition(data, k_aggregates=True)

Decompose data into zonal wavenumber components (k0=mean, k1=amplitude of lowest frequency). Applies a fft along ‘longitude’ and introduces dimension k.

Parameters:
  • data (xr.DataArray or xr.Dataset) – Data for wavenumber decomposition.

  • k_aggregates (boolean or dict) – If True, dimension k has coordinates ‘0’, ‘1’, ‘2’, ‘3’, ‘4-7’, ‘8-20’, ‘21-inf’ where k-ranges contain the sum over these wavenumbers. If False, return full wavenumber components and k will have integer values as coordinate. If dict, apply a custom k_aggregate of the form {0: ‘0’, slice(1-3): ‘1to3’, …}. Defaults to True.

Return type:

xr.DataArray or xr.Dataset

Warning

xr.DataArray not yet supported as input.