openenviro 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openenviro/__init__.py +101 -0
- openenviro/__main__.py +21 -0
- openenviro/_validation.py +78 -0
- openenviro/_version.py +3 -0
- openenviro/annual_waste.py +191 -0
- openenviro/city_scenario.py +372 -0
- openenviro/climate.py +90 -0
- openenviro/compost.py +303 -0
- openenviro/compost_facility.py +176 -0
- openenviro/errors.py +9 -0
- openenviro/fleet.py +254 -0
- openenviro/gas_scenario.py +52 -0
- openenviro/landfill.py +216 -0
- openenviro/landfill_gas.py +74 -0
- openenviro/landfill_phases.py +110 -0
- openenviro/methane.py +119 -0
- openenviro/population.py +51 -0
- openenviro/py.typed +0 -0
- openenviro/waste.py +51 -0
- openenviro-0.1.0.dist-info/METADATA +277 -0
- openenviro-0.1.0.dist-info/RECORD +24 -0
- openenviro-0.1.0.dist-info/WHEEL +5 -0
- openenviro-0.1.0.dist-info/licenses/LICENSE +21 -0
- openenviro-0.1.0.dist-info/top_level.txt +1 -0
openenviro/__init__.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""OpenEnviro Python SDK: environmental engineering calculation models."""
|
|
2
|
+
|
|
3
|
+
from ._version import __version__
|
|
4
|
+
from .errors import OpenEnviroError, ValidationError
|
|
5
|
+
from .population import PopulationProjection, project_population
|
|
6
|
+
from .waste import WasteAllocation, allocate_waste, daily_waste
|
|
7
|
+
from .annual_waste import (
|
|
8
|
+
AnnualWasteInput, AnnualWasteResult, AnnualWasteRow, WasteSchedule, WasteTotals,
|
|
9
|
+
calculate_landfill_schedule, calculate_landfill_year, project_landfill_schedule,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"__version__", "OpenEnviroError", "ValidationError", "PopulationProjection",
|
|
14
|
+
"project_population", "WasteAllocation", "allocate_waste", "daily_waste",
|
|
15
|
+
"AnnualWasteInput", "AnnualWasteResult", "AnnualWasteRow", "WasteSchedule", "WasteTotals",
|
|
16
|
+
"calculate_landfill_schedule", "calculate_landfill_year", "project_landfill_schedule",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
from .fleet import (
|
|
20
|
+
HCSInput, HCSResult, SCSInput, SCSResult, TransferInput, TransferRoute,
|
|
21
|
+
TransferRouteResult, TransferNetworkResult, calculate_hcs, calculate_scs,
|
|
22
|
+
calculate_transfer, calculate_transfer_network,
|
|
23
|
+
)
|
|
24
|
+
from .compost import (
|
|
25
|
+
CompostMaterial, CompostComponent, CompostMixResult, CompostAmendment,
|
|
26
|
+
ConditioningResult, AerobicMaterial, AerationSettings, AerationComponent,
|
|
27
|
+
AerationResult, calculate_compost_mix, sakarya_compost_feed, sakarya_wood_chips,
|
|
28
|
+
solve_moisture_target, solve_cn_target, solve_water_target, solve_joint_targets,
|
|
29
|
+
calculate_compost_aeration, sakarya_aerobic_materials,
|
|
30
|
+
)
|
|
31
|
+
from .compost_facility import (
|
|
32
|
+
WindrowGeometryInput, WindrowGeometryResult, WindrowCapacityInput,
|
|
33
|
+
WindrowCapacityResult, CompostYieldInput, CompostYieldResult, CompostFacilityInput,
|
|
34
|
+
CompostFacilityResult, CompostPadResult, calculate_windrow_geometry,
|
|
35
|
+
calculate_windrow_capacity, calculate_compost_yield, calculate_compost_facility,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
__all__ += [
|
|
39
|
+
"HCSInput", "HCSResult", "SCSInput", "SCSResult", "TransferInput", "TransferRoute",
|
|
40
|
+
"TransferRouteResult", "TransferNetworkResult", "calculate_hcs", "calculate_scs",
|
|
41
|
+
"calculate_transfer", "calculate_transfer_network", "CompostMaterial", "CompostComponent",
|
|
42
|
+
"CompostMixResult", "CompostAmendment", "ConditioningResult", "AerobicMaterial",
|
|
43
|
+
"AerationSettings", "AerationComponent", "AerationResult", "calculate_compost_mix",
|
|
44
|
+
"sakarya_compost_feed", "sakarya_wood_chips", "solve_moisture_target", "solve_cn_target",
|
|
45
|
+
"solve_water_target", "solve_joint_targets", "calculate_compost_aeration",
|
|
46
|
+
"sakarya_aerobic_materials", "WindrowGeometryInput", "WindrowGeometryResult",
|
|
47
|
+
"WindrowCapacityInput", "WindrowCapacityResult", "CompostYieldInput", "CompostYieldResult",
|
|
48
|
+
"CompostFacilityInput", "CompostFacilityResult", "CompostPadResult",
|
|
49
|
+
"calculate_windrow_geometry", "calculate_windrow_capacity", "calculate_compost_yield",
|
|
50
|
+
"calculate_compost_facility",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
from .landfill import (
|
|
54
|
+
LandfillCapacityInput, LandfillCapacityYear, LandfillGeometryInput, LandfillSizingInput,
|
|
55
|
+
calculate_landfill_capacity, calculate_landfill_capacity_schedule, calculate_landfill_geometry,
|
|
56
|
+
landfill_section_at_height, landfill_volume_between_heights, landfill_volume_below_height,
|
|
57
|
+
calculate_landfill_lifts, calculate_landfill_sizing, compare_landfill_sizing_heights, landfill_fill_height,
|
|
58
|
+
)
|
|
59
|
+
from .landfill_gas import (
|
|
60
|
+
BuswellMaterial, LandfillGasWasteYear, NORMAL_MOLAR_VOLUME, calculate_buswell,
|
|
61
|
+
sakarya_landfill_materials, landgem_first_year_factor, project_landfill_gas,
|
|
62
|
+
)
|
|
63
|
+
from .methane import (
|
|
64
|
+
MethaneManagementAssumptions, MethaneManagementChange, EnergyRecoveryAssumptions,
|
|
65
|
+
calculate_methane_management, project_methane_management, calculate_energy_recovery,
|
|
66
|
+
calculate_integrated_energy_recovery, project_energy_recovery,
|
|
67
|
+
)
|
|
68
|
+
from .climate import (
|
|
69
|
+
ClimateAssumptions, ClimateFlows, ClimateAnnualOverride, ClimateScenario, BIOGENIC_METHANE_GWP,
|
|
70
|
+
calculate_climate_impact, project_climate_impact, compare_climate_scenarios,
|
|
71
|
+
)
|
|
72
|
+
from .gas_scenario import GasScenarioInput, calculate_gas_scenario
|
|
73
|
+
|
|
74
|
+
__all__ += [
|
|
75
|
+
'LandfillCapacityInput','LandfillCapacityYear','LandfillGeometryInput','LandfillSizingInput',
|
|
76
|
+
'calculate_landfill_capacity','calculate_landfill_capacity_schedule','calculate_landfill_geometry',
|
|
77
|
+
'landfill_section_at_height','landfill_volume_between_heights','landfill_volume_below_height',
|
|
78
|
+
'calculate_landfill_lifts','calculate_landfill_sizing','compare_landfill_sizing_heights','landfill_fill_height',
|
|
79
|
+
'BuswellMaterial','LandfillGasWasteYear','NORMAL_MOLAR_VOLUME','calculate_buswell','sakarya_landfill_materials',
|
|
80
|
+
'landgem_first_year_factor','project_landfill_gas','MethaneManagementAssumptions','MethaneManagementChange',
|
|
81
|
+
'EnergyRecoveryAssumptions','calculate_methane_management','project_methane_management','calculate_energy_recovery',
|
|
82
|
+
'calculate_integrated_energy_recovery','project_energy_recovery','ClimateAssumptions','ClimateFlows',
|
|
83
|
+
'ClimateAnnualOverride','ClimateScenario','BIOGENIC_METHANE_GWP','calculate_climate_impact',
|
|
84
|
+
'project_climate_impact','compare_climate_scenarios','GasScenarioInput','calculate_gas_scenario',
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
from .landfill_phases import (
|
|
88
|
+
LandfillPhaseYear, landfill_longitudinal_volume, landfill_position_at_volume,
|
|
89
|
+
landfill_phase_end_years, calculate_landfill_phases, evaluate_landfill_phase_scenario,
|
|
90
|
+
)
|
|
91
|
+
__all__ += ['LandfillPhaseYear','landfill_longitudinal_volume','landfill_position_at_volume',
|
|
92
|
+
'landfill_phase_end_years','calculate_landfill_phases','evaluate_landfill_phase_scenario']
|
|
93
|
+
|
|
94
|
+
from .city_scenario import (
|
|
95
|
+
CityProjection, CityScenario, CityEngineeringSettings, CitySimulationResult,
|
|
96
|
+
CityFleetResult, CityCompostResult, CityLandfillResult, simulate_city,
|
|
97
|
+
CITY_SCENARIO_SCHEMA_VERSION, MAX_CITY_OPERATING_YEARS,
|
|
98
|
+
)
|
|
99
|
+
__all__ += ['CityProjection','CityScenario','CityEngineeringSettings','CitySimulationResult',
|
|
100
|
+
'CityFleetResult','CityCompostResult','CityLandfillResult','simulate_city',
|
|
101
|
+
'CITY_SCENARIO_SCHEMA_VERSION','MAX_CITY_OPERATING_YEARS']
|
openenviro/__main__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Local command-line entry point for SDK discovery and version checks."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from collections.abc import Sequence
|
|
5
|
+
|
|
6
|
+
from ._version import __version__
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
10
|
+
parser = argparse.ArgumentParser(
|
|
11
|
+
prog="python -m openenviro",
|
|
12
|
+
description="OpenEnviro Python SDK (development foundation; simulation engines pending).",
|
|
13
|
+
)
|
|
14
|
+
parser.add_argument("--version", action="version", version=f"OpenEnviro SDK {__version__}")
|
|
15
|
+
parser.parse_args(argv)
|
|
16
|
+
parser.print_help()
|
|
17
|
+
return 0
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if __name__ == "__main__":
|
|
21
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Internal numerical contracts shared by future scientific engines.
|
|
2
|
+
|
|
3
|
+
The TypeScript core uses IEEE 754 binary64 numbers. Accept Python int/float
|
|
4
|
+
values (not bool or strings), convert to finite floats, and enforce explicit
|
|
5
|
+
bounds. No silent clipping, string parsing, or integer rounding is performed.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from math import isfinite
|
|
9
|
+
from .errors import ValidationError
|
|
10
|
+
|
|
11
|
+
MAX_SAFE_INTEGER = 2**53 - 1
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def finite_number(value: object, label: str) -> float:
|
|
15
|
+
"""Return a finite binary64 value, with negative zero normalized to zero."""
|
|
16
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
17
|
+
raise ValidationError(f"{label} must be a finite number")
|
|
18
|
+
try:
|
|
19
|
+
number = float(value)
|
|
20
|
+
except (OverflowError, ValueError) as exc:
|
|
21
|
+
raise ValidationError(f"{label} must be a finite number") from exc
|
|
22
|
+
if not isfinite(number):
|
|
23
|
+
raise ValidationError(f"{label} must be a finite number")
|
|
24
|
+
return 0.0 if number == 0 else number
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def nonnegative(value: object, label: str) -> float:
|
|
28
|
+
"""Require a finite number greater than or equal to zero."""
|
|
29
|
+
number = finite_number(value, label)
|
|
30
|
+
if number < 0:
|
|
31
|
+
raise ValidationError(f"{label} must be non-negative")
|
|
32
|
+
return number
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def positive(value: object, label: str) -> float:
|
|
36
|
+
"""Require a finite number strictly greater than zero."""
|
|
37
|
+
number = finite_number(value, label)
|
|
38
|
+
if number <= 0:
|
|
39
|
+
raise ValidationError(f"{label} must be positive")
|
|
40
|
+
return number
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def fraction(value: object, label: str) -> float:
|
|
44
|
+
"""Require a fraction in the closed interval [0, 1], not a percentage."""
|
|
45
|
+
number = finite_number(value, label)
|
|
46
|
+
if not 0 <= number <= 1:
|
|
47
|
+
raise ValidationError(f"{label} must be a fraction between 0 and 1")
|
|
48
|
+
return number
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def safe_integer(
|
|
52
|
+
value: object,
|
|
53
|
+
label: str,
|
|
54
|
+
*,
|
|
55
|
+
minimum: int = -MAX_SAFE_INTEGER,
|
|
56
|
+
maximum: int = MAX_SAFE_INTEGER,
|
|
57
|
+
) -> int:
|
|
58
|
+
"""Require a whole, JS-safe number within the supplied inclusive bounds."""
|
|
59
|
+
if (
|
|
60
|
+
isinstance(minimum, bool) or isinstance(maximum, bool)
|
|
61
|
+
or not isinstance(minimum, int) or not isinstance(maximum, int)
|
|
62
|
+
or not -MAX_SAFE_INTEGER <= minimum <= maximum <= MAX_SAFE_INTEGER
|
|
63
|
+
):
|
|
64
|
+
raise ValueError("Invalid safe-integer bounds")
|
|
65
|
+
number = finite_number(value, label)
|
|
66
|
+
if not number.is_integer() or not minimum <= number <= maximum:
|
|
67
|
+
raise ValidationError(f"{label} must be an integer between {minimum} and {maximum}")
|
|
68
|
+
return int(number)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def year(value: object, label: str = "Year") -> int:
|
|
72
|
+
"""Require a calendar year in the same range as the city engine."""
|
|
73
|
+
return safe_integer(value, label, minimum=1, maximum=9999)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def represented_days(value: object) -> int:
|
|
77
|
+
"""Require 1 through 366 represented operating days."""
|
|
78
|
+
return safe_integer(value, "Represented days", minimum=1, maximum=366)
|
openenviro/_version.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""Annual waste accounting ported from packages/core/src/landfillWaste.ts.
|
|
2
|
+
|
|
3
|
+
Population in persons, waste rate in kg/person/day, daily flows in t/day,
|
|
4
|
+
annual flows in tonnes. Compost rejects refer to incoming wet municipal waste,
|
|
5
|
+
not to the conditioned compost mixture or finished product.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from collections.abc import Sequence
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
|
|
11
|
+
from ._validation import finite_number, fraction, nonnegative, represented_days, year as check_year
|
|
12
|
+
from .errors import ValidationError
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True, slots=True)
|
|
16
|
+
class AnnualWasteInput:
|
|
17
|
+
year: int
|
|
18
|
+
population: float
|
|
19
|
+
waste_rate: float
|
|
20
|
+
recycling_fraction: float
|
|
21
|
+
compost_fraction_of_residual: float
|
|
22
|
+
compost_reject_fraction: float = 0.0
|
|
23
|
+
days_in_year: int = 365
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True, slots=True)
|
|
27
|
+
class AnnualWasteResult:
|
|
28
|
+
year: int
|
|
29
|
+
population: float
|
|
30
|
+
waste_rate: float
|
|
31
|
+
recycling_fraction: float
|
|
32
|
+
compost_fraction_of_residual: float
|
|
33
|
+
compost_reject_fraction: float
|
|
34
|
+
days_in_year: int
|
|
35
|
+
daily_generated: float
|
|
36
|
+
daily_recycled: float
|
|
37
|
+
daily_residual: float
|
|
38
|
+
daily_compost_feed: float
|
|
39
|
+
daily_direct_landfill: float
|
|
40
|
+
daily_compost_reject: float
|
|
41
|
+
daily_compost_retained: float
|
|
42
|
+
daily_landfill: float
|
|
43
|
+
annual_generated: float
|
|
44
|
+
annual_recycled: float
|
|
45
|
+
annual_compost_feed: float
|
|
46
|
+
annual_direct_landfill: float
|
|
47
|
+
annual_compost_reject: float
|
|
48
|
+
annual_compost_retained: float
|
|
49
|
+
annual_landfill: float
|
|
50
|
+
effective_landfill_fraction: float | None
|
|
51
|
+
annual_mass_balance_error: float
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass(frozen=True, slots=True)
|
|
55
|
+
class AnnualWasteRow(AnnualWasteResult):
|
|
56
|
+
cumulative_landfill: float
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass(frozen=True, slots=True)
|
|
60
|
+
class WasteTotals:
|
|
61
|
+
generated: float
|
|
62
|
+
recycled: float
|
|
63
|
+
compost_feed: float
|
|
64
|
+
direct_landfill: float
|
|
65
|
+
compost_reject: float
|
|
66
|
+
compost_retained: float
|
|
67
|
+
landfill: float
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass(frozen=True, slots=True)
|
|
71
|
+
class WasteSchedule:
|
|
72
|
+
start_year: int
|
|
73
|
+
end_year: int
|
|
74
|
+
design_years: int
|
|
75
|
+
total_days: int
|
|
76
|
+
rows: tuple[AnnualWasteRow, ...]
|
|
77
|
+
totals: WasteTotals
|
|
78
|
+
total_landfill_mass: float
|
|
79
|
+
average_daily_landfill: float
|
|
80
|
+
peak_daily_landfill: float
|
|
81
|
+
mass_balance_error: float
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def calculate_landfill_year(data: AnnualWasteInput) -> AnnualWasteResult:
|
|
85
|
+
"""Calculate mutually exclusive destinations and annual waste mass flows."""
|
|
86
|
+
if not isinstance(data, AnnualWasteInput):
|
|
87
|
+
raise ValidationError("Expected AnnualWasteInput")
|
|
88
|
+
y = check_year(data.year)
|
|
89
|
+
p = nonnegative(data.population, "Population")
|
|
90
|
+
rate = nonnegative(data.waste_rate, "Waste generation rate")
|
|
91
|
+
r = fraction(data.recycling_fraction, "Recycling fraction")
|
|
92
|
+
c = fraction(data.compost_fraction_of_residual, "Composting fraction")
|
|
93
|
+
reject = fraction(data.compost_reject_fraction, "Compost reject fraction")
|
|
94
|
+
days = represented_days(data.days_in_year)
|
|
95
|
+
# This order matches landfillWaste.ts (different from daily_waste).
|
|
96
|
+
generated = nonnegative(p * (rate / 1000.0), "Daily generation")
|
|
97
|
+
recycled = generated * r
|
|
98
|
+
residual = generated - recycled
|
|
99
|
+
feed = residual * c
|
|
100
|
+
direct = residual - feed
|
|
101
|
+
rejects = feed * reject
|
|
102
|
+
retained = feed - rejects
|
|
103
|
+
landfill = direct + rejects
|
|
104
|
+
annual = tuple(nonnegative(value * days, "Annual mass") for value in
|
|
105
|
+
(generated, recycled, feed, direct, rejects, retained, landfill))
|
|
106
|
+
ag, ar, af, ad, aj, at, al = annual
|
|
107
|
+
return AnnualWasteResult(
|
|
108
|
+
y, p, rate, r, c, reject, days, generated, recycled, residual,
|
|
109
|
+
feed, direct, rejects, retained, landfill, ag, ar, af, ad, aj, at, al,
|
|
110
|
+
landfill / generated if generated > 0 else None,
|
|
111
|
+
(ag - ar) - at - al,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def calculate_landfill_schedule(inputs: Sequence[AnnualWasteInput]) -> WasteSchedule:
|
|
116
|
+
"""Evaluate consecutive calendar years and cumulative waste destinations."""
|
|
117
|
+
if not isinstance(inputs, Sequence) or isinstance(inputs, (str, bytes, bytearray)) or not 1 <= len(inputs) <= 9999:
|
|
118
|
+
raise ValidationError("Provide a non-empty annual schedule of at most 9999 rows")
|
|
119
|
+
from dataclasses import fields
|
|
120
|
+
|
|
121
|
+
rows: list[AnnualWasteRow] = []
|
|
122
|
+
sums = [0.0] * 7
|
|
123
|
+
total_days = 0
|
|
124
|
+
for data in inputs:
|
|
125
|
+
r = calculate_landfill_year(data)
|
|
126
|
+
if rows and r.year != rows[-1].year + 1:
|
|
127
|
+
raise ValidationError("Annual rows must be consecutive and in chronological order")
|
|
128
|
+
total_days += r.days_in_year
|
|
129
|
+
flows = (r.annual_generated, r.annual_recycled, r.annual_compost_feed,
|
|
130
|
+
r.annual_direct_landfill, r.annual_compost_reject,
|
|
131
|
+
r.annual_compost_retained, r.annual_landfill)
|
|
132
|
+
sums = [nonnegative(a + b, "Cumulative mass") for a, b in zip(sums, flows)]
|
|
133
|
+
values = {f.name: getattr(r, f.name) for f in fields(AnnualWasteResult)}
|
|
134
|
+
rows.append(AnnualWasteRow(**values, cumulative_landfill=sums[-1]))
|
|
135
|
+
totals = WasteTotals(*sums)
|
|
136
|
+
return WasteSchedule(
|
|
137
|
+
rows[0].year, rows[-1].year, len(rows), total_days, tuple(rows), totals,
|
|
138
|
+
totals.landfill, totals.landfill / total_days,
|
|
139
|
+
max(r.daily_landfill for r in rows),
|
|
140
|
+
(totals.generated - totals.recycled) - totals.compost_retained - totals.landfill,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def project_landfill_schedule(
|
|
145
|
+
*,
|
|
146
|
+
base_year: int,
|
|
147
|
+
base_population: float,
|
|
148
|
+
annual_population_growth: float,
|
|
149
|
+
start_year: int,
|
|
150
|
+
end_year: int,
|
|
151
|
+
base_waste_rate: float,
|
|
152
|
+
recycling_fraction: float,
|
|
153
|
+
compost_fraction_of_residual: float,
|
|
154
|
+
annual_waste_rate_growth: float = 0.0,
|
|
155
|
+
compost_reject_fraction: float = 0.0,
|
|
156
|
+
days_in_year: int = 365,
|
|
157
|
+
) -> WasteSchedule:
|
|
158
|
+
"""Project annual flows with independent geometric growth of population/rate.
|
|
159
|
+
|
|
160
|
+
The start and end years are inclusive. Growth inputs are fractions >= -1.
|
|
161
|
+
A zero base remains zero, even if exponentiation would overflow. A -100%
|
|
162
|
+
growth rate leaves the base year intact and gives zero in subsequent years.
|
|
163
|
+
"""
|
|
164
|
+
base = check_year(base_year, "Base year")
|
|
165
|
+
start = check_year(start_year, "Start year")
|
|
166
|
+
end = check_year(end_year, "End year")
|
|
167
|
+
if not base <= start <= end:
|
|
168
|
+
raise ValidationError("Require base year <= start year <= end year")
|
|
169
|
+
p = nonnegative(base_population, "Base population")
|
|
170
|
+
w = nonnegative(base_waste_rate, "Base waste generation rate")
|
|
171
|
+
gp = finite_number(annual_population_growth, "Population growth")
|
|
172
|
+
gw = finite_number(annual_waste_rate_growth, "Waste rate growth")
|
|
173
|
+
if gp < -1 or gw < -1:
|
|
174
|
+
raise ValidationError("Annual growth must be at least -1")
|
|
175
|
+
r = fraction(recycling_fraction, "Recycling fraction")
|
|
176
|
+
c = fraction(compost_fraction_of_residual, "Composting fraction")
|
|
177
|
+
j = fraction(compost_reject_fraction, "Compost reject fraction")
|
|
178
|
+
days = represented_days(days_in_year)
|
|
179
|
+
|
|
180
|
+
def project(value: float, growth: float, elapsed: int) -> float:
|
|
181
|
+
if value == 0:
|
|
182
|
+
return 0.0
|
|
183
|
+
try:
|
|
184
|
+
return nonnegative(value * (1.0 + growth) ** elapsed, "Projected value")
|
|
185
|
+
except OverflowError as exc:
|
|
186
|
+
raise ValidationError("Projected value exceeds numerical range") from exc
|
|
187
|
+
|
|
188
|
+
return calculate_landfill_schedule([
|
|
189
|
+
AnnualWasteInput(y, project(p, gp, y-base), project(w, gw, y-base), r, c, j, days)
|
|
190
|
+
for y in range(start, end + 1)
|
|
191
|
+
])
|