flixopt.io
Classes
CalculationResultsPaths
dataclass
Container for all paths related to saving CalculationResults.
Functions
create_folders
Ensure the folder exists. Args: parents: Whether to create the parent folders if they do not exist.
Functions
remove_none_and_empty
Recursively removes None and empty dicts and lists values from a dictionary or list.
document_linopy_model
Convert all model variables and constraints to a structured string representation. This can take multiple seconds for large models. The output can be saved to a yaml file with readable formating applied.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
Path to save the document. Defaults to None. |
None
|
save_dataset_to_netcdf
save_dataset_to_netcdf(ds: Dataset, path: str | Path, compression: int = 0, engine: Literal['netcdf4', 'scipy', 'h5netcdf'] = 'h5netcdf') -> None
Save a dataset to a netcdf file. Store all attrs as JSON strings in 'attrs' attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
Dataset to save. |
required |
path
|
str | Path
|
Path to save the dataset to. |
required |
compression
|
int
|
Compression level for the dataset (0-9). 0 means no compression. 5 is a good default. |
0
|
Raises:
Type | Description |
---|---|
ValueError
|
If the path has an invalid file extension. |
load_dataset_from_netcdf
Load a dataset from a netcdf file. Load all attrs from 'attrs' attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | Path
|
Path to load the dataset from. |
required |
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Dataset
|
Loaded dataset with restored attrs. |