qlroms.utils.plots
Figure helpers shared by the tutorials and the scripts.
Only the pieces that were being copy-pasted between notebooks live here: the chart palette, symmetric field images, the truth/model/difference snapshot grid, the chart centroids, the partition in phase space, the coordinate and relative-error panels, chart-path statistics and the outputs directory. Everything takes plain arrays (torch tensors are converted), so nothing here knows which model family produced them.
Figures that read a qlroms.utils.diagnosis result dict stay in qlroms.utils.diagnosis_plots.
model_color(label, fallback=0)
The colour label keeps everywhere; unknown labels fall back to the chart palette.
Source code in qlroms/utils/plots.py
40 41 42 43 44 45 46 | |
chart_cmap(K)
Discrete colormap + norm for chart ids 0..K-1 (the palette cycles past 10 charts).
Source code in qlroms/utils/plots.py
49 50 51 52 | |
field_image(ax, data, shape=None, vmax=None, cmap='RdBu_r', origin='lower', ticks=False, **kw)
imshow a field (or an operator matrix) on a symmetric scale, with the ticks off.
shape reshapes a flattened snapshot, e.g. (Nx, Ny); pass None for data that is
already 2-D. vmax defaults to the largest magnitude in data, so pass the one
of the reference field to put several panels on the same scale. ticks=True keeps
the axes, for a map whose axes mean something (extent=[0, T, 0, L]).
Source code in qlroms/utils/plots.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
snapshot_grid(rows, idx, shape, dt=1.0, col_titles=None, vmax=None, suptitle=None, figsize=None)
Grid of fields: one row per (label, snapshots) pair, one column per index in idx.
All panels share the colour scale of the first row, so the difference row reads as an error and not as its own field.
Source code in qlroms/utils/plots.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
field_row(fields, shape=None, titles=None, vmax=None, frames=None, suptitle=None, origin='lower', size=(1.5, 2.2))
One row of fields (or operator matrices) on one shared colour scale, with one colour bar.
fields is a sequence, or an (n, N) array of flattened snapshots that shape reshapes;
pass shape=None and origin="upper" for matrices. vmax defaults to the largest
magnitude over the row, frames colours each panel's border (e.g. CHART_COLORS), and
size is the (width, height) of one panel in inches.
Source code in qlroms/utils/plots.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
plot_centroids(centroids, shape, title=None)
Every chart centroid (K, N) as a field on one shared scale, framed in its chart colour.
Source code in qlroms/utils/plots.py
136 137 138 139 | |
snapshot_triptych(X_true, X_model, err, shape, dt, tag='model', title=None, threshold=0.5, figsize=(6.8, 6.0))
Fields before / at / after the valid time -- the first crossing of threshold.
Rows: truth, model, difference. X_true is the truth over the same window as
X_model, and err its relative-error series (both start at the same snapshot).
Source code in qlroms/utils/plots.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
plot_coords(axes, z_true, dt, preds=None, t0=0.0, pad=0.6)
Truth vs predictions, one panel per row of z_true (r, T).
preds maps a label to the predicted coordinates, optionally with a colour and a
linestyle. The y-range is set by the truth, so a diverging run leaves the panel as
a gap instead of squashing everything else flat.
Source code in qlroms/utils/plots.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
plot_error_curves(ax, curves, dt, threshold=0.5, t0=0.0, xlabel='time [t.u.]', ylabel='relative error', lw=1.2, log=True)
Relative-error series, with the T_ph threshold drawn.
curves maps a label to the error series, optionally with a colour and a linestyle.
log=False gives a linear axis, which reads better when every model stays bounded.
Source code in qlroms/utils/plots.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
plot_evaluation(z_true, models, dt, ids_true=None, threshold=0.5, t0=0.0, title=None, n_coords=3, figsize=(11, 6), log_error=False)
Truth and every model on one figure: coordinates, relative error, active chart.
models maps a label to a dict holding any of "z" (coordinates, drawn vertically
offset), "err" (relative-error series) and "ids" (active chart id per step). Adding
a second model adds curves to the same three panels instead of a second figure: the
truth is drawn once, each model keeps its model_color in every panel and every
case, and the legend sits outside the axes.
Returns (fig, metrics). metrics[label] carries T_ph (time of the first crossing
of threshold, None if it never crosses), err_mean, err_final and chart_match
(fraction of steps in the same chart as ids_true).
Source code in qlroms/utils/plots.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 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 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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
phase_coords(Xtrain, n=3, stride=10)
Map snapshots (N, T) to their n leading global POD coordinates (n, T), as numpy.
The coordinates z = Phi^T (q - qbar) are the phase-space view of a trajectory. The
basis is the POD of every stride-th training snapshot, which resolves the leading
modes at a fraction of the cost. Truth and models projected with the same map are
directly comparable, and their curves do not jump at a chart switch.
Source code in qlroms/utils/plots.py
322 323 324 325 326 327 328 329 330 331 332 333 | |
plot_partition(ax, Z, labels, Zc, every=5, path=0)
Snapshots in phase space coloured by chart, with the chart centroids as crosses.
Z (d, T) and Zc (d, K) are the coordinates of the snapshots and of the centroids
(e.g. from phase_coords), and labels (T,) the chart of each snapshot. A 3-D axis
shows the first three coordinates and a 2-D axis the first two, on an equal aspect.
every thins the scatter, and path > 0 draws the first path steps as a line.
Source code in qlroms/utils/plots.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
chart_stats(ids, K=None)
Occupancy, segments and transition matrix P(j | i) of a chart-id path.
Returns occupancy (K,), the seg_len / seg_lab of every contiguous visit
(in steps, so multiply by dt for times), and the row-normalized T (K, K).
Source code in qlroms/utils/plots.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
outputs_dir()
tutorials/figs, resolved from the repo root or from tutorials/ itself.
Source code in qlroms/utils/plots.py
386 387 388 389 390 | |
start_pdf(name, output_dir=None)
Collect every figure of this notebook into outputs_dir()/<name>.pdf, one per page.
Call it once in the setup cell and close_pdf() in the last cell. Figures are picked up
from save_figure and from every plt.show(), so no cell has to opt in, and nothing is
written twice. Pages land as they come, so a forgotten close still leaves a valid file.
Source code in qlroms/utils/plots.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
close_pdf()
Close the open figure PDF, if any, and say how many pages it got.
Source code in qlroms/utils/plots.py
434 435 436 437 438 439 440 441 442 443 444 445 | |
save_figure(fig, name=None, dpi=150)
Add fig to the notebook's open PDF (see start_pdf) and, if name is given, to a PNG.
Source code in qlroms/utils/plots.py
448 449 450 451 452 453 454 455 456 457 | |