opensced 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opensced/__init__.py +32 -0
- opensced/core/__init__.py +0 -0
- opensced/core/features/__init__.py +7 -0
- opensced/core/features/balance.py +74 -0
- opensced/core/features/mitigation.py +102 -0
- opensced/core/features/network.py +69 -0
- opensced/core/features/reserves.py +169 -0
- opensced/core/features/storage.py +110 -0
- opensced/core/market.py +97 -0
- opensced/core/model.py +181 -0
- opensced/core/program.py +107 -0
- opensced/core/result.py +159 -0
- opensced/core/rules.py +343 -0
- opensced/core/score.py +75 -0
- opensced/core/sequence.py +105 -0
- opensced/core/tables.py +296 -0
- opensced/examples.py +59 -0
- opensced/markets/__init__.py +2 -0
- opensced/markets/ercot/__init__.py +8 -0
- opensced/markets/ercot/adapter.py +911 -0
- opensced/markets/ercot/helpers.py +277 -0
- opensced/markets/ercot/pricing.py +284 -0
- opensced/markets/ercot/rulebooks.py +164 -0
- opensced-0.1.0.dist-info/METADATA +276 -0
- opensced-0.1.0.dist-info/RECORD +27 -0
- opensced-0.1.0.dist-info/WHEEL +4 -0
- opensced-0.1.0.dist-info/licenses/LICENSE +202 -0
opensced/core/tables.py
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"""The input contract: the plain tables one clearing takes, whatever market they came from.
|
|
2
|
+
|
|
3
|
+
Everything the engine knows about an interval arrives through an `Inputs` object. Each table is a pandas DataFrame
|
|
4
|
+
with the columns listed in TABLES below. `opensced.schema()` prints this as a data dictionary, and
|
|
5
|
+
`Inputs.validate()` checks a set of tables against it.
|
|
6
|
+
|
|
7
|
+
Sign conventions
|
|
8
|
+
MW injection into the grid is positive. A battery charging, or a load, is negative.
|
|
9
|
+
shift factor MW of flow on a constraint per MW injected at a node.
|
|
10
|
+
shadow price >= 0. A node's price is lambda - sum(shift factor x shadow price).
|
|
11
|
+
"""
|
|
12
|
+
from dataclasses import dataclass, field, fields, replace
|
|
13
|
+
|
|
14
|
+
import numpy as np
|
|
15
|
+
import pandas as pd
|
|
16
|
+
|
|
17
|
+
SCHEMA_VERSION = '2'
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class Column:
|
|
22
|
+
name: str
|
|
23
|
+
dtype: str # 'text', 'number', 'bool'
|
|
24
|
+
unit: str
|
|
25
|
+
required: bool
|
|
26
|
+
default: object
|
|
27
|
+
doc: str
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True)
|
|
31
|
+
class Table:
|
|
32
|
+
name: str
|
|
33
|
+
row: str # what one row is
|
|
34
|
+
doc: str
|
|
35
|
+
columns: tuple
|
|
36
|
+
key: tuple = () # columns that must be unique together
|
|
37
|
+
required: bool = False
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _c(name, dtype, unit, required, default, doc):
|
|
41
|
+
return Column(name, dtype, unit, required, default, doc)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
TABLES = {t.name: t for t in (
|
|
45
|
+
Table('resources', 'resource', 'Everything that can inject, consume or carry reserves in this interval.', (
|
|
46
|
+
_c('name', 'text', '', True, None, 'Unique id of the resource.'),
|
|
47
|
+
_c('low', 'number', 'MW', True, None, 'Lowest output it can sustain (its low sustained limit). Negative for a battery that can charge.'),
|
|
48
|
+
_c('high', 'number', 'MW', True, None, 'Highest output it can sustain (its high sustained limit).'),
|
|
49
|
+
_c('ramp_low', 'number', 'MW', False, 'low', 'Lowest output it can reach within this interval, given where it is now and its ramp rate.'),
|
|
50
|
+
_c('ramp_high', 'number', 'MW', False, 'high', 'Highest output it can reach within this interval.'),
|
|
51
|
+
_c('output', 'number', 'MW', False, 0.0, 'Its output going into the interval. A resource that is not dispatchable is held here, and the constraints\' `flow` is measured with every resource at this output.'),
|
|
52
|
+
_c('dispatchable', 'bool', '', False, True, 'True if the clearing may move it. False holds it at `output` (it may still carry reserves).'),
|
|
53
|
+
_c('kind', 'text', '', False, 'generator', "'generator', 'storage' or 'load'. Informational, except that a 'load' carries reserves by cutting consumption."),
|
|
54
|
+
_c('status', 'text', '', False, '', 'The market\'s status code for the resource. A rulebook\'s `statuses` say what each may do; adapters use it.'),
|
|
55
|
+
_c('type', 'text', '', False, '', 'The market\'s resource type. Rulebook limits can select on it.'),
|
|
56
|
+
_c('category', 'text', '', False, 'other', 'Fuel or technology category, for helpers that build proxy curves or mitigated offers.'),
|
|
57
|
+
_c('ramp_up', 'number', 'MW/min', False, None, 'Normal ramp rate up. Used by helpers that compute ramp_high.'),
|
|
58
|
+
_c('ramp_down', 'number', 'MW/min', False, None, 'Normal ramp rate down. Used by helpers that compute ramp_low.'),
|
|
59
|
+
_c('output_schedule', 'number', 'MW', False, None, 'Scheduled output of a resource that submitted a schedule instead of an offer curve.'),
|
|
60
|
+
_c('ruc_committed', 'bool', '', False, False, 'Committed by the reliability unit commitment process.'),
|
|
61
|
+
_c('mitigated', 'bool', '', False, False, 'Its offer is capped in the second step of a two-step clearing: it failed the market\'s competitiveness test for this interval.'),
|
|
62
|
+
_c('max_consumption', 'number', 'MW', False, None, 'Maximum power consumption of a load resource.'),
|
|
63
|
+
_c('low_consumption', 'number', 'MW', False, None, 'Low power consumption of a load resource.'),
|
|
64
|
+
), key=('name',), required=True),
|
|
65
|
+
Table('energy_offers', 'offer curve point', 'Each resource\'s energy offer curve. Price is linear between points and flat beyond the ends. A dispatchable resource with no points offers at $0.', (
|
|
66
|
+
_c('resource', 'text', '', True, None, 'Resource name.'),
|
|
67
|
+
_c('mw', 'number', 'MW', True, None, 'Output level. Negative MW is consumption: a battery\'s charging bid.'),
|
|
68
|
+
_c('price', 'number', '$/MWh', True, None, 'Offer price at that output.'),
|
|
69
|
+
)),
|
|
70
|
+
Table('storage', 'battery', 'State of charge of each storage resource. Only needed when reserves are cleared.', (
|
|
71
|
+
_c('resource', 'text', '', True, None, 'Resource name.'),
|
|
72
|
+
_c('soc', 'number', 'MWh', True, None, 'Energy stored going into the interval.'),
|
|
73
|
+
_c('soc_min', 'number', 'MWh', True, None, 'Lowest allowed state of charge.'),
|
|
74
|
+
_c('soc_max', 'number', 'MWh', True, None, 'Highest allowed state of charge.'),
|
|
75
|
+
_c('efficiency', 'number', 'share', False, None, 'Share of charging energy that ends up stored. Scales what charging and downward reserves would add to the state of charge. Default: rules.storage_charge_efficiency.'),
|
|
76
|
+
), key=('resource',)),
|
|
77
|
+
Table('reserve_limits', 'resource and product', 'How much of each reserve product a resource is able to carry.', (
|
|
78
|
+
_c('resource', 'text', '', True, None, 'Resource name.'),
|
|
79
|
+
_c('product', 'text', '', True, None, 'Reserve product, as named in the rulebook.'),
|
|
80
|
+
_c('mw', 'number', 'MW', True, None, 'The most it can be awarded of that product.'),
|
|
81
|
+
), key=('resource', 'product')),
|
|
82
|
+
Table('reserve_offers', 'offer block and product', 'Reserve offers. A block is a quantity of MW that may serve any one of the products priced in it, so one MW is never sold twice. When this table is given, a resource carries only what it offered.', (
|
|
83
|
+
_c('resource', 'text', '', True, None, 'Resource name.'),
|
|
84
|
+
_c('block', 'text', '', True, None, 'Id of the block, unique within the resource.'),
|
|
85
|
+
_c('mw', 'number', 'MW', True, None, 'Size of the block. Repeat it on each of the block\'s product rows.'),
|
|
86
|
+
_c('product', 'text', '', True, None, 'Reserve product the block is offered for.'),
|
|
87
|
+
_c('price', 'number', '$/MW per hour', True, None, 'Offer price for that product.'),
|
|
88
|
+
), key=('resource', 'block', 'product')),
|
|
89
|
+
Table('reserve_demand', 'demand curve point', 'What the system pays for each MW of each reserve product: a falling curve of cumulative MW against price. Giving this table switches reserve co-optimization on.', (
|
|
90
|
+
_c('product', 'text', '', True, None, 'The demand curve\'s name: a reserve product, or the name several products count towards.'),
|
|
91
|
+
_c('mw', 'number', 'MW', True, None, 'Cumulative MW of the product.'),
|
|
92
|
+
_c('price', 'number', '$/MW per hour', True, None, 'Value of the MW at that point. Linear between points.'),
|
|
93
|
+
)),
|
|
94
|
+
Table('constraints', 'network constraint', 'The transmission constraints to enforce: flow + sum(shift factor x (MW - output)) <= limit.', (
|
|
95
|
+
_c('name', 'text', '', True, None, 'Unique id. Must match a row of shift_factors.'),
|
|
96
|
+
_c('limit', 'number', 'MW', True, None, 'The most the element may carry.'),
|
|
97
|
+
_c('flow', 'number', 'MW', True, None, 'Flow on the element with every resource at its `output`.'),
|
|
98
|
+
_c('max_shadow_price', 'number', '$/MWh', True, None, 'Price at which the clearing gives up and lets the limit be exceeded.'),
|
|
99
|
+
_c('kind', 'text', '', False, 'contingency', "'base', 'contingency' or 'irol'. Used by helpers that set max_shadow_price."),
|
|
100
|
+
_c('kv', 'number', 'kV', False, None, 'Voltage of the limiting element. Used by helpers that set max_shadow_price.'),
|
|
101
|
+
_c('competitive', 'bool', '', False, True, 'Whether the constraint is a competitive constraint, for offer mitigation.'),
|
|
102
|
+
), key=('name',)),
|
|
103
|
+
Table('mitigated_offer_caps', 'curve point', 'The cost-based cap on each resource\'s offer, used in the second step of a two-step clearing for resources marked `mitigated`. Linear between points, flat beyond the ends.', (
|
|
104
|
+
_c('resource', 'text', '', True, None, 'Resource name.'),
|
|
105
|
+
_c('mw', 'number', 'MW', True, None, 'Output level.'),
|
|
106
|
+
_c('price', 'number', '$/MWh', True, None, 'The mitigated offer cap at that output.'),
|
|
107
|
+
)),
|
|
108
|
+
Table('reserve_requirements', 'demand curve', 'How many MW of each reserve the system plans to hold. Shares in the rulebook (a limit of 60% of a requirement, MW reserved for one product) are taken of this. Default: the total MW of the product\'s demand curve.', (
|
|
109
|
+
_c('product', 'text', '', True, None, 'The demand curve\'s name.'),
|
|
110
|
+
_c('mw', 'number', 'MW', True, None, 'The requirement.'),
|
|
111
|
+
), key=('product',)),
|
|
112
|
+
Table('limit_values', 'rulebook limit', 'This interval\'s own numbers for limits named in the rulebook, for values the market resets by month or by hour. A row named after a product overrides the MW reserved for that product.', (
|
|
113
|
+
_c('limit', 'text', '', True, None, 'Name of the rulebook Limit, or of a product with reserved MW.'),
|
|
114
|
+
_c('min_mw', 'number', 'MW', False, None, 'Floor for this interval.'),
|
|
115
|
+
_c('max_mw', 'number', 'MW', False, None, 'Cap for this interval.'),
|
|
116
|
+
), key=('limit',)),
|
|
117
|
+
)}
|
|
118
|
+
|
|
119
|
+
OTHER = {
|
|
120
|
+
'demand': 'One number, MW: what the dispatched resources must add up to in this interval.',
|
|
121
|
+
'shift_factors': 'DataFrame. Index: constraint name. Columns: node name, or resource name when resource_nodes is not '
|
|
122
|
+
'given. Value: MW of flow on the constraint per MW injected there. Anything missing is taken as 0.',
|
|
123
|
+
'resource_nodes': 'Where each resource injects. A Series or dict resource -> node, or a DataFrame with columns '
|
|
124
|
+
'resource, node and optionally share for a resource split over several nodes.',
|
|
125
|
+
'mitigated': 'True if energy_offers already hold the mitigated curves, so a two-step rulebook clears once. Default False.',
|
|
126
|
+
'time': 'Optional timestamp of the interval. A market uses it to pick the rulebook in force.',
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@dataclass
|
|
131
|
+
class Inputs:
|
|
132
|
+
"""One interval's inputs. Only `resources` and `demand` are required.
|
|
133
|
+
|
|
134
|
+
inputs = Inputs(resources=res, energy_offers=offers, demand=41_250)
|
|
135
|
+
inputs.validate() # raises with the table and row at fault
|
|
136
|
+
print(inputs) # a one-screen summary
|
|
137
|
+
|
|
138
|
+
Every field is described by `opensced.schema()`."""
|
|
139
|
+
resources: pd.DataFrame
|
|
140
|
+
demand: float
|
|
141
|
+
energy_offers: pd.DataFrame | None = None
|
|
142
|
+
storage: pd.DataFrame | None = None
|
|
143
|
+
reserve_limits: pd.DataFrame | None = None
|
|
144
|
+
reserve_offers: pd.DataFrame | None = None
|
|
145
|
+
reserve_demand: pd.DataFrame | None = None
|
|
146
|
+
reserve_requirements: pd.DataFrame | None = None
|
|
147
|
+
limit_values: pd.DataFrame | None = None
|
|
148
|
+
mitigated_offer_caps: pd.DataFrame | None = None
|
|
149
|
+
constraints: pd.DataFrame | None = None
|
|
150
|
+
shift_factors: pd.DataFrame | None = None
|
|
151
|
+
resource_nodes: object = None
|
|
152
|
+
time: object = None
|
|
153
|
+
mitigated: bool = False # True: energy_offers already hold the mitigated (step-2) curves
|
|
154
|
+
notes: dict = field(default_factory=dict) # anything an adapter wants to pass along (published prices, ...)
|
|
155
|
+
|
|
156
|
+
def copy(self, **changes):
|
|
157
|
+
"""A copy with some tables replaced: inputs.copy(demand=42_000)."""
|
|
158
|
+
return replace(self, **changes)
|
|
159
|
+
|
|
160
|
+
def validate(self, rules=None):
|
|
161
|
+
"""Check every table. Pass the rulebook to also catch misspelled reserve products."""
|
|
162
|
+
if rules is None:
|
|
163
|
+
validate(self)
|
|
164
|
+
else:
|
|
165
|
+
validate(self, rules.product_names or None, rules.demand_names or None)
|
|
166
|
+
return self
|
|
167
|
+
|
|
168
|
+
def __repr__(self):
|
|
169
|
+
r = self.resources
|
|
170
|
+
n = len(r)
|
|
171
|
+
disp = int(r['dispatchable'].sum()) if 'dispatchable' in r else n
|
|
172
|
+
lines = [f'Inputs{f" for {self.time}" if self.time is not None else ""}',
|
|
173
|
+
f' demand {float(self.demand):,.1f} MW',
|
|
174
|
+
f' resources {n:,} ({disp:,} dispatchable)']
|
|
175
|
+
for f in fields(self):
|
|
176
|
+
if f.name in ('resources', 'demand', 'time', 'notes', 'resource_nodes', 'shift_factors', 'mitigated'):
|
|
177
|
+
continue
|
|
178
|
+
v = getattr(self, f.name)
|
|
179
|
+
lines.append(f' {f.name:<16} ' + ('not given' if v is None else f'{len(v):,} rows'))
|
|
180
|
+
s = self.shift_factors
|
|
181
|
+
lines.append(' shift_factors ' + ('not given' if s is None else f'{s.shape[0]:,} constraints x {s.shape[1]:,} columns'))
|
|
182
|
+
lines.append(' resource_nodes ' + ('not given' if self.resource_nodes is None else f'{len(self.resource_nodes):,} entries'))
|
|
183
|
+
return '\n'.join(lines)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _fail(table, msg):
|
|
187
|
+
raise ValueError(f'{table}: {msg}')
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _check_table(df, spec):
|
|
191
|
+
if not isinstance(df, pd.DataFrame):
|
|
192
|
+
_fail(spec.name, f'expected a pandas DataFrame, got {type(df).__name__}')
|
|
193
|
+
miss = [c.name for c in spec.columns if c.required and c.name not in df.columns]
|
|
194
|
+
if miss:
|
|
195
|
+
have = ', '.join(map(str, df.columns)) or 'none'
|
|
196
|
+
_fail(spec.name, f'missing column(s) {miss}. It has: {have}. See opensced.schema("{spec.name}")')
|
|
197
|
+
for c in spec.columns:
|
|
198
|
+
if c.name not in df.columns:
|
|
199
|
+
continue
|
|
200
|
+
col = df[c.name]
|
|
201
|
+
if c.dtype == 'number':
|
|
202
|
+
v = pd.to_numeric(col, errors='coerce')
|
|
203
|
+
bad = v.isna() if c.required else (v.isna() & col.notna())
|
|
204
|
+
if bad.any():
|
|
205
|
+
_fail(spec.name, f'column {c.name!r} must be a number; row {bad.idxmax()!r} has {col[bad.idxmax()]!r}')
|
|
206
|
+
if c.required and not np.isfinite(v.to_numpy(float)).all():
|
|
207
|
+
_fail(spec.name, f'column {c.name!r} must be finite')
|
|
208
|
+
elif c.required and col.isna().any():
|
|
209
|
+
_fail(spec.name, f'column {c.name!r} has an empty value at row {col.isna().idxmax()!r}')
|
|
210
|
+
if spec.key and df.duplicated(list(spec.key)).any():
|
|
211
|
+
d = df.loc[df.duplicated(list(spec.key)), list(spec.key)].iloc[0].tolist()
|
|
212
|
+
_fail(spec.name, f'{" + ".join(spec.key)} must be unique; {d} appears more than once')
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def validate(inputs, products=None, demand_products=None):
|
|
216
|
+
"""Raise ValueError on the first problem that would otherwise give a wrong price instead of an error.
|
|
217
|
+
products: the rulebook's reserve product names, to catch a misspelled product; demand_products: the names its
|
|
218
|
+
demand curves go by (the same, unless several products serve one curve)."""
|
|
219
|
+
_check_table(inputs.resources, TABLES['resources'])
|
|
220
|
+
r = inputs.resources
|
|
221
|
+
lo, hi = pd.to_numeric(r['low']).to_numpy(float), pd.to_numeric(r['high']).to_numpy(float)
|
|
222
|
+
if (lo > hi + 1e-9).any():
|
|
223
|
+
_fail('resources', f'low > high for {r["name"][lo > hi + 1e-9].iloc[0]!r}')
|
|
224
|
+
if 'kind' in r and not r['kind'].isin(['generator', 'storage', 'load']).all():
|
|
225
|
+
_fail('resources', f"kind must be 'generator', 'storage' or 'load'; found {r['kind'][~r['kind'].isin(['generator', 'storage', 'load'])].iloc[0]!r}")
|
|
226
|
+
try:
|
|
227
|
+
d = float(inputs.demand)
|
|
228
|
+
except (TypeError, ValueError):
|
|
229
|
+
_fail('demand', f'expected one number in MW, got {type(inputs.demand).__name__}')
|
|
230
|
+
if not np.isfinite(d):
|
|
231
|
+
_fail('demand', 'must be a finite number of MW')
|
|
232
|
+
names = set(r['name'])
|
|
233
|
+
for t in ('energy_offers', 'storage', 'reserve_limits', 'reserve_offers', 'reserve_demand', 'reserve_requirements', 'limit_values', 'mitigated_offer_caps', 'constraints'):
|
|
234
|
+
df = getattr(inputs, t)
|
|
235
|
+
if df is None:
|
|
236
|
+
continue
|
|
237
|
+
_check_table(df, TABLES[t])
|
|
238
|
+
if 'resource' in df.columns and len(df):
|
|
239
|
+
unknown = set(df['resource']) - names
|
|
240
|
+
if unknown:
|
|
241
|
+
_fail(t, f'{len(unknown):,} resource(s) are not in the resources table, e.g. {sorted(map(str, unknown))[0]!r}')
|
|
242
|
+
known = (demand_products or products) if t in ('reserve_demand', 'reserve_requirements') else products
|
|
243
|
+
if known is not None and 'product' in df.columns and len(df):
|
|
244
|
+
unknown = set(df['product']) - set(known)
|
|
245
|
+
if unknown:
|
|
246
|
+
_fail(t, f'unknown product {sorted(map(str, unknown))[0]!r}. This rulebook has: {", ".join(known)}')
|
|
247
|
+
if inputs.storage is not None and len(inputs.storage):
|
|
248
|
+
s = inputs.storage
|
|
249
|
+
if (s['soc_min'] > s['soc_max']).any():
|
|
250
|
+
_fail('storage', f'soc_min > soc_max for {s["resource"][s["soc_min"] > s["soc_max"]].iloc[0]!r}')
|
|
251
|
+
if inputs.reserve_demand is None and (inputs.reserve_offers is not None or inputs.reserve_limits is not None):
|
|
252
|
+
pass # allowed: reserves are simply not cleared
|
|
253
|
+
if inputs.reserve_demand is not None and inputs.reserve_limits is None:
|
|
254
|
+
_fail('reserve_limits', 'reserve_demand was given, so reserve_limits is needed: it says which resources can carry each product')
|
|
255
|
+
c, s = inputs.constraints, inputs.shift_factors
|
|
256
|
+
if c is not None and len(c):
|
|
257
|
+
if s is None:
|
|
258
|
+
_fail('shift_factors', 'constraints were given without shift_factors')
|
|
259
|
+
if not isinstance(s, pd.DataFrame):
|
|
260
|
+
_fail('shift_factors', 'expected a DataFrame: index = constraint name, columns = node (or resource)')
|
|
261
|
+
miss = [n for n in c['name'] if n not in s.index]
|
|
262
|
+
if miss:
|
|
263
|
+
_fail('shift_factors', f'no row for {len(miss):,} constraint(s), e.g. {miss[0]!r}. Drop them from constraints or add their shift factors')
|
|
264
|
+
cols = set(s.columns)
|
|
265
|
+
where = names if inputs.resource_nodes is None else set(_node_series(inputs.resource_nodes))
|
|
266
|
+
if not (cols & where):
|
|
267
|
+
what = 'resource names' if inputs.resource_nodes is None else 'the nodes in resource_nodes'
|
|
268
|
+
_fail('shift_factors', f'none of its {len(cols):,} columns match {what}, so no resource would affect any constraint')
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _node_series(resource_nodes):
|
|
272
|
+
"""the nodes named by a resource_nodes input, whatever form it took."""
|
|
273
|
+
if isinstance(resource_nodes, pd.DataFrame):
|
|
274
|
+
return resource_nodes['node'].astype(str)
|
|
275
|
+
return pd.Series(resource_nodes).astype(str)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def schema(table=None):
|
|
279
|
+
"""The data dictionary as text. schema() lists every table, schema('resources') one of them."""
|
|
280
|
+
out = []
|
|
281
|
+
for t in TABLES.values():
|
|
282
|
+
if table not in (None, t.name):
|
|
283
|
+
continue
|
|
284
|
+
out.append(f'{t.name} (one row per {t.row}{"; required" if t.required else "; optional"})')
|
|
285
|
+
out.append(f' {t.doc}')
|
|
286
|
+
for c in t.columns:
|
|
287
|
+
need = 'required' if c.required else f'optional, default {c.default}'
|
|
288
|
+
unit = f' [{c.unit}]' if c.unit else ''
|
|
289
|
+
out.append(f' {c.name:<17}{c.dtype:<7}{unit:<16} {need}. {c.doc}')
|
|
290
|
+
out.append('')
|
|
291
|
+
for k, v in OTHER.items():
|
|
292
|
+
if table in (None, k):
|
|
293
|
+
out += [k, f' {v}', '']
|
|
294
|
+
if not out:
|
|
295
|
+
raise ValueError(f'no table called {table!r}. Tables: {", ".join(list(TABLES) + list(OTHER))}')
|
|
296
|
+
return '\n'.join(out).rstrip()
|
opensced/examples.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Small made-up cases that run with no data. Start here.
|
|
2
|
+
|
|
3
|
+
case = opensced.examples.three_bus()
|
|
4
|
+
print(opensced.clear(case))
|
|
5
|
+
"""
|
|
6
|
+
import pandas as pd
|
|
7
|
+
|
|
8
|
+
from opensced.core.rules import Product, Rules
|
|
9
|
+
from opensced.core.tables import Inputs
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def three_bus(demand=250.0, line_limit=80.0):
|
|
13
|
+
"""Three nodes, three generators, one battery, one line that can bind.
|
|
14
|
+
|
|
15
|
+
WEST wind, 150 MW at $5 cheap, behind the line
|
|
16
|
+
NORTH gas, 200 MW at $30-$40 mid-priced
|
|
17
|
+
CITY peaker, 100 MW at $90 at the load; and a 40 MW battery
|
|
18
|
+
|
|
19
|
+
The line WEST->CITY carries 0.6 of what WEST injects, 0.2 of what NORTH injects and nothing from CITY. With the
|
|
20
|
+
default 80 MW limit the wind cannot all get out: the line binds and the three nodes clear at different prices.
|
|
21
|
+
Try three_bus(line_limit=500) to see one price everywhere."""
|
|
22
|
+
resources = pd.DataFrame([
|
|
23
|
+
{'name': 'wind', 'low': 0.0, 'high': 150.0, 'kind': 'generator'},
|
|
24
|
+
{'name': 'gas', 'low': 50.0, 'high': 200.0, 'kind': 'generator'},
|
|
25
|
+
{'name': 'peaker', 'low': 0.0, 'high': 100.0, 'kind': 'generator'},
|
|
26
|
+
{'name': 'battery', 'low': -40.0, 'high': 40.0, 'kind': 'storage'},
|
|
27
|
+
])
|
|
28
|
+
energy_offers = pd.DataFrame([
|
|
29
|
+
{'resource': 'wind', 'mw': 0.0, 'price': 5.0}, {'resource': 'wind', 'mw': 150.0, 'price': 5.0},
|
|
30
|
+
{'resource': 'gas', 'mw': 50.0, 'price': 30.0}, {'resource': 'gas', 'mw': 200.0, 'price': 40.0},
|
|
31
|
+
{'resource': 'peaker', 'mw': 0.0, 'price': 90.0}, {'resource': 'peaker', 'mw': 100.0, 'price': 90.0},
|
|
32
|
+
{'resource': 'battery', 'mw': -40.0, 'price': 20.0}, {'resource': 'battery', 'mw': 0.0, 'price': 20.0},
|
|
33
|
+
{'resource': 'battery', 'mw': 0.0, 'price': 60.0}, {'resource': 'battery', 'mw': 40.0, 'price': 60.0},
|
|
34
|
+
])
|
|
35
|
+
constraints = pd.DataFrame([{'name': 'WEST-CITY', 'limit': float(line_limit), 'flow': 0.0, 'max_shadow_price': 3500.0}])
|
|
36
|
+
shift_factors = pd.DataFrame([[0.6, 0.2, 0.0]], index=['WEST-CITY'], columns=['WEST', 'NORTH', 'CITY'])
|
|
37
|
+
resource_nodes = {'wind': 'WEST', 'gas': 'NORTH', 'peaker': 'CITY', 'battery': 'CITY'}
|
|
38
|
+
return Inputs(resources=resources, demand=float(demand), energy_offers=energy_offers, constraints=constraints,
|
|
39
|
+
shift_factors=shift_factors, resource_nodes=resource_nodes)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def three_bus_rules():
|
|
43
|
+
"""A rulebook for three_bus_with_reserves(): one upward reserve product."""
|
|
44
|
+
return Rules(name='example/three-bus', shortage_price=5000.0, block_mw=5.0, interval_hours=5 / 60,
|
|
45
|
+
products=(Product('Reserve', 'up', duration_hours=1.0),))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def three_bus_with_reserves(demand=250.0, line_limit=80.0, reserve_mw=60.0):
|
|
49
|
+
"""three_bus() plus a reserve requirement, to see energy and reserves compete for the same headroom.
|
|
50
|
+
|
|
51
|
+
The system values the first `reserve_mw` of reserve at $200 a MW. The gas unit, the peaker and the battery can
|
|
52
|
+
carry it. Clear it with opensced.examples.three_bus_rules()."""
|
|
53
|
+
case = three_bus(demand, line_limit)
|
|
54
|
+
case.storage = pd.DataFrame([{'resource': 'battery', 'soc': 60.0, 'soc_min': 0.0, 'soc_max': 80.0}])
|
|
55
|
+
case.reserve_limits = pd.DataFrame([{'resource': r, 'product': 'Reserve', 'mw': mw}
|
|
56
|
+
for r, mw in (('gas', 50.0), ('peaker', 100.0), ('battery', 40.0))])
|
|
57
|
+
case.reserve_demand = pd.DataFrame([{'product': 'Reserve', 'mw': 0.0, 'price': 200.0},
|
|
58
|
+
{'product': 'Reserve', 'mw': float(reserve_mw), 'price': 200.0}])
|
|
59
|
+
return case
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""ERCOT's real-time market (SCED under real-time co-optimization, RTC+B)."""
|
|
2
|
+
from opensced.core.market import Market, register
|
|
3
|
+
from opensced.markets.ercot import adapter, helpers, rulebooks
|
|
4
|
+
|
|
5
|
+
ERCOT = Market(name='ercot', title="ERCOT real-time market (SCED, co-optimized energy and ancillary services)",
|
|
6
|
+
rulebooks=rulebooks.ALL, adapter=adapter, interval_minutes=5)
|
|
7
|
+
ERCOT.helpers = helpers
|
|
8
|
+
register(ERCOT)
|