ensembles⚓︎
Ensemble containers for data assimilation.
Mirrors the layout of :mod:popt.ensembles.
AssimilationEnsemble
⚓︎
Bases: ForecastMixin, OutlierMixin, LocalAnalysisMixin, BaseEnsemble
Class for organizing/initializing misc. variables and simulator for an ensemble-based inversion run. Inherits the PET ensemble structure
RESTART_ATTRIBUTES = ('enX', 'prior_enX', 'pred_data', 'member_outputs', 'member_adjoints', 'adjoints', 'scale_data', 'Am', 'proj', 'iteration', 'sparse_data', 'scale_val')
⚓︎
What a resume must restore on the ensemble: what iterations change (the state, its forecast), and what construction drew or derived from a draw (the prior, the observation scaling, the scaled prior's SVD), so a resumed run continues the interrupted one whatever the random state was when the resuming process built its ensemble.
__init__(keys_da, keys_en, sim)
⚓︎
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys_da
|
dict
|
Options for the data assimilation class
|
required |
keys_en
|
dict
|
Options for the ensemble class
NB: If keys_en is empty dict, it is assumed that the prior info is contained in keys_da. The merged dict keys_da|keys_en is what is sent to the parent class. |
required |
sim
|
callable
|
The forward simulator (e.g. flow) |
required |
check_assimindex_simultaneous()
⚓︎
Check if assim. indices is given as a 1D list as is needed in simultaneous updating. If not, make it a 2D list with one row.
perturb_observations(vecObs)
⚓︎
Generate the perturbed observed data ensemble
restart_state()
⚓︎
What a checkpoint carries for this ensemble: RESTART_ATTRIBUTES plus the random stream's state.
restore_restart_state(state)
⚓︎
Overlay a checkpoint's ensemble state and mark the ensemble as resumed.
ForecastMixin
⚓︎
Forward simulation and predicted-data preparation.
save_folder: str | None
⚓︎
Folder for run artifacts, or None when saving is disabled.
save_folder is accepted too; the config boundary maps it to
savefolder. Reading this creates nothing; :meth:_save_path makes
the folder when something is about to be written into it.
forecast(enX)
⚓︎
Run forecast simulations and prepare predicted data for analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enX
|
The state to predict on. Passed in rather than read off the ensemble, so a scheme can forecast a trial state without first parking it somewhere for this method to find. |
required |
sim_to_pred_data(pred)
⚓︎
Filter the simulator output to match the structure of the predicted data expected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
Any
|
The raw output from the simulator, which may be a list of DataFrames or a single DataFrame. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The processed predicted data, structured to match the ensemble's expected format for analysis. |
treat_modeling_error()
⚓︎
Shift every coarser level so each row's ensemble mean matches the finest level's.
LocalAnalysisMixin
⚓︎
Localized (per-parameter-neighbourhood) analysis update.
local_analysis_update()
⚓︎
Function for updates that can be used by all algorithms. Do this once to avoid duplicate code for local analysis.
OutlierMixin
⚓︎
Replacement of outlier ensemble members.
Ensemble work, like the forecast: it rewrites pred_data, sim_data
and the state matrix in place. Called between forecast and scoring, so the
replacement feeds into the misfit the scheme sees.
remove_outliers(enX)
⚓︎
Replace outlier ensemble members with resampled non-outliers.
Returns the state with outliers resampled -- the same object when there is nothing to replace. Returned rather than written back, because the caller owns the state being forecast.