fluxopt.model_data
¶
Classes:
| Name | Description |
|---|---|
FlowsData |
|
CarriersData |
|
ConvertersData |
|
PiecewiseData |
Piecewise-linear conversion data for converters with |
EffectsData |
|
StoragesData |
|
Dims |
Shared model coordinates and temporal metadata. |
ModelData |
|
FlowsData
dataclass
¶
FlowsData(
bound_type: DataArray,
rel_lb: DataArray,
rel_ub: DataArray,
fixed_profile: DataArray,
size: DataArray,
effect_coeff: DataArray,
sizing_min: DataArray | None = None,
sizing_max: DataArray | None = None,
sizing_mandatory: DataArray | None = None,
sizing_effects_per_size: DataArray | None = None,
sizing_effects_fixed: DataArray | None = None,
status_min_uptime: DataArray | None = None,
status_max_uptime: DataArray | None = None,
status_min_downtime: DataArray | None = None,
status_max_downtime: DataArray | None = None,
status_initial: DataArray | None = None,
status_effects_running: DataArray | None = None,
status_effects_startup: DataArray | None = None,
status_previous_uptime: DataArray | None = None,
status_previous_downtime: DataArray | None = None,
invest_min: DataArray | None = None,
invest_max: DataArray | None = None,
invest_mandatory: DataArray | None = None,
invest_lifetime: DataArray | None = None,
invest_prior_size: DataArray | None = None,
invest_effects_per_size_at_build: DataArray | None = None,
invest_effects_fixed_at_build: DataArray | None = None,
invest_effects_per_size_recurring: DataArray | None = None,
invest_effects_fixed_recurring: DataArray | None = None,
cstatus_min_uptime: DataArray | None = None,
cstatus_max_uptime: DataArray | None = None,
cstatus_min_downtime: DataArray | None = None,
cstatus_max_downtime: DataArray | None = None,
cstatus_initial: DataArray | None = None,
cstatus_effects_running: DataArray | None = None,
cstatus_effects_startup: DataArray | None = None,
cstatus_previous_uptime: DataArray | None = None,
cstatus_previous_downtime: DataArray | None = None,
cstatus_governed_flows: DataArray | None = None,
)
Methods:
| Name | Description |
|---|---|
__post_init__ |
Validate relative bounds: non-negative and lb <= ub. |
to_dataset |
Serialize to xr.Dataset. |
from_dataset |
Deserialize from xr.Dataset. |
build |
Build FlowsData from element objects. |
__post_init__
¶
Validate relative bounds: non-negative and lb <= ub.
Source code in src/fluxopt/model_data.py
from_dataset
classmethod
¶
build
classmethod
¶
build(
flows: list[Flow],
time: TimeIndex,
effects: list[Effect],
dt: float = 1.0,
period: Index | None = None,
component_status_items: list[tuple[str, Status, list[str]]] | None = None,
) -> Self
Build FlowsData from element objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Flow]
|
All collected flows with qualified ids. |
required |
|
TimeIndex
|
Time index. |
required |
|
list[Effect]
|
Effect definitions for cost coefficients. |
required |
|
float
|
Scalar timestep duration in hours for prior duration computation. |
1.0
|
|
Index | None
|
Period index for multi-period models. When provided,
|
None
|
|
list[tuple[str, Status, list[str]]] | None
|
Component-level status entries as
|
None
|
Source code in src/fluxopt/model_data.py
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |
CarriersData
dataclass
¶
Methods:
| Name | Description |
|---|---|
to_dataset |
Serialize to xr.Dataset. |
from_dataset |
Deserialize from xr.Dataset. |
build |
Build CarriersData from explicit carrier declarations. |
from_dataset
classmethod
¶
build
classmethod
¶
Build CarriersData from explicit carrier declarations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Carrier]
|
Declared carriers. |
required |
|
list[Flow]
|
All collected flows. |
required |
|
dict[str, float]
|
Mapping of flow id to +1 (produces) or -1 (consumes). |
required |
Source code in src/fluxopt/model_data.py
ConvertersData
dataclass
¶
ConvertersData(
pair_coeff: DataArray,
pair_converter: DataArray,
pair_flow: DataArray,
eq_mask: DataArray,
)
Methods:
| Name | Description |
|---|---|
to_dataset |
Serialize to xr.Dataset. |
from_dataset |
Deserialize from xr.Dataset. |
build |
Build ConvertersData with sparse pair-based conversion coefficients. |
Attributes:
| Name | Type | Description |
|---|---|---|
flow_coeff |
DataArray
|
Dense (converter, eq_idx, flow, time) view for inspection. |
flow_coeff
property
¶
flow_coeff: DataArray
Dense (converter, eq_idx, flow, time) view for inspection.
from_dataset
classmethod
¶
build
classmethod
¶
build(converters: list[Converter], time: TimeIndex) -> Self | None
Build ConvertersData with sparse pair-based conversion coefficients.
Only linear converters are included; piecewise converters
(conversion is not None) live in :class:PiecewiseData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Converter]
|
Converter definitions. |
required |
|
TimeIndex
|
Time index. |
required |
Source code in src/fluxopt/model_data.py
PiecewiseData
dataclass
¶
PiecewiseData(
breakpoints: DataArray,
pair_converter: DataArray,
pair_flow: DataArray,
pair_bound: DataArray,
method: DataArray,
availability: DataArray,
has_status: DataArray,
)
Piecewise-linear conversion data for converters with PiecewiseConversion.
Stored sparsely as one row per (converter, flow) pair; the method
and availability arrays index by pw_converter.
Methods:
| Name | Description |
|---|---|
to_dataset |
Serialize to xr.Dataset. |
from_dataset |
Deserialize from xr.Dataset. |
converter_ids |
Return list of piecewise converter ids in original order. |
build |
Build PiecewiseData from converters with |
from_dataset
classmethod
¶
Deserialize from xr.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Dataset
|
Dataset with piecewise variables. |
required |
Source code in src/fluxopt/model_data.py
converter_ids
¶
build
classmethod
¶
build(converters: list[Converter], time: TimeIndex) -> Self | None
Build PiecewiseData from converters with PiecewiseConversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Converter]
|
Converter definitions; only those with
|
required |
|
TimeIndex
|
Time index for breakpoint and availability arrays. |
required |
Source code in src/fluxopt/model_data.py
EffectsData
dataclass
¶
EffectsData(
min_bound: DataArray,
max_bound: DataArray,
min_per_period: DataArray,
max_per_period: DataArray,
min_per_hour: DataArray,
max_per_hour: DataArray,
cf_temporal: DataArray | None = None,
period_weights: DataArray | None = None,
)
Methods:
| Name | Description |
|---|---|
to_dataset |
Serialize to xr.Dataset. |
from_dataset |
Deserialize from xr.Dataset. |
build |
Build EffectsData from element objects. |
from_dataset
classmethod
¶
Deserialize from xr.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Dataset
|
Dataset with effect variables and attrs. |
required |
Source code in src/fluxopt/model_data.py
build
classmethod
¶
Build EffectsData from element objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Effect]
|
Effect definitions. |
required |
|
TimeIndex
|
Time index. |
required |
|
Index | None
|
Period index (multi-period only). |
None
|
Source code in src/fluxopt/model_data.py
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 | |
StoragesData
dataclass
¶
StoragesData(
capacity: DataArray,
eta_c: DataArray,
eta_d: DataArray,
loss: DataArray,
rel_level_lb: DataArray,
rel_level_ub: DataArray,
prior_level: DataArray,
cyclic: DataArray,
charge_flow: DataArray,
discharge_flow: DataArray,
sizing_min: DataArray | None = None,
sizing_max: DataArray | None = None,
sizing_mandatory: DataArray | None = None,
sizing_effects_per_size: DataArray | None = None,
sizing_effects_fixed: DataArray | None = None,
invest_min: DataArray | None = None,
invest_max: DataArray | None = None,
invest_mandatory: DataArray | None = None,
invest_lifetime: DataArray | None = None,
invest_prior_size: DataArray | None = None,
invest_effects_per_size_at_build: DataArray | None = None,
invest_effects_fixed_at_build: DataArray | None = None,
invest_effects_per_size_recurring: DataArray | None = None,
invest_effects_fixed_recurring: DataArray | None = None,
)
Methods:
| Name | Description |
|---|---|
__post_init__ |
Validate capacity, efficiencies, and loss rates. |
to_dataset |
Serialize to xr.Dataset. |
from_dataset |
Deserialize from xr.Dataset. |
build |
Build StoragesData from element objects. |
__post_init__
¶
Validate capacity, efficiencies, and loss rates.
Source code in src/fluxopt/model_data.py
from_dataset
classmethod
¶
build
classmethod
¶
build(
storages: list[Storage],
time: TimeIndex,
dt: DataArray,
effects: list[Effect] | None = None,
period: Index | None = None,
) -> Self | None
Build StoragesData from element objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Storage]
|
Storage definitions. |
required |
|
TimeIndex
|
Time index. |
required |
|
DataArray
|
Timestep durations. |
required |
|
list[Effect] | None
|
Effect definitions for sizing cost validation. |
None
|
|
Index | None
|
Period index for period-varying effects. |
None
|
Source code in src/fluxopt/model_data.py
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 | |
Dims
dataclass
¶
Dims(
time: DataArray,
dt: DataArray,
weights: DataArray,
period: DataArray | None = None,
period_weights: DataArray | None = None,
)
Shared model coordinates and temporal metadata.
Owns the time and period dimensions, timestep durations, and weights.
Methods:
| Name | Description |
|---|---|
coords |
Return shared coordinates for variable/DataArray creation. |
to_dataset |
Serialize to xr.Dataset. |
from_dataset |
Deserialize from xr.Dataset. |
build |
Build Dims from a time index and optional periods. |
coords
¶
Return shared coordinates for variable/DataArray creation.
Also the single point of truth for the model's variate dims used by
:func:fluxopt.types.as_dataarray: pick the reach a field supports
(e.g. coords(time=True, period=True) for operational profiles,
coords(period=True) for investment-time fields). When a new
variate dim (e.g. scenario) is added, extend this method once
and every call site picks it up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Include the time coordinate. |
False
|
|
bool
|
Include the period coordinate (no-op in single-period mode). |
False
|
Source code in src/fluxopt/model_data.py
to_dataset
¶
to_dataset() -> Dataset
Serialize to xr.Dataset.
Source code in src/fluxopt/model_data.py
from_dataset
classmethod
¶
Deserialize from xr.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Dataset
|
Dataset with dt, weights, and optional period fields. |
required |
Source code in src/fluxopt/model_data.py
build
classmethod
¶
build(
time: TimeIndex,
dt: DataArray,
periods: list[int] | Index | None = None,
period_weights: list[float] | None = None,
) -> Self
Build Dims from a time index and optional periods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
TimeIndex
|
Normalized time index. |
required |
|
DataArray
|
Timestep durations. |
required |
|
list[int] | Index | None
|
Integer period labels for multi-period optimization. |
None
|
|
list[float] | None
|
Explicit weights per period. Inferred from gaps if None. |
None
|
Source code in src/fluxopt/model_data.py
ModelData
dataclass
¶
ModelData(
flows: FlowsData,
carriers: CarriersData,
converters: ConvertersData | None,
effects: EffectsData,
storages: StoragesData | None,
dims: Dims,
piecewise: PiecewiseData | None = None,
)
Methods:
| Name | Description |
|---|---|
to_netcdf |
Write model data as NetCDF groups under |
from_netcdf |
Read model data from NetCDF groups. |
build |
Build ModelData from element objects. |
to_netcdf
¶
Write model data as NetCDF groups under /model/.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Output file path. |
required |
|
Literal['w', 'a']
|
Write mode ('w' to overwrite, 'a' to append). |
'a'
|
Source code in src/fluxopt/model_data.py
from_netcdf
classmethod
¶
Read model data from NetCDF groups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Input file path. |
required |
Raises:
| Type | Description |
|---|---|
OSError
|
If no model data groups found in the file. |
Source code in src/fluxopt/model_data.py
build
classmethod
¶
build(
timesteps: Timesteps,
carriers: list[Carrier],
effects: list[Effect],
ports: list[Port],
converters: list[Converter] | None = None,
storages: list[Storage] | None = None,
dt: float | list[float] | None = None,
periods: list[int] | Index | None = None,
period_weights: list[float] | None = None,
) -> Self
Build ModelData from element objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Timesteps
|
Time index for the optimization horizon. |
required |
|
list[Carrier]
|
Carrier declarations. |
required |
|
list[Effect]
|
Effects to track. |
required |
|
list[Port]
|
System boundary ports. |
required |
|
list[Converter] | None
|
Linear converters. |
None
|
|
list[Storage] | None
|
Energy storages. |
None
|
|
float | list[float] | None
|
Timestep duration in hours. Auto-derived if None. |
None
|
|
list[int] | Index | None
|
Integer period labels for multi-period optimization. |
None
|
|
list[float] | None
|
Explicit weights per period. Inferred from gaps if None. |
None
|
Source code in src/fluxopt/model_data.py
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 | |