Models¶
Summary¶
Package: dynamodels (re-exported as romda.models)
Base class for all dynamical systems. Every model stores its time history via HistoryTracker and delegates time integration to an Integrator instance.
Key attributes: psi0, dt, alpha (param dict), M (obs matrix), Nphi, Nq, Na
Key concrete methods: time_integrate(), init_ensemble(), get_observables(), get_observable_hist(), reset_model(), copy()
Subclasses must implement:
- obs_labels — property; labels for observable dimensions
- time_derivative(t, psi, **params) — static method (continuous models), or
- time_step(Nt) — discrete-map stepping (discrete models)
Model
├── Lorenz63
├── Lorenz96
├── VdP
├── Annular
├── KS
├── Rijke
├── ESN_model (+ EchoStateNetwork)
│ └── POD_ESN (+ POD)
└── LinearModel
Model API builders¶
HistoryTracker — dynamodels.history¶
Mixin class used by both Model and Bias. Provides a pre-allocated buffer that grows on demand, avoiding repeated np.concatenate calls.
| Property / Method | Description |
|---|---|
hist, hist_t |
Valid portion of the state / time buffer |
current_state, current_time |
Latest entry in the buffer |
update_history(state, t) |
Append, reset, or overwrite last states |
Integrator — dynamodels.integrator¶
Strategy pattern: Model holds one Integrator instance and calls integrator.advance(). The integrator dispatches to advance_single or advance_ensemble depending on the ensemble size.
| Class | Use case | Mechanism |
|---|---|---|
IVPIntegrator |
Continuous ODEs | scipy.integrate.solve_ivp; multiprocessing pool for ensembles |
DiscreteIntegrator |
Discrete maps (ESN, KS, linear) | Calls model.time_step(); interpolates if dt_output ≠ dt_step |
ConstantIntegrator |
Constant-bias placeholder | Returns ψ(t) = ψ(0) |
Integrator
├── IVPIntegrator
├── DiscreteIntegrator
└── ConstantIntegrator
Available Models¶
The concrete subclasses, with figures, live on their own pages:
Physical models (VdP, Lorenz63, Lorenz96, KS, Rijke, Annular)
and Data-driven models (ESN_model, POD_ESN, LinearModel).
dynamodels.model.Model(psi0, dt, integrator_class=IVPIntegrator, **kwargs)
¶
Base class for all forecast models.
A Model couples three ingredients:
- a state history (
HistoryTracker) with pre-allocated storage of shape \((N_t,\, N_\phi\,[+N_\alpha],\, m)\) — time, physical state (plus estimated parameters, onceinit_ensembleaugments them), and ensemble members; - a time-integration strategy
(
Integrator) selected at construction; - the observation operator
M, used by ensemble estimators to map the analysis-augmented state (state, estimated parameters, and observables stacked, size \(N=N_\phi+N_\alpha+N_q\)) to the observables.
Physical models implement time_derivative(t, psi, **params) (continuous) or
time_step(Nt) (discrete maps) and declare their estimable parameters in
params with bounds in alpha_lims. By convention, the leading \(N_q\)
components of the physical state are directly observable (see
get_observables).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi0
|
ndarray or list
|
Initial state, shape \((N_\phi,)\) or \((N_\phi, m)\). |
required |
dt
|
float
|
Output time step. |
required |
integrator_class
|
type[Integrator]
|
Time-integration strategy (default |
IVPIntegrator
|
**kwargs
|
Model-parameter overrides (any attribute defined by the child class). |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
params |
list of str
|
Names of the parameters that can be varied/estimated; declared by child classes. |
fixed_params |
list of str
|
Names of parameters treated as fixed and forwarded to the governing
equations through |
extra_print_params |
list of str
|
Extra attribute names appended to |
governing_eqns_params |
dict
|
Extra keyword arguments passed to |
t_transient |
float
|
Transient time discarded before the pre-allocated history / ensemble
generation starts (see |
t_CR |
float
|
Characteristic (e.g. recurrence) time used to size the "zoom" window in
the |
Nq |
int
|
Number of observable components; declared by child classes (default 1). |
alpha |
dict or None
|
Copy of |
initialized |
bool
|
Set to True once |
results_folder |
str or None
|
Optional path for saving results. |
Source code in dynamodels/model.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
state_labels
property
¶
list of str: LaTeX labels \(\phi_0, \phi_1, \dots\) for each physical
state component, used by the visualize_* helpers.
obs_labels
property
¶
list of str: LaTeX labels for the observable components.
Must be implemented by child classes; raises NotImplementedError here.
name
property
writable
¶
str: Model name used e.g. in filenames and plot titles.
Defaults to the class name if not explicitly set.
alpha_lims
property
writable
¶
dict: Mapping {param_name: (lower, upper)} of physical bounds for
each entry in params.
Lazily initialised to (None, None) (unbounded) for every parameter
the first time it is accessed.
alpha_labels
property
writable
¶
dict: Default parameter-label mapping.
Lazily initialised, the first time it is accessed, to
{name_0: '$\alpha_0$', name_1: '$\alpha_1$', ...} — one entry per
name in params (alphabetically sorted), keyed by parameter name. Assign
a custom mapping via the setter, using the same key convention.
hist
property
¶
Returns only the valid (non-empty) portion of the history buffer.
hist_t
property
¶
Returns only the valid portion of the time history.
current_state
property
¶
ndarray: Most recent state in history, shape \((N_\phi\,[+N_\alpha], m)\).
current_time
property
¶
float: Time stamp of current_state.
filename
property
writable
¶
str: Descriptive filename built from name and the parameters in
alpha0 that differ from their class defaults (falls back to
f"{name}_default" if none differ). Cached after first access; also
extended with an _ensemble_m{m} suffix by init_ensemble.
psi0
property
writable
¶
ndarray: Initial state/ensemble passed at construction, shape
\((N_\phi, m)\) (see the psi0 constructor parameter).
Re-assigning psi0 after construction is unusual and emits a
UserWarning.
alpha0
property
writable
¶
dict: Initial parameter values {name: value}, one entry per name
in params, captured at construction time and never mutated afterwards.
dt
property
writable
¶
float: Output time step, rounded to precision_t decimal places.
precision_t
property
¶
int: Number of decimal places used to round time stamps, derived
from dt (set as a side effect of the dt setter).
dt_step
property
¶
float: Time step used internally by the integrator.
Equal to dt for models whose output and integration steps coincide;
discrete models with distinct output/integration steps override this
(see DiscreteIntegrator).
Nphi
property
¶
int: Number of physical state components, len(psi0).
Na
property
¶
int: Number of parameters currently augmented into the state — the
length of est_alpha if an ensemble is configured, else 0.
N
property
¶
int: Size \(N=N_\phi+N_\alpha+N_q\) of the analysis-augmented state
vector (state, estimated parameters, and observables stacked), used
e.g. to size the observation operator M. This is not the shape of
the stored hist array, which only carries the \(N_\phi\,[+N_\alpha]\)
state/parameter rows.
m
property
¶
int: Ensemble size — the last (member) dimension of hist.
rng
property
¶
numpy.random.Generator: Random-number generator, lazily created
from seed via numpy.random.default_rng.
seed
property
writable
¶
int: Seed used to (re)create rng. Defaults to 0.
M
property
writable
¶
ndarray or callable: Linear observation operator, shape \((N_q, N)\) with \(N=N_\phi+N_\alpha+N_q\).
Used by ensemble estimators to extract the observables from the analysis-augmented state \([\phi;\alpha;y]\) (state, estimated parameters, and observables stacked), \(\mathbf{y}=\mathbf{M}\psi\). Lazily initialised to the default block matrix \([\mathbf{0}_{N_q\times(N_\phi+N_\alpha)},\ \mathbb{I}_{N_q}]\), which selects the trailing \(N_q\) rows — consistent with the observables being appended at the bottom of that augmented vector.
Ma
property
¶
ndarray: Parameter observation operator, shape \((N_\alpha, N)\).
Selects the \(N_\alpha\) estimated-parameter rows from the analysis-augmented state \([\phi;\alpha;y]\): the block matrix \([\mathbf{0}_{N_\alpha\times N_\phi},\ \mathbb{I}_{N_\alpha},\ \mathbf{0}_{N_\alpha\times N_q}]\).
ensemble_cfg
property
writable
¶
dict or False: Ensemble configuration {'est_alpha': [...], 'm': m}
set by init_ensemble, or False if no ensemble has been configured.
est_alpha
property
writable
¶
list of str: Names of the parameters currently estimated (augmented
into the state), or [] if no ensemble is configured.
update_history(psi, t=None, reset=False, modify_saved_states=False)
¶
Append (or overwrite) states in the model's history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi
|
ndarray
|
State(s) to store; reshaped to \((N_t, N_\phi\,[+N_\alpha], m)\) if given with fewer dimensions. |
required |
t
|
ndarray or float
|
Time stamp(s) matching |
None
|
reset
|
bool
|
If True, replace the entire history with |
False
|
modify_saved_states
|
bool
|
If True, overwrite the most recent |
False
|
Source code in dynamodels/model.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
define_print_params()
¶
list of str: Parameter names shown by print_parameters — params
followed by extra_print_params.
Source code in dynamodels/model.py
358 359 360 361 362 | |
t_lyap_from_table(value, table, fallback)
staticmethod
¶
Parameter-dependent Lyapunov time from a table of measured exponents.
table maps sweep-parameter values to the dominant Lyapunov exponent
\(\lambda_1\) measured there (chaotic points only). Inside the tabulated
range, returns \(1/\lambda_1\) with \(\lambda_1\) log-interpolated at
value; outside it (limit cycles, tori, untabulated configurations)
returns fallback, where a Lyapunov time is not defined.
Source code in dynamodels/model.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
set_fixed_params()
¶
Build the instance-level governing_eqns_params used by
time_derivative / time_step.
Collects the current value of every attribute named in fixed_params
and merges it into a fresh instance dict (copied from the class-level
governing_eqns_params, which is left untouched so fixed parameters
do not leak across Model subclasses). Called once during __init__.
Source code in dynamodels/model.py
491 492 493 494 495 496 497 498 499 500 501 502 503 | |
create_long_timeseries(Nt=None)
¶
Integrate the model forward and append the result to history.
Useful e.g. to run a model onto its attractor before further use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of forecast steps. Defaults to |
None
|
Source code in dynamodels/model.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
copy()
¶
Model: A deep copy of this model (copy.deepcopy).
Source code in dynamodels/model.py
549 550 551 | |
get_observables(Nt=1, **kwargs)
¶
Return the most recent observable(s) from history.
By convention, the observables are the leading Nq rows of the
physical state (see state_labels / obs_labels).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of trailing time steps to return. If 1 (default), the
leading |
1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Shape |
Source code in dynamodels/model.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | |
get_observable_hist(Nt=0, **kwargs)
¶
Alias for get_observables with a different default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of trailing time steps to return. With the default 0,
|
0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Shape |
Source code in dynamodels/model.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |
print_parameters(show_header=True, indent=0)
¶
Print the model class, its print_params values, and — if
configured — ensemble_cfg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_header
|
bool
|
If True, print a section header first. |
True
|
indent
|
int
|
Number of leading spaces for each printed line. |
0
|
Source code in dynamodels/model.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
reset_model(psi0=None, **kwargs)
¶
Re-initialise this model in place via Model.__init__.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi0
|
ndarray
|
New initial state; defaults to |
None
|
**kwargs
|
Forwarded to |
{}
|
Source code in dynamodels/model.py
672 673 674 675 676 677 678 679 680 681 682 683 684 685 | |
modify_settings(**kwargs)
¶
Hook for child classes to adjust internal configuration after
ensemble_cfg changes (called by init_ensemble). No-op by default.
Source code in dynamodels/model.py
688 689 690 691 692 | |
close()
¶
Release resources held by the integrator (e.g. multiprocessing
pools); delegates to Integrator.close.
Source code in dynamodels/model.py
695 696 697 698 699 | |
get_alpha(psi=None)
¶
Build the per-member parameter dict(s) for psi.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi
|
ndarray
|
State to read parameters from; defaults to |
None
|
Returns:
| Type | Description |
|---|---|
list of dict
|
One |
Source code in dynamodels/model.py
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
time_integrate(Nt=100, averaged=False)
¶
Forecast the model Nt steps ahead.
Delegates to the currently configured Integrator strategy
(self.integrator.advance); this is just a thin wrapper, kept
overridable in case a child Model needs special handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of forecast steps. |
100
|
averaged
|
bool
|
Only affects ensemble runs ( |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray, shape $(N_t, N_\phi\,[+N_\alpha], m)$
|
Forecasted state, excluding the current (initial) state already
present in |
t |
ndarray, shape $(N_t,)$
|
Time stamps of |
Source code in dynamodels/model.py
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 | |
init_ensemble(m, std_phi=0.001, std_alpha=0.001, est_alpha=[], distribution_phi='normal', distribution_alpha='uniform', ensure_mean_at_init=False, ensemble_psi0=None)
¶
Generate (or validate) the augmented initial ensemble.
Generates state and (optionally) parameter uncertainty, stacks them
into the augmented ensemble psi0 of shape (1, Nphi+Na, m), stores
it in the model history, and updates the model filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
int
|
Ensemble size. |
required |
std_phi
|
float
|
Fractional std for state perturbations. |
0.001
|
std_alpha
|
float or dict
|
Std (or {name: std}) for parameter perturbations. |
0.001
|
est_alpha
|
list[str]
|
Names of parameters to augment into the state. If empty, and std_alpha is a dict, all parameters in std_alpha are estimated. If empty and std_alpha is not a dict, no parameters are estimated. |
[]
|
distribution_phi
|
str
|
Sampling distribution for state ("normal" or "uniform"). |
'normal'
|
distribution_alpha
|
str
|
Sampling distribution for parameters. |
'uniform'
|
ensure_mean_at_init
|
bool
|
If True one member is forced to equal the mean. |
False
|
ensemble_psi0
|
ndarray(Nphi + Na, m) or (1, Nphi + Na, m)
|
Pre-built ensemble; bypasses generation if provided. |
None
|
Notes
Does not return a value; the generated (or validated) ensemble is
written directly to history via update_history(reset=True).
Source code in dynamodels/model.py
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 | |
visualize_history(**kwargs)
¶
Plot observable and parameter histories.
Calls visualize_state_hist, visualize_observable_hist, and
visualize_spatiotemporal_hist in turn, forwarding to each only the
keyword arguments it accepts.
Source code in dynamodels/model.py
924 925 926 927 928 929 930 931 932 933 934 935 936 | |
visualize_config()
¶
No-op hook for subclasses to plot model-specific configuration (e.g. spatial mesh, filter kernels).
Source code in dynamodels/model.py
939 940 941 942 | |
visualize_state(**kwargs)
¶
Plot ensemble state (and parameter) distributions via
plot_state_distribution.
No-op (prints a message) if no ensemble is configured
(ensemble_cfg is False).
Source code in dynamodels/model.py
946 947 948 949 950 951 952 953 954 955 956 957 | |
visualize_state_hist(psi=None, t=None, max_modes=10, t_zoom=None, reference_y=1.0, reference_t=1.0)
¶
Plot the time evolution of each physical state component.
Two panels per component: the full history, and a zoomed-in view of
the last t_zoom steps. Complex-valued states get separate real/imag
traces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi
|
ndarray
|
State history to plot; defaults to |
None
|
t
|
ndarray
|
Matching time stamps; defaults to the tail of |
None
|
max_modes
|
int
|
Maximum number of state components to plot. |
10
|
t_zoom
|
int
|
Number of trailing steps shown in the zoomed panel; defaults to
|
None
|
reference_y
|
float
|
Reference value used to normalise |
1.0
|
reference_t
|
float
|
Reference value used to normalise |
1.0
|
Source code in dynamodels/model.py
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 | |
visualize_observable_hist(y=None, t=None, t_zoom=None, reference_y=1.0, reference_t=1.0)
¶
Plot the time evolution of each observable.
Two panels per observable: the full history, and a zoomed-in view of
the last t_zoom steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
ndarray
|
Observable history to plot; defaults to |
None
|
t
|
ndarray
|
Matching time stamps; defaults to the tail of |
None
|
t_zoom
|
int
|
Number of trailing steps shown in the zoomed panel; defaults to
|
None
|
reference_y
|
float
|
Reference value |
1.0
|
reference_t
|
float
|
Reference value used to normalise |
1.0
|
Source code in dynamodels/model.py
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 | |
visualize_spatiotemporal_hist(y_hist=None, t=None, nrows=None, averaged=False, reference_y=1.0, reference_t=1.0, **kwargs)
¶
Space-time diagram of the state history: state index vs time.
Generic default plotting hist[:, :Nphi] directly — one panel per
ensemble member (up to nrows), or the ensemble mean and standard
deviation with averaged=True. Called by visualize_history. Same
signature as the physical-space overrides in KS, Rijke and
Lorenz96, which rewrite this when the raw state history is not the
physical field.
Source code in dynamodels/model.py
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 | |
dynamodels.history.HistoryTracker(initial_capacity=1000)
¶
Pre-allocated, growable storage for a state (and time) history.
Backs dynamodels.model.Model and bias estimators in downstream packages:
states are written into two pre-allocated arrays, _hist (shape
(capacity, N, m)) and _hist_t (shape (capacity,)), so that
appending new states (the common case, one per forecast step) does not
reallocate on every call. current_ti tracks the index of the next empty
slot; hist / hist_t expose only the [:current_ti] valid prefix.
When the buffer fills up, _increase_hist_size grows it in bulk.
Initialise an empty tracker (the storage arrays themselves are
allocated lazily, by the first update_history(..., reset=True)
call).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_capacity
|
int
|
Initial capacity of the history arrays. |
1000
|
Source code in dynamodels/history.py
61 62 63 64 65 66 67 68 69 70 71 72 73 | |
hist
property
¶
ndarray: The valid (non-empty) portion of the state buffer,
_hist[:current_ti], shape (current_ti, N, m).
hist_t
property
¶
ndarray: The valid portion of the time buffer,
_hist_t[:current_ti], shape (current_ti,).
capacity
property
¶
int: Total number of pre-allocated slots, _hist_t.shape[0]
(>= current_ti).
current_state
property
¶
ndarray: Most recent state, hist[current_ti - 1].
current_time
property
¶
float: Time stamp of current_state.
current_ti = 0
instance-attribute
property
writable
¶
int: Index of the next empty slot in the buffer (i.e. the number of valid entries currently stored).
update_history(state, t, reset=False, modify_saved_states=False)
¶
Write state into the history buffer.
Three mutually exclusive modes, selected by reset /
modify_saved_states:
reset=True: replace the entire buffer withstate(via_reset_history), re-allocating storage sized tomax(state.shape[0], initial_capacity).modify_saved_states=True: overwrite the most recentstate.shape[0]already-stored entries in place (via_reset_last_states), without advancingcurrent_ti.- otherwise (default): append
stateas new entries starting atcurrent_ti, growing the buffer first (via_increase_hist_size) if it would not fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ndarray
|
State(s) to write. In append mode (the default) must have shape
|
required |
t
|
ndarray or None
|
Time stamp(s) matching |
required |
reset
|
bool
|
If True, replace the entire history (see above). |
False
|
modify_saved_states
|
bool
|
If True, overwrite recent entries in place instead of appending
(see above); ignored if |
False
|
Source code in dynamodels/history.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
dynamodels.integrator.Integrator(model_instance)
¶
Abstract base class for the time-integration strategies.
Defines the interface for advancing the model state; child classes implement
advance_single and advance_ensemble. Three strategies are provided:
IVPIntegrator— continuous, variable-step integration with SciPy'ssolve_ivpof \(\dot{\boldsymbol{\psi}} = f(t, \boldsymbol{\psi}, \boldsymbol{\alpha})\); the model must definetime_derivative.DiscreteIntegrator— fixed, discrete-step maps \(\boldsymbol{\psi}_{t+\Delta t} = F(\boldsymbol{\psi}_t, \boldsymbol{\alpha})\) (e.g., ETDRK4, ESN); the model must definetime_step.ConstantIntegrator— holds the state constant, \(\boldsymbol{\psi}(t) = \boldsymbol{\psi}(0)\).
Initialize the integrator with a model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_instance
|
object
|
The (not necessarily |
required |
Source code in dynamodels/integrator.py
49 50 51 52 53 54 55 56 57 58 59 60 61 | |
is_ensemble
property
¶
bool: True if model.current_state carries more than one member
(its last axis has size \(>1\)), i.e. advance should dispatch to
advance_ensemble rather than advance_single.
close()
¶
Close resources held by the integrator (e.g., multiprocessing pools).
Source code in dynamodels/integrator.py
75 76 77 | |
advance(averaged=False, **kwargs)
¶
Common entry point for all integrators; dispatches to
advance_single or advance_ensemble based on is_ensemble.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
averaged
|
bool
|
Forwarded to |
False
|
**kwargs
|
Forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray
|
Forecasted state, excluding the initial condition. |
t |
ndarray
|
Corresponding time stamps. |
Source code in dynamodels/integrator.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
advance_single(**kwargs)
¶
Advance a single (non-ensemble) member. Must be implemented by child classes.
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray
|
Forecasted state, excluding the initial condition. |
t |
ndarray
|
Corresponding time stamps. |
Source code in dynamodels/integrator.py
105 106 107 108 109 110 111 112 113 114 115 116 | |
advance_ensemble(Nt=100, averaged=False, alpha=None)
¶
Advance every ensemble member. Must be implemented by child classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of forecast steps. |
100
|
averaged
|
bool
|
Strategy-dependent flag controlling whether members are propagated individually or only the ensemble mean is integrated. |
False
|
alpha
|
dict
|
Parameter values forwarded to the governing equations. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray
|
Forecasted ensemble state, excluding the initial condition. |
t |
ndarray
|
Corresponding time stamps. |
Source code in dynamodels/integrator.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
dynamodels.integrator.IVPIntegrator(model_instance, method='RK45')
¶
Bases: Integrator
Integrator using SciPy's solve_ivp for continuous, variable-step
integration of \(\dot{\psi}=f(t,\psi,\alpha)\).
The model must define time_derivative(t, psi, **params). A single
member is solved directly with ivp_forecast_helper; an ensemble is
either solved member-by-member in parallel (a multiprocessing pool sized
to model.m, created lazily) or, if averaged=True, solved once for
the ensemble mean with each member's deviation from the mean left
unchanged (see advance_ensemble).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_instance
|
object
|
See |
required |
method
|
str
|
Integration method forwarded to |
'RK45'
|
Source code in dynamodels/integrator.py
305 306 307 | |
close()
¶
Terminate and join the multiprocessing pool, if one was created.
Source code in dynamodels/integrator.py
323 324 325 326 327 328 | |
advance_single(Nt=100, averaged=False, alpha=None)
¶
Solve the IVP for the single (non-ensemble) member.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of forecast steps. |
100
|
averaged
|
bool
|
Accepted for interface compatibility with |
False
|
alpha
|
dict
|
Accepted for interface compatibility but not used: the governing
equations are called with |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray, shape ``(Nt, N, 1)``
|
Forecasted state, excluding the initial condition. |
t |
ndarray, shape ``(Nt,)``
|
Time stamps spaced by |
Source code in dynamodels/integrator.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
advance_ensemble(Nt=100, averaged=False, alpha=None)
¶
Solve the IVP for every ensemble member.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of forecast steps. |
100
|
averaged
|
bool
|
If False (default), each member is solved independently and in
parallel (via a multiprocessing pool), each with its own
parameters from |
False
|
alpha
|
dict
|
Accepted for interface compatibility but not used: parameters are
always taken from |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray, shape ``(Nt, N, m)``
|
Forecasted ensemble state, excluding the initial condition. |
t |
ndarray, shape ``(Nt,)``
|
Time stamps spaced by |
Source code in dynamodels/integrator.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
dynamodels.integrator.DiscreteIntegrator(model_instance)
¶
Bases: Integrator
Integrator for models advanced by a fixed, discrete map or scheme
(single member), \(\psi_{t+\mathrm{d}t}=F(\psi_t,\alpha)\) (e.g. ETDRK4 in
KS, or an ESN).
The model must define time_step(Nt), stepping at its own internal
time step dt_step (dt_integrator); if this differs from the model's
output step dt (dt_output), the integrator's output is linearly
interpolated back onto the requested output times.
Attributes:
| Name | Type | Description |
|---|---|---|
dt_output |
float
|
Output time step, |
dt_integrator |
float
|
Time step used internally by |
relation_integrator_output |
float
|
|
See Integrator.__init__; also derives dt_output,
dt_integrator, and relation_integrator_output from the model.
Source code in dynamodels/integrator.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
advance_single(Nt=100, **kwargs)
¶
Advance the model via model.time_step, resampled onto the
requested output times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of output forecast steps (at spacing |
100
|
**kwargs
|
Accepted for interface compatibility with |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray, shape ``(Nt, N, m)``
|
Forecasted state at the output times, excluding the initial
condition. Taken directly from |
t |
ndarray, shape ``(Nt,)``
|
Output time stamps, spaced by |
Source code in dynamodels/integrator.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
advance_ensemble(Nt=100, averaged=False, alpha=None)
¶
Identical to advance_single; averaged and alpha are
forwarded but unused (the discrete map is applied uniformly to
however many members model.time_step handles internally).
Source code in dynamodels/integrator.py
274 275 276 277 278 279 | |
dynamodels.integrator.ConstantIntegrator(model_instance)
¶
Bases: Integrator
Integrator that holds the state constant over time, \(\psi(t)=\psi(0)\).
Useful for testing or as a placeholder while other model components (e.g. a bias model) are advanced.
See Integrator.__init__.
Source code in dynamodels/integrator.py
150 151 152 | |
advance_single(Nt=100, **kwargs)
¶
Repeat model.current_state at every output time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nt
|
int
|
Number of forecast steps. |
100
|
**kwargs
|
Accepted for interface compatibility with |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
psi |
ndarray, shape ``(Nt, N, m)``
|
|
t |
ndarray, shape ``(Nt,)``
|
Time stamps spaced by |
Source code in dynamodels/integrator.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
advance_ensemble(Nt=100, averaged=False, alpha=None)
¶
Identical to advance_single (the state is constant regardless of
ensemble size); averaged and alpha are forwarded but unused.
Source code in dynamodels/integrator.py
182 183 184 185 186 | |