fix: restore default CO2 characterization for emission flows - #25
Merged
Merged
Conversation
create_characterization_functions_from_method() only mapped CO2 flows whose
categories contained "in air", which is true for the natural resource flow
"Carbon dioxide, in air" but not for actual emissions to ('air', ...). Those
flows got no characterization function and were silently skipped, understating
dynamic climate scores by roughly an order of magnitude.
Uptake is now detected explicitly (soil categories, or "in air" + natural
resource type), all other CO2 flows fall through to the emission function, and
characterize_uptake=False only suppresses the uptake functions instead of all
CO2 characterization. The soil check looks at categories only, so
"Carbon dioxide, from soil or biomass stock" emitted to air is characterized
as an emission.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since 1.4.0,
create_characterization_functions_from_method()assigns no characterization function to ordinary CO2 emission flows (Carbon dioxide, fossilwith categories('air', 'non-urban air or from high stacks')etc.).characterize()then silently skips them, so dynamic LCIA (metric="GWP"or"radiative_forcing") misses ~90% of the climate impact. Downstream, every currentbw_timexinstall is affected, sinceTimexLCA.dynamic_lcia()relies on this default mapping.Root cause: the emission branch required
"in air" in node["categories"], which only holds for the natural-resource flowCarbon dioxide, in air. Real emissions have('air',),('air', 'urban air close to ground'), ... and there was noelsebranch.Carbon dioxide, from soil or biomass stockwas unmapped too, because the uptake check matched"soil"against categories while that flow carries "soil" in its name and('air', ...)categories.1.3.1 and earlier had a catch-all
elseand were fine.Fix
Uptake is detected explicitly, everything else falls through to the emission function:
characterize_uptake=Falsenow suppresses only the uptake functions, not all CO2 characterization.Tests
New
tests/test_default_characterization_functions.pybuilds a synthetic biosphere + method withbw2data.tests.bw2test, so no ecoinvent is needed:from soil or biomass stock) map tocharacterize_co2characterize_uptake=FalseCarbon dioxide, in air(natural resource) and CO2 to soil map tocharacterize_co2_uptake, and are absent whencharacterize_uptake=Falsefixed_time_horizon=Falseis within 5% of the static score of the same inventoryVerified failing before the fix (
KeyErroron the CO2 emission flows; end-to-end 551 vs. 22245 expected) and passing after. Full suite: 94 passed.Version bumped to 1.4.1 with a changelog entry.