API reference#

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

Top-level functions#

Statistical functions#

Linear regression#


Ordinary least squares Linear Regression for xr.DataArray objects.

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

Fit a linear model


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_xr(data, dim, maxlag[, ic])

Select the order of an autoregressive process - xarray wrapper

_fit_auto_regression_xr(data, dim, lags)

fit an auto regression - xarray wrapper

_draw_auto_regression_correlated_np(*, ...)

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

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


lowess(data, dim, *, frac[, use_coords_as_x, it])

LOWESS (Locally Weighted Scatterplot Smoothing) for xarray objects


calc_geodist_exact(lon, lat)

exact great circle distance based on WSG 84


smooth, exponentially decaying Gaspari-Cohn correlation function

Data manipulation#

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 orignal 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 orignal coords

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_mean(data, weights[, x_dim, y_dim])

Calculate the area-weighted global mean

Legacy functions#

Train mesmer#

train_gt(var, targ, esm, time, cfg[, ...])

Derive global trend (emissions + volcanoes) parameters from specified ensemble type with specified method.

train_gv(gv, targ, esm, cfg[, save_params])

Derive global variability parameters for a specified method.

train_lt(preds, targs, esm, cfg[, save_params])

Derive local trends (i.e., forced response) parameters for given ESM for given set of targets and predictors.

train_lv(preds, targs, esm, cfg[, ...])

Derive local variability (i.e., natural variabiliy) parameters.

Create emulations#

gather_gt_data(params_gt, preds_gt, cfg[, ...])

Create global trend (emissions + volcanoes) emulations for specified ensemble type and method.

create_emus_gv(params_gv, preds_gv, cfg[, ...])

Create global variablity emulations for specified method.

create_emus_lt(params_lt, preds_lt, cfg[, ...])

Create local trends (i.e., forced response) emulations for given parameter set and predictors.

create_emus_lv(params_lv, preds_lv, cfg[, ...])

Create local variablity emulations.

create_emus_g(emus_gt, emus_gv, params_gt, ...)

Merge global trend and global variability emulations of the same scenarios.

create_emus_l(emus_lt, emus_lv, params_lt, ...)

Merge local trends and local variability temperature emulations of the same scenarios and targets.

make_realisations(preds_lt, params_lt, ...)

Make climate realisations based on pre-calculated MESMER parameters

create_seed_dict(esms, scenarios[, ...])

define seeds for drawing emulations

Individual methods and utils#

Train mesmer#

train_gv_AR(params_gv, gv, max_lag, sel_crit)

Derive AR parameters of global variability under the assumption that gv does not depend on the scenario.


Derive smooth global trend of variable from single ESM ic ensemble with LOWESS smoother.

train_gt_ic_OLSVOLC(var, gt_lowess, time, cfg)

Derive global trend (emissions + volcanoes) parameters from single ESM ic ensemble by adding volcanic spikes to LOWESS trend.

train_lv_AR1_sci(params_lv, targs, y, ...)

Derive parameters for AR(1) process with spatially-correlated innovations.

train_lv_find_localized_ecov(y, wgt_scen_eq, ...)

Find suitable localization radius for empirical covariance matrix and derive localized empirical cov matrix.


derive scenario weights such that each has equal weight, i.e., 1 / number of samples (= nr_runs * nr_ts)

stack_predictors_and_targets(preds, targs)

Create single array of predictors, and single array of targets

Create emulations#

create_emus_gv_AR(params_gv, nr_emus_v, ...)

Draw global variablity emulations from an AR process.

create_emus_OLS_each_gp_sep(params_lt, ...)

Create local trends with OLS with grid-point-specific predictors

create_emus_lv_AR1_sci(emus_lv, params_lv, ...)

Create local variablity emulations with AR(1) process with spatially-correlated innovations.

create_emus_lv_OLS(params_lv, preds_lv)

Create local variablity emulations with OLS.


Load constant files#

load_phi_gc(lon, lat, ls, cfg[, L_start, ...])

Loads or creates (if not available yet) distance matrix and Gaspari-Cohn correlation matrix.

load_regs_ls_wgt_lon_lat([reg_type, lon, lat])

Load constant files.

Load output#

load_mesmer_output(name, cfg[, method_str, ...])

Load saved MESMER output (parameters or emulations).

Load observations#

load_obs(targ, prod, lon, lat, cfg[, ...])

Load observations which you previously downloaded.

load_obs_tblend(prod, lon, lat, cfg, sel_ref)

Load spatially infilled tblend observations.

load_strat_aod(time, dir_obs)

Load observed global stratospheric aerosol optical depth time series.

Save mesmer bundle#

save_mesmer_bundle(bundle_file, params_lt, ...)

Save all the information required to draw MESMER emulations to disk



Convert dictionary to array.

separate_hist_future(var_c, time_c, cfg)

Separate historical and future time periods into separate keys in dictionary.

extract_land(var[, reg_dict, wgt, ls, ...])

Extract all land grid points and area weights in regions and in land-sea mask for given threshold.

extract_time_period(data, time, start, end)

Extract selected time period.