Skip to content

Commit 44d9faf

Browse files
authored
Add population parameter
#211: Take regional population as given, and calculated susceptible portion as those not infected
2 parents 0a0aece + 85c33f7 commit 44d9faf

File tree

7 files changed

+29
-28
lines changed

7 files changed

+29
-28
lines changed

settings.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
--icu-rate 0.0075
99
--market_share 0.15
1010
--n-days 60
11-
--susceptible 4119405
11+
--population 4119405
1212
--ventilated-los 10
1313
--ventilated-rate 0.005

src/penn_chime/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def parse_args():
9191
1.0,
9292
"Social Distancing Reduction Rate: 0.0 - 1.0",
9393
),
94-
("--susceptible", int, 1, None, "Regional Population >= 1"),
94+
("--population", int, 1, None, "Regional Population >= 1"),
9595
("--ventilated-los", int, 0, None, "Ventilated Length of Stay (days)"),
9696
("--ventilated-rate", float, 0.0, 1.0, "Ventilated Rate: 0.0 - 1.0"),
9797
):
@@ -110,7 +110,7 @@ def main():
110110
market_share=a.market_share,
111111
n_days=a.n_days,
112112
relative_contact_rate=a.relative_contact_rate,
113-
susceptible=a.susceptible,
113+
population=a.population,
114114

115115
hospitalized=RateLos(a.hospitalized_rate, a.hospitalized_los),
116116
icu=RateLos(a.icu_rate, a.icu_los),

src/penn_chime/defaults.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@ class Regions:
77
"""Arbitrary number of counties."""
88

99
def __init__(self, **kwargs):
10-
susceptible = 0
10+
population = 0
1111
for key, value in kwargs.items():
1212
setattr(self, key, value)
13-
susceptible += value
14-
self._susceptible = susceptible
13+
population += value
14+
self.population = population
1515

16-
@property
17-
def susceptible(self):
18-
return self._susceptible
1916

2017

2118
class Constants:
@@ -55,4 +52,4 @@ def __init__(
5552
self.recovery_days = recovery_days
5653

5754
def __repr__(self) -> str:
58-
return f"Constants(susceptible_default: {self.region.susceptible}, known_infected: {self.known_infected})"
55+
return f"Constants(population_default: {self.region.population}, known_infected: {self.known_infected})"

src/penn_chime/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
class SimSirModel:
1919

2020
def __init__(self, p: Parameters) -> SimSirModel:
21-
# TODO missing initial recovered value
22-
susceptible = p.susceptible
21+
# TODO missing initial non-zero 'recovered' value
2322
recovered = 0.0
2423
recovery_days = p.recovery_days
2524

@@ -40,6 +39,8 @@ def __init__(self, p: Parameters) -> SimSirModel:
4039
p.current_hospitalized / p.market_share / p.hospitalized.rate
4140
)
4241

42+
susceptible = p.population - infected
43+
4344
detection_probability = (
4445
p.known_infected / infected if infected > 1.0e-7 else None
4546
)

src/penn_chime/parameters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(
1717
doubling_time: float,
1818
known_infected: int,
1919
relative_contact_rate: float,
20-
susceptible: int,
20+
population: int,
2121

2222
hospitalized: RateLos,
2323
icu: RateLos,
@@ -33,7 +33,7 @@ def __init__(
3333
self.doubling_time = doubling_time
3434
self.known_infected = known_infected
3535
self.relative_contact_rate = relative_contact_rate
36-
self.susceptible = susceptible
36+
self.population = population
3737

3838
self.hospitalized = hospitalized
3939
self.icu = icu

src/penn_chime/presentation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def display_header(st, m, p):
4141

4242
infected_population_warning_str = (
4343
"""(Warning: The number of estimated infections is greater than the total regional population. Please verify the values entered in the sidebar.)"""
44-
if m.infected > p.susceptible
44+
if m.infected > p.population
4545
else ""
4646
)
4747

@@ -92,7 +92,7 @@ def display_header(st, m, p):
9292
detection_prob_str=detection_prob_str,
9393
current_hosp=p.current_hospitalized,
9494
hosp_rate=p.hospitalized.rate,
95-
S=p.susceptible,
95+
S=p.population,
9696
market_share=p.market_share,
9797
recovery_days=p.recovery_days,
9898
r_naught=m.r_naught,
@@ -238,11 +238,11 @@ def display_sidebar(st, d: Constants) -> Parameters:
238238
step=1.0,
239239
format="%f",
240240
)
241-
susceptible_input = NumberInputWrapper(
241+
population_input = NumberInputWrapper(
242242
st_obj,
243243
"Regional Population",
244244
min_value=1,
245-
value=d.region.susceptible,
245+
value=d.region.population,
246246
step=100000,
247247
format="%i",
248248
)
@@ -261,7 +261,7 @@ def display_sidebar(st, d: Constants) -> Parameters:
261261

262262
# Build in desired order
263263
st.sidebar.markdown("### Regional Parameters [ℹ]({docs_url}/what-is-chime/parameters)".format(docs_url=DOCS_URL))
264-
susceptible = susceptible_input()
264+
population = population_input()
265265
market_share = market_share_input()
266266
known_infected = known_infected_input()
267267
current_hospitalized = current_hospitalized_input()
@@ -298,7 +298,7 @@ def display_sidebar(st, d: Constants) -> Parameters:
298298
max_y_axis=max_y_axis,
299299
n_days=n_days,
300300
relative_contact_rate=relative_contact_rate / 100.0,
301-
susceptible=susceptible,
301+
population=population,
302302

303303
hospitalized=RateLos(hospitalized_rate/ 100.0, hospitalized_los),
304304
icu=RateLos(icu_rate/ 100.0, icu_los),

tests/test_app.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
known_infected=5000,
2121
market_share=0.05,
2222
relative_contact_rate=0.15,
23-
susceptible=500000,
23+
population=500000,
2424
hospitalized=RateLos(0.05, 7),
2525
icu=RateLos(0.02, 9),
2626
ventilated=RateLos(0.01, 10),
@@ -33,7 +33,7 @@
3333
known_infected=5000,
3434
market_share=0.05,
3535
relative_contact_rate=0.7,
36-
susceptible=500000,
36+
population=500000,
3737
hospitalized=RateLos(0.05, 7),
3838
icu=RateLos(0.02, 9),
3939
ventilated=RateLos(0.01, 10),
@@ -238,7 +238,7 @@ def test_model(model=MODEL, param=PARAM):
238238
# test the class-calculated attributes
239239
assert model.detection_probability == 0.125
240240
assert model.intrinsic_growth_rate == 0.12246204830937302
241-
assert model.beta == 3.2961405355450555e-07
241+
assert model.beta == 3.582761451679408e-07
242242
assert model.r_t == 2.307298374881539
243243
assert model.r_naught == 2.7144686763312222
244244
assert model.doubling_time_t == 7.764405988534983
@@ -251,16 +251,19 @@ def test_model(model=MODEL, param=PARAM):
251251
second = raw_df.iloc[1, :]
252252
last = raw_df.iloc[-1, :]
253253

254-
assert first.susceptible == 500000.0
254+
assert first.susceptible + first.infected + first.recovered == param.population
255+
assert last.susceptible + last.infected + last.recovered == param.population
256+
257+
assert first.susceptible == 460000.0
255258
assert round(second.infected, 0) == 43735
256259

257-
assert round(last.susceptible, 0) == 67202
258-
assert round(raw_df.recovered[30], 0) == 224048
260+
assert round(last.susceptible, 0) == 59497
261+
assert round(raw_df.recovered[30], 0) == 216711
259262

260263
assert list(model.dispositions_df.iloc[0, :]) == [0, 100.0, 40.0, 20.0]
261-
assert [round(i, 0) for i in model.dispositions_df.iloc[60, :]] == [60, 1182.0, 473.0, 236.0]
264+
assert [round(i, 0) for i in model.dispositions_df.iloc[60, :]] == [60, 1101.0, 441.0, 220.0]
262265

263-
# test that admissions are being properly calculated (thanks @PhilMiller)
266+
# test that admissions are being properly calculated
264267
cumulative_admits = model.admits_df.cumsum()
265268
diff = cumulative_admits.hospitalized[1:-1] - (
266269
0.05 * 0.05 * (raw_df.infected[1:-1] + raw_df.recovered[1:-1]) - 100

0 commit comments

Comments
 (0)