Result File Reader

The instru.instru_file_reader module allows reading data from simulation result files.

This module is not required by the simulator but supports using simulation results in post-processing. The SimResultFile is a low-level representation of a simulation result file, allowing direct access to datasets without having to know the internal file format. It also provides a view of the simulation data as a StreamBundle, allowing chunked processing of saved simulation results. Besides chunked processing, it also allows reading all data into memory at once, collected in a SimResultsNumpyCore or SimResultsNumpyFull instance.

For reading back instrument result files, one should normally use the function lisainstrument.instru.sim_result_file since it additionally supports loading file formats created by previous versions.

class lisainstrument.instru.instru_file_reader.SimResultFile(path: Path | str)[source]

Represents a simulation result file in HDF5 format.

There are low-level methods for direct reading of datasets identified either by name and MOSA or SC index, or by a DatasetIdentifier. For use cases where the results fit into memory, there are methods to create a SimResultsNumpyCore or SimResultsNumpyFull instance with the data and metadata.

For use cases dealing with large data sets, there is a method representing the datasets as streams in a StreamBundle for use with chunked processing. For all those methods, it is possible to restrict the data to a given time interval.

as_stream_bundle(datasets: set[tuple[str, ...]] | None = None, ranges: dict[tuple[str, ...], tuple[int, int]] | None = None) StreamBundle[source]

Represent datasets in the file as StreamBundle

Parameters:
  • datasets – Set of quantities to include

  • ranges – Dictionary with optional entris restricting dataset index range

Returns:

StreamBundle with specified datasets as outputs.

classmethod check_file_version(path: str | Path) tuple[bool, Version][source]

Test if file version is compatible with file reader class

Parameters:

path – Path of file to check

Returns:

Whether file can be read and the file format version

dataset_identifier_set() set[tuple[str, ...]][source]

Set of all available dataset identifiers

property description: str | None

Description text

dt_by_dataset_id(dsid: tuple[str, ...]) float[source]

Get sample period for given dataset

dt_by_idxspace(isp: IdxSpace) float[source]

Get sample period for given index space

static format_specifier() SpecifierSet[source]

Version specifier set compatible with file reader

property format_version: Version

Version number of the file format

idxspace_by_dataset_id(dsid: tuple[str, ...]) IdxSpace[source]

Get index space for dataset

property is_extended: bool

Whether file contains extended set of quantities

property metadata: SimMetaData

Simulation metadata

range_by_dataset_id(dsid: tuple[str, ...]) tuple[int, int][source]

Get range for given dataset

range_by_idxspace(isp: IdxSpace) tuple[int, int][source]

Get range for given index space

read_by_datset_id(dsid: tuple[str, ...], istart: int | None = None, istop: int | None = None) ndarray[source]

Read data identified by a DatasetIdentifier

Optionally, one can restrict the index range. This refers to the logical index range given returned range_by_dataset_id(), not necessarily starting at zero. The returned data will contain indices istart <= i < istop

Parameters:
  • dsidDatasetIdentifier specifying dataset

  • istart – Optionally, exclude lower indices

  • istop – Optionally, first index to exclude

Returns:

1D numpy array with data

read_by_name_and_mosa(name: str, mosa: MosaID | str, istart: int | None = None, istop: int | None = None) ndarray[source]

Like read_by_datset_id but dataset is specified by name and MosaID

Parameters:
  • name – Dataset name

  • mosa – Read dataset for MOSA specified by MosaID or MOSA name

  • istart – Optionally, exclude lower indices

  • istop – Optionally, first index to exclude

Returns:

1D numpy array with data

read_by_name_and_sat(name: str, sc: SatID | str, istart: int | None = None, istop: int | None = None) ndarray[source]

Like read_by_datset_id but dataset is specified by name and SatID

Parameters:
  • name – Dataset name

  • sc – Read dataset for spacecraft specified by SatID or spacecraft name

  • istart – Optionally, exclude lower indices

  • istop – Optionally, first index to exclude

Returns:

1D numpy array with data

read_core(t_min: float | None = None, t_max: float | None = None) SimResultsNumpyCore[source]

Same as read_full but restricted to basic set of quantities

Parameters:
  • t_min – Optionally, only read samples at later times

  • t_max – Optionally, only read samples at earlier times

Returns:

SimResultsNumpyCore instance with data.

read_full(t_min: float | None = None, t_max: float | None = None) SimResultsNumpyFull[source]

Read extended set of quantities into memory as SimResultsNumpyFull instance

If the file does not contain the extended set, an RuntimeError is raised.

Optionally, on can restrict the time range for which the data samples are read. This does not change the index space, i.e. which indices refer to which times. It only changes the index range of the datasets, available through the sat_ranges and mosa_ranges attributes of SimResultsNumpyFull.

Parameters:
  • t_min – Optionally, only read samples at later times

  • t_max – Optionally, only read samples at earlier times

Returns:

SimResultsNumpyFull instance with data.

lisainstrument.instru.instru_file_reader.sim_result_file(path: Path | str, only_compatible: bool = False) SimResultFile | SimResultFile[source]

Open simulation result file

This provides an interface with methods for reading the file. The returned interface depends on the file format version. To require the interface for the current version, use the option only_compatible=True. In this case, trying to read a file that cannot be represented through the current interface raises an exception.

Parameters:
  • path – Path of simulation result file

  • only_compatible – If False (default) allow reading old formats

Returns:

SimResultFile instance for reading file data