flixopt.comparison ¶
Compare multiple FlowSystems side-by-side.
Attributes¶
Classes¶
Comparison ¶
Compare multiple FlowSystems side-by-side.
Combines solutions, statistics, and inputs from multiple FlowSystems into unified xarray Datasets with a 'case' dimension. The existing plotting infrastructure automatically handles faceting by the 'case' dimension.
For comparing solutions/statistics, all FlowSystems must be optimized and have matching dimensions. For comparing inputs only, optimization is not required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow_systems | list[FlowSystem] | List of FlowSystems to compare. | required |
names | list[str] | None | Optional names for each case. If None, uses FlowSystem.name. | None |
Raises:
| Type | Description |
|---|---|
ValueError | If case names are not unique. |
RuntimeError | If accessing solution/statistics without optimized FlowSystems. |
Examples:
# Compare two systems (uses FlowSystem.name by default)
comp = fx.Comparison([fs_base, fs_modified])
# Or with custom names
comp = fx.Comparison([fs_base, fs_modified], names=['baseline', 'modified'])
# Side-by-side plots (auto-facets by 'case')
comp.stats.plot.balance('Heat')
comp.stats.flow_rates.plotly.line()
# Access combined data
comp.solution # xr.Dataset with 'case' dimension
comp.stats.flow_rates # xr.Dataset with 'case' dimension
# Compute differences relative to first case
comp.diff() # Returns xr.Dataset of differences
comp.diff('baseline') # Or specify reference by name
# For systems with different dimensions, align first:
fs_both = ... # Has scenario dimension
fs_mild = fs_both.transform.sel(scenario='Mild') # Select one scenario
fs_other = ... # Also select to match
comp = fx.Comparison([fs_mild, fs_other]) # Now dimensions match
Attributes¶
flow_systems property ¶
Access underlying FlowSystems as a dict mapping name → FlowSystem.
dims property ¶
Shared dimensions across all FlowSystems.
Returns dimensions that exist in all systems with matching sizes.
inputs property ¶
Combined input data Dataset with 'case' dimension.
Concatenates input parameters from all FlowSystems. Each FlowSystem's .inputs Dataset is combined with a 'case' dimension.
Returns:
| Type | Description |
|---|---|
Dataset | xr.Dataset with all input parameters. Variable naming follows |
Dataset | the pattern |
Examples:
Functions¶
diff ¶
ComparisonStatistics ¶
Combined statistics accessor for comparing FlowSystems.
Mirrors StatisticsAccessor properties, concatenating data with a 'case' dimension. Access via Comparison.stats.
Attributes¶
storage_sizes property ¶
Combined storage capacity sizes with 'case' dimension.
charge_states property ¶
Combined storage charge states with 'case' dimension.
temporal_effects property ¶
Combined temporal effects with 'case' dimension.
periodic_effects property ¶
Combined periodic effects with 'case' dimension.
component_colors property ¶
Merged component colors from all cases.
flow_colors property ¶
Merged flow colors from all cases (derived from parent components).
ComparisonStatisticsPlot ¶
Plot accessor for comparison statistics.
Wraps StatisticsPlotAccessor methods, combining data from all FlowSystems with a 'case' dimension for faceting.
Functions¶
balance ¶
balance(node: str, *, select: SelectType | None = None, include: str | list[str] | None = None, exclude: str | list[str] | None = None, unit: Literal['flow_rate', 'flow_hours'] = 'flow_rate', colors: ColorType | None = None, threshold: float | None = 1e-05, show: bool | None = None, data_only: bool = False, **plotly_kwargs: Any) -> PlotResult
Plot node balance comparison across cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node | str | Bus or component label to plot balance for. | required |
select | SelectType | None | xarray-style selection. | None |
include | str | list[str] | None | Filter to include only matching flow labels. | None |
exclude | str | list[str] | None | Filter to exclude matching flow labels. | None |
unit | Literal['flow_rate', 'flow_hours'] | 'flow_rate' or 'flow_hours'. | 'flow_rate' |
colors | ColorType | None | Color specification (dict, list, or colorscale name). | None |
threshold | float | None | Filter out variables where max absolute value is below this. | 1e-05 |
show | bool | None | Whether to display the figure. | None |
data_only | bool | If True, skip figure creation and return only data. | False |
**plotly_kwargs | Any | Additional arguments passed to plotly. | {} |
Returns:
| Type | Description |
|---|---|
PlotResult | PlotResult with combined balance data and figure. |
carrier_balance ¶
carrier_balance(carrier: str, *, select: SelectType | None = None, include: str | list[str] | None = None, exclude: str | list[str] | None = None, unit: Literal['flow_rate', 'flow_hours'] = 'flow_rate', colors: ColorType | None = None, threshold: float | None = 1e-05, show: bool | None = None, data_only: bool = False, **plotly_kwargs: Any) -> PlotResult
Plot carrier balance comparison across cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
carrier | str | Carrier name to plot balance for. | required |
select | SelectType | None | xarray-style selection. | None |
include | str | list[str] | None | Filter to include only matching flow labels. | None |
exclude | str | list[str] | None | Filter to exclude matching flow labels. | None |
unit | Literal['flow_rate', 'flow_hours'] | 'flow_rate' or 'flow_hours'. | 'flow_rate' |
colors | ColorType | None | Color specification (dict, list, or colorscale name). | None |
threshold | float | None | Filter out variables where max absolute value is below this. | 1e-05 |
show | bool | None | Whether to display the figure. | None |
data_only | bool | If True, skip figure creation and return only data. | False |
**plotly_kwargs | Any | Additional arguments passed to plotly. | {} |
Returns:
| Type | Description |
|---|---|
PlotResult | PlotResult with combined carrier balance data and figure. |
flows ¶
flows(*, start: str | list[str] | None = None, end: str | list[str] | None = None, component: str | list[str] | None = None, select: SelectType | None = None, unit: Literal['flow_rate', 'flow_hours'] = 'flow_rate', colors: ColorType | None = None, threshold: float | None = 1e-05, show: bool | None = None, data_only: bool = False, **plotly_kwargs: Any) -> PlotResult
Plot flows comparison across cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start | str | list[str] | None | Filter by source node(s). | None |
end | str | list[str] | None | Filter by destination node(s). | None |
component | str | list[str] | None | Filter by parent component(s). | None |
select | SelectType | None | xarray-style selection. | None |
unit | Literal['flow_rate', 'flow_hours'] | 'flow_rate' or 'flow_hours'. | 'flow_rate' |
colors | ColorType | None | Color specification (dict, list, or colorscale name). | None |
threshold | float | None | Filter out variables where max absolute value is below this. | 1e-05 |
show | bool | None | Whether to display the figure. | None |
data_only | bool | If True, skip figure creation and return only data. | False |
**plotly_kwargs | Any | Additional arguments passed to plotly. | {} |
Returns:
| Type | Description |
|---|---|
PlotResult | PlotResult with combined flows data and figure. |
storage ¶
storage(storage: str, *, select: SelectType | None = None, unit: Literal['flow_rate', 'flow_hours'] = 'flow_rate', colors: ColorType | None = None, threshold: float | None = 1e-05, show: bool | None = None, data_only: bool = False, **plotly_kwargs: Any) -> PlotResult
Plot storage operation comparison across cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage | str | Storage component label. | required |
select | SelectType | None | xarray-style selection. | None |
unit | Literal['flow_rate', 'flow_hours'] | 'flow_rate' or 'flow_hours'. | 'flow_rate' |
colors | ColorType | None | Color specification for flow bars. | None |
threshold | float | None | Filter out variables where max absolute value is below this. | 1e-05 |
show | bool | None | Whether to display the figure. | None |
data_only | bool | If True, skip figure creation and return only data. | False |
**plotly_kwargs | Any | Additional arguments passed to plotly. | {} |
Returns:
| Type | Description |
|---|---|
PlotResult | PlotResult with combined storage operation data and figure. |
charge_states ¶
charge_states(storages: str | list[str] | None = None, *, select: SelectType | None = None, colors: ColorType | None = None, threshold: float | None = 1e-05, show: bool | None = None, data_only: bool = False, **plotly_kwargs: Any) -> PlotResult
Plot charge states comparison across cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storages | str | list[str] | None | Storage label(s) to plot. If None, plots all. | None |
select | SelectType | None | xarray-style selection. | None |
colors | ColorType | None | Color specification (dict, list, or colorscale name). | None |
threshold | float | None | Filter out variables where max absolute value is below this. | 1e-05 |
show | bool | None | Whether to display the figure. | None |
data_only | bool | If True, skip figure creation and return only data. | False |
**plotly_kwargs | Any | Additional arguments passed to plotly. | {} |
Returns:
| Type | Description |
|---|---|
PlotResult | PlotResult with combined charge state data and figure. |
duration_curve ¶
duration_curve(variables: str | list[str], *, select: SelectType | None = None, normalize: bool = False, colors: ColorType | None = None, threshold: float | None = 1e-05, show: bool | None = None, data_only: bool = False, **plotly_kwargs: Any) -> PlotResult
Plot duration curves comparison across cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variables | str | list[str] | Flow label(s) or variable name(s) to plot. | required |
select | SelectType | None | xarray-style selection. | None |
normalize | bool | If True, normalize x-axis to 0-100%. | False |
colors | ColorType | None | Color specification (dict, list, or colorscale name). | None |
threshold | float | None | Filter out variables where max absolute value is below this. | 1e-05 |
show | bool | None | Whether to display the figure. | None |
data_only | bool | If True, skip figure creation and return only data. | False |
**plotly_kwargs | Any | Additional arguments passed to plotly. | {} |
Returns:
| Type | Description |
|---|---|
PlotResult | PlotResult with combined duration curve data and figure. |
sizes ¶
sizes(*, max_size: float | None = 1000000.0, select: SelectType | None = None, colors: ColorType | None = None, threshold: float | None = 1e-05, show: bool | None = None, data_only: bool = False, **plotly_kwargs: Any) -> PlotResult
Plot investment sizes comparison across cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_size | float | None | Maximum size to include (filters defaults). | 1000000.0 |
select | SelectType | None | xarray-style selection. | None |
colors | ColorType | None | Color specification (dict, list, or colorscale name). | None |
threshold | float | None | Filter out variables where max absolute value is below this. | 1e-05 |
show | bool | None | Whether to display the figure. | None |
data_only | bool | If True, skip figure creation and return only data. | False |
**plotly_kwargs | Any | Additional arguments passed to plotly. | {} |
Returns:
| Type | Description |
|---|---|
PlotResult | PlotResult with combined sizes data and figure. |
effects ¶
effects(aspect: Literal['total', 'temporal', 'periodic'] = 'total', *, effect: str | None = None, by: Literal['component', 'contributor', 'time'] | None = None, select: SelectType | None = None, colors: ColorType | None = None, threshold: float | None = 1e-05, show: bool | None = None, data_only: bool = False, **plotly_kwargs: Any) -> PlotResult
Plot effects comparison across cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aspect | Literal['total', 'temporal', 'periodic'] | Which aspect to plot - 'total', 'temporal', or 'periodic'. | 'total' |
effect | str | None | Specific effect name to plot. If None, plots all. | None |
by | Literal['component', 'contributor', 'time'] | None | Group by 'component', 'contributor', or 'time'. | None |
select | SelectType | None | xarray-style selection. | None |
colors | ColorType | None | Color specification (dict, list, or colorscale name). | None |
threshold | float | None | Filter out variables where max absolute value is below this. | 1e-05 |
show | bool | None | Whether to display the figure. | None |
data_only | bool | If True, skip figure creation and return only data. | False |
**plotly_kwargs | Any | Additional arguments passed to plotly. | {} |
Returns:
| Type | Description |
|---|---|
PlotResult | PlotResult with combined effects data and figure. |
heatmap ¶
heatmap(variables: str | list[str], *, select: SelectType | None = None, reshape: tuple[str, str] | Literal['auto'] | None = 'auto', colors: str | list[str] | None = None, threshold: float | None = 1e-05, show: bool | None = None, data_only: bool = False, **plotly_kwargs: Any) -> PlotResult
Plot heatmap comparison across cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variables | str | list[str] | Flow label(s) or variable name(s) to plot. | required |
select | SelectType | None | xarray-style selection. | None |
reshape | tuple[str, str] | Literal['auto'] | None | Time reshape frequencies, 'auto', or None. | 'auto' |
colors | str | list[str] | None | Colorscale name or list of colors. | None |
threshold | float | None | Filter out variables where max absolute value is below this. | 1e-05 |
show | bool | None | Whether to display the figure. | None |
data_only | bool | If True, skip figure creation and return only data. | False |
**plotly_kwargs | Any | Additional arguments passed to plotly. | {} |
Returns:
| Type | Description |
|---|---|
PlotResult | PlotResult with combined heatmap data and figure. |