Repository navigation
A Custom Location buries or dumps its waste in every country - #74
Open
HughRunyan wants to merge 2 commits into
Open
HughRunyan wants to merge 2 commits into
HughRunyan wants to merge 2 commits into
Conversation
City.dst_baseline_blank looked a country's disposal split up with .get(iso3, .get(region, 0)). Southern Asia, South-Eastern Asia and Southern Africa have no row in fraction_open_dumped / fraction_landfilled (no label mismatch: the other regional tables carry them as 0.0 # np.nan), and Canada's, Germany's and Switzerland's country rows are all zeros, so 31 countries got a (0, 0, 0) split. Every landfill took 0% of the waste and the city modelled no landfill methane; the except-KeyError fallback never ran because .get never raises. defaults_2019.disposal_split_for gives the split load_andre_params gives a cities-table row with no landfill data: the country's row if it sends waste anywhere, else the region's, else all landfill in landfill_default_regions and all dumpsite elsewhere. load_andre_params is unchanged, so the cities table doesn't move; the other 218 countries' Custom Location output is bit-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In 31 countries, a WasteMAP Custom Location city modelled no landfill methane at all.
City.dst_baseline_blankgave those countries a disposal split of (0, 0, 0), so every landfill took 0% of the waste. Custom Location now gets the split the cities table already gives a city with no landfill data.Affected (ISO3):
ATF BGD BRN BTN BWA CAN CHE DEU IDN IND IOT IRN KHM LAO LKA LSO MDV MMR MOZ MYS NAM NPL PAK PHL SHN SWZ THA TLS VNM ZAF ZWEEnvironment
main@d5c592e, Python 3.12 (CI) / 3.13 (local)City.dst_baseline_blank, which WasteMAP calls for any city not in the cities table (the frontend's "Custom Location") from/v1/city_emissions/city_baseline_parameters_v1_5and/v1/city_emissions/implement_dst_simple_v1_5api.wastemap.earth, 2026-08-21 build, checked 2026-10-08Reproduction
python -c "from SWEET_python.city_params import City; c = City('x'); c.dst_baseline_blank('Pakistan', 2_000_000, 500.0, 25.0); print(c.baseline_parameters.split_fractions, c.baseline_parameters.total_emissions.loc[2040, 'total'])"At the API (a read-only GET):
curl -sG https://api.wastemap.earth/v1/city_emissions/city_baseline_parameters_v1_5 --data-urlencode "city_name=Custom Location" --data-urlencode country=Pakistan --data-urlencode population=2000000 --data-urlencode precipitation=500 --data-urlencode temperature=25Expected vs actual
2040 total emissions, t CH4/yr, for 2M people, 500 mm, 25 °C:
main(actual)Prod runs an older build (before #71's population growth), which is why its Mexico figure differs from
main.Root cause
It is not a region-label mismatch. Every other regional table (
msw_per_capita_defaults,waste_fraction_defaults,fraction_incinerated,fraction_composted,fraction_unspecified) uses exactly the labels inregion_lookup_iso3. The two disposal tables have no extra or misspelled keys. Two data gaps meet a lookup that hides them:fraction_open_dumped/fraction_landfilled. The other tables carry them as0.0 # np.nan. That is the same gap wp-264 fixed central asia default for afghanistan #18 (WP-264) filled for Central Asia and Rest of Oceania. None of the 28 countries here has a country row; Singapore and Madagascar, which do, were unaffected.dst_baseline_blankread both tables with.get(iso3, .get(region, 0)). The normalization step skipped a zero total, so the waste the city didn't divert left the model. Itsexcept KeyErrorfallback was unreachable, because.getnever raises. The code has been like this since the initial commit.City.load_andre_params, which builds the cities table, handles both gaps. It checks withinand falls back to all landfill inlandfill_default_regions, all dumpsite elsewhere, and it hard-codes CAN/CHE/DEU to all landfill. So a Custom Location in Pakistan disagreed with an equivalent mapped city in Pakistan.Fix
defaults_2019.disposal_split_for(iso3, region), next to the tables it reads (aswaste_composition_foris). It uses the country's row if it sends waste anywhere, else the region's. A place with neither is all landfill inlandfill_default_regionsand all dumpsite elsewhere. CAN/CHE/DEU fall through to their regions' rows, which are landfill-only. That reproducesload_andre_params's hard-coded override without a second copy of the list.dst_baseline_blankcalls it. The deadtry/exceptand the now-redundant normalization are removed.load_andre_paramsis deliberately untouched. It publisheslandfill_split_defaultsas the cities table's "Defaults Used: Landfill Fractions" column, and switching it to the helper would flip that flag for CAN/CHE/DEU. Adding the three regions to the data tables, as wp-264 fixed central asia default for afghanistan #18 did, would flip it for every city in them. Either is a published-output change, so this PR leaves the table alone, and a parity test keeps the two paths from drifting.Blast radius
I ran Custom Location for all 250 ISO3 codes in
region_lookup_iso3onmainand on this branch:DataFrame.equalson the emissions frame.XKX) raisesCountry 'XKX' not foundon both, because pycountry has no Kosovo. That is a separate issue.No other SWEET path reads these tables. In WasteMAP, the endpoint's
no_landfills_present(dumpsite == 1.0) becomes true for the 28 dump-only countries. The City DST then disables "Add gas capture" for them, as it does for any city with only dumpsites.Tests (
tests/test_custom_location_disposal_split.py, ~3 s)On
main, all 38 tests on the reported behaviour fail. The all-countries helper check also fails, trivially, because the helper doesn't exist there. On this branch they all pass.maintest_a_custom_location_models_methane_from_the_waste_it_disposes_oftest_a_country_in_a_region_with_no_row_dumps_its_wastetest_a_country_whose_row_is_all_zeros_landfills_its_wastetest_a_custom_location_starts_from_the_cities_tables_splitload_andre_paramson a no-data row, one country per (region × which row decides): 39 casestest_every_country_has_a_disposal_splitThe 33 parity cases that pass on both are the evidence that nothing else moves. The full suite has 349 passed (272 before).
Known limitations (in the changelog)
msw_per_capita_countrydefault is 1.86 t/yr, which is 5.1 kg/person/day. Fourteen countries there are above 3 kg/person/day. That is a separate data issue.Acceptance criteria
load_andre_params) is unchanged.bug+model-output-change.Definition of Done
changelog/2026-10.md)mainafter, and prod picks the fix up frommainon its next API deploy.🤖 Generated with Claude Code