Skip to content

flixOpt.flow_system

This module contains the FlowSystem class, which is used to collect instances of many other classes by the end User.

Classes

FlowSystem

FlowSystem(time_series: ndarray[datetime64], last_time_step_hours: Optional[Union[int, float]] = None, previous_dt_in_hours: Optional[Union[int, float, ndarray]] = None)

A FlowSystem organizes the high level Elements (Components & Effects).

Parameters:

Name Type Description Default
time_series np.ndarray of datetime64

timeseries of the data. Must be in datetime64 format. Don't use precisions below 'us'. !np.datetime64[ns]!

required
last_time_step_hours Optional[Union[int, float]]

The duration of last time step. Storages needs this time-duration for calculation of charge state after last time step. If None, then last time increment of time_series is used.

None
previous_dt_in_hours Union[int, float, ndarray]

The duration of previous time steps. If None, the first time increment of time_series is used. This is needed to calculate previous durations (for example consecutive_on_hours). If you use an array, take care that its long enough to cover all previous values!

None

Functions

add_elements
add_elements(*args: Element) -> None

add all modeling elements, like storages, boilers, heatpumps, buses, ...

Parameters:

Name Type Description Default
*args childs of Element like Boiler, HeatPump, Bus,...

modeling Elements

()
to_json
to_json(path: Union[str, Path])

Saves the flow system to a json file. This not meant to be reloaded and recreate the object, but rather used to document or compare the object.

Parameters:

path : Union[str, pathlib.Path] The path to the json file.

visualize_network
visualize_network(path: Union[bool, str, Path] = 'flow_system.html', controls: Union[bool, List[Literal['nodes', 'edges', 'layout', 'interaction', 'manipulation', 'physics', 'selection', 'renderer']]] = True, show: bool = True) -> Optional[pyvis.network.Network]

Visualizes the network structure of a FlowSystem using PyVis, saving it as an interactive HTML file.

Parameters: - path (Union[bool, str, pathlib.Path], default='flow_system.html'): Path to save the HTML visualization. - False: Visualization is created but not saved. - str or Path: Specifies file path (default: 'flow_system.html').

  • controls (Union[bool, List[str]], default=True): UI controls to add to the visualization.

    • True: Enables all available controls.
    • List: Specify controls, e.g., ['nodes', 'layout'].
    • Options: 'nodes', 'edges', 'layout', 'interaction', 'manipulation', 'physics', 'selection', 'renderer'.
  • show (bool, default=True): Whether to open the visualization in the web browser.

Returns: - Optional[pyvis.network.Network]: The Network instance representing the visualization, or None if pyvis is not installed.

Usage: - Visualize and open the network with default options:

self.visualize_network()

  • Save the visualization without opening:

    self.visualize_network(show=False)

  • Visualize with custom controls and path:

    self.visualize_network(path='output/custom_network.html', controls=['nodes', 'layout'])

Notes: - This function requires pyvis. If not installed, the function prints a warning and returns None. - Nodes are styled based on type (e.g., circles for buses, boxes for components) and annotated with node information.

get_time_data_from_indices
get_time_data_from_indices(time_indices: Optional[Union[List[int], range]] = None) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.float64]

Computes time series data based on the provided time indices.

Args: time_indices: A list of indices or a range object indicating which time steps to extract. If None, the entire time series is used.

Returns: A tuple containing: - Extracted time series - Time series with the "end time" appended - Differences between consecutive timestamps in hours - Total time in hours

Functions

create_datetime_array

create_datetime_array(start: str, steps: Optional[int] = None, freq: str = '1h', end: Optional[str] = None) -> np.ndarray[np.datetime64]

Create a NumPy array with datetime64 values.

Parameters:

Name Type Description Default
start str

Start date in 'YYYY-MM-DD' format or a full timestamp (e.g., 'YYYY-MM-DD HH:MM').

required
steps int

Number of steps in the datetime array. If end is provided, steps is ignored.

None
freq str

Frequency for the datetime64 array. Supports flexible intervals: - 'Y', 'M', 'W', 'D', 'h', 'm', 's' (e.g., '1h', '15m', '2h'). Defaults to 'h' (hourly).

'1h'
end str

End date in 'YYYY-MM-DD' format or a full timestamp (e.g., 'YYYY-MM-DD HH:MM'). If provided, the function generates an array from start to end using freq.

None

Returns:

Type Description
ndarray

NumPy array of datetime64 values.

Examples:

Create an array with 15-minute intervals:

>>> create_datetime_array('2023-01-01', steps=5, freq='15m')
array(['2023-01-01T00:00', '2023-01-01T00:15', '2023-01-01T00:30', ...], dtype='datetime64[m]')

Create 2-hour intervals:

>>> create_datetime_array('2023-01-01T00', steps=4, freq='2h')
array(['2023-01-01T00', '2023-01-01T02', '2023-01-01T04', ...], dtype='datetime64[h]')

Generate minute intervals until a specified end time:

>>> create_datetime_array('2023-01-01T00:00', end='2023-01-01T01:00', freq='m')
array(['2023-01-01T00:00', '2023-01-01T00:01', ..., '2023-01-01T00:59'], dtype='datetime64[m]')