Source code for cleopy.readconfigfile
"""
Copyright (c) 2024 MPI-M, Clara Bayley
----- CLEO -----
File: readconfigfile.py
Project: cleopy
Created Date: Wednesday 17th April 2024
Author: Clara Bayley (CB)
Additional Contributors:
-----
License: BSD 3-Clause "New" or "Revised" License
https://opensource.org/licenses/BSD-3-Clause
-----
File Description:
"""
from ruamel.yaml import YAML
[docs]
def read_configparams_into_floats(filename):
"""returns dictionary of {key, values} pairs from
keys from a config yaml file which can be assigned float values.
Also obtains dictionary of notfloats for values that couldn't be converted
and converts nspacedims to integer if found in floats."""
yaml = YAML(typ="safe")
with open(filename, "r") as file:
config = yaml.load(file)
floats, notfloats = {}, {}
floats, notfloats = extract_floats(config, floats, notfloats)
try:
floats["nspacedims"] = int(floats["nspacedims"]) # no spatial coords to SDs
except KeyError as e:
print("Warning, ignoring error", e)
pass
return floats