kipe.measurements.data module

Measurements and their data at the measurement times, and how the data are stored.

A Measurement holds the data of one measurement at all its times, with its observation operator (kipe.measurements.operator) and its noise. The data are stored in the numpy format (read_numpy(), write_numpy()), in the order of the measurement’s positions, so that they do not depend on the number of ranks.

class kipe.measurements.data.Measurement(name: str, operator: ObservationOperator, times: NDArray_f64, values: NDArray_f64, stddev: float | NDArray_f64)[source]

Bases: object

A measurement: its data at all measurement times, and its observation operator.

Synthesis produces measurements, estimation consumes them.

name: str

Name of the measurement, for logs and error messages.

operator: ObservationOperator

The observation operator \(\mathcal{H}\), from a model state to predicted data.

times: NDArray_f64

The measurement times, shape (n,).

values: NDArray_f64

This rank’s entries of the measured data at each of the n times, at the positions operator.global_indices, shape (n, number of this rank's entries).

stddev: float | NDArray_f64

scalar or this rank’s entries, in the unit of the data.

Type:

Noise standard deviation

kipe.measurements.data.select_noise_stddev(stddev: float | list[float], size: int, indices: NDArray_i64 | None = None) → float | NDArray_f64[source]

Validate the global noise length and optionally select this rank’s entries.

Scalars apply to all entries; lists must match the measurement model’s output size.

Parameters:
  • stddev – scalar or per-entry standard deviations

  • size – global number of predicted entries

  • indices – optional positions owned by this rank

Returns:

the scalar or the selected standard deviations

Raises:

StudyFileError – if the list does not match the global size

kipe.measurements.data.format_noise(stddev: float | list[float] | NDArray_f64) → str[source]

Format scalar or component-wise noise for logs.

Parameters:

stddev – scalar or per-entry standard deviations

Returns:

a scalar or bracketed list

kipe.measurements.data.measurement_times(times: list[float] | TimeRange) → NDArray_f64[source]

Return the measurement times as an array.

Parameters:

times – the times of a measurement, a list or a range

Returns:

the times; for a range, from start up to and including stop (up to round-off)

kipe.measurements.data.measurement_schedule(times: Mapping[str, NDArray_f64]) → list[tuple[float, list[tuple[str, int]]]][source]

Return the times of all measurements in order, each with the measurements at it.

Times of different measurements that are the same up to round-off (time_tolerance()) are one time, the earliest of them. At each time, the measurements are in the order of times.

Parameters:

times – the times of each measurement, by name

Returns:

the time, and the measurements at it, each as its name and the index of the time in its times

Return type:

for each time, in increasing order

Raises:

StudyFileError – if a measurement has two times that are the same up to round-off

kipe.measurements.data.time_tolerance(t: float) → float[source]

Return the tolerance below which two times are the same, relative to their size.

It absorbs the round-off of computed times, e.g., 0.1 + 0.2 and 0.3. Below |t| = 1 it is absolute, 1e-12: the times must be in a unit in which that is negligible, e.g., seconds for a time step of milliseconds; for much shorter time scales, scale the model’s time.

Parameters:

t – time

Returns:

tolerance

kipe.measurements.data.read_numpy(path: str | Path) → tuple[NDArray_f64, NDArray_f64][source]

Read measurement data from a .npz file with the arrays times and values.

Parameters:

path – path to the .npz file

Returns:

  • times, shape (n,)

  • values, shape (n, m): m values at each of the n times

Raises:

StudyFileError – if the file cannot be read or does not hold the expected arrays

kipe.measurements.data.read_data(name: str, path: str | Path, operator: ObservationOperator, selected: NDArray_f64 | None = None) → tuple[NDArray_f64, NDArray_f64][source]

Read a measurement’s data, keep this rank’s entries, and select the times.

Every rank reads the whole file and keeps the entries it holds (operator.global_indices).

Parameters:
  • name – name of the measurement, for error messages

  • path – path to the .npz file

  • operator – the measurement’s observation operator, which lays out the data

  • selected – the times to keep, e.g., the measurement’s times; all if None

Returns:

  • the times

  • this rank’s entries of the values at these times, one row per time

Raises:

StudyFileError – if the file cannot be read, does not have the measurement’s number of entries per time, or lacks a selected time

kipe.measurements.data.write_numpy(path: str | Path, times: NDArray_f64, values: NDArray_f64) → None[source]

Write measurement data to a .npz file, creating its directory if needed.

Parameters:
  • path – path to the .npz file

  • times – the n measurement times, shape (n,)

  • values – m values at each of the n times, shape (n, m)

kipe.measurements.data.write_data(path: str | Path, operator: ObservationOperator, times: NDArray_f64, values: NDArray_f64, comm: mpi4py.MPI.Comm) → None[source]

Write a measurement’s data, gathered from all ranks, on rank 0 (write_numpy()).

In the format of the data files: what synthesis writes, and the predicted data of the runs of the sensitivity analysis.

Parameters:
  • path – path to the .npz file

  • operator – the measurement’s observation operator, which says where each rank’s entries go (global_indices)

  • times – the measurement times

  • values – this rank’s entries of the data, one row per time

  • comm – communicator over which the entries are distributed