From 50987178d366de3223616f95c1b70183051e7100 Mon Sep 17 00:00:00 2001 From: Hugh Runyan Date: Thu, 19 Nov 2026 10:34:38 -0800 Subject: [PATCH 1/2] A defaulted landfill share captures gas where its country's landfills do; China takes its 2020 split Provisional, pending research. IPCC's default disposal splits carry no gas-capture share, so every defaulted landfill was modelled without capture. landfill_capture moves a share of a defaulted split's landfill-without-capture to landfill-with-capture: researched for the US, Canada, New Zealand and Australia, 0.5 for other high-income countries, else none. China gets a country treatment row: its 2020 urban domestic waste split. Decisions default-landfill-capture-share and china-treatment-split-2020. Co-Authored-By: Claude Opus 5.5 --- SWEET_python/MODEL_DECISIONS.md | 39 +++++- SWEET_python/city_params.py | 6 + SWEET_python/defaults_2019.py | 53 ++++++-- SWEET_python/landfill_capture.py | 133 +++++++++++++++++++ changelog/2026-11.md | 25 ++++ tests/test_custom_location_disposal_split.py | 22 +-- tests/test_default_landfill_capture.py | 123 +++++++++++++++++ 7 files changed, 379 insertions(+), 22 deletions(-) create mode 100644 SWEET_python/landfill_capture.py create mode 100644 tests/test_default_landfill_capture.py diff --git a/SWEET_python/MODEL_DECISIONS.md b/SWEET_python/MODEL_DECISIONS.md index a405e0c..39fee28 100644 --- a/SWEET_python/MODEL_DECISIONS.md +++ b/SWEET_python/MODEL_DECISIONS.md @@ -98,6 +98,7 @@ Where the code applies a decision, a one-line comment names it: | [`combustion-reject`](#combustion-reject) | Diversion | fixed value | medium | | [`other-treatment-shares-landfilled`](#other-treatment-shares-landfilled) | Diversion | simplification | low | | [`diversion-defaults`](#diversion-defaults) | Diversion | fallback | low | +| [`china-treatment-split-2020`](#china-treatment-split-2020) | Diversion | fixed value | low | | [`city-treatment-buckets`](#city-treatment-buckets) | Diversion | method choice | low | | [`diversion-eligibility`](#diversion-eligibility) | Diversion | fixed value | medium | | [`diversion-rejects`](#diversion-rejects) | Diversion | fixed value | low | @@ -109,6 +110,7 @@ Where the code applies a decision, a one-line comment names it: | [`methane-potential-by-waste-type`](#methane-potential-by-waste-type) | Decay model | fixed value | high | | [`oxidation`](#oxidation) | Decay model | fallback | medium | | [`gas-capture-efficiency`](#gas-capture-efficiency) | Decay model | fallback | medium | +| [`default-landfill-capture-share`](#default-landfill-capture-share) | Decay model | fallback | low | | [`flaring-uniform`](#flaring-uniform) | Decay model | simplification | medium | | [`monthly-from-decay-model`](#monthly-from-decay-model) | Decay model | simplification | medium | | [`inert-waste-types`](#inert-waste-types) | Decay model | simplification | low | @@ -468,6 +470,21 @@ A city or place with no treatment data takes its country's, else its region's, c - **Code:** `SWEET_python/city_params.py` (2 places) - **Reviewed:** 2026-10-23 +### `china-treatment-split-2020` + +China's default treatment is its urban domestic waste in 2020: 33% landfilled, 62% incinerated, 5% composted. China had no row of its own and took Eastern Asia's, which landfilled 76%. + +- **Kind:** fixed value +- **Why:** Hugh, 2026-11-19: 2020 is near China's 2015-2024 average (landfilled 60% in 2015, 5% in 2024), and one split covers every year. +- **Paths:** + - `city-model`: a Chinese city with no treatment or landfill shares of its own. + - `custom-location`: every Chinese Custom Location. +- **Confidence:** low +- **Better:** A split by year (`city-shares-constant`): China's landfilling fell from 60% to 5% in nine years. "Other" (5%) is taken as composting; the yearbook doesn't say. Needed before the cities pipeline relies on it. +- **Value:** `SWEET_python.defaults_2019`: the "China" rows of `FRACTION_LANDFILLED_COUNTRY`, `FRACTION_INCINERATED_COUNTRY`, `FRACTION_COMPOSTED_COUNTRY`, `FRACTION_OPEN_DUMPED_COUNTRY`, `FRACTION_UNSPECIFIED_COUNTRY` (China Statistical Yearbook 2021) +- **Code:** `SWEET_python/defaults_2019.py` (5 places) +- **Reviewed:** 2026-11-19 + ### `city-treatment-buckets` A city's reported treatment shares map onto four buckets: sanitary landfill with gas collection is "with capture"; controlled landfill and unspecified landfill are "without capture"; open dump is "dumpsite"; controlled dumpsite is "controlled dumpsite". Advanced thermal treatment counts as incineration. @@ -638,7 +655,7 @@ A site captures its reported efficiency, else a default: the remediated value fo - `site-tool`: `reported`; left blank, `remediated` for a site upgraded in the scenario, else `type-default`. - `adst-site`, `adst-city`: the caller's value, by year where it gives years; none given means 0. - `city-model`: 0.6 on the share sent to landfills with capture; the cities table's efficiency is read but never used. - - `custom-location`: 0.6 on a capture share, but the default split has none, so a Custom Location captures nothing. + - `custom-location`: 0.6 on the capture share its default split now carries (`default-landfill-capture-share`). - `city-dst-scenario`: "add gas capture" sets 0.6 on both landfill shares, `remediated` (30%) on the dumpsite, which it makes a controlled dumpsite, and `type-default` (45%) on the controlled dumpsite, which stays one, from the year after implementation. - **Confidence:** medium - **Better:** Let the city model read each city's reported efficiency. @@ -646,6 +663,26 @@ A site captures its reported efficiency, else a default: the remediated value fo - **Code:** `SWEET_python/city_params.py` (2 places) - **Reviewed:** 2026-10-23 +### `default-landfill-capture-share` + +A defaulted landfill share sends part of its waste to landfills with gas capture: the country's researched share, else half for a high-income country, else none. + +- **Kind:** fallback +- **Why:** IPCC's default splits say nothing about capture, so every defaulted landfill in the US or EU was modelled without it; Hugh, 2026-11-19. +- **Options, best first:** + 1. `reported`: the city's own landfill shares, which are never changed. + 2. `country`: a researched share: US 0.85, Canada 0.66, New Zealand 0.92, Australia 0.6. + 3. `high-income`: 0.5, a placeholder, for a World Bank high-income country. + 4. `none`: no capture. +- **Paths:** + - `city-model`: `reported`; with every landfill share blank or zero, `country`, else `high-income` when the caller passes the income group, else `none`. + - `custom-location`: `country`, else `high-income` when the caller passes the income group, else `none`. +- **Confidence:** low +- **Better:** A researched share for every country, mass-weighted, before this is relied on. The Gulf states and Russia are high income but capture little; Turkey and Mexico capture some but get none. +- **Value:** `SWEET_python.landfill_capture`: `CAPTURE_SHARE_COUNTRY`, `HIGH_INCOME_SHARE` +- **Code:** `SWEET_python/landfill_capture.py`, `SWEET_python/city_params.py`, `SWEET_python/defaults_2019.py` +- **Reviewed:** 2026-11-19 + ### `flaring-uniform` Captured gas is burned at 0.98 efficiency in every year, unless the caller states a value. diff --git a/SWEET_python/city_params.py b/SWEET_python/city_params.py index 837d7df..47ea03a 100644 --- a/SWEET_python/city_params.py +++ b/SWEET_python/city_params.py @@ -27,6 +27,7 @@ import SWEET_python.defaults_2019 as defaults_2019 import SWEET_python.mcf as mcf_defaults import SWEET_python.site_type_defaults as site_type_defaults +import SWEET_python.landfill_capture as landfill_capture from SWEET_python.population import ( average_growth_rates, city_population_series, @@ -2110,6 +2111,8 @@ def load_andre_params( # Normalize landfills to 1 split_total = sum([x for x in split_fractions.values()]) + # No landfill share of the city's own: the split is its country's or region's. + split_defaulted = all_nan_fill or split_total == 0 if split_total == 0: if site_type_defaults.landfill_is_default(iso3, income_id): split_fractions = { @@ -2126,6 +2129,9 @@ def load_andre_params( split_total = sum([x for x in split_fractions.values()]) for site in split_fractions.keys(): split_fractions[site] /= split_total + # decision: default-landfill-capture-share + if split_defaulted: + split_fractions = landfill_capture.with_default_capture(split_fractions, iso3, income_id) # Replace diversion NaN values with 0 ( diff --git a/SWEET_python/defaults_2019.py b/SWEET_python/defaults_2019.py index a55a4ed..e088990 100644 --- a/SWEET_python/defaults_2019.py +++ b/SWEET_python/defaults_2019.py @@ -6,6 +6,7 @@ from pathlib import Path import SWEET_python.gas_capture as gas_capture +import SWEET_python.landfill_capture as landfill_capture import SWEET_python.oxidation as oxidation from SWEET_python.constants import GWP100_CH4, SHORT_TONS_PER_TONNE, WASTE_TYPES @@ -1524,6 +1525,10 @@ def compost_emission_factor(food, green): "Australia": 0.0, "New Zealand": 0.0, "Nigeria": 1.0, + # decision: china-treatment-split-2020 + # China: urban domestic waste, 2020 (China Statistical Yearbook 2021): 235.1 Mt collected, + # 77.7 Mt sanitary landfill, 146.1 Mt incineration, 10.7 Mt other (taken as composting). + "China": 0.0, } FRACTION_OPEN_DUMPED_COUNTRY = { COUNTRY_TO_ISO3[country]: value @@ -1615,6 +1620,10 @@ def compost_emission_factor(food, green): "Australia": 0.52, "New Zealand": 0.85, "Nigeria": 0.0, + # decision: china-treatment-split-2020 + # China: urban domestic waste, 2020 (China Statistical Yearbook 2021): 235.1 Mt collected, + # 77.7 Mt sanitary landfill, 146.1 Mt incineration, 10.7 Mt other (taken as composting). + "China": 0.33, } FRACTION_LANDFILLED_COUNTRY = { COUNTRY_TO_ISO3[country]: value @@ -1641,6 +1650,9 @@ def disposal_split_for(iso3, region, income_id=None): and Switzerland's rows are all zeros, so they take their region's, which is landfill only. + The country's share of landfilled waste that goes to landfills with gas capture + (``landfill_capture``) is then moved to ``landfill_w_capture``. + This is the split ``City.load_andre_params`` gives a cities-table row with no landfill data, so a Custom Location starts from the same split as a mapped city in the same country. @@ -1653,20 +1665,29 @@ def disposal_split_for(iso3, region, income_id=None): landfill = landfilled.get(key, 0.0) total = dumpsite + landfill if total > 0: - return { - "landfill_w_capture": 0.0, - "landfill_wo_capture": landfill / total, - "dumpsite": dumpsite / total, - } + # decision: default-landfill-capture-share + return landfill_capture.with_default_capture( + { + "landfill_w_capture": 0.0, + "landfill_wo_capture": landfill / total, + "dumpsite": dumpsite / total, + }, + iso3, + income_id, + ) # Imported here: site_type_defaults imports this module. from SWEET_python.site_type_defaults import landfill_is_default landfills = landfill_is_default(iso3, income_id) - return { - "landfill_w_capture": 0.0, - "landfill_wo_capture": 1.0 if landfills else 0.0, - "dumpsite": 0.0 if landfills else 1.0, - } + return landfill_capture.with_default_capture( + { + "landfill_w_capture": 0.0, + "landfill_wo_capture": 1.0 if landfills else 0.0, + "dumpsite": 0.0 if landfills else 1.0, + }, + iso3, + income_id, + ) FRACTION_INCINERATED_COUNTRY = { @@ -1754,6 +1775,10 @@ def disposal_split_for(iso3, region, income_id=None): "United States": 0.12, "Australia": 0.08, "New Zealand": 0.0, + # decision: china-treatment-split-2020 + # China: urban domestic waste, 2020 (China Statistical Yearbook 2021): 235.1 Mt collected, + # 77.7 Mt sanitary landfill, 146.1 Mt incineration, 10.7 Mt other (taken as composting). + "China": 0.62, } FRACTION_INCINERATED_COUNTRY = { COUNTRY_TO_ISO3[country]: value @@ -1844,6 +1869,10 @@ def disposal_split_for(iso3, region, income_id=None): "United States": 0.08, "Australia": 0.0, "New Zealand": 0.0, + # decision: china-treatment-split-2020 + # China: urban domestic waste, 2020 (China Statistical Yearbook 2021): 235.1 Mt collected, + # 77.7 Mt sanitary landfill, 146.1 Mt incineration, 10.7 Mt other (taken as composting). + "China": 0.05, } FRACTION_COMPOSTED_COUNTRY = { COUNTRY_TO_ISO3[country]: value @@ -1934,6 +1963,10 @@ def disposal_split_for(iso3, region, income_id=None): "United States": 0.26, "Australia": 0.4, "New Zealand": 0.15, + # decision: china-treatment-split-2020 + # China: urban domestic waste, 2020 (China Statistical Yearbook 2021): 235.1 Mt collected, + # 77.7 Mt sanitary landfill, 146.1 Mt incineration, 10.7 Mt other (taken as composting). + "China": 0.0, } FRACTION_UNSPECIFIED_COUNTRY = { COUNTRY_TO_ISO3[country]: value diff --git a/SWEET_python/landfill_capture.py b/SWEET_python/landfill_capture.py new file mode 100644 index 0000000..5ad8423 --- /dev/null +++ b/SWEET_python/landfill_capture.py @@ -0,0 +1,133 @@ +"""How much of a country's landfilled waste goes to landfills that capture their gas. + +A city or Custom Location with no landfill shares of its own takes its country's or +region's disposal split (``defaults_2019.disposal_split_for``, ``City.load_andre_params``). +That split comes from IPCC 2019 Table 2.1, which says how much waste a country landfills +and dumps, but not how much of the landfilled waste goes to sites with a gas collection +system. Until this module, every defaulted landfill was modelled without capture: a city +in the US or the EU emitted as if no landfill there collected its gas. + +``capture_share`` gives the share of a country's landfilled waste that goes to landfills +with an active gas collection system: + +1. the country's own share, where research gives one (``CAPTURE_SHARE_COUNTRY``); +2. else ``HIGH_INCOME_SHARE`` (0.5) for a World Bank high-income country, the main test + of SWEET's site-type rule (``site_type_defaults.landfill_is_default``): gas-collection + rules track it (the EU Landfill Directive, US federal rules, Japan, Korea); +3. else none, as before. + +``with_default_capture`` moves that share of a defaulted split's "landfill without +capture" to "landfill with capture"; the capture bucket then captures +``gas_capture.GAS_CAPTURE_EFFICIENCY["landfill"]`` (60%) of its methane, as a reported +"sanitary landfill with landfill gas system" share does. The dumpsite share is untouched. +A city that reports its own landfill shares keeps them (``city-treatment-buckets``). + +**Provisional.** Only four countries have a researched share, and two of those are +derived rather than published. The 0.5 is a placeholder, not a finding: the Gulf states +and Russia are high income but capture little, and upper-middle-income countries with +real capture (Turkey, Mexico, Chile before 2023...) get none. Each country needs its own +researched share before this is relied on. See MODEL_DECISIONS.md, +``default-landfill-capture-share``. +""" + +from __future__ import annotations + +from typing import Mapping, NamedTuple, Optional + +__all__ = [ + "CAPTURE_SHARE_COUNTRY", + "HIGH_INCOME_SHARE", + "CaptureShare", + "capture_share", + "with_default_capture", +] + + +class CaptureShare(NamedTuple): + #: Share of landfilled waste going to landfills with gas collection, 0-1. + share: float + #: The year the evidence describes. + year: int + #: What the share is a share of: "mass landfilled", "methane generated"... + basis: str + source: str + url: str + + +#: The share a high-income country without a researched share of its own takes. +#: A placeholder, Hugh 2026-11-19: "a default of 0.5 where we don't have serious research". +HIGH_INCOME_SHARE = 0.5 + +# decision: default-landfill-capture-share +CAPTURE_SHARE_COUNTRY: dict[str, CaptureShare] = { + # Derived, not published: GHGRP 2021 emissions at MSW landfills without a collection + # system (21.3 Mt CO2e) against those with one (61.8), back-calculated to methane + # generated (~90% at sites with a system), then scaled for the ~11% of generation at + # landfills that don't report (assumed uncollected). Cross-checks: the Inventory + # recovers 60% of generated methane (2021); 845 of 1,125 GHGRP landfills had a system + # (2023). + "USA": CaptureShare( + 0.85, 2021, "methane generated (derived)", + "US EPA GHG Inventory 1990-2021, ch. 7, Table 7-3; EPA GHGRP waste sector profile 2011-2023, Tables 8-9", + "https://www.epa.gov/system/files/documents/2024-12/waste_profile_ry23.pdf", + ), + # "66% of MSW disposed at landfills with LFG recovery systems" (ECCC Landfill Gas + # Inventory, about 2023); 37% of methane generated is recovered. + "CAN": CaptureShare( + 0.66, 2023, "mass landfilled", + "ECCC, Landfill Methane Regulations Overview (June 2026), citing the ECCC Landfill Gas Inventory", + "https://acuerdochilecanada.mma.gob.cl/wp-content/uploads/2026/06/ECCC-Presentation-Landfill-Methane-Regulations-Overview-June-2026.pdf", + ), + # 3,350 kt to municipal landfills with capture, 279 kt without (2019). Municipal + # landfills only: non-municipal and farm fills are left out. + "NZL": CaptureShare( + 0.92, 2019, "mass landfilled", + "Climate Change Commission (2021), Supporting Evidence ch. 8 (waste), Table 8.1", + "https://www.climatecommission.govt.nz/assets/Evidence-21/Evidence-CH-8-reducing-emissions-waste.pdf", + ), + # Derived: 45% of methane generated is captured nationally (5-year inventory mean), and + # a site with capture takes about 75% of its own gas, so 0.45 / 0.75. Secondary source. + "AUS": CaptureShare( + 0.6, 2022, "methane generated (derived)", + "Macintosh et al. (ANU, 2024), quoting DCCEEW (2024) ACCU landfill gas method reform options paper", + "https://law.anu.edu.au/files/2024-06/Reform%20of%20ACCU%20Landfill%20Method%20-%20a%20critique%20070623%20%28final%29.pdf", + ), +} + + +def capture_share( + iso3: Optional[str], + income_id: Optional[str] = None, + shares: Optional[Mapping[str, CaptureShare]] = None, +) -> float: + """The share of *iso3*'s landfilled waste that goes to landfills with gas capture. + + *income_id* is the country's World Bank income group ('HIC', 'UMC', ...), from the + caller, as for ``site_type_defaults.landfill_is_default``; without one, only a + researched share applies. + """ + shares = CAPTURE_SHARE_COUNTRY if shares is None else shares + row = shares.get(str(iso3).upper()) if iso3 else None + if row is not None: + return float(row.share) + if isinstance(income_id, str) and income_id == "HIC": + return HIGH_INCOME_SHARE + return 0.0 + + +def with_default_capture( + split: Mapping[str, float], + iso3: Optional[str], + income_id: Optional[str] = None, + shares: Optional[Mapping[str, CaptureShare]] = None, +) -> dict: + """*split* (a defaulted disposal split) with the country's capture share of its + "landfill without capture" moved to "landfill with capture". The total is unchanged.""" + out = dict(split) + share = capture_share(iso3, income_id, shares) + if share <= 0: + return out + moved = out.get("landfill_wo_capture", 0.0) * share + out["landfill_w_capture"] = out.get("landfill_w_capture", 0.0) + moved + out["landfill_wo_capture"] = out.get("landfill_wo_capture", 0.0) - moved + return out diff --git a/changelog/2026-11.md b/changelog/2026-11.md index dfef9e1..99a5982 100644 --- a/changelog/2026-11.md +++ b/changelog/2026-11.md @@ -9,6 +9,31 @@ landfill, and incineration burns what composting and recycling leave. ## Added +- **A defaulted landfill share captures gas where its country's landfills do** + (model-output change, PROVISIONAL; decision `default-landfill-capture-share`). A + city with no landfill shares of its own, and every Custom Location, takes its + country's or region's split from IPCC 2019 Table 2.1, which has no gas-capture + share, so every defaulted landfill was modelled without capture. The new + `landfill_capture` module moves a share of the split's "landfill without capture" + to "landfill with capture", which captures 60% of its methane: + - a researched share for the US (0.85), Canada (0.66), New Zealand (0.92) and + Australia (0.6); + - else 0.5 for a World Bank high-income country, when the caller passes the income + group (`income_id`, as for the site-type rule); + - else none, as before. + A city that reports its own landfill shares keeps them. **The shares need research + before this is relied on**: 0.5 is a placeholder, two of the four researched shares + are derived rather than published, and income is a rough proxy (the Gulf states and + Russia are high income but capture little; Turkey and Mexico capture some but get + none). +- **China has a treatment split of its own** (model-output change, PROVISIONAL; + decision `china-treatment-split-2020`). It took Eastern Asia's, which landfilled + 76% of its waste. It now takes its urban domestic waste in 2020 (China Statistical + Yearbook 2021): 33% landfilled, 62% incinerated, 5% composted. China landfilled + 60% in 2015 and 5% in 2024; 2020 is near the average, and SWEET applies one split + to every year (`city-shares-constant`). A split by year is needed before the + cities pipeline relies on it. + - **The city model sends a controlled-dumpsite share to a controlled dumpsite** (no output change until a caller passes the share, [#121](https://github.com/RMI/SWEET_python/pull/121)). The generic city model had diff --git a/tests/test_custom_location_disposal_split.py b/tests/test_custom_location_disposal_split.py index adfa6c8..b45bae9 100644 --- a/tests/test_custom_location_disposal_split.py +++ b/tests/test_custom_location_disposal_split.py @@ -26,7 +26,7 @@ import numpy as np import pytest -from SWEET_python import defaults_2019 +from SWEET_python import defaults_2019, landfill_capture from SWEET_python.city_params import City POPULATION = 2_000_000 @@ -149,11 +149,11 @@ def test_a_high_income_country_in_a_region_with_no_row_landfills_its_waste(): # caller passes the income group; SWEET holds none. split = _custom_location("BRN", income_id="HIC").split_fractions - assert (split.landfill_w_capture, split.landfill_wo_capture, split.dumpsite) == ( - 0.0, - 1.0, - 0.0, - ) + # All landfilled; half of it at landfills with gas capture, the high-income default + # (landfill_capture). + assert split.landfill_w_capture + split.landfill_wo_capture == pytest.approx(1.0) + assert split.dumpsite == 0.0 + assert split.landfill_w_capture == pytest.approx(landfill_capture.HIGH_INCOME_SHARE) def test_without_an_income_brunei_falls_to_its_regions_rule(): @@ -166,11 +166,11 @@ def test_without_an_income_brunei_falls_to_its_regions_rule(): def test_a_country_whose_row_is_all_zeros_landfills_its_waste(iso3): split = _custom_location(iso3).split_fractions - assert (split.landfill_w_capture, split.landfill_wo_capture, split.dumpsite) == ( - 0.0, - 1.0, - 0.0, - ) + # All landfilled; the share at landfills with gas capture is the country's + # researched one, if any (landfill_capture; no income is passed here). + assert split.landfill_w_capture + split.landfill_wo_capture == pytest.approx(1.0) + assert split.dumpsite == 0.0 + assert split.landfill_w_capture == pytest.approx(landfill_capture.capture_share(iso3)) @pytest.mark.parametrize("iso3", _one_country_per_region_and_rule()) diff --git a/tests/test_default_landfill_capture.py b/tests/test_default_landfill_capture.py new file mode 100644 index 0000000..c6670eb --- /dev/null +++ b/tests/test_default_landfill_capture.py @@ -0,0 +1,123 @@ +"""A defaulted landfill share captures gas where its country's landfills do. + +A city with no landfill shares of its own, and every Custom Location, takes its country's +or region's disposal split (IPCC 2019 Table 2.1). That table says nothing about gas +capture, so every defaulted landfill used to be modelled without it. ``landfill_capture`` +gives the share of a country's landfilled waste that goes to landfills with gas +collection, and the defaulted split moves that share into "landfill with capture". + +A city that reports its own landfill shares keeps them. +""" + +import numpy as np +import pytest + +from SWEET_python import defaults_2019, landfill_capture +from SWEET_python.city_params import City +from SWEET_python.landfill_capture import CaptureShare + +from tests.test_custom_location_disposal_split import _NoDataRow, _cities_table_split + +HALF = CaptureShare(0.5, 2020, "test", "test", "https://example.org") + + +@pytest.fixture +def half_of_usa_captures(monkeypatch): + monkeypatch.setitem(landfill_capture.CAPTURE_SHARE_COUNTRY, "USA", HALF) + + +def test_the_capture_share_moves_landfilled_waste_and_nothing_else(): + split = {"landfill_w_capture": 0.0, "landfill_wo_capture": 0.8, "dumpsite": 0.2} + out = landfill_capture.with_default_capture(split, "XXX", shares={"XXX": HALF}) + assert out == pytest.approx({"landfill_w_capture": 0.4, "landfill_wo_capture": 0.4, "dumpsite": 0.2}) + assert split["landfill_wo_capture"] == 0.8 # not changed in place + + +def test_a_country_with_no_row_captures_nothing_unless_it_is_high_income(): + split = {"landfill_w_capture": 0.0, "landfill_wo_capture": 1.0, "dumpsite": 0.0} + assert landfill_capture.with_default_capture(split, "XXX", shares={}) == split + assert landfill_capture.with_default_capture(split, "XXX", "UMC", shares={}) == split + assert landfill_capture.with_default_capture(split, None, shares={"XXX": HALF}) == split + high = landfill_capture.with_default_capture(split, "XXX", "HIC", shares={}) + assert high["landfill_w_capture"] == pytest.approx(landfill_capture.HIGH_INCOME_SHARE) + + +def test_a_researched_share_beats_the_high_income_default(): + assert landfill_capture.capture_share("XXX", "HIC", shares={"XXX": HALF._replace(share=0.9)}) == 0.9 + assert landfill_capture.capture_share("CAN", "HIC") == landfill_capture.CAPTURE_SHARE_COUNTRY["CAN"].share + + +def test_a_high_income_custom_location_takes_the_default_share(): + region = defaults_2019.region_lookup_iso3["JPN"] + without = defaults_2019.disposal_split_for("JPN", region) + high = defaults_2019.disposal_split_for("JPN", region, "HIC") + assert without["landfill_w_capture"] == 0 + assert high["landfill_w_capture"] == pytest.approx(0.5 * without["landfill_wo_capture"]) + + +def test_a_chinese_city_with_no_figures_takes_chinas_2020_split(): + assert defaults_2019.fraction_landfilled_country["CHN"] == 0.33 + assert defaults_2019.fraction_incinerated_country["CHN"] == 0.62 + assert defaults_2019.fraction_composted_country["CHN"] == 0.05 + split = defaults_2019.disposal_split_for("CHN", defaults_2019.region_lookup_iso3["CHN"], "UMC") + assert split == {"landfill_w_capture": 0.0, "landfill_wo_capture": 1.0, "dumpsite": 0.0} + + +def test_a_custom_location_takes_its_countrys_capture_share(half_of_usa_captures): + split = defaults_2019.disposal_split_for("USA", defaults_2019.region_lookup_iso3["USA"]) + assert split["landfill_w_capture"] == pytest.approx(split["landfill_wo_capture"]) + assert sum(split.values()) == pytest.approx(1.0) + + +def test_a_city_with_no_landfill_shares_takes_its_countrys_capture_share(half_of_usa_captures): + table = _cities_table_split("USA") + custom = defaults_2019.disposal_split_for("USA", defaults_2019.region_lookup_iso3["USA"]) + assert table.landfill_w_capture == pytest.approx(0.5 * (table.landfill_w_capture + table.landfill_wo_capture)) + assert table.landfill_w_capture == pytest.approx(custom["landfill_w_capture"]) + + +def test_a_city_that_reports_its_landfill_shares_keeps_them(half_of_usa_captures): + row = _NoDataRow( + { + "country": "United States", + "iso": "USA", + "population_count": 1_000_000, + "population_year": 2022.0, + "population_data_source": "test", + "msw_generated_metric_tons_per_year": 500_000.0, + "msw_generated_year": 2022.0, + "mean_yearly_precip_2000_2021": 500.0, + "mean_yearly_temp_2000_2021": 25.0, + "latitude": 0.0, + "longitude": 0.0, + "historic_growth_rate": 1.0, + "future_growth_rate": 1.0, + "waste_treatment_controlled_landfill_percent": 70.0, + "waste_treatment_recycling_percent": 30.0, + } + ) + city = City("Reports its landfills") + city.load_andre_params(row) + split = city.baseline_parameters.split_fractions + assert split.landfill_w_capture == 0 + assert split.landfill_wo_capture == pytest.approx(1.0) + + +# The table itself. + +ROWS = sorted(landfill_capture.CAPTURE_SHARE_COUNTRY.items()) + + +@pytest.mark.parametrize("iso3,row", ROWS, ids=[iso3 for iso3, _ in ROWS]) +def test_each_capture_share_is_a_sourced_share_of_a_known_country(iso3, row): + assert iso3 in defaults_2019.region_lookup_iso3 + assert 0 < row.share <= 1 + assert 2005 <= row.year <= 2026 + assert row.basis and row.source and row.url.startswith("http") + + +@pytest.mark.parametrize("iso3", [iso3 for iso3, _ in ROWS]) +def test_custom_location_and_the_cities_table_agree_on_capture(iso3): + custom = defaults_2019.disposal_split_for(iso3, defaults_2019.region_lookup_iso3[iso3]) + table = _cities_table_split(iso3) + assert table.model_dump() == pytest.approx({**table.model_dump(), **custom}) From 17274f1dd5e5b0dfde175d1d16222bba45ce899b Mon Sep 17 00:00:00 2001 From: Hugh Runyan Date: Thu, 19 Nov 2026 10:35:19 -0800 Subject: [PATCH 2/2] Changelog: link #131 Co-Authored-By: Claude Opus 5.5 --- changelog/2026-11.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog/2026-11.md b/changelog/2026-11.md index 99a5982..df7818d 100644 --- a/changelog/2026-11.md +++ b/changelog/2026-11.md @@ -10,7 +10,7 @@ landfill, and incineration burns what composting and recycling leave. ## Added - **A defaulted landfill share captures gas where its country's landfills do** - (model-output change, PROVISIONAL; decision `default-landfill-capture-share`). A + (model-output change, PROVISIONAL, [#131](https://github.com/RMI/SWEET_python/pull/131); decision `default-landfill-capture-share`). A city with no landfill shares of its own, and every Custom Location, takes its country's or region's split from IPCC 2019 Table 2.1, which has no gas-capture share, so every defaulted landfill was modelled without capture. The new @@ -26,7 +26,7 @@ landfill, and incineration burns what composting and recycling leave. are derived rather than published, and income is a rough proxy (the Gulf states and Russia are high income but capture little; Turkey and Mexico capture some but get none). -- **China has a treatment split of its own** (model-output change, PROVISIONAL; +- **China has a treatment split of its own** (model-output change, PROVISIONAL, [#131](https://github.com/RMI/SWEET_python/pull/131); decision `china-treatment-split-2020`). It took Eastern Asia's, which landfilled 76% of its waste. It now takes its urban domestic waste in 2020 (China Statistical Yearbook 2021): 33% landfilled, 62% incinerated, 5% composted. China landfilled