fluxopt.model_data ¶
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: DataArray | None = None,
invest_effects_fixed: DataArray | None = None,
invest_effects_per_size_periodic: DataArray | None = None,
invest_effects_fixed_periodic: DataArray | None = None,
)
__post_init__ ¶
Validate relative bounds: non-negative and lb <= ub.
Source code in src/fluxopt/model_data.py
to_dataset ¶
from_dataset
classmethod
¶
Deserialize from xr.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with matching variable names. |
required |
Source code in src/fluxopt/model_data.py
build
classmethod
¶
build(
flows: list[Flow],
time: TimeIndex,
effects: list[Effect],
dt: float = 1.0,
period: Index | None = None,
) -> Self
Build FlowsData from element objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flows
|
list[Flow]
|
All collected flows with qualified ids. |
required |
time
|
TimeIndex
|
Time index. |
required |
effects
|
list[Effect]
|
Effect definitions for cost coefficients. |
required |
dt
|
float
|
Scalar timestep duration in hours for prior duration computation. |
1.0
|
period
|
Index | None
|
Period index for multi-period models. When provided,
|
None
|
Source code in src/fluxopt/model_data.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 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 | |
CarriersData
dataclass
¶
to_dataset ¶
from_dataset
classmethod
¶
Deserialize from xr.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with |
required |
Source code in src/fluxopt/model_data.py
build
classmethod
¶
Build CarriersData from explicit carrier declarations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
carriers
|
list[Carrier]
|
Declared carriers. |
required |
flows
|
list[Flow]
|
All collected flows. |
required |
carrier_coeff
|
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,
)
flow_coeff
property
¶
Dense (converter, eq_idx, flow, time) view for inspection.
to_dataset ¶
from_dataset
classmethod
¶
Deserialize from xr.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with pair-based converter coefficient variables. |
required |
Source code in src/fluxopt/model_data.py
build
classmethod
¶
Build ConvertersData with sparse pair-based conversion coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
converters
|
list[Converter]
|
Converter definitions. |
required |
time
|
TimeIndex
|
Time index. |
required |
Source code in src/fluxopt/model_data.py
EffectsData
dataclass
¶
EffectsData(
min_total: DataArray,
max_total: DataArray,
min_per_hour: DataArray,
max_per_hour: DataArray,
is_objective: DataArray,
objective_effect: str,
cf_periodic: DataArray | None = None,
cf_temporal: DataArray | None = None,
period_weights_periodic: DataArray | None = None,
period_weights_once: DataArray | None = None,
)
__post_init__ ¶
Validate exactly one objective effect exists.
Source code in src/fluxopt/model_data.py
objective_weights ¶
objective_weights(
global_period_weights: DataArray | None,
) -> tuple[xr.DataArray | int, xr.DataArray | int]
Resolve period weights for the objective effect's two domains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
global_period_weights
|
DataArray | None
|
Default period weights from Dims (or None). |
required |
Returns:
| Type | Description |
|---|---|
DataArray | int
|
(w_periodic, w_once) — weights for recurring and one-time domains. |
DataArray | int
|
Falls back to global_period_weights / 1 when no per-effect override. |
Source code in src/fluxopt/model_data.py
to_dataset ¶
from_dataset
classmethod
¶
Deserialize from xr.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
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 |
|---|---|---|---|
effects
|
list[Effect]
|
Effect definitions. |
required |
time
|
TimeIndex
|
Time index. |
required |
period
|
Index | None
|
Period index (multi-period only). |
None
|
Source code in src/fluxopt/model_data.py
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | |
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: DataArray | None = None,
invest_effects_fixed: DataArray | None = None,
invest_effects_per_size_periodic: DataArray | None = None,
invest_effects_fixed_periodic: DataArray | None = None,
)
__post_init__ ¶
Validate capacity, efficiencies, and loss rates.
Source code in src/fluxopt/model_data.py
to_dataset ¶
from_dataset
classmethod
¶
Deserialize from xr.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with matching variable names. |
required |
Source code in src/fluxopt/model_data.py
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 |
|---|---|---|---|
storages
|
list[Storage]
|
Storage definitions. |
required |
time
|
TimeIndex
|
Time index. |
required |
dt
|
DataArray
|
Timestep durations. |
required |
effects
|
list[Effect] | None
|
Effect definitions for sizing cost validation. |
None
|
period
|
Index | None
|
Period index for period-varying effects. |
None
|
Source code in src/fluxopt/model_data.py
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 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 | |
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.
coords ¶
Return shared coordinates for variable/DataArray creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
bool
|
Include the time coordinate. |
False
|
period
|
bool
|
Include the period coordinate (no-op in single-period mode). |
False
|
Source code in src/fluxopt/model_data.py
to_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 |
|---|---|---|---|
ds
|
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 |
|---|---|---|---|
time
|
TimeIndex
|
Normalized time index. |
required |
dt
|
DataArray
|
Timestep durations. |
required |
periods
|
list[int] | Index | None
|
Integer period labels for multi-period optimization. |
None
|
period_weights
|
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,
)
to_netcdf ¶
Write model data as NetCDF groups under /model/.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Output file path. |
required |
mode
|
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 |
|---|---|---|---|
path
|
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
|
Timesteps
|
Time index for the optimization horizon. |
required |
carriers
|
list[Carrier]
|
Carrier declarations. |
required |
effects
|
list[Effect]
|
Effects to track. |
required |
ports
|
list[Port]
|
System boundary ports. |
required |
converters
|
list[Converter] | None
|
Linear converters. |
None
|
storages
|
list[Storage] | None
|
Energy storages. |
None
|
dt
|
float | list[float] | None
|
Timestep duration in hours. Auto-derived if None. |
None
|
periods
|
list[int] | Index | None
|
Integer period labels for multi-period optimization. |
None
|
period_weights
|
list[float] | None
|
Explicit weights per period. Inferred from gaps if None. |
None
|