eta_ctrl.util.io_utils module
- eta_ctrl.util.io_utils.get_unique_output_path(base_path: Path) Path[source]
Get a unique output path with overwrite protection.
This function ensures that files are not accidentally overwritten by appending a counter to the filename if the original path already exists. For example: ‘file.txt’ -> ‘file_1.txt’ -> ‘file_2.txt’, etc.
- Parameters:
base_path – The desired output path.
- Returns:
A unique path that doesn’t exist.
- eta_ctrl.util.io_utils.json_import(path: Path) list[Any] | dict[str, Any][source]
Extend standard JSON import to allow ‘//’ comments in JSON files.
- Parameters:
path – Path to JSON file.
- Returns:
Parsed dictionary.
- eta_ctrl.util.io_utils.toml_import(path: Path) dict[str, Any][source]
Import a TOML file and return the parsed dictionary.
- Parameters:
path – Path to TOML file.
- Returns:
Parsed dictionary.
- eta_ctrl.util.io_utils.toml_export(path: Path, data: dict[str, Any]) None[source]
Export data to TOML file.
- Parameters:
path – Path to TOML file.
data – Data to be saved as TOML.
- eta_ctrl.util.io_utils.yaml_import(path: Path) dict[str, Any][source]
Import a YAML file and return the parsed dictionary.
- Parameters:
path – Path to YAML file.
- Returns:
Parsed dictionary.
- eta_ctrl.util.io_utils.csv_import(path: Path) dict[str, Any][source]
Import a csv file and return the parsed dictionary.
- Parameters:
path – Path to csv file.
- Returns:
Parsed dictionary.
- eta_ctrl.util.io_utils.load_config(file: Path) dict[str, Any][source]
Load configuration from JSON, TOML, YAML or CSV file. The read file is expected to contain a dictionary of configuration options. CSV files are converted to a list of dictionaries under the key ‘state_vars’.
If file contains a suffix (e.g. .csv or .toml) that suffix is used directly. If no suffix is present the function will try all supported extensions (json, toml, yml, yaml, csv) in this order and pick the first matching file.
- Parameters:
file – Path to the configuration file, with or without extension.
- Returns:
Dictionary of configuration options.
- eta_ctrl.util.io_utils.csv_export(path: Path, data: Mapping[str, Any] | Sequence[Mapping[str, Any] | Any] | pd.DataFrame, names: Sequence[str] | None = None, index: Sequence[int] | pd.DatetimeIndex | None = None, *, sep: str = ';', decimal: str = '.') None[source]
Export data to CSV file.
- Parameters:
path – Directory path to export data.
data – Data to be saved.
names – Field names used when data is a Matrix without column names.
index – Optional sequence to set an index
sep – Separator to use between the fields.
decimal – Sign to use for decimal points.