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

Calculate capacity value #114

Merged
merged 6 commits into from
May 27, 2020
Merged

Calculate capacity value #114

merged 6 commits into from
May 27, 2020

Conversation

danielolsen
Copy link
Contributor

Purpose

Calculate the capacity value for one or more resources. This is defined by the difference between the average demand over the top N hours and the average net demand over the top N hours (with N hours selected independently in each case, since the set of hours may differ).
Closes #80.

What is the code doing

capacity_value.py defines the calculation function.

test_capacity_value.py tests the calculation function.

Time to review

Half an hour. Actual calculations are ~10 lines, the rest is input checking and tests.

# Then calculate capacity value
plant_groupby = grid.plant.groupby('type')
plant_indices = sum(
[plant_groupby.get_group(r).index.tolist() for r in resources], [])
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice trick

@rouille
Copy link
Collaborator

rouille commented May 21, 2020

I don't understand why PyCharm complains about the type of the scenario parameter that you pass to the calculate_capacity_value function in your tests. It says 'Expected Scenario, got MockScenario instead'. It seems that type(class) is not type(obj), where obj is an instance of class.

Copy link

@danlivengood danlivengood left a comment

Choose a reason for hiding this comment

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

Conceptually, I'm happy with this. Those tests might look counterintuitive (capacity value decreases with fewer hours), but I'm seeing similar results with data from Western and Texas. Once Ben's adjustments are addressed, I support Approving this PR.

@danielolsen
Copy link
Contributor Author

@rouille I don't know what PyCharm's issue is. For our MockScenario, we redefine the __class__ attribute, and isinstance will evaluate as true for both Scenario and MockScenario, but the return of type is still the original type. I don't know if this matters for our purposes.

>>> from powersimdata.scenario.scenario import Scenario
>>> from powersimdata.tests.mock_scenario import MockScenario
>>> ms = MockScenario(grid_attrs={})
>>> type(ms)
<class 'powersimdata.tests.mock_scenario.MockScenario'>
>>> ms.__class__
<class 'powersimdata.scenario.scenario.Scenario'>
>>> isinstance(ms, MockScenario)
True
>>> isinstance(ms, Scenario)
True

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.

Looks good. I agree with the calculation. All tests pass.

@rouille
Copy link
Collaborator

rouille commented May 22, 2020

I think PyCharm looks at the docstring and see that the scenario argument should be a powersimdata.scenario.scenario.Scenario and not a powersimdata.tests.mock_scenario.MockScenario. We can't do much about it.

@danielolsen
Copy link
Contributor Author

I added one more calculation method based on conversations with @danlivengood and @yixingxu and generalized the code a bit to be a little less repetitive, now that we have two different methods. The new method is also tested. If y'all liked the old one, you probably still like this too, but I'll leave this open until Monday night to give you a chance to register objections or extra approval.

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.

Looks good. Second function makes sense. All tests pass.

:param powersimdata.scenario.scenario.Scenario scenario: analyzed scenario.
:param (str/list/tuple/set) resources: one or more resources to analyze.
:param int hours: number of hours to analyze.
:return: (*float*) -- difference between peak demand and peak net demand.

Choose a reason for hiding this comment

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

Super nitpicky change request: This looks like a copy/paste from the NLDC function. However, I believe the return for calculate_net_load_peak is returning the resource capacity during the hours of net demand, not the differential.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed!

@danielolsen danielolsen merged commit c8f1a9e into develop May 27, 2020
@danielolsen danielolsen deleted the capacity_value branch May 27, 2020 00:19
@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.

Add analysis of capacity value of VRE generators
3 participants