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

Fix issue with materials and cooling CCS technologies becoming cheaper than non-CCS counterpart #258

Merged
merged 4 commits into from
Dec 4, 2024

Conversation

measrainsey
Copy link
Contributor

@measrainsey measrainsey commented Dec 3, 2024

Very small PR to change how NH3 CCS technologies in materials module are mapped

@ywpratama noticed during ScenarioMIP review process that costs for NH3 CCS technologies were becoming cheaper than the non-CCS NH3 technologies. This issue happened before in #186, due to CCS technologies being mapped to a different WEO technology than its non-CCS counterpart, as well as having different cost reduction assumptions. At the time, only energy technologies existed within the costs tool, and this new issue pertains to materials/industry technologies.

In this case, because the NH3 CCS technologies were mapped to MESSAGE technology igcc_ccs and the non-CCS counterparts were mapped to igcc, this led to issues of their costs crossing. As a fix, now the NH3 CCS and non-CCS technologies are mapped to MESSAGE energy technology igcc.

Because this issue is not ScenaripMIP-specific, I think this small fix should best be treated as a standalone PR, merged to main. Then, additional ScenarioMIP-specific changes related to the SSP cost reduction narratives for these technologies can be added in a separate branch (using the functionality added in #255).

How to review

@ywpratama and/or @macflo8: please check if issue of costs for NH3 CCS still persists

For @khaeru and/or @glatterf42 : Read the diff and note that the CI checks all pass.

PR checklist

  • Continuous integration checks all ✅
  • Add or expand tests; coverage checks both ✅
  • Add, expand, or update documentation.
  • Update doc/whatsnew.

@measrainsey measrainsey added the costs `.tools.costs`/cost data preparation label Dec 3, 2024
@measrainsey measrainsey self-assigned this Dec 3, 2024
measrainsey added a commit that referenced this pull request Dec 3, 2024
@measrainsey measrainsey marked this pull request as ready for review December 3, 2024 12:30
Copy link
Member

@glatterf42 glatterf42 left a comment

Choose a reason for hiding this comment

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

The changes are small, looking good. However, I'm wondering whether we could bake requirements such as this into our test suite somehow. This would avoid being reliant on accidental discovery.

Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.7%. Comparing base (c5e275c) to head (f680ed1).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##            main    #258     +/-   ##
=======================================
- Coverage   77.5%   76.7%   -0.9%     
=======================================
  Files        211     211             
  Lines      16069   16079     +10     
=======================================
- Hits       12469   12333    -136     
- Misses      3600    3746    +146     
Files with missing lines Coverage Δ
...ge_ix_models/tests/tools/costs/test_projections.py 100.0% <100.0%> (ø)

... and 8 files with indirect coverage changes

@macflo8
Copy link
Contributor

macflo8 commented Dec 3, 2024

Wrote a small script to test with the materials wrapper that calls create_cost_projections() with a pre-defined config. It generates the cost output for each SSP (+ LED) and asserts that the difference between the respective ccs and non-ccs NH3 technology is greater than 0. I can confirm that this runs without an AssertionError on this branch.

@glatterf42 Something similar could be integrated into the test suite for all CCS technologies maybe.

import ixmp
import message_ix
from message_ix_models.model.material.data_util import gen_te_projections


mp = ixmp.Platform("<platform-name>")
scen = message_ix.Scenario(mp, f"<scenario-name>", "<model-name>")

# SSP1-5
for i in range(1, 6):
    inv, fix = gen_te_projections(scen, f"SSP{i}", method="gdp")
    for tec in [i + "_NH3" for i in ["biomass", "coal", "gas", "fueloil"]]:
        non_ccs = (
            inv[inv["technology"] == tec]
            .drop(columns=["unit", "technology"])
            .set_index(["node_loc", "year_vtg"])
        )
        ccs = (
            inv[inv["technology"] == tec + "_ccs"]
            .drop(columns=["unit", "technology"])
            .set_index(["node_loc", "year_vtg"])
        )
        assert ccs.sub(non_ccs).le(0).all().all() == False
# LED scenario
inv, fix = gen_te_projections(scen, "LED", method="gdp")
for tec in [i + "_NH3" for i in ["biomass", "coal", "gas", "fueloil"]]:
    non_ccs = (
        inv[inv["technology"] == tec]
        .drop(columns=["unit", "technology"])
        .set_index(["node_loc", "year_vtg"])
    )
    ccs = (
        inv[inv["technology"] == tec + "_ccs"]
        .drop(columns=["unit", "technology"])
        .set_index(["node_loc", "year_vtg"])
    )
    assert ccs.sub(non_ccs).le(0).all().all() == False

@khaeru
Copy link
Member

khaeru commented Dec 3, 2024

@measrainsey —the doc/whatsnew conflict arises from the changes in #225 that I mentioned in Slack. If you rebase you can resolve the conflict by putting your added line from this PR into this section:

Investment and fixed costs
--------------------------
- Fix naming of GDP and population columns in SSP data aggregation for :doc:`/api/tools-costs` (:pull:`219`).
- Edit inputs for storage, CSP, hydrogen, and industry technologies (:pull:`206`).
- Replace solar and wind technologies with new ones (:pull:`206`).
- Reorganize input files and incorporate `first_year.csv` data into `tech_map.csv` (:pull:`221`).
- Reconfigure use and implementation of technology variants/modules to be more agnostic (:pull:`221`).
- Change cost decay to reach reduction percentage specified on the year 2100 (:pull:`227`).
- Add `cooling` technology variant/module (:pull:`222`).
- Add functionality to specify cost reduction values and cost reduction scenarios in a module (:issue:`251`, :pull:`255`).

Please ping me if that's not clear.

Now both CCS and non-CCS variants are mapped to MESSAGE technology `igcc`
@measrainsey
Copy link
Contributor Author

Thanks @khaeru ! I rebased and added my edit to doc/whatsnew in the new section -- hope that looks okay!

Regarding merging, I quickly chatted with @glatterf42 and we discussed me trying to see if I can add tests similar to the code @macflo8 showed above. I will spend a little time tomorrow to see if I can (or should) add this test -- will report back if I think this can be saved as a later PR or if I want to add it onto this PR!

@measrainsey
Copy link
Contributor Author

measrainsey commented Dec 4, 2024

hi all, i've added a short test based on @macflo8's code that checks costs for CCS technologies vs their non-CCS variants. and perhaps good thing too because turns out the test failed for the cooling module 😅 so i've also pushed a commit to change the mapping of the CCS-based cooling technologies (i can check with @adrivinca if this is okay and change the cooling technologies' inputs later on if necessary but for now don't consider this a blocker to pass this PR)

if this new test looks good to all, then please consider all done and ready on my end, and if we can move forward with merging that'd be great -- thanks!

that being said, before the latest push, the macOS python 3.13 tests were failing here:

FAILED message_ix_models/tests/model/transport/test_report.py::test_plot_simulated[stock-ldv] - genno.core.exceptions.MissingKeyError: required keys (<fuel economy:nl-m:ldv+ref>,) not defined

@measrainsey
Copy link
Contributor Author

all tests are passing now so if everything looks good, would be great if we can move forward with merging 🙏🏻

Copy link
Member

@glatterf42 glatterf42 left a comment

Choose a reason for hiding this comment

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

Amazing, thanks to you both for coming up with this test and fixing some previously unnoticed bug! That's exactly why @khaeru and I insist on tests as much as we do :)

@measrainsey measrainsey changed the title Fix issue with NH3 CCS technologies becoming cheaper than non-CCS counterpart Fix issue with materials and cooling CCS technologies becoming cheaper than non-CCS counterpart Dec 4, 2024
@measrainsey measrainsey added water MESSAGEix-Nexus (water) variant material MESSAGEix-Materials variant labels Dec 4, 2024
@khaeru
Copy link
Member

khaeru commented Dec 4, 2024

This appears all checked, approved, and green, so I'll merge.

@khaeru khaeru merged commit 04dad58 into main Dec 4, 2024
30 checks passed
@khaeru khaeru deleted the costs/industry-ccs branch December 4, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
costs `.tools.costs`/cost data preparation material MESSAGEix-Materials variant water MESSAGEix-Nexus (water) variant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants