Skip to content

flixopt.io

Classes

CalculationResultsPaths dataclass

CalculationResultsPaths(folder: Path, name: str)

Container for all paths related to saving CalculationResults.

Functions

all_paths
all_paths() -> dict[str, pathlib.Path]

Return a dictionary of all paths.

create_folders
create_folders(parents: bool = False) -> None

Ensure the folder exists. Args: parents: Whether to create the parent folders if they do not exist.

update
update(new_name: str | None = None, new_folder: Path | None = None) -> None

Update name and/or folder and refresh all paths.

Functions

remove_none_and_empty

remove_none_and_empty(obj)

Recursively removes None and empty dicts and lists values from a dictionary or list.

document_linopy_model

document_linopy_model(model: Model, path: Path | None = None) -> dict[str, str]

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_dataset_from_netcdf(path: str | Path) -> xr.Dataset

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.