read_config⚓︎
Parse config files.
change_file_extension(filename, new_extension)
⚓︎
filename with its extension replaced by new_extension.
convert_txt_to_toml(init_file)
⚓︎
Write a legacy .pipt/.popt file as <name>.toml next to it.
convert_txt_to_yaml(init_file)
⚓︎
Write a legacy .pipt/.popt file as <name>.yaml next to it.
parse_keywords(lines)
⚓︎
Here we parse the lines in the init. file to a Python dictionary. The keys of the dictionary is the keywords in the PIPT init. file, and the information in each keyword is stored in each key of the dictionary. To know how the keyword-information is organized in the keys of the dictionary, confront the manual located in the doc folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines
|
list
|
List of (clean) lines from the PIPT init. file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
keys |
dict
|
Dictionary with all info. from the init. file. |
read(filename)
⚓︎
Read configuration file. Supported formats are toml, .yaml, .pipt and .popt.
read_clean_file(init_file)
⚓︎
Read PIPT init. file and lines that are not comments (marked with octothorpe)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init_file
|
str
|
Name of file to remove all comments. WHOLE filename needed (with suffix!) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
lines |
list
|
Lines from init. file converted to list entries |
read_toml(filepath)
⚓︎
Read and parse a .toml configuration file for PIPT/POPT.
The TOML file should contain one or more of the following top-level keys: - 'dataassim' (dict): Data assimilation configuration - 'optim' (dict): Optimization configuration - 'fwdsim' (dict): Forward simulation configuration - 'ensemble' (dict, optional): Ensemble configuration
Returns:
| Type | Description |
|---|---|
tuple
|
(keys_pr, keys_fwd, keys_en) - keys_pr: dict, parsed 'dataassim' or 'optim' section (empty if not present) - keys_fwd: dict, parsed 'fwdsim' section (empty if not present) - keys_en: dict, parsed 'ensemble' section (empty if not present) |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file does not exist. |
ValueError
|
If the TOML file is missing required sections. |
TOMLDecodeError
|
If the TOML file is invalid. |
read_txt(init_file)
⚓︎
Read a PIPT or POPT input file (.pipt or .popt), parse and output dictionaries for data assimilation or optimization, and simulator classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init_file
|
str
|
PIPT init. file containing info. to run the inversion algorithm |
required |
Returns:
| Name | Type | Description |
|---|---|---|
keys_pr |
dict
|
Parsed keywords from DATAASSIM or OPTIM |
keys_fwd |
dict
|
Parsed keywords from FWDSSIM |
read_yaml(filepath)
⚓︎
Read and parse a .yaml configuration file for PIPT/POPT.
The YAML file should contain one or more of the following top-level keys: - 'dataassim' (dict): Data assimilation configuration - 'optim' (dict): Optimization configuration - 'fwdsim' (dict): Forward simulation configuration - 'ensemble' (dict, optional): Ensemble configuration
Returns:
| Type | Description |
|---|---|
tuple
|
(keys_pr, keys_fwd, keys_en) - keys_pr: dict, parsed 'dataassim' or 'optim' section (empty if not present) - keys_fwd: dict, parsed 'fwdsim' section (empty if not present) - keys_en: dict, parsed 'ensemble' section (empty if not present) |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file does not exist. |
ValueError
|
If the YAML file is missing required sections. |
YAMLError
|
If the YAML file is invalid. |