Skip to main content

Calculation blocks

The calculation, step by step, with every option

Overview of the seven calculation blocks of the NLSA Python toolkit, from setup and data to skill scores, with the classes that hold their options and the functions that carry them out.

An experiment runs through seven blocks. Each page below explains what its block computes, lists every option of the classes involved, with types, defaults and what they do, and names the functions that do the work. The tables of options are generated from the source code of version 0.4.

The seven calculation blocks
Block What it does Options in Result
1. Setup and run control CPU or GPU, precision, which steps to compute or read, and where results go Script switches; initialize_jax JaxEnv; folders of results
2. Data Reads ERA5 or station data; removes the climatology, smooths, standardizes Time, Climatology, era5.Domain, era5.DataSpecs, ws44.DataSpecs, Covariate, Response NPData → Data
3. Delay embedding Turns the time series into samples of 2h + 1 consecutive snapshots; reserves samples for forecasts and derivatives DataPars impl_l2
4. Kernel Measures the similarity of samples, tunes the bandwidth and computes the kernel eigenfunctions ConePars, TunePars, DmKernelPars, BsKernelPars TuneInfo, KernelEigen
5. Koopman analysis Approximates the Koopman generator in the kernel basis and computes its eigenfunctions KoopmanParsDiff, KoopmanParsTransf KoopmanEigen
6. Forecasting Kernel analog forecasts and Koopman forecasts; status of QMDA PredPars Forecasts
7. Skill and outputs Skill scores, spatial patterns, plots ProjectionPars, plot switches SkillScores, figures, files

The functions that carry out each block:

Main functions of each block
Block Main functions
1. Setup and run control clim.initialize_jax
pickleit, h5it and the other saving wrappers
2. Data clim.extract_data_arrays
3. Delay embedding clim.make_data_driven_l2_space
4. Kernel knl.tune_bandwidth
knl.make_data_driven_rbf_kernel
knl.compute_eigen
5. Koopman analysis koop.compute_generator_matrix
koop.compute_diffusion_regularized_generator_eigen
6. Forecasting clim.compute_kaf_expansion_coeffs
knl.compute_kaf_preds
koop.compute_koopman_preds
7. Skill and outputs clim.compute_skill_scores
clim.compute_eigenfunction_projections

flowchart LR
  S["1. Setup and run control"] -.-> D
  D["2. Data"] --> E["3. Delay embedding"]
  E --> K["4. Kernel"]
  K --> F["6. Forecasting"]
  K --> P["5. Koopman analysis"]
  P --> F
  F --> O["7. Skill and outputs"]
  P --> O

The order of the blocks. Block 5 is used only in Koopman experiments; block 1 controls all the others.

Training and test data

Blocks 2 and 3 run twice, once for the training period and once for the test period, with the same settings apart from the dates (and, in some experiments, the extra samples kept at the ends). The kernel and Koopman blocks use only the training data. Forecasts are then made from every sample of the test period, by evaluating the kernel eigenfunctions there with the Nyström extension, and compared with what actually happened.

In the example scripts, the settings that must agree between training and test data are written once in a dictionary, common_pars, and passed to both DataPars objects:

common_pars: CommonPars = {
    "num_half_delays": 6,
    "velocity_covariate": True,
    "velocity_fd_order": 4,
    "num_before": 0,
}
train_data_pars = DataPars(covariate=..., response=..., num_after=24, **common_pars)
test_data_pars = DataPars(covariate=..., response=..., num_after=24, **common_pars)

Where the options live

Options are spread over the parameter classes of the toolkit (in nlsa.jax.kernels, nlsa.jax.koopman, nlsa_models.climate, nlsa_models.era5, nlsa_models.ws44) and the classes defined in each example script (PredPars, TrainPars, TestPars, Pars). The All options page lists them all in one place, and Choosing hyperparameters explains how to set the ones that matter most.