API reference#

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

Top-level functions#

set_options(**kwargs)

Set options for mesmer in a controlled context.

get_options()

Get options for mesmer.

Statistical functions#

Linear regression#

LinearRegression()

Ordinary least squares Linear Regression for xr.DataArray objects.

from_params(params)

initialize LinearRegression class using parameters

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

Fit a linear model

predict(predictors, *[, exclude, only])

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#

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.

predict_harmonic_model(yearly_predictor, ...)

construct a Fourier Series from yearly predictors with fitted coeffs.

Power Transformer#

YeoJohnsonTransformer(name)

lambda_function(coeffs, local_yearly_T)

function defining the covariate 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(yearly_pred, monthly_residuals[, time_dim])

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

transform(yearly_pred, monthly_residuals, ...)

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

inverse_transform(yearly_pred, ...[, time_dim])

apply the inverse power transformation using the fitted lambdas.

constant_lambda_function(coeffs, local_yearly_T)

Use a constant for lambda.

logistic_lambda_function(coeffs, local_yearly_T)

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

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

Conditional distribution#

Define covariance structure of conditional distribution#

Expression(expr, expr_name[, ...])

evaluate_params(coefficients_values, ...[, ...])

Evaluates the parameters for the provided predictors and coefficients

Fit conditional distribution#

ConditionalDistribution(expression, *[, ...])

find_first_guess(predictors, target, weights)

Find a first guess for all coefficients of a conditional distribution

fit(predictors, target, weights, first_guess, *)

fit conditional distribution over all gridpoints.

compute_quality_scores(predictors, target, ...)

Compute scores for fit coefficients.

coefficients

The coefficients of this conditional distribution.

from_netcdf(filename, **kwargs)

read coefficients from a netCDF file with default solver options

to_netcdf(filename, **kwargs)

save coefficients dataset to a netCDF file

MinimizeOptions([method, tol, options])

Transform conditional distribution#

ProbabilityIntegralTransform(distrib_orig, ...)

transform(data, target_name[, preds_orig, ...])

Probability integral transform data given coefficients for the expression of a conditional distribution.

Data handling#

Example and test data#

cmip6_ng_path(*[, relative])

path of the cmip6_ng example data

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

Weighted operations: calculate global mean#

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

calculate global weighted mean

lat_weights(data[, y_dim])

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.

get_weights_density(pred_data)

generate inverse data-density weights

DataTree heplers#

pool_scen_ens(dt, *[, member_dim, time_dim, ...])

prepare data for statistical functions

broadcast_and_pool_scen_ens(predictors, target)

prepare predictors, target, and weights for statistical functions

merge(objects[, compat, join, fill_value, ...])

Merge the datasets of each node of isomorphic DataTree objects together.

collapse_datatree_into_dataset(dt, *, dim, ...)

Take a DataTree and collapse all its subtrees into a single xr.Dataset along dim.

map_over_datasets(func, *args[, kwargs])

Applies a function to every dataset in one or more DataTree objects with the same structure (ie.., that are isomorphic), returning new trees which store the results.

Geospatial#

geodist_exact(lon, lat, *[, equal_dim_suffixes])

exact great circle distance based on WSG 84

Anomalies#

calc_anomaly(dt, reference_period, *[, ...])

subtract mean over the reference period

Resampling#

upsample_yearly_data(yearly_data, monthly_time)

Upsample yearly data to monthly resolution by repeating yearly values.

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(...[, ...])

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

load_stratospheric_aerosol_optical_depth_obs(*)

load stratospheric aerosol optical depth data - a proxy for volcanic activity