Measurements
A measurement consists of measured data and a description of how to predict them from the model state. During estimation, kipe compares the prediction with the data at each measurement time to correct the parameters.
Each measurement is an entry under measurements in the study file, by name. The kipe.examples.fitzhugh_nagumo example measures both fields of its model:
measurements: # each at its own times: w less often, in between those of v
v:
fields: [v]
times: {start: 0.5, stop: 20.0, step: 0.5}
data: {type: numpy, path: data/v.npz}
noise: {stddev: 0.01, seed: 0}
w:
fields: [w]
times: {start: 0.75, stop: 20.0, step: 1.0}
data: {type: numpy, path: data/w.npz}
noise: {stddev: 0.01, seed: 1}
A measurement names the state fields it observes, its times, where its data are
stored, and its noise. For spatially distributed fields, it also specifies how the fields
are brought to the measurement locations (spatial_sampling).
kipe list-fields study.yaml lists the solver’s fields, with their kind, size and, for a
FEniCSx solver, their function space. Study file lists all keys of
measurements.<name>; this page explains how they work together.
From the model state to the data
kipe predicts a measurement’s data from the model state in two steps:
The spatial sampler evaluates the observed fields where the measurement is taken, e.g., interpolates a finite element field onto the cells of a measurement mesh, giving the sampled values \(y\).
The measurement model predicts the data from them, \(\hat{z} = M(y)\), and compares them with the measured data \(z\), giving the innovation, which drives the filter’s correction. The
differencemodel takes the sampled values as the data, \(\hat{z} = y\), and the innovation is \(z - \hat{z}\).
Together, they are the measurement’s observation operator, the same in synthesis and estimation: the data kipe generates are the data it expects. Architecture explains the split and how to add a sampler or a model.
Times
times is a list, e.g., [0.1, 0.2, 0.5], or a range, {start: 0.05, stop: 0.5, step:
0.05}. They must lie after the forward solver’s start time, on its time grid if it has a
constant time step.
Each measurement has its own times, e.g., a pressure every 0.01 s and an image every 0.05 s. The estimation steps through the times of all measurements in order; at each, it assimilates the measurements taken then, together. Times of different measurements that agree up to round-off are the same time.
Spatial sampling
array
All entries of the observed fields, one after another in the order of fields
(ArraySamplingOptions). The fields must be replicated, i.e., held in full
by every MPI rank, as the states of the FitzHugh–Nagumo model or of a lumped-parameter model.
Fields that are distributed over the ranks, as finite element fields, need a sampler of their
backend.
fenicsx.mesh
A finite element field, interpolated onto a measurement mesh, which need not match the
solver’s: it can be coarser, or a surface of it. A vector field can be measured as a whole, or
its component along a direction or the surface normal (projection). The heat example
(kipe.fenicsx.examples.heat) measures the temperature on a coarser mesh:
measurements:
u:
fields: [u]
times: {start: 0.05, stop: 0.5, step: 0.05}
data: {type: numpy, path: data/u.npz}
noise: {stddev: 0.001, seed: 0}
# interpolated onto the measurement mesh; the data are in the order of its vertices
spatial_sampling: {type: fenicsx.mesh, mesh: data/measurement_mesh.xdmf, element: P1}
The values are in the order of the mesh file: by vertex for P1, by cell for DG0.
Meshes written by meshio need mesh_name: Grid.
Points outside the solver’s mesh. A surface mesh, or a coarser mesh, can cut slightly
across the boundary of the solver’s mesh, so that some of its points lie outside. kipe stops
with an error then. padding lets points within a distance outside take the value of the
nearest cell:
spatial_sampling:
type: fenicsx.mesh
mesh: data/endocardium.xdmf
element: DG0
projection: surface_normal
padding: 6.3e-4 # in the unit of the mesh
fenicsx.points
A finite element field, evaluated at given points, in their order:
spatial_sampling:
type: fenicsx.points
points: [[0.25, 0.25], [0.5, 0.5], [0.75, 0.75]]
fenicsx.displaced_vertices
Returns the displaced coordinates X + u(X) of vertices of mesh facets with the given tags.
You must specify combine: use union for vertices of facets with any listed tag, or
intersection for vertices shared by the facet sets of all listed tags:
spatial_sampling:
type: fenicsx.displaced_vertices
tags: [30, 10]
combine: intersection
The mesh and facet tags are provided by the forward solver for the selected field, through
function_space(field).mesh and facet_tags(field). For solvers with multiple meshes,
the field determines which mesh is used. Each tag must exist and the selection must be
nonempty. Cell tags are not supported.
The observed field must be a displacement vector with one component per spatial dimension.
Coordinates are returned vertex by vertex as a flat array (x0, y0, z0, x1, y1, z1, ... in
3D). Only mesh vertices are selected, including when using higher-order elements.
Another sampler? Write a spatial sampler walks through fenicsx.points, step by
step.
Measurement models
difference
The default model uses the sampled values directly as predicted data. Its innovation is measured minus predicted values.
plane
Fits a plane to sampled 3D vertices by orthogonal least squares and predicts its three coefficients:
The data at each time are [a, b, c]: two dimensionless slopes and an intercept in the
coordinates’ length unit. To fit the vertices shared by two tagged surfaces:
measurements:
valve_plane:
fields: [solid.displacement]
times: [0.1, 0.2, 0.3]
data: {type: numpy, path: data/valve_plane.npz}
noise: {stddev: 0.01, seed: 0}
spatial_sampling:
type: fenicsx.displaced_vertices
tags: [30, 10]
combine: intersection
model: {type: plane}
Select at least three noncollinear vertices that determine a unique best-fit plane. Vertical or nearly vertical planes are not supported.
To specify a reference point for normal orientation, add the optional normal_toward:
model:
type: plane
normal_toward: [0.012, -0.008, -0.045]
Use coordinates in your mesh’s coordinate system and units, with the point outside the
first fitted plane. Omit normal_toward when no reference point is available. This option
controls the normal’s orientation; it does not change the predicted coefficients or innovation.
For measured vertices, use the same fitting utility before writing the data file:
import numpy as np
from kipe.measurements.data import write_numpy
from kipe.measurements.plane import fit_from_coordinates
# vertices_at_times: one (n_vertices, 3) array of measured coordinates per time
coefficients = np.vstack([
fit_from_coordinates(vertices).coefficients for vertices in vertices_at_times
])
write_numpy("data/valve_plane.npz", times, coefficients)
The file’s values array has shape (n_times, 3). Set noise.stddev to a scalar or
three values in the order [a, b, c].
Noise
noise.stddev is the standard deviation of measurement noise assumed during estimation.
Use a positive scalar for all entries, or a list of positive values in the data’s column
order. The list must have one value per entry at each time. For a plane, the order is
[a, b, c]:
noise: {stddev: [0.01, 0.01, 0.001], seed: 0}
Noise is independent between entries. The same values weight estimation and sensitivity.
Each standard deviation uses its entry’s units: dimensionless for a and b, and the
coordinates’ length unit for c. These values apply at every measurement time.
See Synthetic data for how synthesis uses this value and can override it for generated
data.
Data
Measurement data are .npz files with two arrays (NumpyDataOptions):
times, shape(n,): the measurement times;values, shape(n, m): the m values of the measurement at each time.
The measurement model defines the order of the m values; by default, it keeps the sampler’s order (see below). This order does not depend on the number of MPI ranks: data written on one rank can be read on eight. To use data from elsewhere, e.g., from an image, write them in this order:
from kipe.measurements.data import write_numpy
write_numpy("data/u.npz", times, values) # = numpy.savez(path, times=..., values=...)