thermopt.config module#

thermopt.config.convert_configuration_options(config)[source]#

Processes configuration data by evaluating string expressions as numerical values and converting lists to numpy arrays.

This function iteratively goes through the configuration dictionary and converts string representations of numbers (e.g., “1+2”, “2*np.pi”) into actual numerical values using Python’s eval function. It also ensures that all numerical values are represented as Numpy types for consistency across the application.

Parameters:
configdict

The configuration data loaded from a YAML file, typically containing a mix of strings, numbers, and lists.

Returns:
dict

The postprocessed configuration data where string expressions are evaluated as numbers, and all numerical values are cast to corresponding NumPy types.

Raises:
ConfigurationError

If a list contains elements of different types after conversion, indicating an inconsistency in the expected data types.

thermopt.config.object_to_dict(obj)[source]#

Recursively convert an object’s attributes to a dictionary.

This function takes an object and converts its attributes to a dictionary format. It handles nested dictionaries, lists, and objects with a __dict__ attribute, recursively converting all attributes to dictionaries or arrays as appropriate.

Parameters:
objany

The object to convert. This can be a dictionary, list, or an object with a __dict__ attribute.

Returns:
dict

A dictionary representation of the object, where all nested attributes are recursively converted.

thermopt.config.read_configuration_file(filename)[source]#

Reads a YAML configuration file and converts options to NumPy types when possible.

Parameters:
filenamestr

The path to the YAML configuration file.

Returns:
dict

A dictionary containing the configuration options, with values converted to NumPy types where applicable.

Raises:
Exception

If there is an error reading or parsing the configuration file.