PyPSA / pypsa-usa

PyPSA-USA: An Open-Source Energy System Optimization Model for the United States
https://pypsa-usa.readthedocs.io
MIT License
35 stars 15 forks source link

Suggestion for Demand Module Refactor #202

Closed trevorb1 closed 2 months ago

trevorb1 commented 4 months ago

Changes proposed in this Pull Request

Description

Suggestion to implement a strategy design to work with demand data. This is hopfully a little more extensible for when new demand sources are added for any sector. Im not saying we merge this, just meant to get a conversation going on how to deal with new datasets as they pop up!

In this example I only implement the reading and writing of EIA data (where writing is really just parsing). I think the reading is fairly clean, however, the writing probably needs a little work. I am not super familiar with how to dissagregation happens between different sources. So maybe instead of of a WriteEia strategy, it should be more along the lines of dissagregation strategies (based on BA, states, regions, population, ect...) or by sector. @ktehranchi may have better insights here!

Or maybe this just over complicates demand. haha. It would just be nice to reuse the demand module to pull heat demand (and eventually transport demand) data, which I think this module should allow.

Adding New Data

To read in a new dataset, the user will:

  1. Add a strategy that inherits from ReadStrategy class (ie. ReadEfs)
  2. Populate methods for _read_data(...) and _format_data(...) for the new class
  3. The _format_data(...) method must output long formatted data (with column labels of HOUR, REGION, YEAR, FUEL, SECTOR. However, format and labels are def up for discussion!

To write out a new dataset, the user will:

  1. Add a strategy that inherits from WriteStrategy class (ie. WriteEfs) -- As noted above, this should maybe be changed to dissagregation methods rather than tied to datasets.
  2. Populate the update_load_dissagregation_names(..) and get_demand_buses(..) methods

Example


n = pypsa.Network(snakemake.input.base_network)

demand_converter = Context(ReadEia(), WriteEia())

# optional arguments of 'fuel', 'sector', 'year'
demand = demand_converter.retrieve_demand("eia_data.csv", n)

Other Notes

Pros of this method are:

Cons of this method are:

Checklist

trevorb1 commented 4 months ago

Chatting with @ktehranchi, likely better to turn the Write strategies into dissagregation strategies instead, then just pass in any renaming dictionaries as kwargs

trevorb1 commented 3 months ago

We should revisist this now that PR #247 has been merged, but not applied

trevorb1 commented 2 months ago

Edit, Found a bug. Not done yet

Hi! I have finished this PR now, I believe. The major update (as described in the original description) is the introduction of a strategy design to handle the reading of different datasets, and the writing via different dissagregation strategies.

The high level UML is given below. Anything in color is implemented, while the white boxes show what I plan to work on next (note, WritePopulation implements breakthrough energy population, rather than county level population).

image

Other notable changes in this PR are:

Finally, the config file has been updated to reflect these changes with the following for electrical demand:

  demand: 
    profile: efs # efs, eia
    scale: 1 # efs, aeo, or a number 
    disaggregation: pop # pop
    scenario: 
      efs_case: reference # reference, medium, high
      efs_speed: moderate # slow, moderate, rapid

and the following for sectors

# docs :
sector:
  demand:
    profile:
      residential: eulp # efs, eulp
      commercial: eulp # efs, eulp
      transport: efs # efs
      industry: efs # efs
    scale:
      residential: aeo # efs, aeo
      commercial: aeo # efs, aeo
      transport: aeo # efs, aeo
      industry: aeo # efs, aeo
    disaggregation: 
      residential: pop # pop
      commercial: pop # pop
      transport: pop # pop
      industry: pop # pop
    scenarios:
      aeo: reference
trevorb1 commented 2 months ago

Okay great, this should be good to merge. @ktehranchi can you give it a quick run on your side though, please. Make sure you grab the config file demand updates! I have checked that both EFS and EIA data produce the same results from before this PR.

For future reference, I will just leave what I see the pros and cons of this method (expanded from initial PR description):