Skip to content

Commit

Permalink
Merge pull request #49 from iiasa/fix/no2010
Browse files Browse the repository at this point in the history
Fix if all emissions data starts in 2015, in :func:`add_year_historical_percentage_offset`
  • Loading branch information
jkikstra authored Dec 1, 2023
2 parents 485f3d2 + 20f3f9f commit 37e9d39
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci-cd-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
- name: Formatting and linters
run: |
black --check src scripts tests setup.py --exclude doc/conf.py
black-nb --check notebooks
isort --check-only --quiet src scripts tests setup.py doc/conf.py
flake8 src scripts tests setup.py doc/conf.py
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ master

Added
~~~~~
- (`#40 https://github.com/iiasa/climate-assessment/pull/43`_) Add combined CSV output option to :func:`climate_assessment.cli.clim_cli`
- (`#43 https://github.com/iiasa/climate-assessment/pull/43`_) Add combined CSV output option to :func:`climate_assessment.cli.clim_cli`
- (`#40 https://github.com/iiasa/climate-assessment/pull/40`_) Update awscli to >= 1.29.4
- (`#36 https://github.com/iiasa/climate-assessment/pull/36`_) Update pyam-iamc to >=1.9.0
- (`#31 https://github.com/iiasa/climate-assessment/pull/31`_) Update pyam-iamc to >=1.7.0
Expand All @@ -28,6 +28,11 @@ Added
- (`#1 <https://github.com/iiasa/climate-assessment/pull/1>`_) Added :func:`climate_assessment.cli.run_workflow`


Fixed
~~~~~
- (`#49 https://github.com/iiasa/climate-assessment/pull/49`_) Fix if all emissions data starts in 2015, in :func:`add_year_historical_percentage_offset`


v0.1.0 - 2022-06-08
-------------------

Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ deploy =
linter =
bandit
black
black-nb
flake8
isort

Expand Down
3 changes: 2 additions & 1 deletion src/climate_assessment/harmonization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def add_year_historical_percentage_offset(df, dfhist, yr=2015, low_yr=2010):
dfno2015[yr] = fill_values[yr].reorder_levels(dfno2015.index.names)
df = pd.concat([df2015, dfno2015])
else:
raise KeyError(f"{low_yr} not in `dfno2015`")
if not dfno2015.empty:
raise KeyError(f"{low_yr} not in `dfno2015`")

return df

Expand Down
17 changes: 17 additions & 0 deletions tests/regression/test_harmonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def check_output(
def test_workflow_harmonization(tmpdir, test_data_dir, update_expected_files):
out_dir = str(tmpdir)

# standard test emissions scenarios file
emissions_id = "ex2"

runner = CliRunner()
Expand Down Expand Up @@ -111,6 +112,22 @@ def test_workflow_harmonization(tmpdir, test_data_dir, update_expected_files):
obj="Comparison with workflow output after checking for negatives",
)

# also test with test data that only has data starting in 2015
emissions_id_2015 = "ex2_starting2015"

runner_2015 = CliRunner()
result_2015 = runner_2015.invoke(
climate_assessment.cli.harmonize,
[
os.path.join(test_data_dir, "{}.csv".format(emissions_id_2015)),
out_dir,
],
)

assert result_2015.exit_code == 0, "{}\n\n{}".format(
traceback.print_exception(*result_2015.exc_info), result_2015.stdout
)


def test_workflow_harmonization_noinputchecks(
tmpdir,
Expand Down
31 changes: 31 additions & 0 deletions tests/test-data/ex2_starting2015.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Model,Scenario,Region,Variable,Unit,2015,2020,2025,2030,2035,2040,2045,2050,2055,2060,2065,2070,2075,2080,2085,2090,2095,2100
model1,1point5,World,Emissions|BC,Mt BC/yr,10.70016593,9.638053494,8.464214366,7.507617718,6.396375551,5.556133493,4.839623622,4.290927929,3.848178128,3.576185377,3.27786788,2.990673195,2.637375742,2.357716923,2.203839801,2.067082614,1.97410705,1.873144781
model1,1point5,World,Emissions|CH4,Mt CH4/yr,349.2655161,310.8153209,291.1688805,273.372279,255.3192562,241.1204483,227.3543533,219.8460899,214.752028,219.0230043,218.4555877,223.9941613,221.196423,222.8977081,218.6504778,215.3958681,217.7858237,219.9701913
model1,1point5,World,Emissions|CO,Mt CO/yr,981.0673789,998.0868231,933.8361993,887.8196655,815.8499917,768.4012065,733.7171685,718.1324989,719.7291893,753.898531,780.4452257,812.0807608,809.9761183,830.3316809,820.6549187,813.9548184,825.9766284,836.1481031
model1,1point5,World,Emissions|CO2,Mt CO2/yr,39412.52133,37855.99706,32349.5685,26839.32928,21581.95802,17992.38495,14567.58604,12015.70265,9824.178097,7970.014276,6406.494901,5070.843906,4265.107555,3548.762507,2951.197814,2642.955972,2445.008407,2164.488878
model1,1point5,World,Emissions|CO2|AFOLU,Mt CO2/yr,4572.672,4793.603869,4811.760302,4720.016198,4403.396081,3904.039648,3327.695577,2721.631318,2085.824135,1420.28527,725.0269714,1,1,1,1,1,1,1
model1,1point5,World,Emissions|CO2|Energy and Industrial Processes,Mt CO2/yr,37280.10127,35483.4875,29744.31775,24089.95224,18880.09989,15551.69186,12456.76602,10293.33139,8528.550349,7138.504918,6074.618764,5271.669408,4434.022706,3689.307557,3068.076936,2747.627496,2541.840423,2250.21121
model1,1point5,World,Emissions|N2O,kt N2O/yr,7630,6384.674386,6237.886495,6196.692604,5921.983441,5459.192277,5111.540289,4864.493252,4649.896864,4689.868465,4496.51009,4571.548368,4308.165892,4297.676692,4043.294109,3813.183663,3755.344533,3639.272374
model1,1point5,World,Emissions|NH3,Mt NH3/yr,52.2237625,54.17814586,56.06194238,57.15376084,56.4330242,55.32240587,53.67340428,52.31129817,51.58043544,52.04222008,51.64064558,51.98183115,51.07320617,50.71431281,49.91101395,49.02794223,49.17227157,49.03921428
model1,1point5,World,Emissions|OC,Mt OC/yr,31.27142181,30.23497517,26.92902851,24.22916557,21.18343603,18.74863349,16.64067225,14.99370208,13.65612234,12.7733758,11.80140359,11.03044107,10.00069472,9.208704515,8.317361491,7.505500119,6.862503838,6.241547967
model1,1point5,World,Emissions|PFC,kt CF4-equiv/yr,16.02718907,3.637938878,3.482541804,2.399934018,2.46987544,2.35233997,2.183197544,2.110133163,2.098594815,2.271331374,2.366451525,2.349471794,2.065199671,1.985626687,1.776892091,1.674421543,1.620573003,1.516924632
model1,1point5,World,Emissions|SF6,kt SF6/yr,8.822,2.748101171,0.420403992,0.194154134,0.193535513,0.182088392,0.178785865,0.165914591,0.158097314,0.200615142,0.203373686,0.194201788,0.186971443,0.18767787,0.199973926,0.216316375,0.234936187,0.254408024
model1,1point5,World,Emissions|Sulfur,Mt SO2/yr,90.69405028,70.01291404,54.24778472,50.40924095,47.17966274,44.6602407,41.99284078,39.70843642,37.72466871,37.37432755,36.74785135,35.50867617,33.21491389,31.73131292,29.37606326,27.36338945,25.91283384,24.41758634
model1,1point5,World,Emissions|VOC,Mt VOC/yr,238.6070603,223.9020506,205.088306,197.7477918,187.5226379,180.0752249,174.3370046,171.3650879,171.0704976,178.7113755,183.9538854,188.3283844,186.6545566,189.1507597,187.3423956,186.2335715,188.069132,188.7944783
model2,1point5,World,Emissions|CO2,Mt CO2/yr,39422.52133,37865.99706,32359.5685,26849.32928,21591.95802,18002.38495,14577.58604,12025.70265,9834.178097,7980.014276,6416.494901,5080.843906,4275.107555,3558.762507,2961.197814,2652.955972,2455.008407,2174.488878
model2,1point5,World,Emissions|CO2|AFOLU,Mt CO2/yr,4582.672,4803.603869,4821.760302,4730.016198,4413.396081,3914.039648,3337.695577,2731.631318,2095.824135,1430.28527,735.0269714,10,10,10,10,10,10,10
model2,1point5,World,Emissions|CO2|Energy and Industrial Processes,Mt CO2/yr,37290.10127,35493.4875,29754.31775,24099.95224,18890.09989,15561.69186,12466.76602,10303.33139,8538.550349,7148.504918,6084.618764,5281.669408,4444.022706,3699.307557,3078.076936,2757.627496,2551.840423,2260.21121
model14,1point5,World,Emissions|BC,Mt BC/yr,10.70016593,9.638053494,8.464214366,7.507617718,6.396375551,5.556133493,4.839623622,4.290927929,3.848178128,3.576185377,3.27786788,2.990673195,2.637375742,2.357716923,2.203839801,2.067082614,1.97410705,1.873144781
model14,1point5,World,Emissions|CH4,Mt CH4/yr,349.2655161,310.8153209,291.1688805,273.372279,255.3192562,241.1204483,227.3543533,219.8460899,214.752028,219.0230043,218.4555877,223.9941613,221.196423,222.8977081,218.6504778,215.3958681,217.7858237,219.9701913
model14,1point5,World,Emissions|CO,Mt CO/yr,981.0673789,998.0868231,933.8361993,887.8196655,815.8499917,768.4012065,733.7171685,718.1324989,719.7291893,753.898531,780.4452257,812.0807608,809.9761183,830.3316809,820.6549187,813.9548184,825.9766284,836.1481031
model14,1point5,World,Emissions|CO2,Mt CO2/yr,39412.52133,37855.99706,32349.5685,26839.32928,21581.95802,17992.38495,14567.58604,12015.70265,9824.178097,7970.014276,6406.494901,5070.843906,4265.107555,3548.762507,2951.197814,2642.955972,2445.008407,2164.488878
model14,1point5,World,Emissions|CO2|AFOLU,Mt CO2/yr,4572.672,4793.603869,4811.760302,4720.016198,4403.396081,3904.039648,3327.695577,2721.631318,2085.824135,1420.28527,725.0269714,1,1,1,1,1,1,1
model14,1point5,World,Emissions|CO2|Energy and Industrial Processes,Mt CO2/yr,37280.10127,35483.4875,29744.31775,24089.95224,18880.09989,15551.69186,12456.76602,10293.33139,8528.550349,7138.504918,6074.618764,5271.669408,4434.022706,3689.307557,3068.076936,2747.627496,2541.840423,2250.21121
model14,1point5,World,Emissions|N2O,kt N2O/yr,7630,6384.674386,6237.886495,6196.692604,5921.983441,5459.192277,5111.540289,4864.493252,4649.896864,4689.868465,4496.51009,4571.548368,4308.165892,4297.676692,4043.294109,3813.183663,3755.344533,3639.272374
model14,1point5,World,Emissions|NH3,Mt NH3/yr,52.2237625,54.17814586,56.06194238,57.15376084,56.4330242,55.32240587,53.67340428,52.31129817,51.58043544,52.04222008,51.64064558,51.98183115,51.07320617,50.71431281,49.91101395,49.02794223,49.17227157,49.03921428
model14,1point5,World,Emissions|OC,Mt OC/yr,31.27142181,30.23497517,26.92902851,,,,,,,,,,,,,,,
model14,1point5,World,Emissions|PFC,kt CF4-equiv/yr,16.02718907,3.637938878,3.482541804,2.399934018,2.46987544,2.35233997,2.183197544,2.110133163,2.098594815,2.271331374,2.366451525,2.349471794,2.065199671,1.985626687,1.776892091,1.674421543,1.620573003,1.516924632
model14,1point5,World,Emissions|SF6,kt SF6/yr,8.822,2.748101171,0.420403992,0.194154134,0.193535513,0.182088392,0.178785865,0.165914591,0.158097314,0.200615142,0.203373686,0.194201788,0.186971443,0.18767787,0.199973926,0.216316375,0.234936187,0.254408024
model14,1point5,World,Emissions|Sulfur,Mt SO2/yr,90.69405028,70.01291404,54.24778472,50.40924095,47.17966274,44.6602407,41.99284078,39.70843642,37.72466871,37.37432755,36.74785135,35.50867617,33.21491389,31.73131292,29.37606326,27.36338945,25.91283384,24.41758634
model14,1point5,World,Emissions|VOC,Mt VOC/yr,238.6070603,223.9020506,205.088306,197.7477918,187.5226379,180.0752249,174.3370046,171.3650879,171.0704976,178.7113755,183.9538854,188.3283844,186.6545566,189.1507597,187.3423956,186.2335715,188.069132,188.7944783
model14,1point5,World,Emissions|CO2|Other,Mt CO2/yr,-2440.25194,-2421.094309,-2206.509552,-1970.639158,-1701.537951,-1463.346558,-1216.875557,-999.260058,-790.196387,-588.775912,-393.1508344,-201.825502,-169.915151,-141.54505,-117.879122,-105.671524,-97.832016,-86.722332

0 comments on commit 37e9d39

Please sign in to comment.