Skip to content

extract_tools⚓︎

Extraction and normalisation of options from the parsed configuration dictionaries.

extract_initial_controls(keys) ⚓︎

Extract and process control variable information from configuration dictionary.

This function parses control variable specifications from the input configuration, handling various formats for initial values, bounds, and variance. It supports loading data from files (.npy, .npz, .csv).

Parameters:

Name Type Description Default
keys dict

Configuration dictionary containing a 'controls' key. Each control variable should be a nested dictionary with the name of the control variable as the key. The dictionary for each control variable should contain the following possible keys:

  • 'initial' or 'mean' : Initial value or mean of control variable Can be scalar, list, numpy array, or filename (.npy, .npz, .csv). If .npz or .csv, the variable name should match the control variable name. Multiple variables can be specified in the same file.

  • 'limits' : tuple or list, optional (lower_bound, upper_bound) for the control variable

  • 'var' or 'variance' : float, list, or array, optional Variance of the control variable

  • 'std' : float, list, array, or str, optional Standard deviation. If string ending with '%', interpreted as percentage of the bound range (requires 'limits' to be specified). Only if 'var'/'variance' is not provided.

required

Returns:

Name Type Description
control_info dict

Dictionary with control variable names as keys. Each value is a dict containing:

  • 'mean' : numpy.ndarray Initial/mean values for the control variable
  • 'limits' : list [lower_bound, upper_bound], or [None, None] if not specified
  • 'variance' : float, numpy.ndarray, or None Variance of the control variable (if provided)

Raises:

Type Description
AssertionError

If neither 'initial' nor 'mean' is provided for a control variable If attempting to use percentage-based 'std' without specifying 'limits' If loading from file fails (e.g., variable name not found in file)

Examples:

>>> keys = {
...     'controls': {
...         'pressure': {
...             'initial': 100.0,
...             'limits': [50.0, 150.0],
...             'std': '10%'
...         },
...         'rate': {
...             'mean': [10, 20, 30],
...             'variance': 2.5
...         }
...     }
... }
>>> control_info = extract_initial_controls(keys)
>>> control_info['pressure']['mean']
array([100.])
>>> control_info['pressure']['variance']
100.0  # (10% of range [50, 150])^2

extract_local_analysis_info(keys, state) ⚓︎

Local-analysis settings from the localanalysis block: parameter and region lists restricted to state, search_range, column_update, and the pickled position and mask files.

extract_maxiter(keys) ⚓︎

max_iter from the iteration or mda block; 1 without either. Reads without rewriting the block.

extract_multilevel_info(keys) ⚓︎

Extract the info needed for ML simulations. Note if the ML keyword is not in keys_en we initialize such that we only have one level -- the high fidelity one

extract_prior_info(keys) ⚓︎

Extract prior information on STATE from keyword(s).

organize_sparse_representation(info) ⚓︎

Function for reading input to wavelet sparse representation of data.

This function takes a dictionary (or a list convertible to a dictionary) describing the configuration for wavelet sparse representation, standardizes boolean options (interpreting 'yes'/'no' as True/False), loads or creates mask files, and collects all relevant parameters into a new dictionary suitable for downstream processing.

Parameters:

Name Type Description Default
info dict or list

Input configuration for sparse representation. If a list, it will be converted to a dictionary. Expected keys include: - 'dim': list of ints, the dimensions of the data to be compressed - 'mask': list of filenames for mask arrays. - 'level', 'wname', 'threshold_rule', 'th_mult', 'order', 'min_noise', 'colored_noise', 'use_hard_th', 'keep_ca', 'inactive_value', 'use_ensemble'.

required

Returns:

Name Type Description
sparse dict

Dictionary containing the processed sparse representation configuration, with masks loaded or created, dimensions flipped for compatibility, and all options standardized.