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

Access a specific GWP when calculating CO2 mass equivalent value #352

Merged
merged 1 commit into from
Mar 20, 2024

Conversation

rouille
Copy link
Collaborator

@rouille rouille commented Mar 19, 2024

Purpose

Allow to calculate a CO2 mass equivalent value using a Global Warming Potential (GWP) value published in any available IPCC's assessment report (AR).

What the code is doing

Modify the calculate_co2e_mass function such that its second parameter can be used to fetch not only the most recent AR that was available in the given year as done previously but also to directly fetch the AR.

Testing

Tested manually

Where to look

In the oge.emissions module

Usage Example/Visuals

>>> import pandas as pd
>>> from emissions import calculate_co2e_mass
>>> calculate_co2e_mass(pd.DataFrame(), "AR32")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/brdo/Singularity/open-grid-emissions/src/oge/emissions.py", line 418, in calculate_co2e_mass
    raise ValueError(
ValueError: version must be a year in [1995, 2021] or a valid AR
>>> calculate_co2e_mass(pd.DataFrame(), 2022)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/brdo/Singularity/open-grid-emissions/src/oge/emissions.py", line 418, in calculate_co2e_mass
    raise ValueError(
ValueError: version must be a year in [1995, 2021] or a valid AR

Review estimate

2min

Future work

N/A

Checklist

  • Update the documentation to reflect changes made in this PR
  • Format all updated python files using black
  • Clear outputs from all notebooks modified
  • Add docstrings and type hints to any new functions created

@rouille rouille added the new feature New feature or request label Mar 19, 2024
@rouille rouille self-assigned this Mar 19, 2024
@rouille rouille requested a review from grgmiller March 19, 2024 22:44
Copy link
Collaborator

@grgmiller grgmiller left a comment

Choose a reason for hiding this comment

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

Some changes requested. It would be helpful if you could test passing the following to see what it returns:

  • 2022 (should return AR6 numbers)
  • "AR4" (should return AR4)
  • Test several variations of AR5 with and without the CC feedback.

src/oge/emissions.py Outdated Show resolved Hide resolved
src/oge/emissions.py Outdated Show resolved Hide resolved
src/oge/emissions.py Outdated Show resolved Hide resolved
src/oge/emissions.py Show resolved Hide resolved
@rouille
Copy link
Collaborator Author

rouille commented Mar 19, 2024

Some changes requested. It would be helpful if you could test passing the following to see what it returns:

* 2022 (should return AR6 numbers)

* "AR4" (should return AR4)

* Test several variations of AR5 with and without the CC feedback.

In the last version of the code where I have a print of the ipcc_version (to be removed before merging) at the end of the if/else logic, I have got the following:

>>> import pandas as pd
>>> from emissions import calculate_co2e_mass
>>> calculate_co2e_mass(pd.DataFrame(), 2022)
AR6
>>> calculate_co2e_mass(pd.DataFrame(), "latest")
AR6
>>> calculate_co2e_mass(pd.DataFrame(), "AR4")
AR4
>>> calculate_co2e_mass(pd.DataFrame(), "AR5")
AR5
>>> calculate_co2e_mass(pd.DataFrame(), "AR5_cc")
AR5_cc
>>> calculate_co2e_mass(pd.DataFrame(), "AR5", ar5_climate_carbon_feedback=True)
AR5
>>> calculate_co2e_mass(pd.DataFrame(), "AR5", ar5_climate_carbon_feedback=False)
AR5
>>> calculate_co2e_mass(pd.DataFrame(), "AR5_cc", ar5_climate_carbon_feedback=False)
AR5_cc
>>> calculate_co2e_mass(pd.DataFrame(), "AR5_cc", ar5_climate_carbon_feedback=True)
AR5_cc
>>> calculate_co2e_mass(pd.DataFrame(), "AR7")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/brdo/Singularity/open-grid-emissions/src/oge/emissions.py", line 418, in calculate_co2e_mass
    raise ValueError(
ValueError: version must be a year > 1995 or a valid AR
>>> calculate_co2e_mass(pd.DataFrame(), 1990)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/brdo/Singularity/open-grid-emissions/src/oge/emissions.py", line 418, in calculate_co2e_mass
    raise ValueError(
ValueError: version must be a year >= 1995 or a valid AR
>>> 

Copy link
Collaborator

@grgmiller grgmiller left a comment

Choose a reason for hiding this comment

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

Thanks Ben, a few small additional documentation changes requested, but otherwise good to go.

@grgmiller
Copy link
Collaborator

Looks good to me! Should be ready to merge.

@rouille rouille merged commit 0d0abd9 into development Mar 20, 2024
2 checks passed
@rouille rouille deleted the ben/gwp branch March 20, 2024 22:44
This was referenced Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants