Interpolation Observation Operators#

CartesianInterpolator([configs])

An obsevation operator that interpolates prognostic (physics) variables from the model grid to the observation grid points.

Class implementing multiple observation-by-interpolation operators.

  • Selection (restriction) operator, as well as 1D, 2D, 3D interpolation operators in cartesian coordinates are developed.

class CartesianInterpolatorConfigs(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', design=None, model=None, targets=None, method='linear')[source]#

Bases: ObservationOperatorConfigs

Configuration class for CartesianInterpolator

Parameters:
  • verbose (bool) – a boolean flag to control verbosity of the object.

  • debug (bool) – a boolean flag that enables adding extra functionality in a debug mode

  • output_dir (str | Path) – the base directory where the output files will be saved.

  • design (None | bool | Sequence[bool] | ndarray[bool]) –

    an experimental design to define active/inactive entries of the observation vector.

    Note

    An experimental design here is always binary (on/off) indicating which entries of the design space are active/inactive. This corresponds to turning on/off some of the observational sensors. Thus, if the design is None, it is set to all ones; that is everything is observed

  • model (SimulationModel | None) – the simulation model from which the source grid is extracted.

  • targets (ndarray | None) – 2D array with shape (n, 2) elements describing coordinates of the n observation/sensor points.

  • model – the simulation model to use for accessing the model grid and the model state/parameter

  • targets – one or two dimensional numpy array (must be same as model_grid) holding observational coordinates corresponding to observation instance entries.

  • method (str) –

    interpolation method to use; default is ‘linear’; supported methods are:

    1. ’linear’

    Note

    Like in scipy interpolate, we will soon add other methods including “linear”, “nearest”, “slinear”, “cubic”, “quintic” and “pchip”.

    Note

    An alias (property actually) to targets named observation_grid is added for backward compatibility.

model: SimulationModel | None#
targets: ndarray | None#
method: str#
__init__(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', design=None, model=None, targets=None, method='linear')#
class CartesianInterpolator(configs=None)[source]#

Bases: ObservationOperator

An obsevation operator that interpolates prognostic (physics) variables from the model grid to the observation grid points.

Note

  • It is assumed in general that there are multiple prognostic variables (one being a special case of course which is handled automatically), thus there must be an assumption about the layout of the model state and the observation entries. Specifically, whether the prognostic variables (all physics variables) at one grid are stored consecutively, or not. This is internally determined here by inspecting the first two entries of the model grid and the observation grid (targets) respectively.

  • It is also assumed that all prognostic variables are observed. One can inherit this class and make any necessary modifications of course!

Warning

All observational grid points must be inside the model domain. Specifically, the functionality in this class can interpolate, but not extrapolate.

Raises:
  • PyOEDConfigsValidationError – if either the model grid (retrieved from the model) or the observation grid (targets) is not in 1D/2D/3D coordinate system or if they are not in the same coordinate system

  • PyOEDConfigsValidationError – if the model or the targets have irregular structure, for example, if not all variables are observed.

  • PyOEDConfigsValidationError – if the observation grid is not within the model grid domain

__init__(configs=None)[source]#
validate_configurations(configs, raise_for_invalid=True)[source]#

Check the passed configuratios and make sure they are conformable with each other, and with current configurations once combined. This guarantees that any key-value pair passed in configs can be properly used

Note

Here only the locally-defined configurations in CartesianInterpolatorConfigs are validated. Finally, super classes validators are called.

Parameters:
  • configs – full or partial (subset) configurations to be validated

  • raise_for_invalid – if True raise an error for invalid configrations type/key. Default True

Returns:

flag indicating whether passed configurations dictionary is valid or not

Raises:
get_observation_grid()[source]#

Return a copy of the full observational grid discarding the design

get_active_observation_grid()[source]#

Return a copy of the active observational grid accounting for the experimental design.

apply(state, eval_at_t=None)[source]#

Given a state vector \(x\) (laid out as defined by the model grid passed upon instantiation), evaluate the observation vector :\(y=H(x)\) where \(H\) is the interpolation observation operator. Here, the observation operator extracts the prognostic variables at each observation grid point and apply interpolation for each prognostic variable. For linear interpolation (as configured in self.configurations), this involves bilinear interpolation for points inside a valid square/rectangle stencil of model grid points.

Note

This function is designed for 1D/2D/3D Cartesian coordinate systems only

Parameters:
  • state – instance of a model state with entries corresponding the model grid passed upon instantiation

  • eval_at_t – the time at which the observation operator is evaluated. Since some observation operators are time-dependent, this parameter is added for generality and for a unified interface.

Returns:

an observation vector/instance

Raises:

PyOEDConfigsValidationError – if the configurations (model and observation grids) are invalid (e.g., if the user has altered them).

Jacobian_T_matvec(observation, eval_at=None, eval_at_t=None)[source]#

Multiply (Matrix-free matrix-vector product) of transpose of the Jacobian/tangent-linear (TLM) of the observation operator by the passed observation. The Jacobian is evaluated (for nonlinear operators) at eval_at.

Note

This function is designed for 1D/2D/3D Cartesian coordinate systems only

Parameters:
  • observation – observation instance/vector

  • eval_at – state around which observation operator is linearized; this is ignored here because the operator is linear.

  • eval_at_t – the time at which the observation operator is evaluated. Since some observation operators are time-dependent, this parameter is added for generality and for a unified interface.

Returns:

result of multiplying the transpose of derivative of the observation operator by the passed observation

Raises:
  • TypeError – if the passed observation is invalid (type/shape/etc.)

  • PyOEDConfigsValidationError – if the configurations (model and observation grids) are invalid (e.g., if the user has altered them).

property shape#

A tuple holding the shape of the observation operator (observation vector size, model state size).

Raises:

PyOEDConfigsValidationError – if the model has not been configured. This typically happens if this property is called before the object is fully instantiated.

property model#

The underlying simulation model