Skip to main content

7. Skill and outputs

Skill scores, spatial patterns, plots and printed tables

The output block of the NLSA Python toolkit: normalized RMSE and anomaly correlation skill scores and how forecasts are aligned with observations, baseline forecasts, projections of fields onto eigenfunctions (spatial modes), the plots of the example scripts, and extended EOF analysis.

Skill scores

Forecasts are scored over all the initial times of the test period, separately for each lead time q. With \(a_{n+q}\) the observed target q steps after test sample n, and \(\hat a_n(q)\) its forecast:

\[ \mathrm{NRMSE}(q) = \left[\frac{\sum_n \big(a_{n+q} - \hat a_n(q)\big)^2}{\sum_n a_{n+q}^2}\right]^{1/2}, \]

\[ \mathrm{ACC}(q) = \frac{\sum_n \delta a_n \, \delta \hat a_n}{\big[\sum_n \delta a_n^2 \, \sum_n \delta \hat a_n^2\big]^{1/2}}, \]

where \(\delta a_n = a_{n+q} - \bar a_q\) and \(\delta \hat a_n = \hat a_n(q) - \bar{\hat a}_q\) are the departures from the means over the test period. The NRMSE is normalized by the size of the observed values themselves, so for an anomaly target, a forecast of zero anomaly (the climatology) has an NRMSE of 1, and skill means an NRMSE below 1. The anomaly correlation (ACC) is the correlation between forecasts and observations; values above about 0.5 are commonly taken as useful skill.

scores = clim.compute_skill_scores(test_data_pars, test_data, preds)
scores["nrmses"], scores["accs"]      # one value per lead time 0 ... num_steps
Arguments of clim.compute_skill_scores (nlsa_models.climate)
Argument Default Description
data_pars required The DataPars of the test data; gives the alignment of forecasts and observations
test_data required The test Data (or any object with a response, such as clim.TimedResponse)
preds required Forecasts, one row per test sample and one column per lead time
what "responses" "responses" scores forecasts of the target; "covariates" scores forecasts of every predictor (iterative KAF)
dropna False Leave out initial times whose forecasts contain missing values

The observation that verifies the forecast from test sample n at lead q is the target at the last snapshot of the sample’s window plus q, that is, at index delay_embedding_end + n + q of the test record. The test data therefore need num_after ≥ num_steps.

The result is a SkillScores dictionary:

SkillScores (nlsa_models.core, defined in src/nlsa_models/core.py)
Field Type Description
nrmses array Normalized root-mean-square error at each lead time 0 … num_steps.
accs array Anomaly correlation at each lead time 0 … num_steps.

The scripts print the scores as a table, plot them (plot "skill_scores") and save them in pred_scores.h5.

Baseline forecasts

The persistence, climatology and autoregressive baselines against which the demonstration scores its forecasts are not yet in the repository. Persistence and climatology are simple to compute on the same initial times; a sketch with NumPy (not tested):

import numpy as np

i0 = test_pars.delay_embedding_end
n = test_pars.num_samples
resp = np.asarray(test.response)
truth = np.stack([resp[i0 + q : i0 + q + n] for q in range(num_steps + 1)], axis=1)

persistence = np.repeat(truth[:, :1], num_steps + 1, axis=1)   # anomaly carried forward
climatology = np.zeros_like(truth)                             # zero anomaly

def nrmse(t, p):
    return np.sqrt(((t - p) ** 2).sum(0) / (t**2).sum(0))

def acc(t, p):
    ta, pa = t - t.mean(0), p - p.mean(0)
    return (ta * pa).sum(0) / np.sqrt((ta**2).sum(0) * (pa**2).sum(0))

nrmse(truth, persistence), acc(truth, persistence), nrmse(truth, climatology)

The anomaly correlation of the climatology forecast is undefined, since the forecast does not vary.

Spatial patterns

Eigenfunctions are time series, but each has a spatial pattern: the mode obtained by projecting a gridded field onto it. With \(\psi_k\) the dual of eigenfunction k (kernel or Koopman) on the training samples, and \(F(s, t)\) the field at grid point s,

\[ \mathrm{mode}_k(s) = w \sum_{n} \psi_k(x_n)\, F(s, t_0 + n), \]

where \(t_0\) aligns the samples with the field (the centre of the first delay window in the examples) and \(w\) is a normalization (the scripts use \(w = 1/(N + 2h)\), one over num_delay_samples). The field is read like any ERA5 data specification, so it can differ from the predictors: the ENSO examples use predictors over the Niño 3.4 or Indo-Pacific region but project global SST.

ds_modes = clim.compute_eigenfunction_projections(
    pars.koopman_projection,                                   # a ProjectionPars
    koopman_eigen.dual_evecs(kernel_eigen,
                             which_kernel_eigs=pars.train.koopman.which_kernel_eigs),
    weights=1 / pars.train.data.num_delay_samples,
)
ProjectionPars (nlsa_models.climate, defined in src/nlsa_models/climate.py)
Option Type or values Default Description
data era5.DataSpecs required The gridded field to project, as an era5.DataSpecs (for example global SST).
which_pcs int or slice or Sequence[int] slice(None) Eigenfunctions to project onto: an integer (a single eigenfunction), a slice or a list of indices.
time_origin str or int 0 Index or date that aligns the eigenfunction time series with the field. The examples use the centre of the delay window, delay_embedding_center.
lead_steps int or Sequence[int] 0 Time shift, in samples, between the field and the eigenfunctions; a list gives one pattern per shift, stored along a lead dimension.

The result is an xarray data set with one variable per field variable and dimensions lead, mode and the spatial dimensions (complex for Koopman modes), saved as kernel_eigen_proj.nc or koopman_eigen_proj.nc. The plots "kernel_modes" and "koopman_modes" draw it on maps.

Plots

The plots that WHICH_PLOTS can select, the functions that draw them, and the files they are saved to (with PLOT_MODE = "save", in the folder of the step that makes them):

Plots of the ENSO example scripts
Plot name Shows Drawn by, saved as Scripts
"all" Every plot below. Both
"bandwidth_tuning" Tuning curve of the variable-bandwidth function (estimated dimension against trial bandwidth). knl.plot_kernel_tuning
bandwidth_tuning_func.png (folder of the bandwidth function)
Both
"bandwidth_func" The bandwidth function on the training and test samples. clim.plot_bandwidth_function
bandwidth_func.png
Both
"kernel_tuning" Tuning curve of the kernel bandwidth. knl.plot_kernel_tuning
bandwidth_tuning_func.png (folder of the kernel)
Both
"laplacian_spec" Laplace eigenvalues computed from the kernel eigenvalues. knl.plot_laplacian_spectrum
lapl_spec.png
Both
"kernel_eigen" Kernel eigenfunctions as time series. clim.make_kernel_evecs_plotter
kernel_eigen_<j>.png
Both
"kernel_modes" Spatial patterns (projections of a field onto kernel eigenfunctions). clim.make_2d_mode_plotter_with_leads
kernel_modes_<j>.png
Both
"generator_mat" Heat map of the generator matrix. koop.plot_operator_matrix
gen_mat.png
Koopman
"generator_spec" Koopman spectrum: eigenfrequency against Dirichlet energy. koop.plot_generator_spectrum
gen_spec.png
Koopman
"koopman_eigen" Koopman eigenfunctions in the complex plane and as time series. clim.make_koopman_evecs_plotter
koopman_eigen_<j>.png
Koopman
"koopman_modes" Spatial Koopman modes (real and imaginary parts). clim.make_2d_mode_plotter_with_leads
koopman_modes_<j>.png
Koopman
"expansion_coeffs" Heat map of the KAF expansion coefficients (lead time against eigenfunction). knl.plot_kaf_expansion_coeffs
kaf_expansion_coeffs.png
Both
"running_pred" Forecasts at a fixed lead time against the truth over the test period. clim.make_running_pred_plotter
pred_running_<q>.png
Both
"pred_timeseries" A single forecast against lead time, from one initialization. clim.make_pred_timeseries_plotter
pred_timeseries_<n>.png
Both
"skill_scores" Normalized RMSE and anomaly correlation against lead time. clim.plot_forecast_skill_scores
pred_scores.png
Both

In file names, <j> is an eigenfunction or mode number, <q> a lead time and <n> the index of an initial time in the test period, as chosen with the *_PLT switches.

Printed tables

During a run, the scripts print:

  • the JAX environment (jax_env.tabulate()) and the data settings (pars.tabulate()): numbers of samples, delays and reserved samples;
  • the bandwidth tuning results (TuneInfo.tabulate()): selected bandwidth and estimated dimension;
  • the leading kernel eigenvalues (kernel_eigen.tabulate(num_tabulate=NUM_TABULATE));
  • in the Koopman script, the Koopman eigenvalue table: growth rate, Dirichlet energy, frequency and period of each eigenfunction (see Koopman analysis);
  • the skill table: NRMSE and ACC for each lead time;
  • the time taken by each step.

For a scheduled run, redirect this output to a log file (see Running unattended on a server).

Extended EOF analysis

Extended empirical orthogonal functions (EEOFs), the principal components of delay-embedded data, are the conventional counterpart of kernel and Koopman eigenfunctions, and are used to compare the Koopman indices with standard ones. The toolkit has the building blocks, but no example script uses them yet:

EEOFPars (nlsa.eofs, defined in src/nlsa/eofs.py)
Option Type or values Default Description
num_delays int required Number of delays in the extended EOF analysis.
delay_step int 1 Step between delays, in samples.
eigensolver "svd" "svd" Solver; only "svd" is available.
num_eigs int or None None Number of EOF pairs kept.
batch_size int or None None Batch size for matrix products.

The computation is in nlsa.jax.eofs (compute_eigen, make_data_driven_eigenbasis, plot_eeof_spectrum), and clim.make_eeof_evecs_plotter plots the EEOF time series in the same way as Koopman eigenfunctions.