eta_ctrl.util.utils module
- eta_ctrl.util.utils.import_class_from_module(path: str, base_class: type[T] | None = None) type[T][source]
Import a class from a given python module path.
- Parameters:
path (str) – Path to the class, e.g. ‘my_package.my_module.MyClass’
- Raises:
ModuleNotFoundError – Passed module not found
AttributeError – Passed class not found
- Returns:
Imported class
- Return type:
- eta_ctrl.util.utils.dict_get_any(dikt: dict[str, Any], *names: str, fail: bool = True, default: Any = None) Any[source]
Get any of the specified items from dictionary, if any are available.
The function will return the first value it finds, even if there are multiple matches.
- Parameters:
dikt – Dictionary to get values from.
names – Item names to look for.
fail – Flag to determine, if the function should fail with a KeyError, if none of the items are found. If this is False, the function will return the value specified by ‘default’.
default – Value to return, if none of the items are found and ‘fail’ is False.
- Returns:
Value from dictionary.
- Raise:
KeyError, if none of the requested items are available and fail is True.
- eta_ctrl.util.utils.dict_pop_any(dikt: dict[str, Any], *names: str, fail: bool = True, default: Any = None) Any[source]
Pop any of the specified items from dictionary, if any are available.
The function will return the first value it finds, even if there are multiple matches. This function removes the found values from the dictionary!
- Parameters:
dikt – Dictionary to pop values from.
names – Item names to look for.
fail – Flag to determine, if the function should fail with a KeyError, if none of the items are found. If this is False, the function will return the value specified by ‘default’.
default – Value to return, if none of the items are found and ‘fail’ is False.
- Returns:
Value from dictionary.
- Raise:
KeyError, if none of the requested items are available and fail is True.
- eta_ctrl.util.utils.dict_search(dikt: dict[str, str], val: str) str[source]
Get key of _psr_types dictionary, given value.
Raise ValueError in case of value not specified in data.
- Parameters:
val – value to search
data – dictionary to search for value
- Returns:
key of the dictionary
- eta_ctrl.util.utils.deep_mapping_update(source: Any, overrides: Mapping[str, str | Mapping[str, Any]]) dict[str, str | Mapping[str, Any]][source]
Perform a deep update of a nested dictionary or similar mapping.
- Parameters:
source – Original mapping to be updated.
overrides – Mapping with new values to integrate into the new mapping.
- Returns:
New Mapping with values from the source and overrides combined.
- eta_ctrl.util.utils.camel_to_snake_case(camel_name: str) str[source]
Convert a string from camel to snake case convention
- eta_ctrl.util.utils.snake_to_camel_case(snake_name: str) str[source]
Convert a string from snake_case to PascalCase convention.
- eta_ctrl.util.utils.timestep_to_seconds(timestep: TimeStep | str) float[source]
Convert a TimeStep or string representation to seconds as a float value.
- Parameters:
timestep – Original timestamp value
- Returns:
Value in seconds
- eta_ctrl.util.utils.timestep_to_timedelta(timestep: TimeStep | str) timedelta[source]
Convert a TimeStep or string representation to a timedelta object.
- Parameters:
timestep – Original timestamp value
- Returns:
timedelta object representing the duration