Skip to content

sdst honors the caller-supplied gas flaring efficiency - #41

Open
HughRunyan wants to merge 2 commits into
mainfrom
fix-sdst-flaring-efficiency
Open

sdst honors the caller-supplied gas flaring efficiency#41
HughRunyan wants to merge 2 commits into
mainfrom
fix-sdst-flaring-efficiency

Conversation

@HughRunyan

@HughRunyan HughRunyan commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

City.sdst_v1_5 declared a new_landfill_flaring parameter but never read it. Its flaring block referenced an undefined bare name flaring, and the resulting NameError was swallowed by a bare except that forced flare destruction efficiency to a hardcoded 0.98. The flaring efficiency forwarded by WasteMAP's /v1/site_emissions/sdst_v1_5 endpoint — the /sdst "Gas flaring efficiency" control — therefore never affected results.

Environment

  • Component: SWEET_python/city_params.py, City.sdst_v1_5
  • Consumer: WasteMAP backend /v1/site_emissions/sdst_v1_5 (backend/sweet_launch.py), which passes its flaring Body param as new_landfill_flaring=flaring
  • Affected since: the parameter was introduced; the newer adst path is not affected

Reproduction

Call /v1/site_emissions/sdst_v1_5 twice with gas capture on (so there is captured methane to flare), changing only the flaring efficiency:

  • gas_efficiencies: {"baseline": [0.75], "scenario": [0.75]}
  • run A → flaring: {"baseline": [0.0], "scenario": [0.0]} (no flaring)
  • run B → flaring: {"baseline": [0.98], "scenario": [0.98]} (full flaring)

Expected vs actual

Summed total emissions across all modeled years:

flaring efficiency before (actual) after (expected)
0.0 — no flaring 6648.34 23422.34
0.98 — full flaring 6648.34 6648.34

Actual (before): both runs return an identical 6648.34 — the input is discarded and flaring is always 0.98.
Expected (after): no flaring produces materially higher emissions, since captured methane is vented rather than destroyed.

Root cause

# Check if flaring is defined as a variable
try:
    flaring_series_baseline = pd.Series(flaring["baseline"], index=years)   # NameError
    ...
except:                                                                     # swallows it
    flaring_series_baseline = pd.Series(0.98, index=years)                  # always taken

flaring is not defined in this scope; the method's parameter is new_landfill_flaring. Every call took the except branch.

The fix

Read new_landfill_flaring[scenario_key][0] (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 genuine errors surface instead of silently degrading to a default.

Acceptance criteria

  • City.sdst_v1_5 reads the caller-supplied new_landfill_flaring for both baseline and scenario.
  • The scenario value is spliced in from implement_year onward; the baseline value applies before it.
  • When no flaring is supplied (None), behaviour is unchanged: DEFAULT_FLARE_EFFICIENCY (0.98).
  • No bare except masking errors in this block.
  • Verified end-to-end through the WasteMAP endpoint (numbers above); red→green confirmed by reverting the fix.
  • Changelog entry added under Fixed, flagged as a model-output change.
  • Existing SWEET_python tests pass (86 passed); WasteMAP fast backend suite passes (55 passed).

Model-output change

Labelled model-output-change, not breaking-change: nothing stops running and no data contract changes. Any /sdst run that set a non-0.98 flaring efficiency with gas capture on will now return different — correct — numbers. Runs that left flaring at the default are unchanged, as are all adst runs.

Notes for the reviewer

Definition of Done

  • Acceptance criteria met
  • Tests and checks pass
  • Docs/changelog updated
  • Reviewed and merged

🤖 Generated with Claude Code

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 <noreply@anthropic.com>
@HughRunyan HughRunyan added bug Something isn't working python Pull requests that update python code model-output-change Changes model OUTPUT values (expected progress, not breaking); results differ from prior runs labels Aug 6, 2026
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working model-output-change Changes model OUTPUT values (expected progress, not breaking); results differ from prior runs python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants