utils
Helpers used across the models and by downstream packages: create_dataset
(a cached, noisy long timeseries for a model class), .mat load/save,
interpolation, the Chebyshev differentiation matrix used by
Rijke, and the normalization helpers behind the
visualize_* plots.
dynamodels.utils
Shared helpers vendored from romda.utils (pure numpy/scipy, no romda dependency).
allowed_kwargs_for_func(func, kwargs)
Return the subset of kwargs that are valid parameter names of func.
Source code in dynamodels/utils.py
13 14 15 16 17 | |
normalized_time(reference_t, *times)
Rescale each array in times by reference_t and build a matching axis label.
Source code in dynamodels/utils.py
22 23 24 25 26 27 28 | |
normalized_y(reference_y, y_labels, *ys)
Divide each array in ys by reference_y (scalar or per-observable) and
annotate y_labels accordingly.
Source code in dynamodels/utils.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
normalized_alpha(alpha, alpha_keys, alpha_labels, reference_a=None)
Divide each estimated parameter in alpha by its reference_a value (default
1.0) and annotate alpha_labels accordingly.
Source code in dynamodels/utils.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
mean_vector_to_ensemble(rng, mean_vec, std, m, method='uniform', ensure_mean_at_init=False)
Perturb a mean state/parameter vector to build an initial ensemble.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rng
|
Generator
|
Random number generator used to draw the perturbations. |
required |
mean_vec
|
ndarray
|
Mean vector to perturb, shape |
required |
std
|
(float, ndarray, list or dict)
|
Uncertainty around |
required |
m
|
int
|
Ensemble size. |
required |
method
|
(uniform, normal)
|
Sampling distribution. Default |
'uniform'
|
ensure_mean_at_init
|
bool
|
If True, overwrite the first ensemble member with the unperturbed mean. Default False. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Ensemble array, shape |
Source code in dynamodels/utils.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
Cheb(Nc, lims=(0, 1), getg=False)
Compute the Chebyshev collocation derivative matrix and grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Nc
|
int
|
Number of Chebyshev intervals; the grid has |
required |
lims
|
tuple of float
|
Domain limits. If |
(0, 1)
|
getg
|
bool
|
If True, also return the grid points. Default False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
D |
ndarray
|
Chebyshev differentiation matrix, shape |
g |
(ndarray, optional)
|
Chebyshev grid points, shape |
Source code in dynamodels/utils.py
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 191 192 193 194 195 196 197 198 | |
interpolate(t_y, y, t_eval, fill_values=None)
Linearly interpolate y(t_y) (along its leading axis) at t_eval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t_y
|
array - like
|
Time points of |
required |
y
|
array - like
|
Values to interpolate, shape |
required |
t_eval
|
array - like
|
Time points at which to evaluate the interpolant. |
required |
fill_values
|
tuple of float or str
|
Value(s) used outside the range of |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Interpolated values at |
Source code in dynamodels/utils.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
load_from_mat_file(filename, squeeze_me=True)
Load a .mat file as a dict (thin wrapper around scipy.io.loadmat).
Source code in dynamodels/utils.py
234 235 236 | |
save_to_mat_file(filename, data, oned_as='column', do_compression=True)
Save data to a .mat file, creating parent directories (wraps scipy.io.savemat).
Source code in dynamodels/utils.py
239 240 241 242 | |
create_dataset(model_class, data_folder, num_lyap_times=300, noise_level=0.02, seed=0, **kwargs)
Long noisy time series of any Model, cached as a .mat file in data_folder.
Integrates a fresh model_class(**kwargs) for num_lyap_times Lyapunov times
and adds Gaussian noise of noise_level times each component's standard
deviation (seeded by seed). The full state is returned — a data-driven model
trains on all the state variables; select its inputs downstream.
The cache file is keyed by Model.filename (which encodes the non-default
parameters, fixed_params such as Lorenz96's Nx included) plus the record
length, noise level and seed.
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in dynamodels/utils.py
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 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |