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: calculate MW-miles for transmission-expanded change tables #41

Merged
merged 4 commits into from
Nov 8, 2019

Conversation

danielolsen
Copy link
Contributor

This branch adds a new script analyze/mwmiles.py to calculate the aggregate MW-miles of upgrades from a given Scenario object, with a corresponding test_mwmiles.py script. This testing functionality uses several testing tools added in the PR for carbon (#39): the tests/ folder in root, the context.py file to ensure that the tests always import the right version of PostREISE, and the mock objects in mocks.py.

@danielolsen
Copy link
Contributor Author

The unit tests test the individual functions with the mocks. An integration test against the real object can be run as:

from powersimdata.scenario.scenario import Scenario
from postreise.analyze.mwmiles import calculate_mw_miles
scenario = Scenario('130')
mwmiles = calculate_mw_miles(scenario)
print(mwmiles)

@rouille
Copy link
Collaborator

rouille commented Nov 8, 2019

I ran the following and got an error:

>>> from powersimdata.scenario.scenario import Scenario
>>> s = Scenario('87')
SCENARIO: base | WesternBase_2016_noHVDC_Final_2019Sep

--> State
analyze
--> Loading ct
--> Loading Western interconnect
Loading zone
Loading sub
Loading bus2sub
Loading bus
Loading plant
Loading plant cost
Loading branch
Loading DC line
>>> from postreise.analyze.mwmiles import calculate_mw_miles
>>> a = calculate_mw_miles(s)
--> Loading Western interconnect
Loading zone
Loading sub
Loading bus2sub
Loading bus
Loading plant
Loading plant cost
Loading branch
Loading DC line
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/brdo/REM/PostREISE/postreise/analyze/mwmiles.py", line 46, in calculate_mw_miles
    upgrades = _calculate_mw_miles(original_grid, ct)
  File "/Users/brdo/REM/PostREISE/postreise/analyze/mwmiles.py", line 68, in _calculate_mw_miles
    upgraded_branches = ct['branch']['branch_id']
KeyError: 'branch'

This is the base case scenario and hence branches are not upgraded, i.e., ct['branch'] throws you an error. I guess we could add a if or try here to handle that as you did in interstate/intrastate:

if 'branch' not in ct or 'branch_id' not in ct['branch']:
        return upgraded_branches

@danielolsen
Copy link
Contributor Author

Good catch @rouille, I added an if/return to handle this case.

Copy link
Collaborator

@rouille rouille left a comment

Choose a reason for hiding this comment

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

One more

@rouille rouille merged commit fb95a74 into develop Nov 8, 2019
@rouille rouille deleted the calc_mw_miles branch November 8, 2019 23:22
@rouille rouille restored the calc_mw_miles branch November 11, 2019 20:11
@ahurli ahurli mentioned this pull request Mar 16, 2021
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.

2 participants