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

feat: add functionality to load Grid objects with HIFLD grid model #566

Merged
merged 3 commits into from
Dec 18, 2021

Conversation

danielolsen
Copy link
Contributor

@danielolsen danielolsen commented Nov 22, 2021

Pull Request doc

Purpose

Allows the user to instantiate HIFLD grid objects by adding the necessary folder structure and sub-modules. Closes #551.

What the code is doing

  • In powersimdata.network.hifld.model: defining an HIFLD class, and populating it with necessary methods. Most of this code is copied directly from powersimdata.network.usa_tamu.model
  • In powersimdata.input.grid: adding "hifld" as an allowable model/source input, and instantiating an HIFLD object as appropriate.
  • In powersimdata.network.model: adding "hifld" as an acceptable model for instantiating a ModelImmutables object.
  • Mostly-empty __init__.py files as necessary within powersimdata.network.hifld.constants. These will be filled in before this PR gets promoted out of draft stage.

Testing

Current testing relies on Breakthrough-Energy/PreREISE#236 and Breakthrough-Energy/PreREISE#240. Through their combination in the PreREISE testing branch daniel/hifld_top_level_rebased, and with the branch for this PR (EDIT: #240 has been merged). Using the branch for #236, we can:

# Building the hifld grid
# This step currently takes 20-30 minutes to download/process all data
from prereise.gather.griddata.hifld import create_csvs
create_csvs("path/to/powersimdata/network/hifld/data")

# Loading and checking the hifld grid
from powersimdata import Grid
from powersimdata.input.check import check_grid
check_grid(Grid("USA", "hifld"))
check_grid(Grid("Eastern", "hifld"))
check_grid(Grid("Western", "hifld"))
check_grid(Grid("ERCOT", "hifld"))
check_grid(Grid(["Eastern", "Western"], "hifld"))
check_grid(Grid(["Eastern", "ERCOT"], "hifld"))
check_grid(Grid(["ERCOT", "Western"], "hifld"))

Checks should all pass, returning None without raising any exceptions.

Other entries within powersimdata.network.hifld.constants still need to be populated, but those will be just straightforward data-filling and shouldn't affect code functionality, besides enabling the relevant information to be looked up for hifld Grid object by other functions/methods.

Time estimate

15-30 minutes. Most new code isn't actually new, just copied with slight tweaks.

@danielolsen danielolsen requested a review from kasparm November 22, 2021 17:54
@danielolsen danielolsen self-assigned this Nov 22, 2021
@rouille
Copy link
Collaborator

rouille commented Nov 22, 2021

I know we made a mistake to use Texas in place of ERCOT for the TAMU grid but should right our mistake for HIFLD? We have a lot of code that check/analyze/plot interconnect(s), I presume these expect Texas.

@danielolsen
Copy link
Contributor Author

I know we made a mistake to use Texas in place of ERCOT for the TAMU grid but should right our mistake for HIFLD? We have a lot of code that check/analyze/plot interconnect(s), I presume these expect Texas.

I think any code that's not model-specific should look to the grid model for the appropriate interconnections. If our check/analyze/plot code isn't working, then we should change it to look for the right information in the right place (and make sure that information is there). We'll need this sooner or later, either for the new USA grid model or for models of other grids (e.g. Europe).

@danielolsen danielolsen force-pushed the daniel/read_hifld_grid branch from 9acf63c to d78a404 Compare November 23, 2021 00:08
@danielolsen
Copy link
Contributor Author

After tweaking the output plant CSV a bit more within Breakthrough-Energy/PreREISE#236 (adding type, adding heat rate columns, translating to PowerSimData naming expectations), and updating the placeholders within in constants sub-module, we can also successfully call powersimdata.input.export_data.export_case_mat on the resulting grids.

@danielolsen danielolsen marked this pull request as ready for review November 29, 2021 22:10
@danielolsen
Copy link
Contributor Author

danielolsen commented Nov 29, 2021

The latest commits add the missing constants required to fully populate the ModelImmutables object which should enable the full suite of Grid analyses:

>>> from powersimdata.network.model import ModelImmutables
>>> mi_tamu = ModelImmutables("usa_tamu")
>>> mi_hifld = ModelImmutables("hifld")
>>> mi_tamu.plants.keys() == mi_hifld.plants.keys()
True
>>> mi_tamu.zones.keys() == mi_hifld.zones.keys()
True
>>> mi_tamu.storage.keys() == mi_hifld.storage.keys()
True

constants.plants and constants.storage are identical between the usa_tamu and hifld grid models, and constants.zones only differs by using "ERCOT" in place of "Texas".

Therefore, this is now ready for a full review.

@danielolsen danielolsen force-pushed the daniel/read_hifld_grid branch from fe1e27f to ca9892c Compare December 1, 2021 01:40
@danielolsen danielolsen requested a review from jenhagg December 6, 2021 22:52


class HIFLD(AbstractGrid):
def __init__(self, interconnect):
Copy link
Collaborator

@jenhagg jenhagg Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could move all the instance methods to AbstractGrid, then just declare:

class HIFLD(AbstractGrid):
    pass

Same for the TAMU grid. Edit: I guess the __file__ would have to be passed to super

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense. Is that still an abstract class then. It would look like a Parent class. Do we need to rename it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, didn't see this one so replied below

Copy link
Contributor Author

@danielolsen danielolsen Dec 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do within the child HIFLD and TAMU classes:

def __init__(self, interconnect):
    self.top_dirname = os.path.dirname(__file__)
    self.interconnect = check_and_format_interconnect(interconnect)
    super().__init__()

and then within the parent AbstractGrid class:

def __init__(self):
    self._set_data_loc()
    self._build_network()

def _set_data_loc(self):
    """Sets data location
    :raises IOError: if directory does not exist.
    """
    data_loc = os.path.join(self.top_dirname, "data")
    if os.path.isdir(data_loc) is False:
        raise IOError("%s directory not found" % data_loc)
    else:
        self.data_loc = data_loc

And within the ScenarioGrid class:

def __init__(self, filename):
    self.filename = filename
    super().__init__()

def _set_data_loc(self):
    """Sets data location.
    :raises FileNotFoundError: if file does not exist.
    """
    if os.path.isfile(self.filename) is False:
        raise FileNotFoundError("%s file not found" % self.filename)
    else:
        self.data_loc = filename

The result: the children set their pre-init information (self.top_dirname for TAMU and HIFLD, from __file__; self.filename for ScenarioGrid), and then the parent always calls _set_data_loc and _build_network, which are tweaked to take only self as an input and look to the appropriate attributes to get the directory or filename that they need to work with.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved things around and everything appears to be working, including loading a grid from a previously-run Scenario.

"solar_curtailment": "Solar Curtailment",
"wind_curtailment": "Wind Curtailment",
"wind_offshore_curtailment": "Offshore Wind Curtailment",
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that PostREISE plotting functions rely on this dictionary and it is convenient to group generator type and curtailment but it is ugly. Curtailment color label/color should be moved in a dedicated dictionary. This completely out of the scope of this PR.

"solar_curtailment": "xkcd:grey",
"wind_curtailment": "xkcd:grey",
"wind_offshore_curtailment": "xkcd:grey",
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here curtailment is not a generator type



class HIFLD(AbstractGrid):
def __init__(self, interconnect):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense. Is that still an abstract class then. It would look like a Parent class. Do we need to rename it?

@jenhagg
Copy link
Collaborator

jenhagg commented Dec 8, 2021

It makes sense. Is that still an abstract class then. It would look like a Parent class. Do we need to rename it?

An abstract class can have some behavior defined. Typically it would also declare abstract methods, to be implemented by derived classes. So if there are only "concrete" methods, a rename could make sense, e.g. BaseGrid. I don't feel strongly about it though since python doesn't enforce such things. Compared to e.g. java/c# where abstract is a keyword and enforced by the compiler.

@danielolsen danielolsen force-pushed the daniel/read_hifld_grid branch from 292e70d to 4595c56 Compare December 18, 2021 01:42
@danielolsen danielolsen changed the base branch from develop to hifld December 18, 2021 01:44
@danielolsen danielolsen merged commit 66203b4 into hifld Dec 18, 2021
@danielolsen danielolsen deleted the daniel/read_hifld_grid branch December 18, 2021 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable HIFLD grid model to instantiate Grid objects
3 participants