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

Factor out functions that check input parameters #153

Merged
merged 2 commits into from
Aug 29, 2020
Merged

Conversation

rouille
Copy link
Collaborator

@rouille rouille commented Aug 27, 2020

Purpose

Factor out functions that check input parameters of analysis functions and gather them in a common module.

What is the code doing

I moved things around to avoid duplicates

Where to look

  • a new postreise.analyze.check module has been created.
  • already existing check functions from analysis modules have been moved in this new module.
  • some tests have been modified

Time estimate

20min. The tests fail because PR Breakthrough-Energy/PowerSimData#273 need to be merged

@rouille rouille added this to the WTT90s milestone Aug 27, 2020
@rouille rouille requested review from danielolsen and jenhagg August 27, 2020 00:14
@rouille
Copy link
Collaborator Author

rouille commented Aug 27, 2020

I could probably write some tests for the check functions but since we test the input parameters of the analysis functions that use these functions I thought it was not necessary.

@jenhagg
Copy link
Collaborator

jenhagg commented Aug 27, 2020

Are we still using _resource_func defined in curtailment.py? There are still docstrings referencing it instead of the new constants in powersimdata.

@danielolsen
Copy link
Contributor

Are we still using _resource_func defined in curtailment.py? There are still docstrings referencing it instead of the new constants in powersimdata.

Yes, we use it within calculate_curtailment_time_series() so that we know that to get the profiles for both 'wind' and 'wind_offshore' we use the get_wind() method. It is another example of ugly getattr code from a few months back: https://github.com/Breakthrough-Energy/PostREISE/blob/develop/postreise/analyze/generation/curtailment.py#L100

@rouille
Copy link
Collaborator Author

rouille commented Aug 27, 2020

Are we still using _resource_func defined in curtailment.py? There are still docstrings referencing it instead of the new constants in powersimdata.

Yes, we use it within calculate_curtailment_time_series() so that we know that to get the profiles for both 'wind' and 'wind_offshore' we use the get_wind() method. It is another example of ugly getattr code from a few months back: https://github.com/Breakthrough-Energy/PostREISE/blob/develop/postreise/analyze/generation/curtailment.py#L100

Should we have a get_wind_offshore in the Analyze class that returns the None if there is no such generators in the scenario and the profile for the wind offshore plant otherwise?

@jenhagg
Copy link
Collaborator

jenhagg commented Aug 27, 2020

Oh I see how it's used. We might still want to update the docstring, since the default is now renewable_resources instead of _resource_func.keys(). Also, minor point, but we are introducing the requirement that those two are equal, otherwise there could be a KeyError on _resource_func - might be worth having a test to validate that.

@rouille
Copy link
Collaborator Author

rouille commented Aug 27, 2020

Oh I see how it's used. We might still want to update the docstring, since the default is now renewable_resources instead of _resource_func.keys(). Also, minor point, but we are introducing the requirement that those two are equal, otherwise there could be a KeyError on _resource_func - might be worth having a test to validate that.

We can revert and use the keys. I used the renewable_resources list with the hope of getting rid of the dict but I gave up.

@jenhagg
Copy link
Collaborator

jenhagg commented Aug 27, 2020

Oh I see how it's used. We might still want to update the docstring, since the default is now renewable_resources instead of _resource_func.keys(). Also, minor point, but we are introducing the requirement that those two are equal, otherwise there could be a KeyError on _resource_func - might be worth having a test to validate that.

We can revert and use the keys. I used the renewable_resources list with the hope of getting rid of the dict but I gave up.

It seems like a step in the right direction, no need to revert in my opinion (up to you though).

@danielolsen
Copy link
Contributor

Should we have a get_wind_offshore in the Analyze class that returns the None if there is no such generators in the scenario and the profile for the wind offshore plant otherwise?

This might be the cleanest way to get rid of a lot of the ugliness in our codebase. Storing the 'wind_offshore' profiles within get_wind() seemed easy at the time, and stays consistent with the profiles living in e.g. usa_wind_v*.csv on the server, but there is lots of weirdness that we had to do to make everything work around this.

@rouille
Copy link
Collaborator Author

rouille commented Aug 27, 2020

@danielolsen. Is the following:

# For simple methods:
# MWh to metric tons of CO2
# Source: IPCC Special Report on Renewable Energy Sources and Climate Change
# Mitigation (2011), Annex II: Methodology, Table A.II.4, 50th percentile
# http://www.ipcc-wg3.de/report/IPCC_SRREN_Annex_II.pdf
carbon_per_mwh = {
    "coal": 1001,
    "dfo": 840,
    "ng": 469,
}

# For curve methods:
# MMBTu of fuel per hour to metric tons of CO2 per hour
# Source: https://www.epa.gov/energy/greenhouse-gases-equivalencies-calculator-calculations-and-references
# = (Heat rate MMBTu/h) * (kg C/mmbtu) * (mass ratio CO2/C) / (kg to tonnes)
carbon_per_mmbtu = {
    "coal": 26.05,
    "dfo": 20.31,
    "ng": 14.46,
}

defined in the carbon module something that could be moved in powersimdata.network.usa_tamu.constants.plants? If yes, this can be part of PR Breakthrough-Energy/PowerSimData#273

@danielolsen
Copy link
Contributor

@danielolsen. Is the following:

# For simple methods:
# MWh to metric tons of CO2
# Source: IPCC Special Report on Renewable Energy Sources and Climate Change
# Mitigation (2011), Annex II: Methodology, Table A.II.4, 50th percentile
# http://www.ipcc-wg3.de/report/IPCC_SRREN_Annex_II.pdf
carbon_per_mwh = {
    "coal": 1001,
    "dfo": 840,
    "ng": 469,
}

# For curve methods:
# MMBTu of fuel per hour to metric tons of CO2 per hour
# Source: https://www.epa.gov/energy/greenhouse-gases-equivalencies-calculator-calculations-and-references
# = (Heat rate MMBTu/h) * (kg C/mmbtu) * (mass ratio CO2/C) / (kg to tonnes)
carbon_per_mmbtu = {
    "coal": 26.05,
    "dfo": 20.31,
    "ng": 14.46,
}

defined in the carbon module something that could be moved in powersimdata.network.usa_tamu.constants.plants? If yes, this can be part of PR Breakthrough-Energy/PowerSimData#273

Yes.

@rouille rouille force-pushed the ben/factor-out branch 3 times, most recently from e194079 to 2952aa4 Compare August 27, 2020 23:13
Copy link
Contributor

@danielolsen danielolsen left a comment

Choose a reason for hiding this comment

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

The code looks good, thanks for cleaning this up. If the tests pass once the dependency issue is worked out, I think it's good to go.

@rouille rouille force-pushed the ben/factor-out branch 3 times, most recently from 763dc58 to 49f1d62 Compare August 28, 2020 19:53
@rouille rouille linked an issue Aug 29, 2020 that may be closed by this pull request
@rouille rouille merged commit 16d36d0 into develop Aug 29, 2020
@rouille rouille deleted the ben/factor-out branch August 29, 2020 00:08
@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.

Factor out functions that check input parameters
3 participants