City.sdst_v1_5 scenario matches baseline before the implementation year - #47
Merged
Conversation
…ation year City.sdst_v1_5 models the baseline and scenario as two independent landfills. Before the scenario's implementation year nothing has been changed, so the scenario landfill must receive exactly the baseline waste — mass and composition — and emit identically until then. The scenario waste-mass series already splices the total mass at implement_year, but the scenario composition (fractions) was applied to every year. The two TRACE-reconciled branches (real sites) correct this with `waste_masses_df_scenario.loc[:implement_year-1, :] = waste_masses_df_baseline...`, and the newer advanced_dst / advanced_dst_city engines force baseline pre-implement too. Only the blank/custom-site branch (baseline_data=None, a "Custom Location" in the /sdst UI) omitted the splice, so a scenario that changed the waste composition wrongly back-dated the new composition onto deposits from before the implementation year — the baseline and scenario diverged before the change was even implemented (~6% on the scenario series in a representative case). Add the same pre-implement splice the sibling branches already use. It is a no-op whenever baseline and scenario composition match, so it only changes output for a composition-changing scenario on the custom-site path. model-output-change. Adds tests/test_sdst_v1_5_preimplement_composition.py (fails on the pre-fix engine). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes a correctness bug in City.sdst_v1_5 for blank/custom sites (baseline_data=None) where scenario waste composition could be applied to pre-implementation-year deposits, causing baseline/scenario emissions to diverge before implement_year.
Changes:
- Splice baseline generated waste masses (mass + composition) into the scenario series for all years
< implement_yearon the blank/custom-site branch (matching the existing TRACE-reconciled branches’ behavior). - Add a regression test covering composition-changing scenarios on the custom-site path to ensure pre-implement scenario emissions equal baseline emissions.
- Update August 2026 changelog and changelog index entry to document the model-output change.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
SWEET_python/city_params.py |
Forces scenario generated waste masses to equal baseline before implement_year for blank/custom sites, preventing back-dated scenario composition. |
tests/test_sdst_v1_5_preimplement_composition.py |
New regression test ensuring scenario == baseline emissions pre-implement when only composition differs on custom-site path. |
changelog/README.md |
Updates the 2026-08 summary line to include this fix. |
changelog/2026-08.md |
Documents the fix under “Fixed” with impact/behavior notes and PR link. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Purpose
City.sdst_v1_5(the engine behind WasteMAP's/v1/site_emissions/sdst_v1_5)models the baseline and the scenario as two independent landfills. Before the
scenario's implementation year nothing has changed, so the scenario landfill must
receive exactly the baseline waste — mass and composition — and emit identically
until then. For blank/custom sites it did not: a scenario that changed the waste
composition had the new composition wrongly back-dated onto deposits from before
the implementation year, so baseline and scenario diverged before the change was
even implemented.
Bug
SWEET_python/city_params.py,City.sdst_v1_5, the blank/custom-site branch (baseline_data=None).rmi_id) with baseline waste fractions ≠ scenario waste fractions (e.g. the/sdst"Custom Location" flow, where the UI exposes independent baseline and scenario composition columns).implement_year, scenario total emissions == baseline total emissions.Root cause
_generated_waste_masses()splices the scenario total mass atimplement_yearbut multiplies by the scenario composition for every year. The two
TRACE-reconciled branches (real sites) already correct this:
(city_params.py:8236 and :8271), and
advanced_dst.run_advanced_dst(:161) andadvanced_dst_city.run_advanced_dst_city(:296) both force baseline pre-implement.Only the
else(blank/custom-site) branch omitted the splice.Fix
Add the same pre-implement splice the sibling branches already use, before the
open/close window is applied. It copies the baseline generated waste (mass +
composition) into the scenario frame for every year
< implement_year.Blast radius
output for a composition-changing scenario on the custom-site path. Baseline
output is never touched.
/sdstUI (custom locations send normi_id→ thecustom-site branch; the composition inputs have separate baseline/scenario
columns).
sdst_v1_5tests use identicalbaseline/scenario composition).
Acceptance criteria
< implement_year.run_advanced_dstandCity.sdst_v1_5now produce identical output for equivalent single-site inputs including composition changes (verified by WasteMAP'scompare_sdst_adst_parity.py).Definition of Done
tests/test_sdst_v1_5_preimplement_composition.py(fails on the pre-fix engine, passes after)changelog/2026-08.md)model-output-change (not breaking-change): changes output values only for a
composition-changing scenario on the custom-site path; nothing stops running.
Paired with WasteMAP RMI/WasteMAP#747 (same branch name), which adds the
endpoint-level regression test and the
sdst↔adstparity harness. Merge together.🤖 Generated with Claude Code