dafi (Package)¶
Modules:
- dafi.inverse
- dafi.random_field
- dafi.random_field.covariance
- dafi.random_field.foam
foam_header_info()foam_header_logo()foam_sep()get_cell_centres()get_cell_volumes()get_neighbors()get_number_cells()read_cell_centres()read_cell_volumes()read_field()read_field_file()read_header()read_scalar_field()read_symmTensor_field()read_tensor_field()read_vector_field()write()write_Tau()write_U()write_controlDict()write_epsilon()write_field_file()write_k()write_nut()write_omega()write_p()
GaussianProcessGaussianProcess.__init__()GaussianProcess.logpdf()GaussianProcess.pdf()GaussianProcess.project_func_field()GaussianProcess.project_gp_field()GaussianProcess.reconstruct_func()GaussianProcess.reconstruct_gp()GaussianProcess.sample_coeffs()GaussianProcess.sample_func()GaussianProcess.sample_gp()
LogNormalcalc_kl_modes()calc_kl_modes_coverage()gp_samples_cholesky()gp_samples_kl()gp_samples_kl_coverage()gp_samples_klmodes()gp_sqrexp_samples()inner_product()integral()interpolate_field_rbf()inverse_distance_weights()kl_coverage()norm()project_kl()projection()projection_magnitude()reconstruct_kl()scale_kl_modes()sparse_cholesky()unit_field()
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)