From e692bed2cd67b38c4cfb7e5dde9233a92b056d96 Mon Sep 17 00:00:00 2001 From: Hugh Runyan Date: Wed, 5 Aug 2026 17:50:50 -0700 Subject: [PATCH 1/2] Caller-supplied /sdst flaring efficiency reaches the model again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit City.sdst_v1_5 declared a `new_landfill_flaring` parameter but its flaring block referenced an undefined bare name `flaring`. The resulting NameError was swallowed by a bare `except`, which forced flare destruction efficiency to a hardcoded 0.98 on every call — so the flaring efficiency forwarded by the WasteMAP /v1/site_emissions/sdst_v1_5 endpoint (the "Gas flaring efficiency" control) never affected results. Read `new_landfill_flaring[scenario_key][0]` instead (sdst models a single landfill, index 0), fall back to DEFAULT_FLARE_EFFICIENCY only when no value is supplied, and drop the bare `except` so real errors are no longer masked. Model-output change: any sdst run that set a non-0.98 flaring efficiency, with gas capture on so there is captured methane to flare, now produces different and correct results. Verified end-to-end through the WasteMAP endpoint: with gas capture at 0.75, flaring 0.0 vs 0.98 returned an identical 6648.34 total before this change and 23422.34 vs 6648.34 after it. Runs that left flaring at the default are unchanged. The newer adst endpoint already handled flaring correctly and is unaffected. Co-Authored-By: Claude Opus 4.8 --- SWEET_python/city_params.py | 30 ++++++++++++++++++++++-------- changelog/2026-08.md | 6 ++++++ changelog/README.md | 1 + 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 changelog/2026-08.md diff --git a/SWEET_python/city_params.py b/SWEET_python/city_params.py index 830bf8d..f8d48ab 100644 --- a/SWEET_python/city_params.py +++ b/SWEET_python/city_params.py @@ -8345,14 +8345,28 @@ def _apply_open_close_window( if oxidation_override["baseline"]: ox_value_series_baseline.loc[:] = float(oxidation_override["baseline"]) - # Check if flaring is defined as a variable - try: - flaring_series_baseline = pd.Series(flaring["baseline"], index=years) - flaring_series_scenario = flaring_series_baseline.copy() - flaring_series_scenario.loc[implement_year:] = flaring["scenario"] - except: - flaring_series_baseline = pd.Series(0.98, index=years) - flaring_series_scenario = flaring_series_baseline.copy() + # Flaring destruction efficiency of captured methane. The endpoint forwards a + # Variant, {"baseline": [...], "scenario": [...]}, with one value per landfill; + # sdst models a single landfill (index 0). This block previously referenced an + # undefined name `flaring`; the resulting NameError was swallowed by a bare + # `except`, so the user-supplied efficiency was silently ignored and flaring was + # always forced to the default. Read `new_landfill_flaring`, falling back to the + # canonical default only when no value is supplied. + from SWEET_python.dst_common import DEFAULT_FLARE_EFFICIENCY + + flaring = {} + for scenario_key in ("baseline", "scenario"): + value = ( + None + if new_landfill_flaring is None + else new_landfill_flaring[scenario_key][0] + ) + flaring[scenario_key] = ( + DEFAULT_FLARE_EFFICIENCY if value is None else value + ) + flaring_series_baseline = pd.Series(flaring["baseline"], index=years) + flaring_series_scenario = flaring_series_baseline.copy() + flaring_series_scenario.loc[implement_year:] = flaring["scenario"] if biocover["baseline"] > 0: baseline_biocover = float(biocover["baseline"]) diff --git a/changelog/2026-08.md b/changelog/2026-08.md new file mode 100644 index 0000000..b110013 --- /dev/null +++ b/changelog/2026-08.md @@ -0,0 +1,6 @@ +# SWEET_python Changelog — August 2026 + +**Highlights:** A variable-name bug in `City.sdst_v1_5` was silently discarding the `/sdst` flaring efficiency and forcing flare destruction to the 0.98 default on every run. Sites that set a non-default flaring efficiency now model the value the user supplied. This is a model-output change for any sdst run with a non-0.98 flaring efficiency. + +## Fixed +- `City.sdst_v1_5` now reads the caller-supplied flaring efficiency again. The flaring block referenced an undefined bare name `flaring` (the endpoint parameter is `new_landfill_flaring`); the resulting `NameError` was swallowed by a bare `except`, so flare destruction was always forced to the 0.98 default and the user's input was ignored. The block now reads `new_landfill_flaring[...][0]` per landfill (sdst models a single landfill, index 0), falling back to `DEFAULT_FLARE_EFFICIENCY` only when no value is supplied. **Model-output change:** any sdst run that set a non-0.98 flaring efficiency will now produce different (correct) results. (PR: _pending_) diff --git a/changelog/README.md b/changelog/README.md index 0c62df3..1cce4ca 100644 --- a/changelog/README.md +++ b/changelog/README.md @@ -15,6 +15,7 @@ The project does not publish semantic version tags, so releases are tracked by Newest first: +- [2026-08](2026-08.md) — `/sdst` flaring efficiency reached the model again: fixed a variable-name bug in `City.sdst_v1_5` that silently forced flare destruction to 0.98 and ignored the user's input (model-output change) - [2026-07](2026-07.md) — All ten waste types eligible for combustion (metal/glass/other added); methane-only model treats combustion as landfill diversion (model-output change) - [2026-06](2026-06.md) — New single-site and city-level ADST modeling modules, min-cost max-flow rewrite of the city DST diversion allocator, physical-k fix for cold/dry sites, no more spurious negative food-waste mass - [2026-05](2026-05.md) — SDST models from a landfill's actual open year (1950–2050), Central Asia/Afghanistan disposal-default fix, auto-Jira issue tooling, professional-comment cleanup From c68ef9b7d698c2ae4e63ac28042136360160d8bb Mon Sep 17 00:00:00 2001 From: Hugh Runyan Date: Wed, 5 Aug 2026 17:52:36 -0700 Subject: [PATCH 2/2] Link the changelog entry to PR #41 Co-Authored-By: Claude Opus 4.8 --- changelog/2026-08.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/2026-08.md b/changelog/2026-08.md index b110013..606f6b7 100644 --- a/changelog/2026-08.md +++ b/changelog/2026-08.md @@ -3,4 +3,4 @@ **Highlights:** A variable-name bug in `City.sdst_v1_5` was silently discarding the `/sdst` flaring efficiency and forcing flare destruction to the 0.98 default on every run. Sites that set a non-default flaring efficiency now model the value the user supplied. This is a model-output change for any sdst run with a non-0.98 flaring efficiency. ## Fixed -- `City.sdst_v1_5` now reads the caller-supplied flaring efficiency again. The flaring block referenced an undefined bare name `flaring` (the endpoint parameter is `new_landfill_flaring`); the resulting `NameError` was swallowed by a bare `except`, so flare destruction was always forced to the 0.98 default and the user's input was ignored. The block now reads `new_landfill_flaring[...][0]` per landfill (sdst models a single landfill, index 0), falling back to `DEFAULT_FLARE_EFFICIENCY` only when no value is supplied. **Model-output change:** any sdst run that set a non-0.98 flaring efficiency will now produce different (correct) results. (PR: _pending_) +- `City.sdst_v1_5` now reads the caller-supplied flaring efficiency again. The flaring block referenced an undefined bare name `flaring` (the endpoint parameter is `new_landfill_flaring`); the resulting `NameError` was swallowed by a bare `except`, so flare destruction was always forced to the 0.98 default and the user's input was ignored. The block now reads `new_landfill_flaring[...][0]` per landfill (sdst models a single landfill, index 0), falling back to `DEFAULT_FLARE_EFFICIENCY` only when no value is supplied. **Model-output change:** any sdst run that set a non-0.98 flaring efficiency will now produce different (correct) results. ([#41](https://github.com/RMI/SWEET_python/pull/41))