API reference#

This page provides an auto-generated summary of mesmers’ API.

Statistical functions#

Linear regression#

LinearRegression()

Ordinary least squares Linear Regression for xr.DataArray objects.

fit(predictors, target, dim[, weights, ...])

Fit a linear model

predict(predictors[, exclude])

Predict using the linear model.

residuals(predictors, target)

Calculate the residuals of the fitted linear model

to_netcdf(filename, **kwargs)

save params to a netCDF file

from_netcdf(filename, **kwargs)

read params from a netCDF file

Auto regression#

_select_ar_order_scen_ens(*objs, dim, ...[, ic])

Select the order of an autoregressive process and potentially calculate the median over ensemble members and scenarios

_fit_auto_regression_scen_ens(*objs, dim, ...)

fit an auto regression and potentially calculate the mean over ensemble members and scenarios

select_ar_order(data, dim, maxlag[, ic])

Select the order of an autoregressive process

fit_auto_regression(data, dim, lags)

fit an auto regression

fit_auto_regression_monthly(monthly_data[, ...])

fit a cyclo-stationary auto-regressive process of lag one (AR(1)) on monthly data.

draw_auto_regression_uncorrelated(ar_params, ...)

draw time series of an auto regression process

draw_auto_regression_correlated(ar_params, ...)

draw time series of an auto regression process with spatially-correlated innovations

draw_auto_regression_monthly(ar_params, ...)

draw time series of a cyclo-stationary auto-regressive process of lag one (AR(1)) using individual parameters for each month including spatially-correlated innovations.

Harmonic Model#

predict_harmonic_model(yearly_predictor, ...)

construct a Fourier Series from yearly predictors with fitted coeffs.

fit_harmonic_model(yearly_predictor, ...[, ...])

fit harmonic model i.e. a Fourier Series to every gridcell using BIC score to select the order and least squares to fit the coefficients for each order.

Power Transformer#

lambda_function(coeffs, local_yearly_T)

Use logistic function to calculate lambda depending on the local yearly values.

get_lambdas_from_covariates(lambda_coeffs, ...)

function that relates fitted coefficients and the yearly predictor to the lambdas.

fit_yeo_johnson_transform(yearly_pred, ...)

estimate the optimal coefficients for the parameters \(\lambda\) for each gridcell, to normalize monthly residuals conditional on yearly predictor.

yeo_johnson_transform(yearly_pred, ...)

transform monthly_residuals following Yeo-Johnson transformer with parameters \(\lambda\), fit with fit_yeo_johnson_transform.

inverse_yeo_johnson_transform(yearly_pred, ...)

apply the inverse power transformation using the fitted lambdas.

Localized covariance#

adjust_covariance_ar1(covariance, ar_coefs)

adjust localized empirical covariance matrix for autoregressive process of order one

find_localized_empirical_covariance(data, ...)

determine localized empirical covariance by cross validation

find_localized_empirical_covariance_monthly(...)

determine localized empirical covariance by cross validation for each month.

Smoothing#

lowess(data, dim, *[, combine_dim, n_steps, ...])

LOWESS (Locally Weighted Scatterplot Smoothing) for xarray objects

Gaspari-Cohn correlation matrix#

gaspari_cohn_correlation_matrices(geodist, ...)

Gaspari-Cohn correlation matrices for a range of localisation radii

gaspari_cohn(r)

smooth, exponentially decaying Gaspari-Cohn correlation function

Data handling#

Grid manipulation#

wrap_to_180(obj[, lon_name])

wrap array with longitude to [-180..180)

wrap_to_360(obj[, lon_name])

wrap array with longitude to [0..360)

stack_lat_lon(data, *[, x_dim, y_dim, ...])

Stack a regular lat-lon grid to a 1D (unstructured) grid

unstack_lat_lon_and_align(data, coords_orig, *)

unstack an 1D grid to a regular lat-lon grid and align with original coords

unstack_lat_lon(data, *[, x_dim, y_dim, ...])

unstack an 1D grid to a regular lat-lon grid but do not align

align_to_coords(data, coords_orig)

align an unstacked lat-lon grid with its original coords

Masking regions#

mask_ocean_fraction(data, threshold, *[, ...])

mask out ocean using fractional overlap

mask_ocean(data, *[, x_coords, y_coords])

mask out ocean

mask_antarctica(data, *[, y_coords])

mask out ocean

mask_3D_frac_approx(regions, lon, lat, **kwargs)

3D mask of the fractional overlap of a set of regions for the given lat/ lon grid

Weighted operations: calculate global mean#

global_mean(data[, weights, x_dim, y_dim])

calculate global weighted mean

lat_weights(lat_coords)

area weights based on the cosine of the latitude

weighted_mean(data, weights[, dims])

weighted mean - convenience function which ignores data_vars missing dims

equal_scenario_weights_from_datatree(dt[, ...])

Create a DataTree isomorphic to dt, holding the weights for each scenario to weight the ensemble members of each scenario such that each scenario contributes equally to some fitting procedure.

Geospatial#

geodist_exact(lon, lat[, equal_dim_suffixes])

exact great circle distance based on WSG 84

Emulator functions#

Volcanic influence#

fit_volcanic_influence(tas_residuals, ...[, ...])

estimate volcanic influence on temperature residuals using aerosol optical depth observations as proxy

superimpose_volcanic_influence(...[, dim, ...])

superimpose volcanic influence on smooth temperature anomalies using aerosol optical depth observations as proxy