fluxopt.types
¶
Type Aliases:
| Name | Description |
|---|---|
Variate |
Any input that varies over a subset of the model's variate dims ( |
Classes:
| Name | Description |
|---|---|
IdList |
Frozen, ordered container with access by id (str) or position (int). |
Functions:
| Name | Description |
|---|---|
fast_concat |
Stack DataArrays along a new leading dimension. |
as_dataarray |
Convert a Variate to a DataArray aligned to given coordinates. |
normalize_timesteps |
Normalize user-provided timesteps to an internal time index. |
compute_dt |
Compute dt (hours) for each timestep as a DataArray. |
Variate
¶
Any input that varies over a subset of the model's variate dims (time,
optionally period, eventually scenario).
- Scalar: broadcast to all variate dims.
- 1-D (
list/ndarray): matched to a coord by length (must be unambiguous). - 1-D (
pd.Series): index name selects the dim if set; else matched by length. - 2-D (
pd.DataFrame):index.nameandcolumns.namemust match target dims. - n-D (
xr.DataArray): dims must be a subset of the target; coords must match exactly.
Per-field reach (which dims a particular field can vary over) is documented on
the field itself; as_dataarray enforces that user input only uses dims the
caller declared in coords.
IdList
¶
Frozen, ordered container with access by id (str) or position (int).
Supports concatenation via +.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Iterable[T]
|
Elements to store. Must have unique ids. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
On duplicate ids. |
Source code in src/fluxopt/types.py
fast_concat
¶
Stack DataArrays along a new leading dimension.
Drop-in replacement for xr.concat when all slices already share the
same dims, shape, and coords. Skips alignment, deepcopy, and reindex —
just stacks the underlying numpy arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[DataArray]
|
DataArrays with identical dims, shape, and coords. |
required |
|
Index
|
Index for the new leading dimension. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If arrays is empty or any slice has a different shape or dims than the first. |
Source code in src/fluxopt/types.py
as_dataarray
¶
as_dataarray(
value: Variate,
coords: Mapping[str, Any],
*,
name: str = 'value',
broadcast: bool = True,
) -> DataArray
Convert a Variate to a DataArray aligned to given coordinates.
Pipeline: convert → validate dims → validate coord values → broadcast.
See :data:Variate for accepted inputs. Pandas inputs (Series,
DataFrame) follow the same convention as linopy.as_dataarray: the
axis name attribute selects the corresponding target dim. For
ndarray/list, the dim is selected by length (must be unambiguous).
For DataArray, dims must be a subset of coords and coord values must
match exactly — alignment errors are surfaced loudly, not silently masked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Variate
|
Scalar, list, ndarray, Series, DataFrame, or DataArray. |
required |
|
Mapping[str, Any]
|
Target coordinates, e.g. |
required |
|
str
|
Name for the resulting DataArray. |
'value'
|
|
bool
|
Expand result to span all dimensions in coords. |
True
|
Source code in src/fluxopt/types.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
normalize_timesteps
¶
normalize_timesteps(timesteps: Timesteps) -> TimeIndex
Normalize user-provided timesteps to an internal time index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Timesteps
|
Datetime objects, integers, or a DatetimeIndex. |
required |
Returns:
| Type | Description |
|---|---|
TimeIndex
|
A datetime index for datetime inputs, or an integer index for integer inputs. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If timesteps are not strictly monotonically increasing. |
Source code in src/fluxopt/types.py
compute_dt
¶
Compute dt (hours) for each timestep as a DataArray.
When dt is None, auto-derives from timesteps: - Datetime: consecutive differences in hours; first = second (forward-looking). - Integer: 1.0 for all. - Single timestep: 1.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
TimeIndex
|
Time index. |
required |
|
float | list[float] | None
|
Override timestep duration. Validated against timesteps length. |
required |