Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify grid model when creating scenario #337

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion powersimdata/input/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class Grid(object):
"""Grid

:param str/list interconnect: interconnect name(s).
:param str source: model used to build the network.
:param str source: should be either the name of a grid model within the
'*powersimdata/network*' directory or a filename for a '*.mat*' file, which
will be interpreted based on the engine which created it.
:param str engine: engine used to run scenario, if using ScenarioGrid.
:raises TypeError: if source and engine are not both strings.
:raises ValueError: if model or engine does not exist.
Expand Down
96 changes: 57 additions & 39 deletions powersimdata/scenario/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def __init__(self, scenario):
("start_date", ""),
("end_date", ""),
("interval", ""),
("engine", ""),
("engine", "REISE.jl"),
("grid_model", "usa_tamu"),
]
)
super().__init__(scenario)
Expand All @@ -69,6 +70,7 @@ def _update_scenario_info(self):
self._scenario_info["base_solar"] = self.builder.solar
self._scenario_info["base_wind"] = self.builder.wind
self._scenario_info["engine"] = self.builder.engine
self._scenario_info["grid_model"] = self.builder.grid_model
if bool(self.builder.change_table.ct):
self._scenario_info["change_table"] = "Yes"
else:
Expand All @@ -83,7 +85,6 @@ def _generate_and_set_scenario_id(self):
def _add_entry_in_execute_list(self):
"""Adds scenario to the execute list file on server and update status
information.

"""
self._execute_list_manager.add_entry(self._scenario_info)
self._scenario_status = "created"
Expand Down Expand Up @@ -231,26 +232,55 @@ def print_scenario_info(self):
for key, val in self._scenario_info.items():
print("%s: %s" % (key, val))

def set_engine(self, engine):
"""Sets simulation engine to be used for scenario.

:param str engine: simulation engine
"""
possible = ["REISE", "REISE.jl"]
if engine not in possible:
raise ValueError("Available engines: %s" % " | ".join(possible))
else:
self._scenario_info["engine"] = engine

def set_grid_model(self, model):
"""Sets grid model to be used for scenario.

:param str model: grid model
"""
possible = ["usa_tamu"]
if model not in possible:
raise ValueError("Available grid model: %s" % " | ".join(possible))
else:
self._scenario_info["grid_model"] = model

def set_builder(self, interconnect):
"""Sets builder.

:param list interconnect: name of interconnect(s).
"""

check_interconnect(interconnect)
n = len(interconnect)
if n == 1:
if "Eastern" in interconnect:
self.builder = Eastern(self._data_access)
self.builder = Eastern(
self._scenario_info["grid_model"], self._data_access
)
elif "Texas" in interconnect:
self.builder = Texas(self._data_access)
self.builder = Texas(
self._scenario_info["grid_model"], self._data_access
)
elif "Western" in interconnect:
self.builder = Western(self._data_access)
self.builder = Western(
self._scenario_info["grid_model"], self._data_access
)
elif "USA" in interconnect:
self.builder = USA(self._data_access)
self.builder = USA(self._scenario_info["grid_model"], self._data_access)
elif n == 2:
if "Western" in interconnect and "Texas" in interconnect:
self.builder = TexasWestern(self._data_access)
self.builder = TexasWestern(
self._scenario_info["grid_model"], self._data_access
)
elif "Eastern" in interconnect and "Texas" in interconnect:
print("Not implemented yet")
return
Expand All @@ -277,7 +307,8 @@ def set_builder(self, interconnect):
class _Builder(object):
"""Scenario Builder.

:param list interconnect: list of interconnect(s) to build.
:param tuple grid_info: first element is a list of interconnect(s). Second element
is the grid model.
:param powersimdata.utility.transfer_data.DataAccess data_access:
data access object.
"""
Expand All @@ -296,13 +327,12 @@ class _Builder(object):
hydro = ""
solar = ""
wind = ""
engine = "REISE.jl"
name = "builder"

def __init__(self, interconnect, data_access):
def __init__(self, grid_info, data_access):
"""Constructor."""
self.base_grid = Grid(interconnect)
self.profile = CSV(interconnect, data_access)
self.base_grid = Grid(grid_info[0], source=grid_info[1])
self.profile = CSV(grid_info[0], data_access)
self.change_table = ChangeTable(self.base_grid)
self._scenario_list_manager = ScenarioListManager(data_access)

Expand Down Expand Up @@ -389,18 +419,6 @@ def set_base_profile(self, kind, version):
% (kind, " + ".join(self.interconnect), " | ".join(possible))
)

def set_engine(self, engine):
"""Sets simulation engine to be used for scenarion.

:param str engine: simulation engine
"""
possible = ["REISE", "REISE.jl"]
if engine not in possible:
print("Available engines: %s" % " | ".join(possible))
return
else:
self.engine = engine

def load_change_table(self, filename):
"""Uploads change table.

Expand Down Expand Up @@ -429,21 +447,21 @@ class Eastern(_Builder):

name = "Eastern"

def __init__(self, data_access):
def __init__(self, grid_model, data_access):
"""Constructor."""
self.interconnect = ["Eastern"]
super().__init__(self.interconnect, data_access)
super().__init__((self.interconnect, grid_model), data_access)


class Texas(_Builder):
"""Builder for Texas interconnect."""

name = "Texas"

def __init__(self, data_access):
def __init__(self, grid_model, data_access):
"""Constructor."""
self.interconnect = ["Texas"]
super().__init__(self.interconnect, data_access)
super().__init__((self.interconnect, grid_model), data_access)


class Western(_Builder):
Expand All @@ -454,10 +472,10 @@ class Western(_Builder):

name = "Western"

def __init__(self, data_access):
def __init__(self, grid_model, data_access):
"""Constructor."""
self.interconnect = ["Western"]
super().__init__(self.interconnect, data_access)
super().__init__((self.interconnect, grid_model), data_access)


class TexasWestern(_Builder):
Expand All @@ -468,43 +486,43 @@ class TexasWestern(_Builder):

name = "Texas_Western"

def __init__(self, data_access):
def __init__(self, grid_model, data_access):
"""Constructor."""
self.interconnect = ["Texas", "Western"]
super().__init__(self.interconnect, data_access)
super().__init__((self.interconnect, grid_model), data_access)


class TexasEastern(_Builder):
"""Builder for Texas + Eastern interconnect."""

name = "Texas_Eastern"

def __init__(self, data_access):
def __init__(self, grid_model, data_access):
"""Constructor."""
self.interconnect = ["Texas", "Eastern"]
super().__init__(self.interconnect, data_access)
super().__init__((self.interconnect, grid_model), data_access)


class EasternWestern(_Builder):
"""Builder for Eastern + Western interconnect."""

name = "Eastern_Western"

def __init__(self, data_access):
def __init__(self, grid_model, data_access):
"""Constructor."""
self.interconnect = ["Eastern", "Western"]
super().__init__(self.interconnect, data_access)
super().__init__((self.interconnect, grid_model), data_access)


class USA(_Builder):
"""Builder for USA interconnect."""

name = "USA"

def __init__(self, data_access):
def __init__(self, grid_model, data_access):
"""Constructor."""
self.interconnect = ["USA"]
super().__init__(self.interconnect, data_access)
super().__init__((self.interconnect, grid_model), data_access)


class CSV(object):
Expand Down
9 changes: 6 additions & 3 deletions powersimdata/scenario/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def __init__(self, scenario):

def _set_ct_and_grid(self):
"""Sets change table and grid."""
base_grid = Grid(self._scenario_info["interconnect"].split("_"))
base_grid = Grid(
self._scenario_info["interconnect"].split("_"),
source=self._scenario_info["grid_model"],
)
if self._scenario_info["change_table"] == "Yes":
input_data = InputData()
self.ct = input_data.get_data(self._scenario_info, "ct")
Expand Down Expand Up @@ -162,8 +165,8 @@ def prepare_simulation_input(self, profiles_as=None):
def launch_simulation(self, threads=None, extract_data=True):
"""Launches simulation on server.

:param int/None threads: the number of threads to be used. This defaults to None,
where None means auto.
:param int/None threads: the number of threads to be used. This defaults to
None, where None means auto.
:param bool extract_data: whether the results of the simulation engine should
automatically extracted after the simulation has run. This defaults to True.
:raises TypeError: if threads is not an int or if extract_data is not a boolean
Expand Down