Reading an answer into pandas or xarray¶
How to read a result into pandas or xarray. specsolve installs neither library:
The examples solve dispatch.
As a pandas table¶
import specsolve as sps
result = sps.solve('dispatch.yaml', sources)
print(result.to_pandas('p').head(3))
The table has the shape primal
gives. kind='dual' reads a constraint's duals, and kind='expression' a
named expression:
As a labelled xarray array¶
<xarray.DataArray 'p' (snapshot: 4, generator: 2)> Size: 64B
array([[ 0., 60.],
[ 40., 80.],
[100., 80.],
[ 10., 80.]])
Coordinates:
* snapshot (snapshot) int64 32B 0 1 2 3
* generator (generator) object 16B 'gas' 'wind'
The array is dense. A coordinate that a where: removed comes back NaN. A
label that no row holds is not on the axis, so p has no solar column
(to_dataarray).
Every variable as one xarray dataset¶
result.to_dataset() # every variable
result.to_dataset('power_balance', kind='dual') # the duals you name
One call reads one kind. On a large model, name the few you need.
From a sweep¶
A sweep has the same three bridges. The slice key
of a scenario sweep becomes a dimension. A rolling horizon comes back over the
dimension it sliced, or window by window with per_window=True: