rizer.misc.simulation.post_process_io#

Fast binary I/O for post-processed simulation results.

postprocess_and_save extracts the raw state columns plus every rizer.misc.simulation.post_process_registry.POST_PROCESSORS output once, right after a simulation finishes, and writes them to a numpy .npz file plus a companion metadata YAML; load_simulation_results reads them back without needing Cantera or the run’s mechanism file at all.

Attributes#

Exceptions#

LegacyResultsFormatError

Raised when a run folder holds only the pre-refactor Cantera .save() format.

Classes#

SimulationData

Post-processed simulation results: raw + derived columns, units, and descriptions.

Functions#

postprocess_and_save(→ SimulationData)

Extract raw columns, run every post-processor, and save the merged result.

load_simulation_results(→ SimulationData)

Load simulation results saved by postprocess_and_save.

Module Contents#

rizer.misc.simulation.post_process_io.RESULTS_NPZ_NAME = 'simulation_results.npz'#
rizer.misc.simulation.post_process_io.RESULTS_METADATA_NAME = 'simulation_results_metadata.yaml'#
rizer.misc.simulation.post_process_io.RESULTS_CANTERA_NAME = 'simulation_results.yaml'#
rizer.misc.simulation.post_process_io.RAW_COLUMN_UNITS: dict[str, str]#
exception rizer.misc.simulation.post_process_io.LegacyResultsFormatError#

Bases: ValueError

Raised when a run folder holds only the pre-refactor Cantera .save() format.

class rizer.misc.simulation.post_process_io.SimulationData(arrays: dict[str, numpy.ndarray], units: dict[str, str], descriptions: dict[str, str], species_names: tuple[str, Ellipsis])#

Post-processed simulation results: raw + derived columns, units, and descriptions.

__getattr__ forwards to arrays, so e.g. data.T_e, data.V_p, data.radius work exactly like the corresponding attribute access on the cantera.SolutionArray this replaces. __getitem__ slices every array in arrays and returns a new SimulationData, so e.g. data[start:end] also works the same way.

Parameters:
  • arrays (dict of str to numpy.ndarray) – Every column (raw and derived), keyed by column name.

  • units (dict of str to str) – Unit for every key in arrays.

  • descriptions (dict of str to str) – Human-readable description for every key in arrays.

  • species_names (tuple of str) – Species names, in the mechanism’s own order.

arrays#
units#
descriptions#
species_names#
mole_fraction_percent(species: collections.abc.Iterable[str]) dict[str, numpy.ndarray]#

Return {species: mole_fraction_percent} for species, scaled to 0-100.

Single shared place for the “read the stored X_<species> column and scale it to a percentage for display” conversion, so every renderer (matplotlib, the Rizer Spice backend, analysis scripts) applies the same scaling instead of re-deriving it independently.

Parameters:

species (collections.abc.Iterable of str) – Species to look up (a subset of species_names, or all of them).

Returns:

{species_name: mole_fraction_percent}, in species’s order.

Return type:

dict of str to numpy.ndarray

rizer.misc.simulation.post_process_io.postprocess_and_save(states: cantera.SolutionArray, case_path: pathlib.Path, generator: rizer.electric_circuit.generator.PurelyResistiveBaseGenerator | None = None, cable: rizer.electric_circuit.cable.IdealCable | None = None) SimulationData#

Extract raw columns, run every post-processor, and save the merged result.

Writes case_path / “simulation_results.npz” (via numpy.savez) and case_path / “simulation_results_metadata.yaml” (column order, species order, and per-column unit/description).

Also writes case_path / “simulation_results.yaml” (Cantera .save()) for backwards compatibility, but load_simulation_results ignores it entirely and only reads the .npz + metadata YAML.

Parameters:
Returns:

The saved data, in memory.

Return type:

SimulationData

Raises:

ValueError – If exactly one of generator/cable is given, if a post-processor’s or the mid-cable computation’s output column collides with another column of the same name, or if any column ends up without both a unit and a description.

rizer.misc.simulation.post_process_io.load_simulation_results(case_path: pathlib.Path) SimulationData#

Load simulation results saved by postprocess_and_save.

Parameters:

case_path (pathlib.Path) – Case folder to load from.

Return type:

SimulationData

Raises:
  • LegacyResultsFormatError – If case_path has no simulation_results.npz but does have a pre-refactor simulation_results.yaml/.csv (Cantera .save() format) – the run predates this refactor and must be re-run to get a simulation_results.npz.

  • FileNotFoundError – If case_path has neither the new nor the legacy results format.