dynamic-characterization 2.0.0__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.
Files changed (68) hide show
  1. {dynamic_characterization-2.0.0/dynamic_characterization.egg-info → dynamic_characterization-2.0.1}/PKG-INFO +1 -1
  2. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/__init__.py +1 -1
  3. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/dynamic_characterization.py +2 -1
  4. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/ipcc_ar6/data/ar6_parameters.json +7 -7
  5. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/ipcc_ar6/data/precursor_parameters.json +10 -2
  6. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/ipcc_ar6/gases.py +3 -3
  7. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/ipcc_ar6/radiative_forcing.py +5 -4
  8. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/options.py +1 -1
  9. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1/dynamic_characterization.egg-info}/PKG-INFO +1 -1
  10. dynamic_characterization-2.0.1/tests/test_ar6_core.py +286 -0
  11. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/tests/test_ar6_dispatch.py +24 -13
  12. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/tests/test_default_characterization_functions.py +4 -3
  13. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/tests/test_precursors.py +9 -8
  14. dynamic_characterization-2.0.0/tests/test_ar6_core.py +0 -209
  15. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/LICENSE +0 -0
  16. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/MANIFEST.in +0 -0
  17. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/README.md +0 -0
  18. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/ar6_dispatch.py +0 -0
  19. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/ar6_prospective.py +0 -0
  20. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/classes.py +0 -0
  21. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/flows.py +0 -0
  22. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/ipcc_ar6/__init__.py +0 -0
  23. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/ipcc_ar6/ar6_core.py +0 -0
  24. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/ipcc_ar6/data/hodnebrog20.csv +0 -0
  25. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/original_temporalis_functions/__init__.py +0 -0
  26. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/original_temporalis_functions/radiative_forcing.py +0 -0
  27. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/__init__.py +0 -0
  28. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/_common.py +0 -0
  29. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/agtp.py +0 -0
  30. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/agwp.py +0 -0
  31. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/config.py +0 -0
  32. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_001.xlsx +0 -0
  33. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_002.xlsx +0 -0
  34. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_003.xlsx +0 -0
  35. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_004.xlsx +0 -0
  36. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_009.xlsx +0 -0
  37. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_010.xlsx +0 -0
  38. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_011.xlsx +0 -0
  39. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_012.xlsx +0 -0
  40. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_013.xlsx +0 -0
  41. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_014.xlsx +0 -0
  42. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_015.xlsx +0 -0
  43. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_016.xlsx +0 -0
  44. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_017.xlsx +0 -0
  45. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_018.xlsx +0 -0
  46. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_019.xlsx +0 -0
  47. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_020.xlsx +0 -0
  48. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_021.xlsx +0 -0
  49. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_022.xlsx +0 -0
  50. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_023.xlsx +0 -0
  51. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_024.xlsx +0 -0
  52. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_025.xlsx +0 -0
  53. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data/es5c12391_si_026.xlsx +0 -0
  54. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/data_loader.py +0 -0
  55. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/radiative_forcing.py +0 -0
  56. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization/prospective/watanabe2026.py +0 -0
  57. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization.egg-info/SOURCES.txt +0 -0
  58. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization.egg-info/dependency_links.txt +0 -0
  59. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization.egg-info/requires.txt +0 -0
  60. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/dynamic_characterization.egg-info/top_level.txt +0 -0
  61. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/pyproject.toml +0 -0
  62. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/setup.cfg +0 -0
  63. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/tests/test_ar6_prospective.py +0 -0
  64. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/tests/test_characterize_dynamic_inventory.py +0 -0
  65. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/tests/test_characterize_prospective_fallback.py +0 -0
  66. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/tests/test_flows.py +0 -0
  67. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/tests/test_paper_watanabe2026.py +0 -0
  68. {dynamic_characterization-2.0.0 → dynamic_characterization-2.0.1}/tests/test_prospective.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dynamic_characterization
3
- Version: 2.0.0
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>
@@ -23,7 +23,7 @@ __all__ = (
23
23
  "prospective",
24
24
  )
25
25
 
26
- __version__ = "2.0.0"
26
+ __version__ = "2.0.1"
27
27
 
28
28
  from . import ipcc_ar6, original_temporalis_functions, prospective
29
29
  from .dynamic_characterization import (
@@ -363,7 +363,8 @@ def create_characterization_functions_from_method(
363
363
  """
364
364
  Default dynamic characterization functions for the flows of a static LCIA method.
365
365
 
366
- The functions reproduce the IPCC AR6 emission metrics (WG1 Ch. 7, Tables 7.15 and 7.SM.7):
366
+ The functions reproduce the IPCC AR6 emission metrics (WG1 Ch. 7, Tables 7.15 and 7.SM.7, as
367
+ corrected by the AR6 WGI errata of 7 October 2025):
367
368
  CO2, fossil and non-fossil CH4 (incl. oxidation CO2), N2O and all halocarbons of Table 7.SM.7,
368
369
  with the climate-carbon feedback; CO, VOC and H2 include their indirect effects from published
369
370
  parameter sets, NO/NOx optionally. Flows are matched by CAS number, then by exact name. With
@@ -27,8 +27,8 @@
27
27
  ]
28
28
  },
29
29
  "co2": {
30
- "_source": "co2.py and notebook 335: Meinshausen 2020 ERF of +1 ppm, x1.05 adjustment; Joos et al. 2013 impulse response",
31
- "radiative_efficiency_W_m2_ppm": 0.013330689487029318,
30
+ "_source": "radiative efficiency: derivative of the Meinshausen 2020 forcing relative to pre-industrial at the 2019 background, x1.05 adjustment, as corrected by the AR6 WGI errata (7 Oct 2025; 1.39e-5 W m-2 ppb-1); impulse response: Joos et al. 2013 (co2.py, notebook 335)",
31
+ "radiative_efficiency_W_m2_ppm": 0.013876805909029954,
32
32
  "a": [
33
33
  0.2173,
34
34
  0.224,
@@ -42,8 +42,8 @@
42
42
  ]
43
43
  },
44
44
  "ch4": {
45
- "_source": "ch4.py and notebook 335; oxidation: AR6 Eq. 7.SM.5.8 and Section 7.6.1.3",
46
- "radiative_efficiency_direct_W_m2_ppb": 0.00038864402860869495,
45
+ "_source": "ch4.py and notebook 335; direct radiative efficiency as corrected by the AR6 WGI errata (7 Oct 2025; 3.74e-4 W m-2 ppb-1); oxidation: AR6 Eq. 7.SM.5.8 and Section 7.6.1.3",
46
+ "radiative_efficiency_direct_W_m2_ppb": 0.0003742973028741936,
47
47
  "tropospheric_adjustment": -0.14,
48
48
  "_radiative_efficiency_direct": "Meinshausen 2020 SARF x (1 + tropospheric_adjustment); a scenario-dependent SARF gets the same adjustment",
49
49
  "radiative_efficiency_ozone_W_m2_ppb": 0.00014,
@@ -57,8 +57,8 @@
57
57
  "oxidation_lifetime": 9.7
58
58
  },
59
59
  "n2o": {
60
- "_source": "n2o.py and notebook 335 (CH4 destruction from AR5 8.SM.11.3.3)",
61
- "radiative_efficiency_direct_W_m2_ppb": 0.00319550741640458,
60
+ "_source": "n2o.py and notebook 335 (CH4 destruction from AR5 8.SM.11.3.3); direct radiative efficiency as corrected by the AR6 WGI errata (7 Oct 2025; 3.21e-3 W m-2 ppb-1)",
61
+ "radiative_efficiency_direct_W_m2_ppb": 0.0032102204163150794,
62
62
  "tropospheric_adjustment": 0.07,
63
63
  "radiative_efficiency_ozone_W_m2_ppb": 0.00055,
64
64
  "ch4_per_n2o": -1.7,
@@ -74,7 +74,7 @@
74
74
  "lifetime_overrides": {
75
75
  "2551-62-4": {
76
76
  "lifetime": 1000.0,
77
- "_source": "SF6: AR6 Table 7.15 (GWP100 24 300, as in the static IPCC 2021 methods) uses a lifetime of 1000 yr; Table 7.SM.7 keeps the Hodnebrog et al. 2020 value of 3200 yr (GWP100 25 200)"
77
+ "_source": "SF6: the assessed lifetime of 1000 yr (AR6 Section 2.2.4.3), as in the corrected Table 7.SM.7 of the AR6 WGI errata (7 Oct 2025; GWP100 23 500); hodnebrog20.csv has 3200 yr"
78
78
  }
79
79
  }
80
80
  },
@@ -436,7 +436,11 @@
436
436
  3.1
437
437
  ]
438
438
  },
439
- "agwp_co2": "ar6",
439
+ "agwp_co2": {
440
+ "20": 2.43e-14,
441
+ "100": 8.95e-14,
442
+ "500": 3.14e-13
443
+ },
440
444
  "source": "Warwick et al. 2023, Table 3 (AR6 column)"
441
445
  }
442
446
  },
@@ -498,7 +502,11 @@
498
502
  100,
499
503
  500
500
504
  ],
501
- "agwp_co2": "ar6",
505
+ "agwp_co2": {
506
+ "20": 2.43e-14,
507
+ "100": 8.95e-14,
508
+ "500": 3.14e-13
509
+ },
502
510
  "source": "Sand et al. 2023, main text"
503
511
  }
504
512
  }
@@ -84,10 +84,10 @@ def ch4(
84
84
 
85
85
  - ``"ar6"``: oxidation CO2 is added and the carbon that was taken up by the biomass
86
86
  (M_CO2/M_CH4 kg CO2 per kg CH4) is subtracted at the time of emission, as in AR6
87
- Table 7.15 "non-fossil" (GWP100 27.0).
87
+ Table 7.15 "non-fossil" (GWP100 25.3, corrected table of the AR6 errata 2025).
88
88
  - ``"neutral"``: neither term, i.e. the CH4 pulse alone (GWP100 27.9).
89
89
  - ``"explicit"``: oxidation CO2 is added, uptake is assumed to be modelled in the
90
- inventory (GWP100 29.8, as fossil).
90
+ inventory (GWP100 28.0, as fossil).
91
91
  oxidation_yield : float, optional
92
92
  Fraction of the CH4 that is oxidised to CO2 (AR6: 0.75, range 0.5-1).
93
93
  ccf : CCFParameters, optional
@@ -165,7 +165,7 @@ def halocarbon_table() -> Dict[str, dict]:
165
165
  Rows of ``hodnebrog20.csv`` with a lifetime, keyed by canonical CAS number.
166
166
 
167
167
  Applies the CFC-11/12 tropospheric adjustment and the lifetime overrides of
168
- ``ar6_parameters.json`` (SF6: 1000 yr as in AR6 Table 7.15).
168
+ ``ar6_parameters.json`` (SF6: the assessed 1000 yr, as in the corrected AR6 Table 7.SM.7).
169
169
  """
170
170
  adjustment = load_parameters()["halocarbons"]["tropospheric_adjustment"]
171
171
  lifetime_overrides = load_parameters()["halocarbons"]["lifetime_overrides"]
@@ -1,6 +1,7 @@
1
1
  """
2
2
  Dynamic characterization functions based on the IPCC AR6 emission metrics (WG1 Ch. 7, Tables 7.15
3
- and 7.SM.7), built from the pulse responses of :mod:`.ar6_core` and :mod:`.gases`.
3
+ and 7.SM.7, as corrected by the AR6 WGI errata of 7 October 2025), built from the pulse responses
4
+ of :mod:`.ar6_core` and :mod:`.gases`.
4
5
 
5
6
  All functions have the signature ``(series, period=100, cumulative=False) -> CharacterizedRow``.
6
7
  The value stamped at ``date + k`` years is the forcing integrated over the year starting then
@@ -10,10 +11,10 @@ The public names of earlier versions are kept:
10
11
 
11
12
  - ``characterize_co2`` / ``characterize_co2_uptake``: CO2 (AR6 Table 7.SM.7 CO2 response);
12
13
  - ``characterize_ch4``: fossil CH4 incl. ozone, stratospheric water vapour, oxidation CO2 and the
13
- climate-carbon feedback (GWP100 29.8);
14
- - ``characterize_n2o``: N2O incl. its ozone and CH4 effects and the climate-carbon feedback (273);
14
+ climate-carbon feedback (GWP100 28.1);
15
+ - ``characterize_n2o``: N2O incl. its ozone and CH4 effects and the climate-carbon feedback (267);
15
16
  - ``characterize_co``: fossil CO incl. its ozone, CH4 and sulfate effects (Fry et al. 2012) and
16
- oxidation CO2 (GWP100 3.2);
17
+ oxidation CO2 (GWP100 3.1);
17
18
  - ``create_generic_characterization_function``: a function from a user-supplied decay series.
18
19
 
19
20
  Before version 2.0 these were simplified functions without climate-carbon feedback, without the
@@ -30,7 +30,7 @@ class CharacterizationOptions:
30
30
  Gasser et al. (2017) parameter set; mean is AR6, upper/lower are +-1 SD.
31
31
  biogenic_oxidation_co2 : {"ar6", "neutral", "explicit"}
32
32
  Treatment of the carbon in non-fossil CH4 (see
33
- ``ipcc_ar6.gases.ch4``). Default ``"ar6"`` (GWP100 27.0).
33
+ ``ipcc_ar6.gases.ch4``). Default ``"ar6"`` (GWP100 25.3).
34
34
  ch4_oxidation_yield : float, optional
35
35
  Fraction of CH4 oxidised to CO2. Default None = AR6 value 0.75.
36
36
  unspecified_origin : {"fossil", "non-fossil"}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dynamic_characterization
3
- Version: 2.0.0
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>
@@ -0,0 +1,286 @@
1
+ """
2
+ The AR6 pulse responses reproduce the IPCC AR6 emission metrics (Tables 7.15 and 7.SM.7):
3
+
4
+ - as corrected by the AR6 WGI errata of 7 October 2025 (the parameters of the package), and
5
+ - as originally published in 2021, when computed with the 2021 radiative efficiencies of CO2,
6
+ CH4 and N2O, which shows that the errata changes nothing but these three numbers.
7
+ """
8
+
9
+ import contextlib
10
+ import csv
11
+ import importlib.util
12
+ import os
13
+
14
+ import numpy as np
15
+ import pandas as pd
16
+ import pytest
17
+
18
+ from dynamic_characterization.flows import normalize_cas
19
+ from dynamic_characterization.ipcc_ar6 import ar6_core, gases
20
+ from dynamic_characterization.ipcc_ar6.radiative_forcing import (
21
+ characterize_co2_ar6,
22
+ make_characterization_function,
23
+ )
24
+
25
+ ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
26
+ AR6_TABLE = os.path.join(ROOT, "tests", "data", "ar6_metrics_supplement_cleaned.csv")
27
+
28
+
29
+ def _load_dev_script(name):
30
+ spec = importlib.util.spec_from_file_location(name, os.path.join(ROOT, "dev", f"{name}.py"))
31
+ module = importlib.util.module_from_spec(spec)
32
+ spec.loader.exec_module(module)
33
+ return module
34
+
35
+
36
+ BUILD_AR6_DATA = _load_dev_script("build_ar6_data")
37
+
38
+ CCF = ar6_core.ccf_parameters("gasser2017_mean")
39
+ CO2 = gases.co2()
40
+ GWP_HORIZONS = (20.0, 100.0, 500.0)
41
+ GTP_HORIZONS = (50.0, 100.0)
42
+
43
+
44
+ def gwp(spec, horizon):
45
+ return float(ar6_core.agwp(spec, horizon) / ar6_core.agwp(CO2, horizon))
46
+
47
+
48
+ def gtp(spec, horizon):
49
+ return float(ar6_core.agtp(spec, horizon) / ar6_core.agtp(CO2, horizon))
50
+
51
+
52
+ def published_tolerance(value):
53
+ """Table 7.SM.7 is rounded to 3 significant figures, small values to 3 decimals."""
54
+ return max(0.01 * abs(value), 6e-4)
55
+
56
+
57
+ def _ar6_rows():
58
+ with open(AR6_TABLE, newline="", encoding="utf-8") as f:
59
+ rows = list(csv.DictReader(f))
60
+ for row in rows:
61
+ row["CAS"] = normalize_cas(row["CAS"].strip('="'))
62
+ return rows
63
+
64
+
65
+ AR6_ROWS = _ar6_rows() # Table 7.SM.7 as published in 2021
66
+ SF6_CAS = "2551-62-4"
67
+ HALOCARBON_ROWS = [row for row in AR6_ROWS if row["CAS"] is not None and row["Lifetime (yr)"]]
68
+ # the 2021 Table 7.SM.7 used the Hodnebrog et al. 2020 SF6 lifetime of 3200 yr; the package and the
69
+ # corrected table (errata 2025) use the assessed 1000 yr (Section 2.2.4.3)
70
+ HALOCARBON_ROWS_SM7_2021 = [row for row in HALOCARBON_ROWS if row["CAS"] != SF6_CAS]
71
+
72
+ ERRATA_TABLE = os.path.join(ROOT, "tests", "data", "ar6_errata_2025_table_7sm7.csv")
73
+ METRICS = ("GWP20", "GWP100", "GWP500", "GTP50", "GTP100")
74
+
75
+
76
+ def _errata_rows():
77
+ with open(ERRATA_TABLE, encoding="utf-8") as f:
78
+ return list(csv.DictReader(line for line in f if not line.startswith("#")))
79
+
80
+
81
+ ERRATA_ROWS = _errata_rows()
82
+
83
+
84
+ def _spec_for(key, ccf=CCF):
85
+ if key == "Methane":
86
+ return gases.ch4("non-fossil", "neutral", ccf=ccf) # the plain CH4 pulse of Table 7.SM.7
87
+ if key == "Nitrous oxide":
88
+ return gases.n2o(ccf=ccf)
89
+ wanted = key.lower().replace("sulphur", "sulfur")
90
+ (cas,) = [c for c, r in gases.halocarbon_table().items() if wanted in (r["acronym"].lower(), r["name"].lower())]
91
+ return gases.halocarbon(cas, ccf=ccf)
92
+
93
+
94
+ def _metrics(spec):
95
+ return [gwp(spec, h) for h in GWP_HORIZONS] + [gtp(spec, h) for h in GTP_HORIZONS]
96
+
97
+
98
+ def _assert_published(spec, published):
99
+ for name, computed, value in zip(METRICS, _metrics(spec), published):
100
+ assert computed == pytest.approx(value, abs=published_tolerance(value)), name
101
+
102
+
103
+ _CACHED = ("_ar6_co2_component", "_release_as_component", "_co2_grids", "_ccf_on_grid", "_release_on_grid", "annual_cumulative")
104
+
105
+
106
+ def _clear_caches():
107
+ for name in _CACHED:
108
+ getattr(ar6_core, name).cache_clear()
109
+
110
+
111
+ @contextlib.contextmanager
112
+ def ar6_2021_radiative_efficiencies():
113
+ """Compute with the radiative efficiencies of the original (2021) AR6 tables (test only)."""
114
+ p = ar6_core.load_parameters()
115
+ keys = (("co2", "radiative_efficiency_W_m2_ppm"), ("ch4", "radiative_efficiency_direct_W_m2_ppb"), ("n2o", "radiative_efficiency_direct_W_m2_ppb"))
116
+ saved = [p[gas][key] for gas, key in keys]
117
+ for (gas, key), value in zip(keys, BUILD_AR6_DATA.radiative_efficiencies_ar6_2021()):
118
+ p[gas][key] = value
119
+ _clear_caches()
120
+ try:
121
+ yield
122
+ finally:
123
+ for (gas, key), value in zip(keys, saved):
124
+ p[gas][key] = value
125
+ _clear_caches()
126
+
127
+
128
+ # --- corrected values: AR6 WGI errata of 7 October 2025 (the package's parameters) ----------
129
+
130
+
131
+ def test_radiative_efficiencies_are_those_of_the_errata():
132
+ """Errata, Chapter 7 p. 1012: 1.39e-5, 3.74e-4 and 3.21e-3 W m-2 ppb-1."""
133
+ p = ar6_core.load_parameters()
134
+ assert p["co2"]["radiative_efficiency_W_m2_ppm"] / 1e3 == pytest.approx(1.39e-5, abs=0.005e-5)
135
+ assert p["ch4"]["radiative_efficiency_direct_W_m2_ppb"] == pytest.approx(3.74e-4, abs=0.005e-4)
136
+ assert p["n2o"]["radiative_efficiency_direct_W_m2_ppb"] == pytest.approx(3.21e-3, abs=0.005e-3)
137
+
138
+
139
+ def test_co2_agwp_and_agtp():
140
+ """Corrected Table 7.SM.7: AGWP 0.0253 / 0.093 / 0.326 pW m-2 yr kg-1, AGTP 0.000445 / 0.00041 pK kg-1."""
141
+ for horizon, value in zip(GWP_HORIZONS, (0.0253e-12, 0.093e-12, 0.326e-12)):
142
+ assert float(ar6_core.agwp(CO2, horizon)) == pytest.approx(value, rel=0.005)
143
+ for horizon, value in zip(GTP_HORIZONS, (0.000445e-12, 0.00041e-12)):
144
+ assert float(ar6_core.agtp(CO2, horizon)) == pytest.approx(value, rel=0.01)
145
+
146
+
147
+ @pytest.mark.parametrize(
148
+ "spec_args, published",
149
+ [
150
+ # corrected Table 7.15 (errata p. 1017): GWP20, GWP100, GWP500, GTP50, GTP100
151
+ ((gases.ch4, ("fossil",)), (77.4, 28.1, 9.5, 12.5, 7.1)),
152
+ ((gases.ch4, ("non-fossil",)), (74.7, 25.3, 6.8, 9.8, 4.4)),
153
+ ((gases.n2o, ()), (267, 267, 127, 283, 228)),
154
+ ((gases.halocarbon, ("75-10-5",)), (2590, 743, 212, 176, 137)), # HFC-32
155
+ ((gases.halocarbon, ("811-97-2",)), (3990, 1470, 420, 709, 295)), # HFC-134a
156
+ ((gases.halocarbon, ("75-69-4",)), (8010, 6000, 2020, 6120, 3410)), # CFC-11
157
+ ((gases.halocarbon, ("75-73-0",)), (5100, 7110, 10200, 7380, 8730)), # PFC-14
158
+ ],
159
+ ids=["CH4 fossil", "CH4 non-fossil", "N2O", "HFC-32", "HFC-134a", "CFC-11", "PFC-14"],
160
+ )
161
+ def test_corrected_table_7_15(spec_args, published):
162
+ builder, args = spec_args
163
+ spec = builder(*args, ccf=CCF)
164
+ for name, computed, value in zip(METRICS, _metrics(spec), published):
165
+ # Table 7.15 rounds CH4 to one decimal
166
+ assert computed == pytest.approx(value, abs=max(0.01 * value, 0.05)), name
167
+
168
+
169
+ @pytest.mark.parametrize("row", ERRATA_ROWS, ids=[r["key"] for r in ERRATA_ROWS])
170
+ def test_corrected_table_7sm7(row):
171
+ """A sample of 41 rows of the corrected Table 7.SM.7 (errata p. 16 of the SM, incl. SF6 at 1000 yr)."""
172
+ _assert_published(_spec_for(row["key"]), [float(row[m]) for m in METRICS])
173
+
174
+
175
+ def test_every_ar6_halocarbon_is_available():
176
+ missing = [row["Name"] for row in HALOCARBON_ROWS if gases.halocarbon(row["CAS"]) is None]
177
+ assert not missing
178
+
179
+
180
+ # --- original 2021 tables: same method, 2021 radiative efficiencies -------------------------
181
+
182
+
183
+ def test_2021_co2_agwp_and_agtp():
184
+ co2_row = AR6_ROWS[0]
185
+ assert co2_row["Formula"] == "CO2"
186
+ with ar6_2021_radiative_efficiencies():
187
+ for horizon in GWP_HORIZONS:
188
+ published = float(co2_row[f"AGWP{int(horizon)} (W m-2 yr kg-1)"])
189
+ assert ar6_core.agwp(CO2, horizon) == pytest.approx(published, rel=0.005)
190
+ for horizon in GTP_HORIZONS:
191
+ published = float(co2_row[f"AGTP{int(horizon)} (K kg-1)"])
192
+ assert ar6_core.agtp(CO2, horizon) == pytest.approx(published, rel=0.005)
193
+
194
+
195
+ @pytest.mark.parametrize("key, formula", [("Methane", "CH4"), ("Nitrous oxide", "N2O")])
196
+ def test_2021_ch4_and_n2o_table_7sm7(key, formula):
197
+ row = next(r for r in AR6_ROWS if r["Formula"] == formula)
198
+ with ar6_2021_radiative_efficiencies():
199
+ _assert_published(_spec_for(key), [float(row[m]) for m in METRICS])
200
+
201
+
202
+ @pytest.mark.parametrize(
203
+ "origin, published",
204
+ [("fossil", (82.5, 29.8, 10.0)), ("non-fossil", (79.7, 27.0, 7.2))], # 2021 Table 7.15
205
+ )
206
+ def test_2021_ch4_fossil_and_non_fossil_table_7_15(origin, published):
207
+ with ar6_2021_radiative_efficiencies():
208
+ spec = gases.ch4(origin, ccf=CCF)
209
+ for horizon, value in zip(GWP_HORIZONS, published):
210
+ assert gwp(spec, horizon) == pytest.approx(value, abs=max(0.01 * value, 0.05))
211
+
212
+
213
+ @pytest.mark.parametrize("row", HALOCARBON_ROWS_SM7_2021, ids=[r["Name"] for r in HALOCARBON_ROWS_SM7_2021])
214
+ def test_2021_halocarbons_table_7sm7(row):
215
+ with ar6_2021_radiative_efficiencies():
216
+ _assert_published(gases.halocarbon(row["CAS"], ccf=CCF), [float(row[m]) for m in METRICS])
217
+
218
+
219
+ def test_ccf_parameter_sets_are_ordered():
220
+ values = [gwp(gases.ch4(ccf=ar6_core.ccf_parameters(name)), 100.0) for name in ("gasser2017_lower", "gasser2017_mean", "gasser2017_upper")]
221
+ no_ccf = gwp(gases.ch4(ccf=None), 100.0)
222
+ assert no_ccf < values[0] < values[1] < values[2]
223
+
224
+
225
+ def test_ccf_grows_relative_to_direct_forcing():
226
+ """The CCF tail: small at first, larger than the direct CH4 forcing after several decades."""
227
+ with_ccf = gases.ch4("non-fossil", "neutral", ccf=CCF)
228
+ without = gases.ch4("non-fossil", "neutral", ccf=None)
229
+ t = np.array([10.0, 50.0, 100.0])
230
+ share = ar6_core.radiative_forcing(with_ccf, t) / ar6_core.radiative_forcing(without, t) - 1
231
+ assert 0.0 < share[0] < 0.1
232
+ assert share[1] > 0.2
233
+ assert share[2] > 1.0
234
+
235
+
236
+ def test_oxidation_co2_is_the_convolution_of_source_and_co2_response():
237
+ """co2_from_decay (analytic) equals a numerical convolution of the source with the CO2 RF."""
238
+ dt = 0.001
239
+ t = np.arange(0, 100 + dt / 2, dt)
240
+ lifetime = 9.7
241
+ source = np.exp(-t / lifetime) / lifetime
242
+ rf_numeric = np.convolve(source, ar6_core.radiative_forcing(CO2, t))[: t.size] * dt
243
+ rf_analytic = ar6_core.radiative_forcing(ar6_core.co2_from_decay(1.0, lifetime), t)
244
+ assert np.allclose(rf_numeric[1000::1000], rf_analytic[1000::1000], rtol=2e-3)
245
+
246
+
247
+ def test_agtp_is_the_convolution_of_rf_and_temperature_response():
248
+ dt = 0.001
249
+ t = np.arange(0, 100 + dt / 2, dt)
250
+ spec = ar6_core.exponential_spec("test", 1e-13, 12.0)
251
+ q, d = (np.asarray(v) for v in (ar6_core.load_parameters()["temperature_response"][k] for k in "qd"))
252
+ response = sum(qj / dj * np.exp(-t / dj) for qj, dj in zip(q, d))
253
+ numeric = np.convolve(ar6_core.radiative_forcing(spec, t), response)[: t.size] * dt
254
+ assert numeric[-1] == pytest.approx(float(ar6_core.agtp(spec, 100.0)), rel=2e-3)
255
+
256
+
257
+ # --- characterization functions built from the specs ---------------------------------------
258
+
259
+
260
+ class Row:
261
+ def __init__(self, amount=1.0):
262
+ self.date = pd.Timestamp("2024-01-01")
263
+ self.amount = amount
264
+ self.flow = 1
265
+ self.activity = 2
266
+
267
+
268
+ @pytest.mark.parametrize("period", [1, 20, 100, 500])
269
+ def test_annual_forcing_adds_up_to_agwp(period):
270
+ func = make_characterization_function(gases.ch4(ccf=CCF))
271
+ result = func(Row(amount=2.0), period)
272
+ assert result.amount.shape == (period,)
273
+ assert result.amount.sum() == pytest.approx(2.0 * func.agwp(period), rel=1e-12)
274
+ cumulative = func(Row(amount=2.0), period, cumulative=True).amount
275
+ assert np.allclose(np.cumsum(result.amount), cumulative)
276
+
277
+
278
+ def test_first_year_is_stamped_at_the_emission_date():
279
+ result = characterize_co2_ar6(Row(), 3)
280
+ assert result.date[0] == np.datetime64("2024-01-01T00:00:00")
281
+ assert result.amount[0] == pytest.approx(float(ar6_core.agwp(CO2, 1.0)))
282
+
283
+
284
+ def test_functions_are_memoized_per_spec():
285
+ assert make_characterization_function(gases.n2o(ccf=CCF)) is make_characterization_function(gases.n2o(ccf=CCF))
286
+ assert make_characterization_function(gases.n2o(ccf=CCF)) is not make_characterization_function(gases.n2o())
@@ -41,6 +41,21 @@ BIOFLOWS = {
41
41
  }
42
42
  AR6_MATCHED = [code for code in BIOFLOWS if code not in ("co_fossil", "water")]
43
43
 
44
+ # GWP100 of the corrected AR6 Table 7.15 / 7.SM.7 (AR6 WGI errata, 7 October 2025). The static
45
+ # factors above are those of ecoinvent 3.12, which predate the errata.
46
+ CORRECTED_AR6 = {
47
+ "co2_fossil": 1.0,
48
+ "co2_non_fossil": 1.0,
49
+ "co2_in_air": -1.0,
50
+ "co2_to_soil": -1.0,
51
+ "ch4_fossil": 28.1,
52
+ "ch4_non_fossil": 25.3,
53
+ "ch4_soil": 28.1,
54
+ "ch4_unspecified": 28.1,
55
+ "n2o": 267.0,
56
+ "cf4": 7110.0,
57
+ }
58
+
44
59
 
45
60
  def setup_project():
46
61
  clear_characterization_function_cache()
@@ -67,15 +82,11 @@ def setup_project():
67
82
  def test_compare_with_static_matches_ar6_factors():
68
83
  ids = setup_project()
69
84
  table = compare_with_static(METHOD, 100, AR6).set_index("flow")
70
- for code in AR6_MATCHED:
71
- static = BIOFLOWS[code][-1]
72
- assert table.loc[ids[code], "dynamic_gwp"] == pytest.approx(static, rel=0.01, abs=1e-3), code
73
-
74
-
75
- def test_parameter_set_is_not_an_option():
76
- """The AR6 functions are the only ones since 2.0; there is no parameter set to choose."""
77
- with pytest.raises(ValueError, match="Unknown characterization option"):
78
- CharacterizationOptions.from_value({"parameter_set": "ar6"})
85
+ for code, corrected in CORRECTED_AR6.items():
86
+ assert table.loc[ids[code], "dynamic_gwp"] == pytest.approx(corrected, rel=0.01, abs=1e-3), code
87
+ # without a corrected published value at hand: the errata lowers them by the CO2 reference
88
+ for code in ("dichloromethane", "vinylidene_fluoride"):
89
+ assert 0.94 < table.loc[ids[code], "ratio"] < 0.98, code
79
90
 
80
91
 
81
92
  @bw2test
@@ -113,9 +124,9 @@ def test_unspecified_origin_and_overrides():
113
124
  flow_overrides={(bd.config.biosphere, "ch4_soil"): {"origin": "non-fossil"}, ids["water"]: {"species": None}},
114
125
  )
115
126
  table = compare_with_static(METHOD, 100, options).set_index("flow")
116
- assert table.loc[ids["ch4_unspecified"], "dynamic_gwp"] == pytest.approx(27.0, rel=0.01)
117
- assert table.loc[ids["ch4_soil"], "dynamic_gwp"] == pytest.approx(27.0, rel=0.01)
118
- assert table.loc[ids["ch4_fossil"], "dynamic_gwp"] == pytest.approx(29.8, rel=0.01)
127
+ assert table.loc[ids["ch4_unspecified"], "dynamic_gwp"] == pytest.approx(25.3, rel=0.01)
128
+ assert table.loc[ids["ch4_soil"], "dynamic_gwp"] == pytest.approx(25.3, rel=0.01)
129
+ assert table.loc[ids["ch4_fossil"], "dynamic_gwp"] == pytest.approx(28.1, rel=0.01)
119
130
 
120
131
 
121
132
  @bw2test
@@ -148,7 +159,7 @@ def inventory(ids):
148
159
  def test_dynamic_gwp100_matches_static_ar6_score():
149
160
  ids = setup_project()
150
161
  amounts, df = inventory(ids)
151
- static = sum(amount * BIOFLOWS[code][-1] for code, amount in amounts.items())
162
+ static = sum(amount * CORRECTED_AR6[code] for code, amount in amounts.items())
152
163
  result = characterize(df, metric="GWP", base_lcia_method=METHOD, time_horizon=100, characterization_options=AR6)
153
164
  assert result.amount.sum() == pytest.approx(static, rel=0.005)
154
165
 
@@ -218,7 +218,8 @@ def test_public_names_are_the_ar6_functions():
218
218
 
219
219
  co2 = ipcc_ar6.characterize_co2.agwp(100)
220
220
  assert ipcc_ar6.characterize_co2 is characterize_co2_ar6
221
- assert ipcc_ar6.characterize_ch4.agwp(100) / co2 == pytest.approx(29.8, rel=0.005) # fossil CH4
222
- assert ipcc_ar6.characterize_n2o.agwp(100) / co2 == pytest.approx(273, rel=0.005)
223
- assert ipcc_ar6.characterize_co.agwp(100) / co2 == pytest.approx(3.20, abs=0.01) # fossil CO, all effects
221
+ # corrected AR6 Table 7.15 (AR6 WGI errata, 7 October 2025)
222
+ assert ipcc_ar6.characterize_ch4.agwp(100) / co2 == pytest.approx(28.1, rel=0.005) # fossil CH4
223
+ assert ipcc_ar6.characterize_n2o.agwp(100) / co2 == pytest.approx(267, rel=0.005)
224
+ assert ipcc_ar6.characterize_co.agwp(100) / co2 == pytest.approx(3.14, abs=0.01) # fossil CO, all effects
224
225
  assert ipcc_ar6.characterize_co2_uptake.agwp(100) == pytest.approx(-co2)
@@ -216,11 +216,11 @@ def test_default_precursor_functions():
216
216
  ids = setup_project()
217
217
  table = compare_with_static(METHOD, 100, AR6).set_index("flow")
218
218
  gwp = table["dynamic_gwp"]
219
- assert gwp[ids["co_non_fossil"]] == pytest.approx(1.63, abs=0.01) # Fry et al. 2012 with AR6 CO2
220
- assert gwp[ids["co_fossil"]] == pytest.approx(1.63 + 1.57, abs=0.02)
219
+ assert gwp[ids["co_non_fossil"]] == pytest.approx(1.57, abs=0.01) # Fry et al. 2012 with AR6 CO2
220
+ assert gwp[ids["co_fossil"]] == pytest.approx(1.57 + 1.57, abs=0.02)
221
221
  assert gwp[ids["co_soil"]] == gwp[ids["co_fossil"]]
222
- assert gwp[ids["h2"]] == pytest.approx(11.37, abs=0.02) # Warwick et al. 2023
223
- assert gwp[ids["voc"]] == pytest.approx(4.5, rel=0.01) # Fry et al. 2012, 0.845 kg C / kg VOC
222
+ assert gwp[ids["h2"]] == pytest.approx(10.92, abs=0.02) # Warwick et al. 2023, with the corrected AR6 CO2
223
+ assert gwp[ids["voc"]] == pytest.approx(4.32, rel=0.01) # Fry et al. 2012, 0.845 kg C / kg VOC
224
224
  assert gwp[ids["nmvoc"]] == gwp[ids["voc"]]
225
225
  for code in ("no", "nox", "hydrogen_sulfide"):
226
226
  assert np.isnan(gwp[ids[code]]), code # NOx is opt-in
@@ -231,10 +231,11 @@ def test_nox_opt_in_and_parameter_sets():
231
231
  ids = setup_project()
232
232
  options = dict(AR6, include_nox=True, precursor_parameter_sets={"H2": "sand2023", "CO": "derwent2001"})
233
233
  gwp = compare_with_static(METHOD, 100, options).set_index("flow")["dynamic_gwp"]
234
- assert gwp[ids["no"]] == pytest.approx(-8.59 * 14.007 / 30.006 * 8.56 / 8.947, rel=0.01)
234
+ agwp_co2 = float(ar6_core.agwp(gases.co2(), 100.0)) * 1e14
235
+ assert gwp[ids["no"]] == pytest.approx(-8.59 * 14.007 / 30.006 * 8.56 / agwp_co2, rel=0.01)
235
236
  assert gwp[ids["nox"]] == pytest.approx(gwp[ids["no"]] * 30.006 / 46.006)
236
- assert gwp[ids["h2"]] == pytest.approx(11.73, abs=0.02)
237
- assert gwp[ids["co_non_fossil"]] == pytest.approx(1.90, abs=0.01)
237
+ assert gwp[ids["h2"]] == pytest.approx(11.27, abs=0.02)
238
+ assert gwp[ids["co_non_fossil"]] == pytest.approx(1.83, abs=0.01)
238
239
 
239
240
 
240
241
  @bw2test
@@ -271,4 +272,4 @@ def test_characterize_with_precursors():
271
272
  rf = characterize(df, base_lcia_method=METHOD, time_horizon=100, characterization_options=AR6)
272
273
  assert set(rf.flow) == {ids["co_fossil"], ids["h2"], ids["voc"]}
273
274
  gwp = characterize(df, metric="GWP", base_lcia_method=METHOD, time_horizon=100, characterization_options=AR6)
274
- assert gwp.amount.sum() == pytest.approx(10 * 3.20 + 2 * 11.37 + 5 * 4.50, rel=0.01)
275
+ assert gwp.amount.sum() == pytest.approx(10 * 3.14 + 2 * 10.92 + 5 * 4.32, rel=0.01)
@@ -1,209 +0,0 @@
1
- """The "ar6" pulse responses reproduce the IPCC AR6 emission metrics (Tables 7.15 and 7.SM.7)."""
2
-
3
- import csv
4
- import importlib.util
5
- import os
6
-
7
- import numpy as np
8
- import pandas as pd
9
- import pytest
10
-
11
- from dynamic_characterization.flows import normalize_cas
12
- from dynamic_characterization.ipcc_ar6 import ar6_core, gases
13
- from dynamic_characterization.ipcc_ar6.radiative_forcing import (
14
- characterize_co2_ar6,
15
- make_characterization_function,
16
- )
17
-
18
- ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
19
- AR6_TABLE = os.path.join(ROOT, "tests", "data", "ar6_metrics_supplement_cleaned.csv")
20
-
21
-
22
- def _load_dev_script(name):
23
- spec = importlib.util.spec_from_file_location(name, os.path.join(ROOT, "dev", f"{name}.py"))
24
- module = importlib.util.module_from_spec(spec)
25
- spec.loader.exec_module(module)
26
- return module
27
-
28
-
29
- BUILD_AR6_DATA = _load_dev_script("build_ar6_data")
30
-
31
- CCF = ar6_core.ccf_parameters("gasser2017_mean")
32
- CO2 = gases.co2()
33
- GWP_HORIZONS = (20.0, 100.0, 500.0)
34
- GTP_HORIZONS = (50.0, 100.0)
35
-
36
-
37
- def gwp(spec, horizon):
38
- return float(ar6_core.agwp(spec, horizon) / ar6_core.agwp(CO2, horizon))
39
-
40
-
41
- def gtp(spec, horizon):
42
- return float(ar6_core.agtp(spec, horizon) / ar6_core.agtp(CO2, horizon))
43
-
44
-
45
- def published_tolerance(value):
46
- """Table 7.SM.7 is rounded to 3 significant figures, small values to 3 decimals."""
47
- return max(0.01 * abs(value), 6e-4)
48
-
49
-
50
- def _ar6_rows():
51
- with open(AR6_TABLE, newline="", encoding="utf-8") as f:
52
- rows = list(csv.DictReader(f))
53
- for row in rows:
54
- row["CAS"] = normalize_cas(row["CAS"].strip('="'))
55
- return rows
56
-
57
-
58
- AR6_ROWS = _ar6_rows()
59
- SF6_CAS = "2551-62-4"
60
- HALOCARBON_ROWS = [row for row in AR6_ROWS if row["CAS"] is not None and row["Lifetime (yr)"]]
61
- # SF6 follows AR6 Table 7.15 (lifetime 1000 yr), not Table 7.SM.7 (3200 yr), see test_sf6_matches_table_7_15
62
- HALOCARBON_ROWS_SM7 = [row for row in HALOCARBON_ROWS if row["CAS"] != SF6_CAS]
63
-
64
-
65
- def test_parameter_file_is_up_to_date():
66
- path = os.path.join(ROOT, "dynamic_characterization", "ipcc_ar6", "data", "ar6_parameters.json")
67
- with open(path, encoding="utf-8") as f:
68
- assert f.read() == BUILD_AR6_DATA.render(), "run python dev/build_ar6_data.py"
69
-
70
-
71
- def test_co2_agwp_and_agtp():
72
- co2_row = AR6_ROWS[0]
73
- assert co2_row["Formula"] == "CO2"
74
- for horizon in GWP_HORIZONS:
75
- published = float(co2_row[f"AGWP{int(horizon)} (W m-2 yr kg-1)"])
76
- assert ar6_core.agwp(CO2, horizon) == pytest.approx(published, rel=0.005)
77
- for horizon in GTP_HORIZONS:
78
- published = float(co2_row[f"AGTP{int(horizon)} (K kg-1)"])
79
- assert ar6_core.agtp(CO2, horizon) == pytest.approx(published, rel=0.005)
80
- # AR6 Table 7.SM.7 / Section 7.6.1: AGWP20 and AGWP100 of CO2
81
- assert ar6_core.agwp(CO2, 20.0) == pytest.approx(2.434e-14, rel=1e-3)
82
- assert ar6_core.agwp(CO2, 100.0) == pytest.approx(8.947e-14, rel=1e-3)
83
-
84
-
85
- @pytest.mark.parametrize(
86
- "formula, spec",
87
- [
88
- ("CH4", gases.ch4("non-fossil", "neutral", ccf=CCF)), # the plain CH4 pulse of Table 7.SM.7
89
- ("N2O", gases.n2o(ccf=CCF)),
90
- ],
91
- )
92
- def test_ch4_and_n2o_match_table_7sm7(formula, spec):
93
- row = next(r for r in AR6_ROWS if r["Formula"] == formula)
94
- for horizon in GWP_HORIZONS:
95
- published = float(row[f"GWP{int(horizon)}"])
96
- assert gwp(spec, horizon) == pytest.approx(published, abs=published_tolerance(published))
97
- for horizon in GTP_HORIZONS:
98
- published = float(row[f"GTP{int(horizon)}"])
99
- assert gtp(spec, horizon) == pytest.approx(published, abs=published_tolerance(published))
100
-
101
-
102
- @pytest.mark.parametrize(
103
- "origin, published",
104
- [
105
- # AR6 WG1 Table 7.15: GWP20, GWP100, GWP500
106
- ("fossil", (82.5, 29.8, 10.0)),
107
- ("non-fossil", (79.7, 27.0, 7.2)),
108
- ],
109
- )
110
- def test_ch4_fossil_and_non_fossil_match_table_7_15(origin, published):
111
- spec = gases.ch4(origin, ccf=CCF)
112
- for horizon, value in zip(GWP_HORIZONS, published):
113
- assert gwp(spec, horizon) == pytest.approx(value, abs=max(0.01 * value, 0.05))
114
-
115
-
116
- def test_n2o_matches_table_7_15():
117
- for horizon, value in zip(GWP_HORIZONS, (273, 273, 130)):
118
- assert gwp(gases.n2o(ccf=CCF), horizon) == pytest.approx(value, rel=0.01)
119
-
120
-
121
- def test_every_ar6_halocarbon_is_available():
122
- missing = [row["Name"] for row in HALOCARBON_ROWS if gases.halocarbon(row["CAS"]) is None]
123
- assert not missing
124
-
125
-
126
- @pytest.mark.parametrize("row", HALOCARBON_ROWS_SM7, ids=[r["Name"] for r in HALOCARBON_ROWS_SM7])
127
- def test_halocarbons_match_table_7sm7(row):
128
- spec = gases.halocarbon(row["CAS"], ccf=CCF)
129
- for horizon in GWP_HORIZONS:
130
- published = float(row[f"GWP{int(horizon)}"])
131
- assert gwp(spec, horizon) == pytest.approx(published, abs=published_tolerance(published))
132
- for horizon in GTP_HORIZONS:
133
- published = float(row[f"GTP{int(horizon)}"])
134
- assert gtp(spec, horizon) == pytest.approx(published, abs=published_tolerance(published))
135
-
136
-
137
- def test_sf6_matches_table_7_15():
138
- """AR6 Table 7.15 and the static IPCC 2021 methods: SF6 GWP100 24 300 (lifetime 1000 yr)."""
139
- assert gwp(gases.halocarbon(SF6_CAS, ccf=CCF), 100.0) == pytest.approx(24300, rel=0.005)
140
-
141
-
142
- def test_ccf_parameter_sets_are_ordered():
143
- values = [gwp(gases.ch4(ccf=ar6_core.ccf_parameters(name)), 100.0) for name in ("gasser2017_lower", "gasser2017_mean", "gasser2017_upper")]
144
- no_ccf = gwp(gases.ch4(ccf=None), 100.0)
145
- assert no_ccf < values[0] < values[1] < values[2]
146
-
147
-
148
- def test_ccf_grows_relative_to_direct_forcing():
149
- """The CCF tail: small at first, larger than the direct CH4 forcing after several decades."""
150
- with_ccf = gases.ch4("non-fossil", "neutral", ccf=CCF)
151
- without = gases.ch4("non-fossil", "neutral", ccf=None)
152
- t = np.array([10.0, 50.0, 100.0])
153
- share = ar6_core.radiative_forcing(with_ccf, t) / ar6_core.radiative_forcing(without, t) - 1
154
- assert 0.0 < share[0] < 0.1
155
- assert share[1] > 0.2
156
- assert share[2] > 1.0
157
-
158
-
159
- def test_oxidation_co2_is_the_convolution_of_source_and_co2_response():
160
- """co2_from_decay (analytic) equals a numerical convolution of the source with the CO2 RF."""
161
- dt = 0.001
162
- t = np.arange(0, 100 + dt / 2, dt)
163
- lifetime = 9.7
164
- source = np.exp(-t / lifetime) / lifetime
165
- rf_numeric = np.convolve(source, ar6_core.radiative_forcing(CO2, t))[: t.size] * dt
166
- rf_analytic = ar6_core.radiative_forcing(ar6_core.co2_from_decay(1.0, lifetime), t)
167
- assert np.allclose(rf_numeric[1000::1000], rf_analytic[1000::1000], rtol=2e-3)
168
-
169
-
170
- def test_agtp_is_the_convolution_of_rf_and_temperature_response():
171
- dt = 0.001
172
- t = np.arange(0, 100 + dt / 2, dt)
173
- spec = ar6_core.exponential_spec("test", 1e-13, 12.0)
174
- q, d = (np.asarray(v) for v in (ar6_core.load_parameters()["temperature_response"][k] for k in "qd"))
175
- response = sum(qj / dj * np.exp(-t / dj) for qj, dj in zip(q, d))
176
- numeric = np.convolve(ar6_core.radiative_forcing(spec, t), response)[: t.size] * dt
177
- assert numeric[-1] == pytest.approx(float(ar6_core.agtp(spec, 100.0)), rel=2e-3)
178
-
179
-
180
- # --- characterization functions built from the specs ---------------------------------------
181
-
182
-
183
- class Row:
184
- def __init__(self, amount=1.0):
185
- self.date = pd.Timestamp("2024-01-01")
186
- self.amount = amount
187
- self.flow = 1
188
- self.activity = 2
189
-
190
-
191
- @pytest.mark.parametrize("period", [1, 20, 100, 500])
192
- def test_annual_forcing_adds_up_to_agwp(period):
193
- func = make_characterization_function(gases.ch4(ccf=CCF))
194
- result = func(Row(amount=2.0), period)
195
- assert result.amount.shape == (period,)
196
- assert result.amount.sum() == pytest.approx(2.0 * func.agwp(period), rel=1e-12)
197
- cumulative = func(Row(amount=2.0), period, cumulative=True).amount
198
- assert np.allclose(np.cumsum(result.amount), cumulative)
199
-
200
-
201
- def test_first_year_is_stamped_at_the_emission_date():
202
- result = characterize_co2_ar6(Row(), 3)
203
- assert result.date[0] == np.datetime64("2024-01-01T00:00:00")
204
- assert result.amount[0] == pytest.approx(float(ar6_core.agwp(CO2, 1.0)))
205
-
206
-
207
- def test_functions_are_memoized_per_spec():
208
- assert make_characterization_function(gases.n2o(ccf=CCF)) is make_characterization_function(gases.n2o(ccf=CCF))
209
- assert make_characterization_function(gases.n2o(ccf=CCF)) is not make_characterization_function(gases.n2o())