rizer.pipeline.plotting.plt_simulation#
Plotting helpers for 2T0D constant-mass NRP simulation results.
This module provides SimulationPlotter, a class wrapping the figures
produced from a post-processed SimulationData
simulation output. Per-plot configuration (axis limits, annotations) is
externalized to a YAML file consumed by SimulationPlotter._apply_axis_config
and SimulationPlotter._apply_annotations.
Classes#
Plot results of the 2T0D constant-mass NRP simulation. |
Functions#
|
Format x-ticks as ns (or µs above 1000 ns). |
Split states into per-radius segments at known radius-change times. |
|
|
Warn (and clamp) when text/annotation artists sit outside limits. |
Module Contents#
- rizer.pipeline.plotting.plt_simulation.tick_func(x: float, pos: int) str#
Format x-ticks as ns (or µs above 1000 ns).
- rizer.pipeline.plotting.plt_simulation.split_states_by_radius_changes(states: rizer.pipeline.post_process.results_io.SimulationData, radius_changes: list[tuple[float, float]]) list[rizer.pipeline.post_process.results_io.SimulationData]#
Split states into per-radius segments at known radius-change times.
Unlike detecting a change from a heuristic jump threshold on the recorded radius itself (fragile: it silently misses a real but small change, or misfires on numerical noise), this uses the exact change times from the simulation’s own input configuration – see
rizer.pipeline.run_nrp_simulation.get_radius_change_events()– so the split always matches what the simulation actually did, however large or small each radius step is, and however many of them there are.- Parameters:
states (
SimulationData) – Full simulation state array, as saved byrizer.pipeline.post_process.results_io.postprocess_and_save()and restored viarizer.pipeline.post_process.results_io.load_simulation_results().radius_changes (
listoftupleoffloat) –(time_of_change, new_radius)pairs, sorted by increasing time, as returned byrizer.pipeline.run_nrp_simulation.get_radius_change_events(). An empty list means the radius stayed constant for the whole run.
- Returns:
len(radius_changes) + 1contiguous, non-overlapping segments covering the whole of states, in order, split at the first recorded state at or after each change time.- Return type:
- rizer.pipeline.plotting.plt_simulation.validate_text_in_figure(fig: matplotlib.figure.Figure, identifier: str) None#
Warn (and clamp) when text/annotation artists sit outside limits.
Walks every axis on
figand inspects itsAnnotationand data-coordinateTextchildren. Axis labels and titles usetransAxes/transFigureand are skipped. For each artist outside the axis’s currentxlim/ylim:an
Annotation’sxy(arrow target) is reported but not moved – clamping it would silently re-anchor the arrow to a different data point;an
Annotation’sxytext(label position) is clamped just inside the limits viamatplotlib.text.Text.set_position()(Annotationinherits it, rather than overriding it);a free
Textartist’s position is clamped viamatplotlib.text.Text.set_position().
Each adjustment (or refusal) is reported via
warnings.warn()with a message that names the identifier, the axis, the artist kind, the original position, the limits, and the action taken.Shared by SimulationPlotter._finalize and rizer.spice.backend.services.results_plotting’s SVG export renderer, so both code paths warn/clamp identically.
- class rizer.pipeline.plotting.plt_simulation.SimulationPlotter(states: rizer.pipeline.post_process.results_io.SimulationData, segments: list[rizer.pipeline.post_process.results_io.SimulationData], change_times: list[float], figure_subfolder: str, annotations_yaml_path: str | pathlib.Path | None = None, experiment_ids: list[str] | None = None, run_id: str | None = None, save: bool = True, show: bool = True, validate_text_positions: bool = True)#
Plot results of the 2T0D constant-mass NRP simulation.
Each plotting method builds a figure and returns it together with its axes. Saving and displaying are controlled by the
saveandshowflags set on the instance.- Parameters:
states (
SimulationData) – Full simulation state array.segments (
listofSimulationData) – states split at each radius-change time – seesplit_states_by_radius_changes(). A single-element list means no radius change occurred.change_times (
listoffloat) – Time of each radius change, in s, in order (len(change_times) == len(segments) - 1). Empty if no radius change occurred.figure_subfolder (
str) – Sub-path underfigures/where SVGs are saved.annotations_yaml_path (
strorpathlib.PathorNone, optional) – Path to a YAML file with per-plot configuration keyed by method name. Each top-level key may contain anaxesmapping (axis name ->{xlim, ylim}) and/or anannotationslist (each entry matchingrizer.misc.plt_utils.get_annotation()parameters). If None, no auto-applied configuration is loaded. Whensaveis True, a copy of this YAML is dropped next to the figures (<figures>/<figure_subfolder>/) on the first successful save, so the saved figures and the configuration that produced them stay paired.experiment_ids (
listofstr, optional) – Experiment .npz ids (relative to data/experiments/, e.g."T326/run24/electron_density.npz") to overlay wherever a plot method supports an experiment comparison. Empty by default – no experiment .npz is baked in unless explicitly requested, unlike the overlays this class drew before per-run experiment selection existed (see _matching_experiment_data).run_id (
strorNone, optional) – This run’s opaque identifier (see rizer.spice.backend.models.results_schemas.RunInfo.id), used only by plot_electrical_signals_unified to look up its own entry in a time_offsets_ns dict keyed the same way experiment ids are. None (default) if the caller has no such identifier (e.g. a standalone archival script) – plot_electrical_signals_unified then applies no offset to this run’s own curves.save (
bool, optional) – If True, save each figure withsave_current_figure. Default True.show (
bool, optional) – If True, callplt.show()after each figure. Default True.validate_text_positions (
bool, optional) – If True, just before saving/showing each figure, walk every axis and warn (viawarnings) when aTextorAnnotationartist sits outside the axis limits. Moveable positions (text and annotationxytext) are clamped just inside the limits; annotationxyarrow targets are flagged but never moved (clamping would silently re-anchor the arrow to a different data point). Default True.
- states#
- segments#
- change_times#
- figure_subfolder#
- experiment_ids#
- run_id = None#
- save = True#
- show = True#
- validate_text_positions = True#
- times_ns#
- annotations_yaml_path#
- plot_experimental_electrical_signal() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes, matplotlib.axes.Axes]#
Plot the experimental electrical signal (voltage and current).
- plot_electric_generators_comparison() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]#
Plot the experimental signal vs the trapezoidal generator voltage.
- plot_temperatures_electric_field_zoomed() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes, matplotlib.axes.Axes]#
Plot zoomed temperatures, electric field and voltages.
- plot_generator_plasma_voltage_zoomed() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes, matplotlib.axes.Axes]#
Plot the generator voltage (zoomed) with a placeholder twin axis.
- plot_temperatures_electric_field_full() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes, matplotlib.axes.Axes]#
Plot full-time-range temperatures and plasma voltage.
- plot_voltage_current_energy_zoomed() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes, matplotlib.axes.Axes, matplotlib.axes.Axes]#
Plot zoomed plasma voltage, current and cumulated energy.
- plot_voltage_current_energy_full() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes, matplotlib.axes.Axes, matplotlib.axes.Axes]#
Plot full-range plasma voltage, current and cumulated energy.
- plot_plasma_resistance() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]#
Plot the plasma resistance versus the cable impedance.
- plot_electron_density_vs_experiment() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]#
Plot the simulated electron density against experimental data.
- plot_species_mole_fractions() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]#
Plot the species mole fractions and the residual ‘Others’ curve.
- plot_pressure() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]#
Plot the pressure versus time.
- plot_plasma_radius() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]#
Plot the simulated plasma radius against experimental diameters.
- plot_density() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]#
Plot the gas density versus time.
- plot_elastic_inelastic_power_ratio() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]#
Plot the inelastic-to-elastic power ratio with plasma-on shading.
- plot_power_repartition() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]#
Plot the power repartition curves (no save in original code).
- plot_electrical_signals_unified(*, hidden_groups: tuple[str, ...] = (), time_offsets_ns: dict[str, float] | None = None) tuple[matplotlib.figure.Figure, matplotlib.axes.Axes, matplotlib.axes.Axes, matplotlib.axes.Axes]#
Plot plasma, mid-cable, generator, and experimental electrical signals together.
Replaces plot_experimental_electrical_signal, plot_electric_generators_comparison, and plot_voltage_current_energy_full with one panel, so every electrical-signal curve overlays on the same 3 axes (voltage, current, energy) instead of being split across 3 disconnected plots.
- Parameters:
hidden_groups (
tupleofstr, optional) – Curve-group ids (see rizer.pipeline.plotting.plot_registry.PlotKind.curve_groups) to skip drawing entirely. Default: draw every available group.time_offsets_ns (
dictofstrtofloatorNone, optional) – Per-source time offset, in nanoseconds, keyed by self.run_id for this run’s own curves (plasma_*, mid_cable_*, generator_voltage) or by experiment id for experimental_*. Added to the raw nanosecond time value before any display-unit conversion. None (default) applies no offset to anything.
- Returns:
fig (
matplotlib.figure.Figure)ax_v, ax_i, ax_e (
matplotlib.axes.Axes) – Voltage [kV], current [A], and cumulated energy [mJ] axes.
- plot_collision_frequencies() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]#
Plot the electron-heavy/electron-electron/electron-ion collision frequencies.
- plot_reduced_electric_field() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]#
Plot the reduced electric field E/N, in Townsend.
- plot_electron_transport_properties() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes, matplotlib.axes.Axes, matplotlib.axes.Axes]#
Plot electron thermal conductivity, diffusion/thermal-diffusivity, and mobility.
- Returns:
fig (
matplotlib.figure.Figure)ax_kappa, ax_D, ax_mu (
matplotlib.axes.Axes) – Thermal conductivity [W/(m.K)], diffusion/thermal-diffusivity [m^2/s] (D_e and alpha_e share this axis – directly comparable, same units), and mobility [m^2/(V.s)] axes.
- plot_maxwellian_validity() tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]#
Plot the 3 Maxwellian-distribution validity ratios (Mitchner Eq VIII-3.8/3.10/3.12).
Unlike the interactive Rizer Spice view (see rizer.spice.backend.services.results_plotting.builders._build_maxwellian_validity), this static rendering does not draw the green/red joint-validity background shading – a decorative overlay with no static-export precedent in this class (e.g. plot_elastic_inelastic_power_ratio’s plasma-on/off shading has no web-view equivalent either, the same simplification in the other direction).