fluxopt.types
¶
Type Aliases:
| Name | Description |
|---|---|
Variate |
Any input that varies over a subset of the model's variate dims ( |
Classes:
| Name | Description |
|---|---|
ProfileRef |
Reference to a time-series stored outside the model definition. |
Functions:
| Name | Description |
|---|---|
variate_out_of_range |
The first value outside |
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.
ProfileRef
pydantic-model
¶
Bases: BaseModel
Reference to a time-series stored outside the model definition.
A serializable stand-in for an inline Variate array: the profile lives
in a data file / dataset and is named here, so structural definitions
round-trip to YAML/JSON without inlining 8760-point series. Resolve it to a
:class:xr.DataArray with :meth:resolve before building the model.
Show JSON schema:
{
"description": "Reference to a time-series stored outside the model definition.\n\nA serializable stand-in for an inline ``Variate`` array: the profile lives\nin a data file / dataset and is named here, so structural definitions\nround-trip to YAML/JSON without inlining 8760-point series. Resolve it to a\n:class:`xr.DataArray` with :meth:`resolve` before building the model.",
"properties": {
"dataset": {
"title": "Dataset",
"type": "string"
},
"variable": {
"title": "Variable",
"type": "string"
}
},
"required": [
"dataset",
"variable"
],
"title": "ProfileRef",
"type": "object"
}
Config:
frozen:True
Fields:
resolve
¶
Look up the referenced series in profiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Dataset | Mapping[str, DataArray]]
|
Mapping from dataset id to a dataset (or mapping) that
contains |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If dataset or variable is absent from profiles. |
Source code in src/fluxopt/types.py
variate_out_of_range
¶
variate_out_of_range(
value: Variate, *, low: float, high: float, low_open: bool = False
) -> float | None
The first value outside [low, high], or None if all of them are in.
A :data:Variate is a scalar, a series, or a :class:ProfileRef that
names numbers living somewhere else. The first two can be checked where
they are written, which is what this is for; a ProfileRef cannot,
because its values arrive when profiles are resolved — so it reads as in
range here and is checked again once it is real
(docs/design/validation-layers.md).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Variate
|
The declared value. |
required |
|
float
|
Lower bound. |
required |
|
float
|
Upper bound. |
required |
|
bool
|
Whether low itself is excluded. |
False
|
Returns:
| Type | Description |
|---|---|
float | None
|
An offending value, or None. |
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
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 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 | |
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 |