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 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
37 38 39 40 41 42 43 | |
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
46 47 48 49 | |
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
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
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
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
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
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
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
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
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
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
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
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 199 200 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 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 | |
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
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
outputs_dir()
tutorials/figs, resolved from the repo root or from tutorials/ itself.
Source code in qlroms/utils/plots.py
304 305 306 307 308 | |
start_pdf(name)
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
335 336 337 338 339 340 341 342 343 344 345 346 347 | |
close_pdf()
Close the open figure PDF, if any, and say how many pages it got.
Source code in qlroms/utils/plots.py
350 351 352 353 354 355 356 357 358 359 360 361 | |
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
364 365 366 367 368 369 370 371 372 373 | |