Skip to content

Commit 595a9b6

Browse files
committed
Replace load_aug
1 parent 84269bb commit 595a9b6

File tree

20 files changed

+597
-850
lines changed

20 files changed

+597
-850
lines changed

docs/Developing Modules.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ Some modules need to define objects to be shared across multiple modules.
3535
for adding constraints, expressions, variables, sets or parameters to the model.
3636

3737
Sometimes Sets or Parameters should be initialized from an input csv file.
38-
If this is the case, add the following arguments to the component definition:
39-
`input_file`, `input_optional` (optional), `input_column` (optional).
38+
If this is the case, add `input_file=` (and optionally `input_column`) to the
39+
set or parameter definition.
4040

41-
For example the following code snippet defines a set and a parameter
41+
For example the following code snippet defines a Set and a parameter
4242
indexed over that set. Both the set and parameter are initialized from
43-
the input.csv file.
43+
the `input.csv` file.
4444

4545
```python
46-
from switch_model.utilities.pyo import *
46+
from switch_model.utilities.custom_loading import *
47+
4748

4849
def define_components(mod):
4950
mod.SetA = Set(
5051
dimen=2,
5152
input_file="input.csv",
52-
input_optional=True, # the default is False
5353
)
5454

5555
mod.some_indexed_param = Param(
5656
mod.SetA,
5757
input_file="input.csv",
58-
input_column="param1" # default is the name of the component, in this case 'some_indexed_param'
58+
input_column="param1" # only specify when the name of the column in the csv is not the same as the component name
5959
)
6060
```
6161

switch_model/balancing/load_zones.py

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,29 @@
33

44
"""
55
Defines load zone parameters for the Switch model.
6+
7+
INPUT FILE INFORMATION
8+
Import load zone data. The following tab-separated files are
9+
expected in the input directory. Their index columns need to be on
10+
the left, but the data columns can be in any order. Extra columns
11+
will be ignored during import, and optional columns can be dropped.
12+
Other modules (such as local_td) may look for additional columns in
13+
some of these files. If you don't want to specify data for any
14+
optional parameter, use a dot . for its value. Optional columns and
15+
files are noted with a *.
16+
17+
load_zones.csv
18+
LOAD_ZONE, zone_ccs_distance_km*, zone_dbid*
19+
20+
loads.csv
21+
LOAD_ZONE, TIMEPOINT, zone_demand_mw
22+
23+
zone_coincident_peak_demand.csv*
24+
LOAD_ZONE, PERIOD, zone_expected_coincident_peak_demand
625
"""
726
import os
8-
from switch_model.utilities.pyo import *
27+
28+
from pyomo.environ import *
929
from switch_model.reporting import write_table
1030
from switch_model.tools.graph import graph
1131

@@ -106,10 +126,14 @@ def define_components(mod):
106126
mod.EXTERNAL_COINCIDENT_PEAK_DEMAND_ZONE_PERIODS = Set(
107127
dimen=2,
108128
within=mod.LOAD_ZONES * mod.PERIODS,
129+
input_file="zone_coincident_peak_demand.csv",
130+
input_optional=True,
109131
doc="Zone-Period combinations with zone_expected_coincident_peak_demand data.",
110132
)
111133
mod.zone_expected_coincident_peak_demand = Param(
112-
mod.EXTERNAL_COINCIDENT_PEAK_DEMAND_ZONE_PERIODS, within=NonNegativeReals
134+
mod.EXTERNAL_COINCIDENT_PEAK_DEMAND_ZONE_PERIODS,
135+
input_file="zone_coincident_peak_demand.csv",
136+
within=NonNegativeReals,
113137
)
114138
mod.zone_total_demand_in_period_mwh = Param(
115139
mod.LOAD_ZONES,
@@ -150,39 +174,6 @@ def define_dynamic_components(mod):
150174
)
151175

152176

153-
def load_inputs(mod, switch_data, inputs_dir):
154-
"""
155-
Import load zone data. The following tab-separated files are
156-
expected in the input directory. Their index columns need to be on
157-
the left, but the data columns can be in any order. Extra columns
158-
will be ignored during import, and optional columns can be dropped.
159-
Other modules (such as local_td) may look for additional columns in
160-
some of these files. If you don't want to specify data for any
161-
optional parameter, use a dot . for its value. Optional columns and
162-
files are noted with a *.
163-
164-
load_zones.csv
165-
LOAD_ZONE, zone_ccs_distance_km*, zone_dbid*
166-
167-
loads.csv
168-
LOAD_ZONE, TIMEPOINT, zone_demand_mw
169-
170-
zone_coincident_peak_demand.csv*
171-
LOAD_ZONE, PERIOD, zone_expected_coincident_peak_demand
172-
173-
"""
174-
# Include select in each load() function so that it will check out
175-
# column names, be indifferent to column order, and throw an error
176-
# message if some columns are not found.
177-
switch_data.load_aug(
178-
optional=True,
179-
filename=os.path.join(inputs_dir, "zone_coincident_peak_demand.csv"),
180-
index=mod.EXTERNAL_COINCIDENT_PEAK_DEMAND_ZONE_PERIODS,
181-
select=("LOAD_ZONE", "PERIOD", "zone_expected_coincident_peak_demand"),
182-
param=(mod.zone_expected_coincident_peak_demand),
183-
)
184-
185-
186177
def post_solve(instance, outdir):
187178
"""
188179
Exports load_balance.csv, load_balance_annual_zonal.csv, and load_balance_annual.csv.

switch_model/balancing/operating_reserves/areas.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33

44
"""
55
Defines balancing areas for operational reserves.
6+
7+
INPUT FILE INFORMATION
8+
9+
Import balancing_area data. The following files are expected in the input
10+
directory:
11+
12+
load_zones.csv
13+
LOAD_ZONE, ..., zone_balancing_area
614
"""
7-
import os
815
from pyomo.environ import *
916

1017
dependencies = "switch_model.timescales", "switch_model.balancing.load_zones"
@@ -32,7 +39,10 @@ def define_components(mod):
3239
"""
3340

3441
mod.zone_balancing_area = Param(
35-
mod.LOAD_ZONES, default="system_wide_balancing_area", within=Any
42+
mod.LOAD_ZONES,
43+
input_file="load_zones.csv",
44+
default="system_wide_balancing_area",
45+
within=Any,
3646
)
3747
mod.BALANCING_AREAS = Set(
3848
ordered=False,
@@ -45,22 +55,3 @@ def define_components(mod):
4555
),
4656
)
4757
mod.BALANCING_AREA_TIMEPOINTS = Set(initialize=mod.BALANCING_AREAS * mod.TIMEPOINTS)
48-
49-
50-
def load_inputs(mod, switch_data, inputs_dir):
51-
"""
52-
Import balancing_area data. The following files are expected in the input
53-
directory:
54-
55-
load_zones.csv
56-
LOAD_ZONE, ..., zone_balancing_area
57-
58-
"""
59-
# Include select in each load() function so that it will check out
60-
# column names, be indifferent to column order, and throw an error
61-
# message if some columns are not found.
62-
switch_data.load_aug(
63-
filename=os.path.join(inputs_dir, "load_zones.csv"),
64-
auto_select=True,
65-
param=(mod.zone_balancing_area),
66-
)

switch_model/balancing/planning_reserves.py

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@
4444
rules (and the need to improve them)
4545
https://www.caiso.com/Documents/Jan29_2016_Comments_2017Track1Proposals_ResourceAdequacyProgram_R14-10-010.pdf
4646
47+
48+
INPUT FILE FORMAT
49+
reserve_capacity_value.csv
50+
GEN, TIMEPOINT, gen_capacity_value
51+
52+
planning_reserve_requirement_zones.csv
53+
PLANNING_RESERVE_REQUIREMENTS, prr_cap_reserve_margin, prr_enforcement_timescale
54+
55+
generation_projects_info.csv
56+
..., gen_can_provide_cap_reserves
57+
58+
planning_reserve_requirement_zones.csv
59+
PRR, ZONE
60+
4761
"""
4862

4963
import os
@@ -128,22 +142,29 @@ def define_components(model):
128142
will not reflect any DER activities.
129143
"""
130144
model.PLANNING_RESERVE_REQUIREMENTS = Set(
131-
doc="Areas and times where planning reserve margins are specified.", dimen=1
145+
doc="Areas and times where planning reserve margins are specified.",
146+
input_file="planning_reserve_requirements.csv",
147+
dimen=1,
132148
)
133149
model.PRR_ZONES = Set(
134150
dimen=2,
151+
input_file="planning_reserve_requirement_zones.csv",
135152
doc=(
136153
"A set of (prr, z) that describes which zones contribute to each "
137154
"Planning Reserve Requirement."
138155
),
139156
)
140157
model.prr_cap_reserve_margin = Param(
141-
model.PLANNING_RESERVE_REQUIREMENTS, within=PercentFraction, default=0.15
158+
model.PLANNING_RESERVE_REQUIREMENTS,
159+
within=PercentFraction,
160+
input_file="planning_reserve_requirements.csv",
161+
default=0.15,
142162
)
143163
model.prr_enforcement_timescale = Param(
144164
model.PLANNING_RESERVE_REQUIREMENTS,
145165
default="period_peak_load",
146166
validate=lambda m, value, prr: value in ("all_timepoints", "peak_load"),
167+
input_file="planning_reserve_requirements.csv",
147168
doc=(
148169
"Determines whether planning reserve requirements are enforced in "
149170
"each timepoint, or just timepoints with peak load (zone_demand_mw)."
@@ -199,6 +220,7 @@ def PRR_TIMEPOINTS_init(m):
199220
model.GENERATION_PROJECTS,
200221
within=Boolean,
201222
default=True,
223+
input_file="generation_projects_info.csv",
202224
doc="Indicates whether a generator can provide capacity reserves.",
203225
)
204226

@@ -220,6 +242,7 @@ def gen_capacity_value_default(m, g, t):
220242
# Previously domain was PercentFraction however we want to allow renewable factors greater than 1
221243
# or less than 0.
222244
within=Reals,
245+
input_file="reserve_capacity_value.csv",
223246
default=gen_capacity_value_default,
224247
validate=lambda m, value, g, t: (
225248
value == 0.0 if not m.gen_can_provide_cap_reserves[g] else True
@@ -299,42 +322,3 @@ def define_dynamic_components(model):
299322
"of REQUIREMENTS_FOR_CAPACITY_RESERVES for each of PRR_TIMEPOINTS."
300323
),
301324
)
302-
303-
304-
def load_inputs(model, switch_data, inputs_dir):
305-
"""
306-
reserve_capacity_value.csv
307-
GEN, TIMEPOINT, gen_capacity_value
308-
309-
planning_reserve_requirement_zones.csv
310-
PLANNING_RESERVE_REQUIREMENTS, prr_cap_reserve_margin, prr_enforcement_timescale
311-
312-
generation_projects_info.csv
313-
..., gen_can_provide_cap_reserves
314-
315-
planning_reserve_requirement_zones.csv
316-
PRR, ZONE
317-
318-
"""
319-
switch_data.load_aug(
320-
filename=os.path.join(inputs_dir, "reserve_capacity_value.csv"),
321-
optional=True,
322-
auto_select=True,
323-
param=(model.gen_capacity_value),
324-
)
325-
switch_data.load_aug(
326-
filename=os.path.join(inputs_dir, "planning_reserve_requirements.csv"),
327-
auto_select=True,
328-
index=model.PLANNING_RESERVE_REQUIREMENTS,
329-
param=(model.prr_cap_reserve_margin, model.prr_enforcement_timescale),
330-
)
331-
switch_data.load_aug(
332-
filename=os.path.join(inputs_dir, "generation_projects_info.csv"),
333-
auto_select=True,
334-
optional_params=["gen_can_provide_cap_reserves"],
335-
param=(model.gen_can_provide_cap_reserves),
336-
)
337-
switch_data.load_aug(
338-
filename=os.path.join(inputs_dir, "planning_reserve_requirement_zones.csv"),
339-
set=model.PRR_ZONES,
340-
)

switch_model/energy_sources/fuel_costs/markets.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ def zone_fuel_cost_adder_validate(model, val, z, fuel, p):
328328
mod.ZONE_FUELS,
329329
mod.PERIODS,
330330
input_file="zone_fuel_cost_diff.csv",
331-
input_optional=True,
332331
input_column="fuel_cost_adder",
333332
within=Reals,
334333
default=0,

switch_model/energy_sources/fuel_costs/simple.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
serves as an alternative to the more complex fuel_markets with tiered
88
supply curves. This is mutually exclusive with the fuel_markets module.
99
10+
INPUT FILE INFORMATION
11+
The following files are expected in the input directory:
12+
13+
fuel_cost.csv
14+
load_zone, fuel, period, fuel_cost
1015
"""
11-
import os
1216
from pyomo.environ import *
1317

1418
dependencies = (
@@ -50,11 +54,14 @@ def define_components(mod):
5054

5155
mod.ZONE_FUEL_PERIODS = Set(
5256
dimen=3,
57+
input_file="fuel_cost.csv",
5358
validate=lambda m, z, f, p: (
5459
z in m.LOAD_ZONES and f in m.FUELS and p in m.PERIODS
5560
),
5661
)
57-
mod.fuel_cost = Param(mod.ZONE_FUEL_PERIODS, within=NonNegativeReals)
62+
mod.fuel_cost = Param(
63+
mod.ZONE_FUEL_PERIODS, input_file="fuel_cost.csv", within=NonNegativeReals
64+
)
5865
mod.min_data_check("ZONE_FUEL_PERIODS", "fuel_cost")
5966

6067
mod.GEN_TP_FUELS_UNAVAILABLE = Set(
@@ -85,22 +92,3 @@ def FuelCostsPerTP_rule(m, t):
8592

8693
mod.FuelCostsPerTP = Expression(mod.TIMEPOINTS, rule=FuelCostsPerTP_rule)
8794
mod.Cost_Components_Per_TP.append("FuelCostsPerTP")
88-
89-
90-
def load_inputs(mod, switch_data, inputs_dir):
91-
"""
92-
93-
Import simple fuel cost data. The following files are expected in
94-
the input directory:
95-
96-
fuel_cost.csv
97-
load_zone, fuel, period, fuel_cost
98-
99-
"""
100-
101-
switch_data.load_aug(
102-
filename=os.path.join(inputs_dir, "fuel_cost.csv"),
103-
select=("load_zone", "fuel", "period", "fuel_cost"),
104-
index=mod.ZONE_FUEL_PERIODS,
105-
param=[mod.fuel_cost],
106-
)

0 commit comments

Comments
 (0)