kipe.measurements module
Measurements, and how predicted data are compared with them.
The observation operator compares a model state with a measurement in two steps: a spatial
sampler (kipe.sampling) evaluates the observed fields at the measurement locations,
giving \(y\); a MeasurementModel predicts the data from it,
\(\hat{z} = M(y)\), and compares them with the measured data \(z\), giving the
innovation \(\Gamma(z, \hat{z})\). Models act on arrays only, so they are the same for
every backend. The ObservationOperator \(\mathcal{H} = M \circ S\) combines the
two steps: it takes a model state to predicted data.
To add a model: subclass MeasurementModel, implement both methods, add its options
to kipe.options and a case to build_model().
- class kipe.measurements.MeasurementModel[source]
Bases:
ABCTurns sampled model fields into predicted data and compares them with the measurement.
- abstractmethod predict(y: NDArray_f64) NDArray_f64[source]
Predict the measured data from the sampled state, \(\hat{z} = M(y)\).
- Parameters:
y – sampled state \(y\), as returned by
kipe.sampling.SpatialSampler.sample()- Returns:
predicted data \(\hat{z}\), in the measurement space
- abstractmethod innovation(z_hat: NDArray_f64, z: NDArray_f64) NDArray_f64[source]
Compare predicted and measured data, \(\Gamma(z, \hat{z})\).
- Parameters:
z_hat – predicted data \(\hat{z}\), as returned by
predict()z – measured data at the current assimilation time, in the measurement space
- Returns:
innovation, before weighting with the measurement noise
- class kipe.measurements.DifferenceModel[source]
Bases:
MeasurementModelThe measured data are the sampled fields: \(\hat{z} = y\), and the innovation is \(\Gamma = z - \hat{z}\).
- kipe.measurements.build_model(options: DifferenceModelOptions) MeasurementModel[source]
Construct the measurement model given by the
modeloptions of a measurement.- Parameters:
options –
modeloptions of the measurement- Returns:
the measurement model
- class kipe.measurements.ObservationOperator(fields: list[str], sampler: SpatialSampler, model: MeasurementModel)[source]
Bases:
objectThe observation operator \(\mathcal{H} = M \circ S\) of a measurement.
Takes a model state \(\chi\) to predicted data \(\hat{z} = \mathcal{H}(\chi)\): the spatial sampler \(S\) evaluates the observed fields at the measurement locations, the measurement model \(M\) predicts the data from them.
- fields: list[str]
Names of the observed state fields.
- sampler: SpatialSampler
The spatial sampler \(S\).
- model: MeasurementModel
The measurement model \(M\).
- property size: int
Number of entries of the predicted data, over all ranks.
The models act entry by entry, so the predicted data have the sampler’s entries.
- property global_indices: NDArray_i64
Positions of this rank’s entries in the measurement’s data, see
kipe.sampling.SpatialSampler.global_indices.
- kipe.measurements.build_observation_operator(name: str, options: MeasurementOptions, solver: ForwardSolver, comm: mpi4py.MPI.Comm = mpi4py.MPI.COMM_WORLD) ObservationOperator[source]
Construct the observation operator of a measurement.
- Parameters:
name – name of the measurement, for error messages
options – the measurement options
solver – the forward solver
comm – communicator of the run
- Returns:
the observation operator
- Raises:
StudyFileError – if the measurement observes a field the solver does not have, or one its sampler cannot sample
- class kipe.measurements.Measurement(name: str, operator: ObservationOperator, times: NDArray_f64, values: NDArray_f64, stddev: float)[source]
Bases:
objectA 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
Standard deviation of the measurement noise, in the unit of the data.
- kipe.measurements.measurement_times(times: list[float] | TimeRange) NDArray_f64[source]
Return the measurement times as an array.
- Parameters:
times – the
timesof a measurement, a list or a range- Returns:
the times; for a range, from
startup to and includingstop(up to round-off)
- kipe.measurements.read_numpy(path: str | Path) tuple[NDArray_f64, NDArray_f64][source]
Read measurement data from a
.npzfile with the arraystimesandvalues.- Parameters:
path – path to the
.npzfile- 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.write_numpy(path: str | Path, times: NDArray_f64, values: NDArray_f64) None[source]
Write measurement data to a
.npzfile, creating its directory if needed.- Parameters:
path – path to the
.npzfiletimes – the n measurement times, shape
(n,)values – m values at each of the n times, shape
(n, m)