dynamic-characterization 1.4.3__tar.gz → 2.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dynamic_characterization-1.4.3/dynamic_characterization.egg-info → dynamic_characterization-2.0.1}/PKG-INFO +1 -1
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/__init__.py +8 -3
- dynamic_characterization-2.0.1/dynamic_characterization/ar6_dispatch.py +224 -0
- dynamic_characterization-2.0.1/dynamic_characterization/ar6_prospective.py +227 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/dynamic_characterization.py +189 -227
- dynamic_characterization-2.0.1/dynamic_characterization/flows.py +104 -0
- dynamic_characterization-2.0.1/dynamic_characterization/ipcc_ar6/ar6_core.py +434 -0
- dynamic_characterization-2.0.1/dynamic_characterization/ipcc_ar6/data/ar6_parameters.json +123 -0
- dynamic_characterization-2.0.1/dynamic_characterization/ipcc_ar6/data/precursor_parameters.json +605 -0
- dynamic_characterization-2.0.1/dynamic_characterization/ipcc_ar6/gases.py +325 -0
- dynamic_characterization-2.0.1/dynamic_characterization/ipcc_ar6/radiative_forcing.py +158 -0
- dynamic_characterization-2.0.1/dynamic_characterization/options.py +155 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/__init__.py +8 -6
- dynamic_characterization-2.0.1/dynamic_characterization/prospective/_common.py +44 -0
- dynamic_characterization-2.0.1/dynamic_characterization/prospective/agtp.py +25 -0
- dynamic_characterization-2.0.1/dynamic_characterization/prospective/agwp.py +58 -0
- dynamic_characterization-2.0.1/dynamic_characterization/prospective/radiative_forcing.py +99 -0
- dynamic_characterization-2.0.1/dynamic_characterization/prospective/watanabe2026.py +335 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1/dynamic_characterization.egg-info}/PKG-INFO +1 -1
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization.egg-info/SOURCES.txt +26 -2
- dynamic_characterization-2.0.1/tests/test_ar6_core.py +286 -0
- dynamic_characterization-2.0.1/tests/test_ar6_dispatch.py +201 -0
- dynamic_characterization-2.0.1/tests/test_ar6_prospective.py +228 -0
- dynamic_characterization-2.0.1/tests/test_characterize_prospective_fallback.py +128 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/tests/test_default_characterization_functions.py +16 -1
- dynamic_characterization-2.0.1/tests/test_flows.py +126 -0
- dynamic_characterization-2.0.1/tests/test_paper_watanabe2026.py +208 -0
- dynamic_characterization-2.0.1/tests/test_precursors.py +275 -0
- dynamic_characterization-2.0.1/tests/test_prospective.py +299 -0
- dynamic_characterization-1.4.3/dynamic_characterization/ipcc_ar6/data/decay_multipliers.json +0 -1
- dynamic_characterization-1.4.3/dynamic_characterization/ipcc_ar6/radiative_forcing.py +0 -466
- dynamic_characterization-1.4.3/dynamic_characterization/prospective/agtp.py +0 -250
- dynamic_characterization-1.4.3/dynamic_characterization/prospective/agwp.py +0 -236
- dynamic_characterization-1.4.3/dynamic_characterization/prospective/radiative_forcing.py +0 -366
- dynamic_characterization-1.4.3/tests/test_characterize_prospective_fallback.py +0 -68
- dynamic_characterization-1.4.3/tests/test_prospective.py +0 -1259
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/LICENSE +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/MANIFEST.in +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/README.md +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/classes.py +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/ipcc_ar6/__init__.py +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/ipcc_ar6/data/hodnebrog20.csv +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/original_temporalis_functions/__init__.py +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/original_temporalis_functions/radiative_forcing.py +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/config.py +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_001.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_002.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_003.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_004.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_009.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_010.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_011.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_012.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_013.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_014.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_015.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_016.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_017.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_018.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_019.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_020.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_021.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_022.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_023.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_024.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_025.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_026.xlsx +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data_loader.py +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization.egg-info/dependency_links.txt +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization.egg-info/requires.txt +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/dynamic_characterization.egg-info/top_level.txt +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/pyproject.toml +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/setup.cfg +0 -0
- {dynamic_characterization-1.4.3 → dynamic_characterization-2.0.1}/tests/test_characterize_dynamic_inventory.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dynamic_characterization
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.1
|
|
4
4
|
Summary: Collection of functions for characterizing life cycle inventories with temporal information
|
|
5
5
|
Author-email: Timo Diepers <timo.diepers@ltt.rwth-aachen.de>
|
|
6
6
|
Maintainer-email: Timo Diepers <timo.diepers@ltt.rwth-aachen.de>
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Collection of dynamic characterization functions for life cycle inventories with temporal information.
|
|
3
3
|
|
|
4
4
|
Provides:
|
|
5
|
-
- ipcc_ar6: IPCC AR6
|
|
6
|
-
|
|
5
|
+
- ipcc_ar6: characterization functions following the IPCC AR6 emission metrics (CO2, CH4, N2O,
|
|
6
|
+
halocarbons) and the indirect effects of CO, VOC, H2 and NOx
|
|
7
|
+
- prospective: prospective characterization after Barbosa Watanabe & Cherubini (2026)
|
|
7
8
|
- original_temporalis_functions: Legacy functions from bw_temporalis
|
|
8
9
|
|
|
9
10
|
For prospective metrics (pGWP, pGTP), set the scenario first:
|
|
@@ -15,15 +16,19 @@ __all__ = (
|
|
|
15
16
|
"__version__",
|
|
16
17
|
"characterize",
|
|
17
18
|
"create_characterization_functions_from_method",
|
|
19
|
+
"compare_with_static",
|
|
20
|
+
"CharacterizationOptions",
|
|
18
21
|
"original_temporalis_functions",
|
|
19
22
|
"ipcc_ar6",
|
|
20
23
|
"prospective",
|
|
21
24
|
)
|
|
22
25
|
|
|
23
|
-
__version__ = "
|
|
26
|
+
__version__ = "2.0.1"
|
|
24
27
|
|
|
25
28
|
from . import ipcc_ar6, original_temporalis_functions, prospective
|
|
26
29
|
from .dynamic_characterization import (
|
|
27
30
|
characterize,
|
|
31
|
+
compare_with_static,
|
|
28
32
|
create_characterization_functions_from_method,
|
|
29
33
|
)
|
|
34
|
+
from .options import CharacterizationOptions
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"""Default characterization functions of the ``"ar6"`` parameter set, matched to biosphere flows."""
|
|
2
|
+
|
|
3
|
+
from typing import Callable, Dict, Iterable, NamedTuple, Optional
|
|
4
|
+
|
|
5
|
+
from loguru import logger
|
|
6
|
+
|
|
7
|
+
from dynamic_characterization import ar6_prospective
|
|
8
|
+
from dynamic_characterization.flows import is_co2_uptake, normalize_cas
|
|
9
|
+
from dynamic_characterization.ipcc_ar6 import ar6_core, gases
|
|
10
|
+
from dynamic_characterization.ipcc_ar6.radiative_forcing import (
|
|
11
|
+
characterize_co2_ar6,
|
|
12
|
+
characterize_co2_uptake_ar6,
|
|
13
|
+
make_characterization_function,
|
|
14
|
+
)
|
|
15
|
+
from dynamic_characterization.options import CharacterizationOptions
|
|
16
|
+
|
|
17
|
+
SPECIES_BY_CAS = {
|
|
18
|
+
"124-38-9": "CO2",
|
|
19
|
+
"74-82-8": "CH4",
|
|
20
|
+
"10024-97-2": "N2O",
|
|
21
|
+
"630-08-0": "CO",
|
|
22
|
+
"1333-74-0": "H2",
|
|
23
|
+
"10102-43-9": "NO",
|
|
24
|
+
"10102-44-0": "NO2",
|
|
25
|
+
"11104-93-1": "NOx",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# exact (lower-case) names, for flows without a CAS number. Never match by substring:
|
|
29
|
+
# "methane" is also part of "Methane, dichloro-", "Tetrafluoromethane", ...
|
|
30
|
+
SPECIES_BY_NAME = {
|
|
31
|
+
"carbon dioxide": "CO2",
|
|
32
|
+
"carbon dioxide, fossil": "CO2",
|
|
33
|
+
"carbon dioxide, non-fossil": "CO2",
|
|
34
|
+
"carbon dioxide, from soil or biomass stock": "CO2",
|
|
35
|
+
"carbon dioxide, to soil or biomass stock": "CO2",
|
|
36
|
+
"carbon dioxide, in air": "CO2",
|
|
37
|
+
"methane": "CH4",
|
|
38
|
+
"methane, fossil": "CH4",
|
|
39
|
+
"methane, non-fossil": "CH4",
|
|
40
|
+
"methane, from soil or biomass stock": "CH4",
|
|
41
|
+
"dinitrogen monoxide": "N2O",
|
|
42
|
+
"carbon monoxide": "CO",
|
|
43
|
+
"carbon monoxide, fossil": "CO",
|
|
44
|
+
"carbon monoxide, non-fossil": "CO",
|
|
45
|
+
"carbon monoxide, from soil or biomass stock": "CO",
|
|
46
|
+
"hydrogen": "H2",
|
|
47
|
+
"voc, volatile organic compounds": "VOC",
|
|
48
|
+
"nmvoc, non-methane volatile organic compounds": "VOC",
|
|
49
|
+
"nitric oxide": "NO",
|
|
50
|
+
"nitrogen dioxide": "NO2",
|
|
51
|
+
"nitrogen oxides": "NOx",
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
_NAMED_SPECIES = ("CO2", "CO2 uptake", "CH4", "N2O", "CO", "H2", "VOC", "NO", "NO2", "NOx")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class FlowClass(NamedTuple):
|
|
58
|
+
species: Optional[str] # one of _NAMED_SPECIES, a canonical CAS, or None
|
|
59
|
+
origin: Optional[str] # "fossil", "non-fossil" or None (not stated in the flow name)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def origin_from_name(name: str) -> Optional[str]:
|
|
63
|
+
"""Fossil or non-fossil origin as stated in an ecoinvent-style flow name, else None.
|
|
64
|
+
|
|
65
|
+
"from soil or biomass stock" counts as fossil, as in the ecoinvent IPCC 2021 implementation
|
|
66
|
+
(carbon released from a stock, not recently taken up).
|
|
67
|
+
"""
|
|
68
|
+
name = name.lower()
|
|
69
|
+
if ", non-fossil" in name:
|
|
70
|
+
return "non-fossil"
|
|
71
|
+
if ", fossil" in name or "from soil or biomass stock" in name:
|
|
72
|
+
return "fossil"
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def classify_flow(node, options: Optional[CharacterizationOptions] = None) -> FlowClass:
|
|
77
|
+
"""Species and origin of a biosphere flow, for the ``"ar6"`` default functions."""
|
|
78
|
+
options = options or CharacterizationOptions()
|
|
79
|
+
name = (node.get("name") or "").strip()
|
|
80
|
+
origin = origin_from_name(name)
|
|
81
|
+
cas = normalize_cas(node.get("CAS number"))
|
|
82
|
+
|
|
83
|
+
if cas is not None:
|
|
84
|
+
species = SPECIES_BY_CAS.get(cas, cas)
|
|
85
|
+
else:
|
|
86
|
+
species = SPECIES_BY_NAME.get(name.lower())
|
|
87
|
+
|
|
88
|
+
if species == "CO2" and is_co2_uptake(node):
|
|
89
|
+
species = "CO2 uptake"
|
|
90
|
+
|
|
91
|
+
override = options.override_for(node)
|
|
92
|
+
if override:
|
|
93
|
+
species = override.get("species", species)
|
|
94
|
+
if species is not None and species not in _NAMED_SPECIES:
|
|
95
|
+
species = normalize_cas(species) or species
|
|
96
|
+
origin = override.get("origin", origin)
|
|
97
|
+
return FlowClass(species, origin)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def function_for(
|
|
101
|
+
flow_class: FlowClass,
|
|
102
|
+
options: CharacterizationOptions,
|
|
103
|
+
flow_label: str = "",
|
|
104
|
+
prospective: bool = False,
|
|
105
|
+
) -> Optional[Callable]:
|
|
106
|
+
"""
|
|
107
|
+
The ``"ar6"`` characterization function for a classified flow, or None.
|
|
108
|
+
|
|
109
|
+
With ``prospective=True`` the function follows the scenario of ``prospective.set_scenario``
|
|
110
|
+
(see ``ar6_prospective``): CO2 terms use the scenario CO2 response, CH4 and N2O the
|
|
111
|
+
scenario radiative efficiencies.
|
|
112
|
+
"""
|
|
113
|
+
ccf = ar6_core.ccf_parameters(options.ccf_parameters) if options.climate_carbon_feedback else None
|
|
114
|
+
precursor_ccf = ccf if options.precursor_ccf else None
|
|
115
|
+
species, origin = flow_class
|
|
116
|
+
|
|
117
|
+
if species is None:
|
|
118
|
+
return None
|
|
119
|
+
method = options.prospective_method
|
|
120
|
+
if species == "CO2":
|
|
121
|
+
return ar6_prospective.co2_function(method) if prospective else characterize_co2_ar6
|
|
122
|
+
if species == "CO2 uptake":
|
|
123
|
+
return ar6_prospective.co2_function(method, uptake=True) if prospective else characterize_co2_uptake_ar6
|
|
124
|
+
if prospective and method == "watanabe2026" and species in ("CH4", "N2O"):
|
|
125
|
+
if species == "CH4" and origin is None:
|
|
126
|
+
logger.warning(
|
|
127
|
+
"Flow {!r} does not state a fossil or non-fossil origin; the Watanabe & Cherubini "
|
|
128
|
+
"(2026) CH4 metric does not distinguish them.",
|
|
129
|
+
flow_label,
|
|
130
|
+
)
|
|
131
|
+
return ar6_prospective.paper_function(species)
|
|
132
|
+
if species == "CH4":
|
|
133
|
+
if origin is None:
|
|
134
|
+
origin = options.unspecified_origin
|
|
135
|
+
logger.warning(
|
|
136
|
+
"Flow {!r} does not state a fossil or non-fossil origin; treated as {} CH4 "
|
|
137
|
+
"(set 'unspecified_origin' or 'flow_overrides' to change this).",
|
|
138
|
+
flow_label,
|
|
139
|
+
origin,
|
|
140
|
+
)
|
|
141
|
+
ch4_options = dict(
|
|
142
|
+
origin=origin,
|
|
143
|
+
biogenic_oxidation_co2=options.biogenic_oxidation_co2,
|
|
144
|
+
oxidation_yield=options.ch4_oxidation_yield,
|
|
145
|
+
ccf=ccf,
|
|
146
|
+
)
|
|
147
|
+
if prospective:
|
|
148
|
+
return ar6_prospective.make_prospective_function(
|
|
149
|
+
ar6_prospective.Recipe(kind="CH4", method="ar6", options=tuple(sorted(ch4_options.items())))
|
|
150
|
+
)
|
|
151
|
+
spec = gases.ch4(**ch4_options)
|
|
152
|
+
elif species == "N2O":
|
|
153
|
+
if prospective:
|
|
154
|
+
return ar6_prospective.make_prospective_function(
|
|
155
|
+
ar6_prospective.Recipe(kind="N2O", method="ar6", options=(("ccf", ccf),))
|
|
156
|
+
)
|
|
157
|
+
spec = gases.n2o(ccf=ccf)
|
|
158
|
+
elif species == "CO":
|
|
159
|
+
if "CO" in options.include_precursors:
|
|
160
|
+
if origin is None:
|
|
161
|
+
origin = options.unspecified_origin
|
|
162
|
+
spec = gases.co(
|
|
163
|
+
origin=origin,
|
|
164
|
+
parameter_set=options.precursor_parameter_set("CO"),
|
|
165
|
+
biogenic_oxidation_co2="explicit" if options.biogenic_oxidation_co2 == "explicit" else "neutral",
|
|
166
|
+
ccf=precursor_ccf,
|
|
167
|
+
)
|
|
168
|
+
else:
|
|
169
|
+
spec = gases.co_oxidation()
|
|
170
|
+
elif species == "VOC":
|
|
171
|
+
if "VOC" not in options.include_precursors:
|
|
172
|
+
return None
|
|
173
|
+
spec = gases.voc(options.precursor_parameter_set("VOC"), ccf=precursor_ccf)
|
|
174
|
+
elif species == "H2":
|
|
175
|
+
if "H2" not in options.include_precursors:
|
|
176
|
+
return None
|
|
177
|
+
spec = gases.h2(options.precursor_parameter_set("H2"), ccf=precursor_ccf)
|
|
178
|
+
elif species in ("NO", "NO2", "NOx"):
|
|
179
|
+
if not options.include_nox:
|
|
180
|
+
return None
|
|
181
|
+
spec = gases.nox(
|
|
182
|
+
emitted_as="NO" if species == "NO" else "NO2",
|
|
183
|
+
parameter_set=options.precursor_parameter_set("NOx"),
|
|
184
|
+
nitrate=options.nox_nitrate,
|
|
185
|
+
nitrate_parameter_set=options.precursor_parameter_set("nitrate"),
|
|
186
|
+
ccf=precursor_ccf,
|
|
187
|
+
)
|
|
188
|
+
else:
|
|
189
|
+
spec = gases.halocarbon(species, ccf=ccf)
|
|
190
|
+
if spec is None:
|
|
191
|
+
return None
|
|
192
|
+
if prospective:
|
|
193
|
+
return ar6_prospective.fixed(spec, method=method)
|
|
194
|
+
return make_characterization_function(spec)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
SCENARIO_SPECIES = ("CO2", "CO2 uptake", "CH4", "N2O")
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def build_functions(
|
|
201
|
+
nodes: Iterable,
|
|
202
|
+
options: CharacterizationOptions,
|
|
203
|
+
characterize_uptake: bool = True,
|
|
204
|
+
prospective: bool = False,
|
|
205
|
+
fallback_to_ipcc: bool = True,
|
|
206
|
+
) -> Dict[int, Callable]:
|
|
207
|
+
"""
|
|
208
|
+
``{node.id: function}`` for all nodes that have an ``"ar6"`` characterization function.
|
|
209
|
+
|
|
210
|
+
With ``prospective=True`` the functions follow the prospective scenario; with
|
|
211
|
+
``fallback_to_ipcc=False`` only the gases with scenario data (CO2, CH4, N2O) are included.
|
|
212
|
+
"""
|
|
213
|
+
functions = {}
|
|
214
|
+
for node in nodes:
|
|
215
|
+
flow_class = classify_flow(node, options)
|
|
216
|
+
if flow_class.species == "CO2 uptake" and not characterize_uptake:
|
|
217
|
+
continue
|
|
218
|
+
if prospective and not fallback_to_ipcc and flow_class.species not in SCENARIO_SPECIES:
|
|
219
|
+
continue
|
|
220
|
+
label = f"{node.get('name')} {tuple(node.get('categories') or ())}"
|
|
221
|
+
func = function_for(flow_class, options, flow_label=label, prospective=prospective)
|
|
222
|
+
if func is not None:
|
|
223
|
+
functions[node.id] = func
|
|
224
|
+
return functions
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The ``"ar6"`` parameter set with a prospective scenario (metrics pGWP, pGTP and
|
|
3
|
+
prospective_radiative_forcing), for the scenario of ``prospective.set_scenario`` and the year of
|
|
4
|
+
each emission. Two methods (option ``prospective_method``):
|
|
5
|
+
|
|
6
|
+
``"watanabe2026"`` (default)
|
|
7
|
+
CO2, CH4 and N2O as in Barbosa Watanabe & Cherubini (2026), with two errors of the published
|
|
8
|
+
code corrected (see ``prospective.watanabe2026``): scenario RE and impulse responses, AR6 ozone
|
|
9
|
+
and stratospheric water vapour terms, the CH4 effect of N2O, a climate-carbon feedback, and an
|
|
10
|
+
annual two-layer temperature model.
|
|
11
|
+
All other gases (halocarbons, CO, VOC, H2, NOx) keep their AR6 / literature forcing, with their
|
|
12
|
+
CO2 terms following the same scenario CO2 response and their AGTP from the same temperature
|
|
13
|
+
scheme, so that the CO2 reference is consistent.
|
|
14
|
+
|
|
15
|
+
``"ar6"``
|
|
16
|
+
The AR6 recipe with scenario inputs: CO2 terms follow the scenario CO2 response, CH4 and N2O
|
|
17
|
+
use the scenario direct RE with the AR6 tropospheric adjustments and indirect terms, and the
|
|
18
|
+
temperature response is the AR6 one.
|
|
19
|
+
|
|
20
|
+
The scenario CO2 impulse response covers 100 years, so do these metrics: longer horizons are
|
|
21
|
+
truncated to 100 years, with a warning. ``time_varying_re=True`` lets the radiative
|
|
22
|
+
efficiencies of CO2, CH4 and N2O follow the scenario over the response (``"watanabe2026"`` only;
|
|
23
|
+
the ``"ar6"`` method uses those of the emission year and warns).
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from dataclasses import dataclass
|
|
27
|
+
from functools import lru_cache
|
|
28
|
+
from typing import Optional, Tuple
|
|
29
|
+
|
|
30
|
+
import warnings
|
|
31
|
+
|
|
32
|
+
import numpy as np
|
|
33
|
+
|
|
34
|
+
from dynamic_characterization.classes import CharacterizedRow
|
|
35
|
+
from dynamic_characterization.ipcc_ar6 import ar6_core, gases
|
|
36
|
+
from dynamic_characterization.prospective import watanabe2026
|
|
37
|
+
from dynamic_characterization.prospective.config import get_scenario
|
|
38
|
+
from dynamic_characterization.prospective.data_loader import (
|
|
39
|
+
load_irf_co2,
|
|
40
|
+
load_re_ch4,
|
|
41
|
+
load_re_co2,
|
|
42
|
+
load_re_n2o,
|
|
43
|
+
)
|
|
44
|
+
from dynamic_characterization.prospective._common import CONST_CO2, _get_year_index
|
|
45
|
+
|
|
46
|
+
METHODS = ("watanabe2026", "ar6")
|
|
47
|
+
MAX_YEARS = 100
|
|
48
|
+
_RE_LOADERS = {"CO2": load_re_co2, "CH4": load_re_ch4, "N2O": load_re_n2o}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _emission_year(date) -> int:
|
|
52
|
+
return int(str(np.datetime64(date, "s"))[:4])
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _current_scenario() -> Tuple[str, str, str]:
|
|
56
|
+
scenario = get_scenario()
|
|
57
|
+
return scenario["iam"], scenario["ssp"], scenario["rcp"]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@lru_cache(maxsize=None)
|
|
61
|
+
def scenario_radiative_efficiency(gas: str, iam: str, ssp: str, rcp: str, year: int) -> float:
|
|
62
|
+
"""Direct radiative efficiency [W m-2 ppb-1] of CO2, CH4 or N2O in a scenario and year."""
|
|
63
|
+
data = _RE_LOADERS[gas](iam)
|
|
64
|
+
series = data[ssp][rcp]
|
|
65
|
+
return float(series[min(_get_year_index(year, data["_years"]), len(series) - 1)])
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@lru_cache(maxsize=None)
|
|
69
|
+
def scenario_co2_response(iam: str, ssp: str, rcp: str, year: int, method: str = "ar6") -> ar6_core.TabulatedCO2Response:
|
|
70
|
+
"""
|
|
71
|
+
RF of 1 kg CO2 emitted in ``year`` of the scenario: CO2 RE of the emission year x impulse
|
|
72
|
+
response of the scenario's RCP. With ``method="watanabe2026"`` the ppb-to-kg conversion is
|
|
73
|
+
that of the paper's code, so that its AGWP equals the CO2 AGWP of ``prospective.watanabe2026``.
|
|
74
|
+
"""
|
|
75
|
+
re_co2 = scenario_radiative_efficiency("CO2", iam, ssp, rcp, year)
|
|
76
|
+
if method == "watanabe2026":
|
|
77
|
+
per_kg = re_co2 * CONST_CO2
|
|
78
|
+
else:
|
|
79
|
+
per_kg = re_co2 / ar6_core.kg_per_ppb(ar6_core.load_parameters()["constants"]["M_co2"])
|
|
80
|
+
irf = load_irf_co2()[watanabe2026.co2_irf_key(rcp)]
|
|
81
|
+
return ar6_core.TabulatedCO2Response(name=f"{iam}-{ssp}-{rcp}, {year}", rf=tuple(per_kg * float(v) for v in irf))
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@dataclass(frozen=True)
|
|
85
|
+
class Recipe:
|
|
86
|
+
"""
|
|
87
|
+
How to build the response of a flow for a scenario and year.
|
|
88
|
+
|
|
89
|
+
``kind``: "CH4" / "N2O" (scenario radiative efficiencies), "fixed" (``spec`` as it is, with
|
|
90
|
+
its CO2 terms following the scenario), or "paper" (``gas`` "CO2", "CH4" or "N2O" from
|
|
91
|
+
``prospective.watanabe2026``, multiplied by ``sign``).
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
kind: str
|
|
95
|
+
method: str = "ar6"
|
|
96
|
+
options: Tuple[Tuple[str, object], ...] = ()
|
|
97
|
+
spec: Optional[ar6_core.GasSpec] = None
|
|
98
|
+
gas: Optional[str] = None
|
|
99
|
+
sign: float = 1.0
|
|
100
|
+
|
|
101
|
+
def spec_for(self, iam: str, ssp: str, rcp: str, year: int) -> ar6_core.GasSpec:
|
|
102
|
+
options = dict(self.options)
|
|
103
|
+
if self.kind == "CH4":
|
|
104
|
+
return gases.ch4(direct_radiative_efficiency=scenario_radiative_efficiency("CH4", iam, ssp, rcp, year), **options)
|
|
105
|
+
if self.kind == "N2O":
|
|
106
|
+
return gases.n2o(
|
|
107
|
+
direct_radiative_efficiency=scenario_radiative_efficiency("N2O", iam, ssp, rcp, year),
|
|
108
|
+
ch4_direct_radiative_efficiency=scenario_radiative_efficiency("CH4", iam, ssp, rcp, year),
|
|
109
|
+
**options,
|
|
110
|
+
)
|
|
111
|
+
return self.spec
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def label(self) -> str:
|
|
115
|
+
if self.kind == "paper":
|
|
116
|
+
return f"{self.gas} (Watanabe & Cherubini 2026)" + (" uptake" if self.sign < 0 else "")
|
|
117
|
+
return self.spec.name if self.spec is not None else self.kind
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
_WARNED = set()
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _warn_once(key: str, message: str) -> None:
|
|
124
|
+
if key not in _WARNED:
|
|
125
|
+
_WARNED.add(key)
|
|
126
|
+
warnings.warn(message, UserWarning, stacklevel=3)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _truncated(period) -> int:
|
|
130
|
+
"""The horizon actually characterized: at most 100 years (with a one-time warning)."""
|
|
131
|
+
if period > MAX_YEARS:
|
|
132
|
+
_warn_once(
|
|
133
|
+
"horizon",
|
|
134
|
+
f"Prospective characterization covers {MAX_YEARS} years (the length of the scenario CO2 "
|
|
135
|
+
f"impulse response); time horizons beyond that are truncated to {MAX_YEARS} years.",
|
|
136
|
+
)
|
|
137
|
+
return MAX_YEARS
|
|
138
|
+
return int(period)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@lru_cache(maxsize=None)
|
|
142
|
+
def _annual(recipe: Recipe, iam: str, ssp: str, rcp: str, year: int, time_varying_re: bool = False):
|
|
143
|
+
"""(cumulative AGWP at the end of years 1..100, AGTP at years 1..100), per kg."""
|
|
144
|
+
if recipe.kind == "paper":
|
|
145
|
+
agwp = recipe.sign * watanabe2026.scenario_series(recipe.gas, "agwp", iam, ssp, rcp, year, time_varying_re)[:MAX_YEARS]
|
|
146
|
+
agtp = recipe.sign * watanabe2026.scenario_series(recipe.gas, "agtp", iam, ssp, rcp, year, time_varying_re)[:MAX_YEARS]
|
|
147
|
+
return np.asarray(agwp), np.asarray(agtp)
|
|
148
|
+
if time_varying_re:
|
|
149
|
+
if recipe.method == "ar6":
|
|
150
|
+
_warn_once(
|
|
151
|
+
"time_varying_re",
|
|
152
|
+
"time_varying_re is not supported by prospective_method='ar6'; the radiative "
|
|
153
|
+
"efficiencies of the emission year are used.",
|
|
154
|
+
)
|
|
155
|
+
time_varying_re = False
|
|
156
|
+
spec = recipe.spec_for(iam, ssp, rcp, year)
|
|
157
|
+
response = scenario_co2_response(iam, ssp, rcp, year, recipe.method)
|
|
158
|
+
agwp = ar6_core.annual_cumulative(spec, MAX_YEARS, response)
|
|
159
|
+
if recipe.method == "watanabe2026":
|
|
160
|
+
# AGTP with the paper's temperature scheme (Code #7), applied to the annual RF
|
|
161
|
+
rf = ar6_core.radiative_forcing(spec, np.arange(MAX_YEARS, dtype="float64"), co2_response=response)
|
|
162
|
+
agtp = watanabe2026.agtp_from_rf(rf)
|
|
163
|
+
else:
|
|
164
|
+
agtp = ar6_core.agtp(spec, np.arange(1, MAX_YEARS + 1, dtype="float64"), co2_response=response)
|
|
165
|
+
return np.asarray(agwp), np.asarray(agtp)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
@lru_cache(maxsize=None)
|
|
169
|
+
def make_prospective_function(recipe: Recipe):
|
|
170
|
+
"""
|
|
171
|
+
Characterization function for a recipe, with the legacy signature ``(series, period=100,
|
|
172
|
+
cumulative=False)``. The scenario is read from ``prospective.get_scenario()`` and the year
|
|
173
|
+
from the emission date. As for the other ``"ar6"`` functions, the value at ``date + k`` years
|
|
174
|
+
is the forcing of the year starting then; the annual values add up to the AGWP of the
|
|
175
|
+
horizon. ``.agwp_for(date, H)`` and ``.agtp_for(date, H)`` give the per-kg metrics.
|
|
176
|
+
"""
|
|
177
|
+
|
|
178
|
+
def annual(date, time_varying_re=False):
|
|
179
|
+
return _annual(recipe, *_current_scenario(), _emission_year(date), bool(time_varying_re))
|
|
180
|
+
|
|
181
|
+
def characterize_ar6_prospective(
|
|
182
|
+
series, period: int = 100, cumulative: bool = False, time_varying_re: bool = False
|
|
183
|
+
) -> CharacterizedRow:
|
|
184
|
+
period = _truncated(period)
|
|
185
|
+
agwp, _ = annual(series.date, time_varying_re)
|
|
186
|
+
date_beginning: np.datetime64 = series.date.to_numpy()
|
|
187
|
+
dates = date_beginning + np.arange(start=0, stop=period, dtype="timedelta64[Y]").astype("timedelta64[s]")
|
|
188
|
+
forcing = np.array(series.amount * agwp[:period], dtype="float64")
|
|
189
|
+
if not cumulative:
|
|
190
|
+
forcing = np.diff(forcing, prepend=0)
|
|
191
|
+
return CharacterizedRow(
|
|
192
|
+
date=np.array(dates, dtype="datetime64[s]"), amount=forcing, flow=series.flow, activity=series.activity
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
def agwp_for(date, time_horizon, time_varying_re: bool = False) -> float:
|
|
196
|
+
horizon = _truncated(time_horizon)
|
|
197
|
+
return float(annual(date, time_varying_re)[0][horizon - 1]) if horizon >= 1 else 0.0
|
|
198
|
+
|
|
199
|
+
def agtp_for(date, time_horizon, time_varying_re: bool = False) -> float:
|
|
200
|
+
horizon = _truncated(time_horizon)
|
|
201
|
+
return float(annual(date, time_varying_re)[1][horizon - 1]) if horizon >= 1 else 0.0
|
|
202
|
+
|
|
203
|
+
characterize_ar6_prospective.__name__ = f"characterize_ar6_prospective[{recipe.label}, {recipe.method}]"
|
|
204
|
+
characterize_ar6_prospective.__qualname__ = characterize_ar6_prospective.__name__
|
|
205
|
+
characterize_ar6_prospective.recipe = recipe
|
|
206
|
+
characterize_ar6_prospective.agwp_for = agwp_for
|
|
207
|
+
characterize_ar6_prospective.agtp_for = agtp_for
|
|
208
|
+
return characterize_ar6_prospective
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def fixed(spec: ar6_core.GasSpec, method: str = "ar6"):
|
|
212
|
+
"""Prospective function for a pulse response that does not depend on the scenario (except CO2)."""
|
|
213
|
+
return make_prospective_function(Recipe(kind="fixed", spec=spec, method=method))
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def co2_function(method: str = "watanabe2026", uptake: bool = False):
|
|
217
|
+
"""The CO2 (or CO2 uptake) function of a method; the CO2 one is also the pGWP/pGTP reference."""
|
|
218
|
+
if method == "watanabe2026":
|
|
219
|
+
return make_prospective_function(
|
|
220
|
+
Recipe(kind="paper", method=method, gas="CO2", sign=-1.0 if uptake else 1.0)
|
|
221
|
+
)
|
|
222
|
+
return fixed(gases.co2_uptake() if uptake else gases.co2(), method="ar6")
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def paper_function(gas: str):
|
|
226
|
+
"""CH4 or N2O as in Watanabe & Cherubini (2026), corrected."""
|
|
227
|
+
return make_prospective_function(Recipe(kind="paper", method="watanabe2026", gas=gas))
|