Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 39 additions & 25 deletions SWEET_python/advanced_dst_city.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
``{year: [frac per landfill]}`` ordered to match the ``landfills`` list, with
each year's fractions summing to ~1.
* a facility may set ``combusts``: it burns the waste routed to it instead of
depositing it, and deposits only the reject, ``City.combustion_reject_rate``,
depositing it. It deposits the metal and glass it receives, which don't burn,
and the reject of the rest, ``City.combustion_reject_rate``,
which is 0. See :class:`CityLandfillSpec`.
* ``other_landfills`` (optional) is where the rest goes. With it, each year's
fractions may sum to less than 1, a listed landfill's share goes to other
Expand All @@ -53,7 +54,7 @@
import SWEET_python.defaults_2019 as defaults_2019
from SWEET_python.city_params import City, CityParameters, CustomError
from SWEET_python.class_defs import DivsDF, LandfillType, LandfillWasteMassDF, Variant
from SWEET_python.constants import MODEL_START_YEAR
from SWEET_python.constants import MODEL_START_YEAR, UNBURNABLE_TYPES
from SWEET_python import dst_allocation
from SWEET_python import dst_common as common
from SWEET_python import site_inflow
Expand Down Expand Up @@ -145,12 +146,13 @@ class CityLandfillSpec(BaseModel):
"Whether this facility burns the waste routed to it -- incineration, "
"with or without energy recovery -- instead of depositing it. The "
"share of the city's disposed waste sent here still arrives here, "
"and only the reject (``City.combustion_reject_rate``) is "
"deposited; the rest is destroyed. The reject is 0, so a burning "
"facility deposits nothing and produces no methane: what an "
"incinerator leaves is ash with almost no organic carbon. The burnt "
"share is not re-routed to another site. Were the reject set above "
"0, the remaining per-site fields would describe its pile: "
"and it deposits only what does not burn: the metal and glass it "
"receives, and the reject of the rest "
"(``City.combustion_reject_rate``); the rest is destroyed. The "
"reject is 0, so a burning facility deposits only its metal and "
"glass, which make no methane: what an incinerator leaves is ash "
"with almost no organic carbon. The burnt share is not re-routed to "
"another site. The remaining per-site fields describe its ash pile: "
"``landfill_type`` is its disposal category, and the gas/biocover "
"fields are the pile's, not the incinerator's. Omit (the default) "
"for a depositing site."
Expand Down Expand Up @@ -383,10 +385,11 @@ def _mass_flow(
``sites_received`` is what the city sends each site, and ``sites`` is what
each site deposits, the mass its methane comes from. They are the same
except at a site that burns its waste (``combusts``): it receives its share
and deposits only the reject, which is none at the default rate. So an
incinerator taking half the city's waste reads half of ``landfilled`` in
``sites_received`` and nothing in ``sites``. A caller saying how much waste
goes to a site reads ``sites_received``.
and deposits only its metal and glass, which don't burn, and the reject of the
rest, which is none at the default rate. So an incinerator taking half the
city's waste reads half of ``landfilled`` in ``sites_received`` and half its
metal and glass in ``sites``. A caller saying how much waste goes to a site
reads ``sites_received``.

Both are per landfill in request order, already windowed by each one's
open/close years, with other landfills last when the request has them.
Expand Down Expand Up @@ -710,15 +713,25 @@ def _split_timeline_to_df(
return df.sort_index().reindex(years).ffill().bfill()


def _deposited_share(combusts: bool, city: City) -> float:
"""Fraction of the waste arriving at a facility that is actually deposited.
def _deposited(mass: pd.DataFrame, combusts: bool, city: City) -> pd.DataFrame:
"""What a facility deposits of the waste arriving at it, per waste type.

A depositing site keeps all of it. A combusting facility keeps only the
reject, ``combustion_reject_rate``, which is 0, so it keeps none. The
combustion diversion pathway, like every pathway here, keeps everything it
is sent (``_diverted_masses``), so the residue is the facility's alone.
A depositing site keeps all of it. A combusting facility burns what burns and
keeps only the reject of it, ``combustion_reject_rate``, which is 0. Metal and
glass don't burn (``constants.UNBURNABLE_TYPES``), so it keeps all of them: the
ash it landfills. They make no methane, so only the mass flow sees them. The
combustion diversion pathway, like every pathway here, keeps everything it is
sent (``_diverted_masses``), so the residue is the facility's alone.
"""
return float(city.combustion_reject_rate) if combusts else 1.0
if not combusts:
return mass
kept = pd.Series(
{
column: 1.0 if column in UNBURNABLE_TYPES else float(city.combustion_reject_rate)
for column in mass.columns
}
)
return mass.mul(kept, axis=1)


def _windowed_pair(
Expand Down Expand Up @@ -2086,14 +2099,15 @@ def run_advanced_dst_city(
baseline_received.append(received_base)
scenario_received.append(received_scen)

# A combusting facility burns its intake and deposits only the reject
# (none, at the default rate).
# A combusting facility burns its intake and deposits only what does not
# burn: its metal and glass, and the reject of the rest (none, at the
# default rate).
# Scaled per variant here, ahead of both the window and the pre-implement
# splice, so a site that starts combusting at implement_year keeps
# depositing everything until then -- and one that stops burning starts to.
mass_base, mass_scen = _windowed_pair(
mass_base * _deposited_share(base_combusts, city),
mass_scen * _deposited_share(scen_combusts, city),
_deposited(mass_base, base_combusts, city),
_deposited(mass_scen, scen_combusts, city),
*windows,
)
baseline_masses.append(mass_base)
Expand All @@ -2103,8 +2117,8 @@ def run_advanced_dst_city(
# three transformations in the same order.
if surplus_base_masses is not None:
surplus_base_masses, surplus_scen_masses = _windowed_pair(
surplus_base_masses * _deposited_share(base_combusts, city),
surplus_scen_masses * _deposited_share(scen_combusts, city),
_deposited(surplus_base_masses, base_combusts, city),
_deposited(surplus_scen_masses, scen_combusts, city),
*windows,
)
# A stated total at or below the city's allocation in every year
Expand Down
8 changes: 8 additions & 0 deletions SWEET_python/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,11 @@ def symmetric_difference(self, other):

def copy(self):
return self


UNBURNABLE_TYPES: WasteTypeSet = WasteTypeSet({"metal", "glass"})
"""The waste types an incinerator does not burn. A share of incineration counts
only waste that burns: metal and glass the city did not recycle are landfilled,
whether they were sorted out before the furnace or pulled from its ash. Recycling
takes its share first, so metal recovered from incinerator ash is read as part of
the city's recycling."""
9 changes: 9 additions & 0 deletions changelog/2026-11.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ what it buries, so an incinerator no longer reads as taking no waste.

## Changed

- **An advanced DST site that burns its waste keeps the metal and glass it
receives** (no methane change). Metal and glass don't burn, so a `combusts`
site now deposits all the metal and glass it receives, as its ash, and burns
the rest. They make no methane, so emissions don't move; the mass flow's
`sites` shows the ash. `constants.UNBURNABLE_TYPES` names the two, as on main,
where incineration stopped burning them in the same change. WasteMAP's
advanced DST sizes its incinerator so it burns the share of the city's waste
the city reports burning.

- **Nothing sent to an incinerator is landfilled unburned, on `am-waste-flow`
too** (model-output change). SWEET main set `City.combustion_reject_rate` to 0
in [#100](https://github.com/RMI/SWEET_python/pull/100) (decision
Expand Down
29 changes: 21 additions & 8 deletions tests/test_adst_city_incineration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

``CityLandfillSpec.combusts`` marks a facility as an incinerator (with or
without energy recovery): the share of the city's disposed waste routed to it
still arrives, and only the reject -- ``City.combustion_reject_rate`` -- is
deposited and left to decay. The rest is destroyed, producing no methane in
this model, and is *not* re-routed to another site.
still arrives, and only what does not burn is deposited: the metal and glass
it receives, and the reject of the rest -- ``City.combustion_reject_rate``.
The rest is destroyed, producing no methane in this model, and is *not*
re-routed to another site.

The reject is 0: everything sent to an incinerator stops producing methane.
It was 10% of the burnable waste, landfilled as the material it was, until
Expand Down Expand Up @@ -32,6 +33,7 @@
run_advanced_dst_city,
)
from SWEET_python.city_params import City
from SWEET_python.constants import UNBURNABLE_TYPES

YEARS = range(2000, 2051)
FRACTIONS = [0.5, 0.1, 0.05, 0.1, 0.05, 0.1, 0.02, 0.03, 0.0, 0.05] # sums to 1.0
Expand Down Expand Up @@ -184,16 +186,24 @@ def _flow(request, variant="baseline"):
return run_advanced_dst_city(request, with_mass_flow=True)["mass_flow"][variant]


def test_a_burning_site_receives_its_share_and_deposits_none_of_it():
def _unburnable(flow):
"""The metal and glass in what the city disposed of, per year."""
return flow["landfilled"][list(UNBURNABLE_TYPES)].sum(axis=1)


def test_a_burning_site_receives_its_share_and_deposits_only_its_metal_and_glass():
"""Before ``sites_received`` the mass flow said only what a site deposits,
so an incinerator taking half the city's waste read as taking none."""
so an incinerator taking half the city's waste read as taking none. It burns
all of it but the metal and glass, which don't burn."""
flow = _flow(_request([_landfill(), _landfill(combusts=BURNS)], [0.5, 0.5]))
landfilled = flow["landfilled"].sum(axis=1)
unburnable = _unburnable(flow)

for year in YEARS:
assert landfilled[year] > 0
assert flow["sites_received"][1][year] == pytest.approx(0.5 * landfilled[year])
assert flow["sites"][1][year] == 0.0
assert flow["sites"][1][year] == pytest.approx(0.5 * unburnable[year])
assert unburnable[year] == pytest.approx(0.05 * landfilled[year])
# The landfill beside it is untouched: it buries all it receives.
assert flow["sites"][0][year] == pytest.approx(flow["sites_received"][0][year])

Expand Down Expand Up @@ -224,7 +234,7 @@ def test_a_site_that_starts_burning_receives_the_same_waste_throughout():
if year < IMPLEMENT_YEAR:
assert scenario["sites"][0][year] == pytest.approx(baseline["sites"][0][year])
else:
assert scenario["sites"][0][year] == 0.0
assert scenario["sites"][0][year] == pytest.approx(_unburnable(scenario)[year])
assert scenario["sites_received"][0][year] > 0


Expand Down Expand Up @@ -271,11 +281,14 @@ def test_a_reject_is_deposited_as_its_share_of_intake(with_a_reject):


def test_a_reject_is_what_the_site_deposits_of_what_it_receives(with_a_reject):
"""The reject of what burns, besides all the metal and glass."""
flow = _flow(_request([_landfill(combusts=BURNS)], [1.0]))
unburnable = _unburnable(flow)

for year in YEARS:
burnable = flow["sites_received"][0][year] - unburnable[year]
assert flow["sites"][0][year] == pytest.approx(
with_a_reject * flow["sites_received"][0][year]
with_a_reject * burnable + unburnable[year]
)


Expand Down