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#
Raised when a run folder holds only the pre-refactor Cantera .save() format. |
Classes#
Post-processed simulation results: raw + derived columns, units, and descriptions. |
Functions#
|
Extract raw columns, run every post-processor, and save the merged result. |
|
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'#
- exception rizer.misc.simulation.post_process_io.LegacyResultsFormatError#
Bases:
ValueErrorRaised 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#
- 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.Iterableofstr) – 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:
dictofstrtonumpy.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:
states (
cantera.SolutionArray) – Full simulation state array, as returned by rizer.misc.simulation.simulation.run_constant_mass_nrp_simulation.case_path (
pathlib.Path) – Case folder to save into.generator (
rizer.electric_circuit.generator.PurelyResistiveBaseGeneratororNone, optional) – The run’s own generator. Given together with cable to also compute and save mid-cable V_mid/I_mid/E_mid columns (see rizer.misc.simulation.cable_transport); omit both to skip.cable (
rizer.electric_circuit.cable.IdealCableorNone, optional) – The run’s own cable. Given together with generator.
- Returns:
The saved data, in memory.
- Return type:
- 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:
- 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.