kipe.plot module
Plots of the estimation history, kipe plot-estimation, and of the sensitivity
analysis, kipe plot-sensitivity (plot_sensitivity()).
The estimation history:
One subplot per parameter: the estimate after each assimilation step with its physical 1σ
range, over physical time. The outer iterations are side by side, each over its own time axis,
from the initial state to the last assimilation time, so that steps at irregular times are
where they belong. The history is read from history.csv, which the estimation writes as it
runs, so a running estimation can be plotted too. If the run’s plan is known from its
provenance (kipe.provenance), the x axis spans the whole run from the start, with all
outer iterations.
Draws with matplotlib (plot_histories()) or as text in the terminal with plotext
(render_histories()), e.g., to follow an estimation on a cluster (watch_histories()).
- exception kipe.plot.PlotError[source]
Bases:
ExceptionThe history cannot be plotted, e.g., because it does not exist (yet).
- class kipe.plot.History(names: list[str], iteration: NDArray_f64, time: NDArray_f64, parameters: NDArray_f64, lower: NDArray_f64, upper: NDArray_f64, end_time: float | None = None, iterations: int | None = None)[source]
Bases:
objectThe estimation history, as read from
history.csv.- names: list[str]
Names of the estimated parameters.
- iteration: NDArray_f64
Index of the outer iteration of each step, shape
(k,).
- time: NDArray_f64
Time of each step, shape
(k,); each outer iteration starts at the initial state’s.
- parameters: NDArray_f64
The estimate after each step, as physical values, shape
(k, p).
- lower: NDArray_f64
Lower end of the physical 1σ range, shape
(k, p).
- upper: NDArray_f64
Upper end of the physical 1σ range, shape
(k, p).
- end_time: float | None = None
The last assimilation time of each outer iteration, from the run’s plan; None if unknown.
- iterations: int | None = None
Number of outer iterations, from the run’s plan; None if unknown.
- property start_time: float
Time of the initial state, at which each outer iteration starts.
- property span: float
Time span of an outer iteration if the run’s plan is known, else reached so far.
- property iteration_count: int
Number of outer iterations if the run’s plan is known, else reached so far.
- kipe.plot.read_history(path: str | Path) History[source]
Read an estimation history from
history.csv, and the run’s plan next to it.The plan, the last assimilation time and the number of outer iterations, comes from the provenance of the run: the assimilation times in
run.yaml, the iterations instudy.yaml(the options the run started with).- Parameters:
path – path to
history.csv- Returns:
the history
- Raises:
PlotError – if the file does not exist or holds no steps yet
- kipe.plot.plot_histories(figure: Figure, histories: dict[str, History], truth: Parameters | None = None) None[source]
Plot estimation histories into a figure, one subplot per parameter.
With a single history, each subplot title shows the latest estimate and range; with a truth, also the true value.
- Parameters:
figure – the figure to draw into
histories – label -> history; all must estimate the same parameters
truth – true values, drawn as reference lines (e.g., in a twin experiment)
- Raises:
PlotError – if the histories estimate different parameters
- kipe.plot.plot_sensitivity(figure: Figure, sensitivity: Sensitivity) None[source]
Plot the result of a sensitivity analysis into a figure, in three panels.
The singular values \(s_i\) of the noise-weighted sensitivities over their index, with the condition number, and the noise floor \(s = 1\) if it is within their range: below it, a unit change of \(\theta\) along a singular vector changes the predicted data by less than the noise; the right singular vectors \(\bs{v}_i\), one row each, from the best to the worst determined combination of the parameters, each with its largest entry positive (the sign of a whole vector is arbitrary, the signs of its entries relative to each other are not); and the Cramér-Rao correlations, unless the Fisher information is singular.
The heatmaps order the parameters by identifiability: first the one that dominates \(\bs{v}_1\), then the one of the others that dominates \(\bs{v}_2\), and so on. Where each combination is mainly one parameter, the diagonal of the singular vectors is dominant, and the order is the ranking from the best to the worst determined parameter.
- Parameters:
figure – the figure to draw into
sensitivity – the result, e.g., from
kipe.sensitivity.read_sensitivity()
- kipe.plot.render_histories(histories: Mapping[str, History], truth: Parameters | None = None, height: int | None = None, color: bool = True, columns: int = 1, all_iterations: bool = False) str[source]
Render estimation histories as text for the terminal, one subplot per parameter.
Like
plot_histories(), with the 1σ range drawn as gray lines below and above the estimate. With a single history, each subplot title shows the latest estimate and range. Several histories get a legend below the plot, and a last line explains the lines: the gray 1σ range, with all iterations the green vertical lines at the starts of the outer iterations, and with a truth its reference line.By default, only the current (latest) outer iteration is drawn, which zooms in on where the estimate converges, over the time of that iteration.
- Parameters:
histories – label -> history; all must estimate the same parameters
truth – true values, drawn as reference lines (e.g., in a twin experiment)
height – number of lines, legend included; if not given, 12 per parameter; never less than that, so that the plots keep their resolution in a small terminal
color – whether to color the output with ANSI escape codes
columns – number of subplots per row; the parameters fill the grid row by row
all_iterations – whether to draw all outer iterations instead of the current one
- Returns:
the rendered plot
- Raises:
PlotError – if the histories estimate different parameters
- kipe.plot.watch_histories(paths: Mapping[str, Path], truth: Parameters | None = None, interval: float = 2.0, columns: int = 1, all_iterations: bool = False) None[source]
Redraw estimation histories in the terminal as they grow, until Ctrl+C.
Fills the terminal, but each plot keeps at least the height it has with
--terminal; waits while a history does not exist yet or holds no steps.- Parameters:
paths – label -> path to
history.csvtruth – true values, drawn as reference lines
interval – seconds between redraws
columns – number of subplots per row
all_iterations – whether to draw all outer iterations instead of the current one
- Raises:
PlotError – if the histories estimate different parameters