dafi (Package)

Modules:

DAFI: a Python package for data assimilaton and field inversion.

dafi.main.run(model_file, inverse_method, nsamples, ntime=None, perturb_obs_option='iter', obs_err_multiplier=1.0, analysis_to_obs=False, convergence_option='max', max_iterations=1, convergence_residual=None, convergence_factor=1.0, save_level=None, save_dir='results_dafi', rand_seed=None, verbosity=0, inputs_inverse={}, inputs_model={})[source]

Run DAFI.

Accesible through dafi.run().

Parameters:
  • model_file (str) – Name (path) of dynamic model module/package.

  • inverse_method (str) – Name of inverse method from dafi.inverse_methods module.

  • nsamples (int) – Number of samples in ensemble.

  • ntime (int) – Number of data assimilation times. For stationary use ‘1’ or ‘None’. Default ‘None’.

  • perturb_obs_option (str) – Option on when to perturb observations: ‘iter’ to perturb at each iteration (inner loop), ‘time’ to perturb only once each data assimilaton time (outer loop), ‘None’ to not perturb observations. Default ‘iter’.

  • obs_err_multiplier (float) – Factor by which to multiply the observation error matrix. This is done by some authors in the literature. Default ‘1.0’.

  • analysis_to_obs (bool) – Map analysis state to observation space. Default ‘False’.

  • convergence_option (str) – Convergence criteria to use: ‘discrepancy’ to use the discrepancy principle, ‘residual’ to use the iterative residual, ‘max’ to reach the maximum iterations. Default ‘max’.

  • max_iterations (int) – Maximum number of iterations at a given time-step. Default ‘1’.

  • convergence_residual (float) – Residual value for convergence if reach_max is ‘False’ and convergence_option is ‘residual’. Default ‘None’.

  • convergence_factor (float) – Factor used in the discrepancy principle convergence option. Default ‘1.0’.

  • save_level (str) – Level of results to save: ‘None’ to not save results, ‘time’ to save results at each data assimilation time step, ‘iter’ to save results at each iteration, ‘debug’ to save additional intermediate quantities. Default ‘None’.

  • save_dir (str) – Folder where to save results. Default ‘./results_dafi’.

  • rand_seed (float) – Seed for numpy.random. If None random seed not set. Default ‘None’.

  • verbosity (int) – Logging verbosity level, between -1 and 9 (currently -1-3 used). For no logging use ‘-1’. For debug-level logging use ‘debug’. Default ‘0’.

  • inputs_inverse (dict) – Inverse method specific inputs. Default empty dictionary ‘{}’.

  • inputs_model (dict) – Physics model specific inputs. Default empty dictionary ‘{}’.

Returns:

state_analysis_list – List of analysis states at each DA time. Length is number of DA time steps. Each entry is an nd.array containing the ensemble analysis states (\(x_a\)) at that time step. If only one DA time (e.g. stationary, inversion problem) is the single ndarray. Each entry is: dtype=float, ndim=2, shape=(nstate, nsamples).

Return type:

list

Template for physics models.

class dafi.physics_model.PhysicsModel(inputs_dafi, inputs)[source]

Parent class for physics models.

Accessible through dafi.PhysicsModel. Use this as a template to write new dynamic models. The required attributes and methods are summarized below.

Attributes

  • name - Name of the forward model for reporting. str

  • nstate - Number of states in the state vector. int

  • nobs - Number of observations in the observation vector. int

  • init_state - Initial mean value of the state vector. ndarray, dtype=float, ndim=1, shape=(nstate)

Methods

See the method’s docstring for information on each.

  • generate_ensemble

  • forecast_to_time

  • state_to_observation

  • get_obs

__init__(inputs_dafi, inputs)[source]

Parse input file and assign values to class attributes.

Parameters:
  • inputs_dafi (dict) – Dictionary containing all the dafi inputs in case the model requires access to this information.

  • inputs (dict) – Dictionary containing required model inputs.

forecast_to_time(state, time)[source]

Return states at the next end time.

Parameters:
  • state (ndarray) – Current ensemble of states (Xa). dtype=float, ndim=2, shape=(nstate, nsamples)

  • time (int) – Next end time index. Any concept of real time is implemented the physics model (e.g. this file).

Returns:

state – Updated ensemble matrix of states (Xf). dtype=float, ndim=2, shape=(nstate, nsamples)

Return type:

ndarray

generate_ensemble()[source]

Return states at the first data assimilation time-step.

Returns:

state – Ensemble matrix of states (X0). dtype=float, ndim=2, shape=(nstate, nsamples)

Return type:

ndarray

get_obs()[source]

Return the observation and error matrix.

Parameters:

time (int) – Time index at which observation is requested. Any concept of real time is implemented the physics model (e.g. this file).

Returns:

  • obs (ndarray) – Observations. dtype=float, ndim=2, shape=(nobs, nsamples)

  • obs_error (ndarray) – Observation error (covariance) matrix. dtype=float, ndim=2, shape=(nobs, nobs)

state_to_observation(state)[source]

Map the states to observation space (X to HX).

Parameters:

state (ndarray) – Ensemble of states. dtype=float, ndim=2, shape=(nstate, nsamples)

Returns:

state_obs – Ensemble in observation space. dtype=float, ndim=2, shape=(nobs, nsamples)

Return type:

ndarray