Skip to content

layout⚓︎

The two layouts every PET array follows: rows of the data vector, rows of the state.

Observed data arrive as a frame with one row per report label (a time, a date, an index) and one column per data type; a cell holds a scalar or a vector, or nothing when that type was not observed at that label. Every matrix the analyses work on -- the observation vector, its variance, the predicted-data ensemble, the adjoints -- lists those cells in one fixed order, label-major then type, skipping the empty ones. :class:DataLayout is that order, computed once from the observed frame. Anything built from it is aligned with anything else built from it by construction, which is what the frame filters used to promise and could not keep once a cell was empty.

The state is a plain (nx, ne) array. Its {variable: (start, stop)} row map used to ride on an ndarray subclass, copied onto every slice and view (wrongly) and lost on unpickling. It now lives once, as the ensemble's idX dictionary, and :class:StateLayout gives it the conversions the boundary needs: one dictionary per variable for saving and QA/QC, one dictionary per member for the simulator, clipping to the prior's limits, and the two constructors that build a state, from a dictionary of arrays or from the prior description.

DataLayout ⚓︎

The order of the data vector, derived once from the observed frame.

nd: int ⚓︎

Length of the data vector.

from_frame(frame) ⚓︎

Walk frame label-major then type, as the frame flatten did, skipping empty cells.

matrix(frame, ne) ⚓︎

The cells of an ensemble frame -- (ne,) or (size, ne) each -- as (nd, ne).

row(label, datatype) ⚓︎

The row of (label, datatype); KeyError when that cell was not observed.

row_datatypes() ⚓︎

The data type of every row of the vector, (nd,).

to_frame(values, name=None) ⚓︎

A frame view of values -- (nd,) or (nd, ne) -- with empty cells None.

Cells come out as the flatten expects them back: a scalar for a one-row observation, a vector or an (size, ne) block otherwise.

vector(frame) ⚓︎

The observed cells of frame as an (nd,) vector, in layout order.

LayoutRow ⚓︎

One observed cell and the rows it owns: [start, stop).

rows: slice ⚓︎

The slice of the data vector this cell owns.

size: int ⚓︎

Number of rows this cell owns.

StateLayout ⚓︎

Row ranges of the state variables in an (nx, ne) state matrix, in stacking order.

nx: int ⚓︎

Number of state rows.

variables: tuple ⚓︎

Variable names in stacking order.

clip(matrix, limits) ⚓︎

Clip matrix in place to limits.

limits is a (lower, upper) pair for every variable, a {variable: (lower, upper)} dict, or a list of pairs in stacking order; None bounds are left open.

from_dict(member, ne=None) ⚓︎

Stack {variable: (n, ne) array} into a state matrix; returns (matrix, layout).

With ne given, only the first ne columns of each array are used.

from_prior_info(prior_info, ne, rng=None, save=True) ⚓︎

Draw a prior ensemble from the prior description; returns (matrix, layout).

Parameters:

Name Type Description Default
prior_info dict

Per variable: mean, variance (per layer), the grid size nx/ny/nz and, for fields, the covariance description.

required
ne int

Number of members.

required
rng RandomState - like

The stream to draw from; the global one by default.

None
save bool

Write the prior to prior_ensemble.npz (default True).

True

member_dicts(matrix) ⚓︎

One {variable: values} per member -- what a simulator takes.

rows(name) ⚓︎

The row slice of variable name.

to_dict(matrix) ⚓︎

{variable: rows} views of matrix.

is_missing(cell) ⚓︎

Whether a frame cell holds no observation: None or nothing but NaN.