structures⚓︎
PET's data containers.
PETDataFrame is the ragged table observed and predicted data arrive in
and are saved as; on the analysis path the data live in matrices ordered by
a DataLayout (PredictedData for the forecast). The state is a plain
(nx, ne) array whose variable layout is a StateLayout.
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
⚓︎
PETDataFrame
⚓︎
Bases: DataFrame
Pandas DataFrame subclass that preserves all pandas behavior while allowing project-specific custom methods.
filter_dataframe(index=None, columns=None)
⚓︎
Return a new PETDataFrame filtered to the specified columns and index.
from_csv(filepath, **kwargs)
⚓︎
Load a PETDataFrame from a CSV file.
from_pandas(df, name=None, is_ensemble=False)
⚓︎
Create a PETDataFrame from an existing pd.DataFrame.
from_pickle(filepath)
⚓︎
Load a PETDataFrame from a pickle file.
invert_scale(type='max-min', **kwargs)
⚓︎
Invert the scaling transformation applied to the DataFrame.
merge_dataframes(dfs)
⚓︎
Combine a list of DataFrames (one per ensemble member) into a single PETDataFrame where each cell contains an array of ensemble values.
scale(type='max-min', **kwargs)
⚓︎
Scale each column of DataFrame using the specified method.
to_matrix(filter=True, is_jacobian=False, squeeze=True)
⚓︎
Legacy flatten of the observed cells, label-major then type; misc.structures.DataLayout is the analysis path's equivalent.
to_series()
⚓︎
Cells as a Series indexed by (label, datatype), label-major: the legacy flatten order.
PredictedData
⚓︎
Predictions for every observed cell, one column per member.
Built straight from what each member's simulation returned, so its rows
are the layout's rows: the same rows the observation vector and its
variance have. The frame the older code passed around is available as a
view (:meth:to_frame) for saving and inspection.
nd: int
⚓︎
Number of data rows.
ne: int
⚓︎
Number of members.
from_frame(layout, frame, ne)
⚓︎
From a prediction frame whose cells are (ne,) or (size, ne) arrays.
from_members(layout, members, position=None, scale=None, transform=None)
⚓︎
Fill the matrix from one output per member.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
members
|
sequence
|
One output per member: a list of records (one dict per report point, keyed by data type) or a DataFrame indexed by label. |
required |
position
|
dict
|
Where each observed label sits in a member's records. Omit when the labels are the positions. |
None
|
scale
|
(minimum, maximum)
|
Per-data-type max-min scaling to apply, as the observations were
scaled: |
None
|
transform
|
callable
|
|
None
|
rows_of(datatype)
⚓︎
The row slices holding datatype, in layout order.
take_members(index)
⚓︎
The predictions of the members index names, in that order.
to_frame(name=None)
⚓︎
The frame view: one cell per observed label and data type.
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: |
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 |
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.