Skip to content

Commit 2360c55

Browse files
committed
Further improvements
1 parent 595a9b6 commit 2360c55

File tree

9 files changed

+348
-7
lines changed

9 files changed

+348
-7
lines changed

docs/Developing Modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ indexed over that set. Both the set and parameter are initialized from
4343
the `input.csv` file.
4444

4545
```python
46-
from switch_model.utilities.custom_loading import *
46+
from pyomo.environ import *
4747

4848

4949
def define_components(mod):

switch_model/balancing/demand_response/simple.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
demand shifting. This does not include a Shed Service (curtailment of load),
99
nor a Shimmy Service (fast dispatch for load following or regulation).
1010
11+
INPUT FILE FORMAT
12+
Import demand response-specific data from an input directory.
13+
14+
dr_data.csv
15+
LOAD_ZONE, TIMEPOINT, dr_shift_down_limit, dr_shift_up_limit
1116
"""
1217

1318
import os
@@ -53,11 +58,21 @@ def define_components(mod):
5358
mod.TIMEPOINTS,
5459
default=0.0,
5560
within=NonNegativeReals,
61+
<<<<<<< HEAD
5662
validate=lambda m, value, z, t: value <= m.zone_demand_mw[z, t],
5763
)
5864
mod.dr_shift_up_limit = Param(
5965
mod.LOAD_ZONES, mod.TIMEPOINTS, default=float("inf"), within=NonNegativeReals
6066
)
67+
=======
68+
input_file="dr_data.csv",
69+
validate=lambda m, value, z, t: value <= m.zone_demand_mw[z, t])
70+
mod.dr_shift_up_limit = Param(
71+
mod.LOAD_ZONES, mod.TIMEPOINTS,
72+
default= float('inf'),
73+
input_file="dr_data.csv",
74+
within=NonNegativeReals)
75+
>>>>>>> 941c8e2e (Further improvements)
6176
mod.ShiftDemand = Var(
6277
mod.LOAD_ZONES,
6378
mod.TIMEPOINTS,
@@ -77,6 +92,7 @@ def define_components(mod):
7792
try:
7893
mod.Distributed_Power_Withdrawals.append("ShiftDemand")
7994
except AttributeError:
95+
<<<<<<< HEAD
8096
mod.Zone_Power_Withdrawals.append("ShiftDemand")
8197

8298

@@ -96,3 +112,6 @@ def load_inputs(mod, switch_data, inputs_dir):
96112
autoselect=True,
97113
param=(mod.dr_shift_down_limit, mod.dr_shift_up_limit),
98114
)
115+
=======
116+
mod.Zone_Power_Withdrawals.append('ShiftDemand')
117+
>>>>>>> 941c8e2e (Further improvements)

switch_model/balancing/electric_vehicles/simple.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
of each timeseries they must be charged at some specific level according
1212
to users necessity.
1313
14+
INPUT FILE FORMAT
15+
Import virtual batteries specific location and power limits
16+
from an input directory.
17+
18+
ev_limits.tab
19+
LOAD_ZONES, TIMEPOINT, ev_cumulative_charge_upper_mwh,
20+
ev_cumulative_charge_upper_mwh, ev_charge_limit_mw
1421
"""
1522

1623
import os
@@ -66,6 +73,7 @@ def define_components(mod):
6673
"""
6774

6875
mod.ev_charge_limit_mw = Param(
76+
<<<<<<< HEAD
6977
mod.LOAD_ZONES, mod.TIMEPOINTS, default=float("inf"), within=NonNegativeReals
7078
)
7179

@@ -76,6 +84,24 @@ def define_components(mod):
7684
mod.ev_cumulative_charge_lower_mwh = Param(
7785
mod.LOAD_ZONES, mod.TIMEPOINTS, default=0.0, within=NonNegativeReals
7886
)
87+
=======
88+
mod.LOAD_ZONES, mod.TIMEPOINTS,
89+
default = float('inf'),
90+
input_file="ev_limits.csv",
91+
within=NonNegativeReals)
92+
93+
mod.ev_cumulative_charge_upper_mwh = Param(
94+
mod.LOAD_ZONES, mod.TIMEPOINTS,
95+
default = 0.0,
96+
input_file="ev_limits.csv",
97+
within=NonNegativeReals)
98+
99+
mod.ev_cumulative_charge_lower_mwh = Param(
100+
mod.LOAD_ZONES, mod.TIMEPOINTS,
101+
default = 0.0,
102+
input_file="ev_limits.csv",
103+
within=NonNegativeReals)
104+
>>>>>>> 941c8e2e (Further improvements)
79105

80106
mod.EVCharge = Var(
81107
mod.LOAD_ZONES,
@@ -111,6 +137,7 @@ def define_components(mod):
111137
if "Distributed_Power_Injections" in dir(mod):
112138
mod.Distributed_Power_Withdrawals.append("EVCharge")
113139
else:
140+
<<<<<<< HEAD
114141
mod.Zone_Power_Withdrawals.append("EVCharge")
115142

116143

@@ -136,3 +163,6 @@ def load_inputs(mod, switch_data, inputs_dir):
136163
mod.ev_charge_limit_mw,
137164
),
138165
)
166+
=======
167+
mod.Zone_Power_Withdrawals.append('EVCharge')
168+
>>>>>>> 941c8e2e (Further improvements)

switch_model/balancing/unserved_load.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
specially useful when running production costing simulations, though not
77
strictly required in all cases.
88
9+
INPUT FILE FORMAT
10+
The cost penalty of unserved load in units of $/MWh is the only parameter
11+
that can be inputted. The following file is not mandatory, because the
12+
parameter defaults to a value of 500 $/MWh. This file contains one header
13+
row and one data row.
14+
15+
optional input files:
16+
lost_load_cost.csv
17+
unserved_load_penalty
918
"""
1019

1120
import os
@@ -35,6 +44,7 @@ def define_components(mod):
3544
3645
"""
3746

47+
<<<<<<< HEAD
3848
mod.unserved_load_penalty = Param(within=NonNegativeReals, default=500)
3949
mod.UnservedLoad = Var(mod.LOAD_ZONES, mod.TIMEPOINTS, within=NonNegativeReals)
4050
mod.Zone_Power_Injections.append("UnservedLoad")
@@ -66,3 +76,19 @@ def load_inputs(mod, switch_data, inputs_dir):
6676
auto_select=True,
6777
param=(mod.unserved_load_penalty,),
6878
)
79+
=======
80+
mod.unserved_load_penalty = Param(
81+
within=NonNegativeReals,
82+
input_file="lost_load_cost.csv",
83+
default=500)
84+
mod.UnservedLoad = Var(
85+
mod.LOAD_ZONES, mod.TIMEPOINTS,
86+
within=NonNegativeReals)
87+
mod.Zone_Power_Injections.append('UnservedLoad')
88+
89+
mod.UnservedLoadPenalty = Expression(
90+
mod.TIMEPOINTS,
91+
rule=lambda m, tp: sum(m.UnservedLoad[z, tp] *
92+
m.unserved_load_penalty for z in m.LOAD_ZONES))
93+
mod.Cost_Components_Per_TP.append('UnservedLoadPenalty')
94+
>>>>>>> 941c8e2e (Further improvements)

switch_model/generators/extensions/hydro_system.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ def load_inputs(mod, switch_data, inputs_dir):
459459
hydro is treated like any other variable renewable resource, and
460460
expects data in variable_capacity_factors.csv.
461461
462+
TODO use new input loading format with input_file=
462463
"""
463464

464465
switch_data.load_aug(

switch_model/solve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
)
3434
from switch_model.upgrade import do_inputs_need_upgrade, upgrade_inputs
3535
from switch_model.tools.graph.cli_graph import main as graph_main
36-
from switch_model.utilities.custom_loading import patch_to_allow_loading
36+
from switch_model.utilities.load_data import patch_to_allow_loading
3737
from switch_model.utilities.results_info import save_info, add_info, ResultsInfoSection
3838

3939

switch_model/transmission/local_td.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
distribution pathway that incurs distribution losses. Distributed Energy
99
Resources (DER) impact the energy balance at the distribution node, avoiding
1010
losses from the distribution network.
11+
12+
INPUT FILE FORMAT
13+
Import local transmission & distribution data. The following files
14+
are expected in the input directory. Both files will
15+
contain additional columns that are used by the load_zones module
16+
and transmission.transport.build module.
17+
18+
load_zones.csv
19+
load_zone, existing_local_td, local_td_annual_cost_per_mw
20+
21+
trans_params.csv
22+
distribution_loss_rate
23+
24+
If distribution_loss_rate is not specified, or if trans_params.csv doesn't
25+
exist, mod.distribution_loss_rate will default to 0.053.
1126
"""
1227
from __future__ import division
1328

@@ -123,8 +138,13 @@ def define_components(mod):
123138
"""
124139

125140
# Local T&D
141+
<<<<<<< HEAD
126142
mod.existing_local_td = Param(mod.LOAD_ZONES, within=NonNegativeReals)
127143
mod.min_data_check("existing_local_td")
144+
=======
145+
mod.existing_local_td = Param(mod.LOAD_ZONES, within=NonNegativeReals, input_file="load_zones.csv")
146+
mod.min_data_check('existing_local_td')
147+
>>>>>>> 941c8e2e (Further improvements)
128148

129149
mod.BuildLocalTD = Var(mod.LOAD_ZONES, mod.PERIODS, within=NonNegativeReals)
130150
mod.LocalTDCapacity = Expression(
@@ -136,16 +156,23 @@ def define_components(mod):
136156
for bld_yr in m.CURRENT_AND_PRIOR_PERIODS_FOR_PERIOD[period]
137157
),
138158
)
139-
mod.distribution_loss_rate = Param(default=0.053)
159+
mod.distribution_loss_rate = Param(default=0.053, input_file="trans_params.csv")
140160

141161
mod.Meet_Local_TD = Constraint(
142162
mod.EXTERNAL_COINCIDENT_PEAK_DEMAND_ZONE_PERIODS,
143163
rule=lambda m, z, period: m.LocalTDCapacity[z, period]
144164
* (1 - m.distribution_loss_rate)
145165
>= m.zone_expected_coincident_peak_demand[z, period],
146166
)
167+
<<<<<<< HEAD
147168
mod.local_td_annual_cost_per_mw = Param(mod.LOAD_ZONES, within=NonNegativeReals)
148169
mod.min_data_check("local_td_annual_cost_per_mw")
170+
=======
171+
mod.local_td_annual_cost_per_mw = Param(
172+
mod.LOAD_ZONES,
173+
within=NonNegativeReals, input_file="load_zones.csv")
174+
mod.min_data_check('local_td_annual_cost_per_mw')
175+
>>>>>>> 941c8e2e (Further improvements)
149176
mod.LocalTDFixedCosts = Expression(
150177
mod.PERIODS,
151178
doc="Summarize annual local T&D costs for the objective function.",
@@ -203,6 +230,7 @@ def define_dynamic_components(mod):
203230
)
204231
== sum(
205232
getattr(m, component)[z, t]
233+
<<<<<<< HEAD
206234
for component in m.Distributed_Power_Withdrawals
207235
)
208236
),
@@ -240,3 +268,6 @@ def load_inputs(mod, switch_data, inputs_dir):
240268
optional_params=("distribution_loss_rate",),
241269
param=(mod.distribution_loss_rate),
242270
)
271+
=======
272+
for component in m.Distributed_Power_Withdrawals)))
273+
>>>>>>> 941c8e2e (Further improvements)

switch_model/utilities/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@
77
from __future__ import print_function
88

99
import functools
10-
import os, types, sys, argparse, time, datetime, traceback, subprocess, platform
10+
import os, types, sys, argparse, time, datetime, traceback, subprocess
1111
import warnings
1212

1313
import switch_model.__main__ as main
1414
from pyomo.environ import *
15-
from pyomo.core.base.set import UnknownSetDimen
1615
from pyomo.dataportal import DataManagerFactory
1716
from pyomo.dataportal.plugins.csv_table import CSVTable
1817

1918
from switch_model.utilities.results_info import add_info, ResultsInfoSection
2019
from switch_model.utilities.scaling import _ScaledVariable, _get_unscaled_expression
2120
import pyomo.opt
22-
import switch_model.utilities.custom_loading as pyo
21+
from switch_model.utilities.load_data import load_registered_inputs, load_data
2322

2423
# Define string_types (same as six.string_types). This is useful for
2524
# distinguishing between strings and other iterables.
@@ -277,7 +276,7 @@ def load_inputs(model, inputs_dir=None, attach_data_portal=False):
277276
timer = StepTimer()
278277
data = DataPortal(model=model)
279278
data.load_aug = types.MethodType(load_aug, data)
280-
pyo.load_registered_inputs(data, inputs_dir)
279+
load_registered_inputs(data, inputs_dir)
281280
for module in model.get_modules():
282281
if hasattr(module, "load_inputs"):
283282
module.load_inputs(model, data, inputs_dir)
@@ -596,6 +595,7 @@ def check_mandatory_components(model, *mandatory_model_components):
596595
return True
597596

598597

598+
<<<<<<< HEAD
599599
class InputError(Exception):
600600
"""Exception raised for errors in the input.
601601
@@ -614,11 +614,16 @@ def __str__(self):
614614
def load_aug(
615615
switch_data, optional=False, auto_select=False, optional_params=[], **kwds
616616
):
617+
=======
618+
def load_aug(switch_data, optional=False, auto_select=False,
619+
optional_params=[], **kwds):
620+
>>>>>>> 941c8e2e (Further improvements)
617621
"""
618622
This is a wrapper for the DataPortal object that accepts additional
619623
keywords. This currently supports a flag for the file being optional.
620624
The name load_aug() is not great and may be changed.
621625
"""
626+
<<<<<<< HEAD
622627
# TODO:
623628
# Allow user to specify filename when defining parameters and sets.
624629
# Also allow user to specify the name(s) of the column(s) in each set.
@@ -760,6 +765,9 @@ def get_column_name(p):
760765
# All done with cleaning optional bits. Pass the updated arguments
761766
# into the DataPortal.load() function.
762767
switch_data.load(**kwds)
768+
=======
769+
load_data(switch_data, optional, auto_select, optional_params, **kwds)
770+
>>>>>>> 941c8e2e (Further improvements)
763771

764772

765773
# Register a custom data manager that wraps the default CSVTable DataManager

0 commit comments

Comments
 (0)