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
4 changes: 2 additions & 2 deletions SWEET_python/MODEL_DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ A site or city with no recorded type is assumed a sanitary landfill or an open d
- **Why:** Site type sets MCF, oxidation and the gas-capture default, and most sites and many cities record no type.
- **Options, best first:**
1. `recorded`: the type the caller supplies.
2. `sanitary-by-country`: sanitary landfill if high income, in a listed region, or China, Russia, Mexico, Brazil or Costa Rica. Never Mongolia or Yemen.
2. `sanitary-by-country`: sanitary landfill if high income, in a listed region, or China, Russia, Mexico, Brazil or Costa Rica. Never Mongolia or Yemen. The caller passes the income group; SWEET holds none, so without one only region and named countries count.
3. `dumpsite`: open dump otherwise, including a missing or unplaceable country. Never a controlled dump.
- **Paths:**
- `ct-site`: Climate TRACE fills the type before the call, with its own income groups; SWEET applies the rule again to a blank type.
Expand All @@ -178,7 +178,7 @@ A site or city with no recorded type is assumed a sanitary landfill or an open d
- **Better:** Classify each site from its area, intake or imagery, not its country's income, and use one fallback order on every path.
- **Value:** `SWEET_python.site_type_defaults`: `LANDFILL_DEFAULT_COUNTRIES`, `DUMPSITE_COUNTRIES`, `LANDFILL_DEFAULT_REGIONS`
- **Code:** `SWEET_python/site_type_defaults.py`
- **Reviewed:** 2026-10-22
- **Reviewed:** 2026-10-29

### `waste-composition`

Expand Down
37 changes: 28 additions & 9 deletions SWEET_python/city_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,14 +1507,18 @@ def load_csv_new(

self.baseline_parameters = city_parameters

def load_andre_params(self, row, backfill=False):
def load_andre_params(self, row, backfill=False, income_id: Optional[str] = None):
"""
Loads model parameters from the internal RMI WasteMAP database. Defaults are used
where data is missing, incomplete, or incompatible.

Args:
row (tuple): row[0] is the index of the row in the dataframe used for input,
row[1] is the row itself.
income_id: The country's World Bank income group, for the landfill/dump
split's last fallback (the shared site-type rule).
SWEET holds no income table; without one, only region and named
countries decide.

Returns:
None
Expand Down Expand Up @@ -1885,7 +1889,7 @@ def load_andre_params(self, row, backfill=False):
}
self.landfill_split_defaults = True
else:
if site_type_defaults.landfill_is_default(iso3):
if site_type_defaults.landfill_is_default(iso3, income_id):
split_fractions = {
"landfill_w_capture": 0,
"landfill_wo_capture": 1,
Expand Down Expand Up @@ -1976,7 +1980,7 @@ def load_andre_params(self, row, backfill=False):
}
self.landfill_split_defaults = True
else:
if site_type_defaults.landfill_is_default(iso3):
if site_type_defaults.landfill_is_default(iso3, income_id):
split_fractions = {
"landfill_w_capture": 0.0,
"landfill_wo_capture": 1.0,
Expand Down Expand Up @@ -2009,7 +2013,7 @@ def load_andre_params(self, row, backfill=False):
# Normalize landfills to 1
split_total = sum([x for x in split_fractions.values()])
if split_total == 0:
if site_type_defaults.landfill_is_default(iso3):
if site_type_defaults.landfill_is_default(iso3, income_id):
split_fractions = {
"landfill_w_capture": 0.0,
"landfill_wo_capture": 1.0,
Expand Down Expand Up @@ -2771,13 +2775,16 @@ def check_for_landfill_gaps(
self.estimate_diversion_emissions(scenario=0)
self.sum_landfill_emissions(scenario=0)

def site_only_estimate(self, row=None, pop_data=None):
def site_only_estimate(self, row=None, pop_data=None, income_id: Optional[str] = None):
"""
For generating estimates for sites only

Args:
id (int): The ID of the site.
df (DataFrame): The DataFrame containing site data.
income_id: The country's World Bank income group, for a site with no
recorded type (the shared site-type rule). SWEET holds no income
table; without one, only region and named countries decide.

Returns:
None
Expand Down Expand Up @@ -2896,7 +2903,7 @@ def site_only_estimate(self, row=None, pop_data=None):
depth = None
site_type = row["Site Type"].values[0]
if site_type not in get_site_type_idx.keys():
site_type = site_type_defaults.default_site_type(self.iso3)
site_type = site_type_defaults.default_site_type(self.iso3, income_id)
site_type_idx = get_site_type_idx[site_type]
city_params_dict = baseline.update_cityparams_dict()
baseline.city_params_dict = city_params_dict
Expand Down Expand Up @@ -4846,6 +4853,7 @@ def dst_baseline_blank(
precipitation: float,
temperature: float,
population_series: Optional[pd.Series] = None,
income_id: Optional[str] = None,
) -> None:
"""
Initializes the baseline scenario with given parameters for a blank/custom city.
Expand All @@ -4858,6 +4866,9 @@ def dst_baseline_blank(
out once by country_population_trajectory and stored. The city's waste
grows along it instead of along SWEET's own table. Only its shape
counts: the city's waste is set by ``population``.
income_id (str): the country's World Bank income group, from the caller,
for the disposal split's last fallback
(``defaults_2019.disposal_split_for``). SWEET holds no income table.

Returns:
None
Expand Down Expand Up @@ -4921,7 +4932,7 @@ def dst_baseline_blank(
# Determine waste split fractions, as the cities table does for a city
# with no landfill data
split_fractions = SplitFractions(
**defaults_2019.disposal_split_for(iso3, region)
**defaults_2019.disposal_split_for(iso3, region, income_id)
)

# Instantiate landfill objects
Expand Down Expand Up @@ -9173,6 +9184,7 @@ async def sdst_prepopulate(
sites_list: pd.DataFrame,
latlon: Optional[str] = None,
site_id: Optional[int] = None,
income_by_iso3: Optional[Dict[str, str]] = None,
) -> None:
"""
API endpoing function to prepopulate the SDST,
Expand All @@ -9188,6 +9200,11 @@ async def sdst_prepopulate(
sites_list (pd.DataFrame): DataFrame containing site information.
latlon (Optional[str]): Latitude and longitude as a string. Defaults to None.
site_id (Optional[int]): Site ID. Defaults to None.
income_by_iso3 (Optional[Dict[str, str]]): World Bank income group by
country, from the caller (WasteMAP reads it from the World Bank list
the ingestion pipeline loads). Looked up once the point's country is
known. SWEET holds no income table; a country missing from it gets
only the region and named-country rules.
Returns:
dict: Dictionary containing data for prepopulation.
"""
Expand All @@ -9211,6 +9228,7 @@ async def sdst_prepopulate(
region = defaults_2019.REGION_LOOKUP_ISO3.get(iso3)
if region is None:
raise ValueError(f"Region for ISO3 code '{iso3}' not found.")
income_id = (income_by_iso3 or {}).get(iso3)
else:
location = geolocator.reverse((latlon[0], latlon[1]), language="en")
# geopy gives None where Nominatim can't place the point (open sea), and
Expand All @@ -9226,13 +9244,14 @@ async def sdst_prepopulate(
region = defaults_2019.REGION_LOOKUP_ISO3.get(iso3)
if region is None:
raise ValueError(f"Region for ISO3 code '{iso3}' not found.")
if site_type_defaults.landfill_is_default(iso3):
income_id = (income_by_iso3 or {}).get(iso3)
if site_type_defaults.landfill_is_default(iso3, income_id):
site_type = "Landfill"
else:
site_type = "Dumpsite"
# A site in the sites list with no recorded type takes the same rule.
if pd.isna(site_type) or site_type == "":
site_type = site_type_defaults.default_site_type(iso3)
site_type = site_type_defaults.default_site_type(iso3, income_id)

if site_type in ["Landfill", "Sanitary Landfill"]:
site_type = 0
Expand Down
Loading
Loading