-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
"""CLI for CHIME.""" | ||
|
||
from argparse import ( | ||
Action, | ||
ArgumentParser, | ||
) | ||
from datetime import datetime | ||
|
||
from pandas import DataFrame | ||
|
||
from penn_chime.defaults import RateLos | ||
from penn_chime.models import Parameters | ||
from penn_chime.utils import build_admissions_df, build_census_df | ||
|
||
|
||
class FromFile(Action): | ||
"""From File.""" | ||
|
||
def __call__(self, parser, namespace, values, option_string=None): | ||
with values as f: | ||
parser.parse_args(f.read().split(), namespace) | ||
|
||
|
||
def validator(cast, min_value, max_value): | ||
"""Validator.""" | ||
|
||
def validate(string): | ||
"""Validate.""" | ||
value = cast(string) | ||
if min_value is not None: | ||
assert value >= min_value | ||
if max_value is not None: | ||
assert value <= max_value | ||
return value | ||
|
||
return validate | ||
|
||
|
||
def parse_args(): | ||
"""Parse args.""" | ||
parser = ArgumentParser(description='CHIME') | ||
|
||
parser.add_argument('--file', type=open, action=FromFile) | ||
parser.add_argument( | ||
'--prefix', | ||
type=str, | ||
default=datetime.now().strftime("%Y.%m.%d.%H.%M."), | ||
) | ||
|
||
for arg, cast, min_value, max_value, help in ( | ||
('--current-hospitalized', int, 0, None, "Currently Hospitalized COVID-19 Patients (>= 0)"), | ||
('--doubling-time', float, 0.0, None, "Doubling time before social distancing (days)"), | ||
('--hospitalized-los', int, 0, None, "Hospitalized Length of Stay (days)"), | ||
('--hospitalized-rate', float, 0.00001, 1.0, "Hospitalized Rate: 0.00001 - 1.0"), | ||
('--icu-los', int, 0, None, "ICU Length of Stay (days)"), | ||
('--icu-rate', float, 0.0, 1.0, "ICU Rate: 0.0 - 1.0"), | ||
('--known-infected', int, 0, None, | ||
"Currently Known Regional Infections (>=0) (only used to compute detection rate - does not change projections)"), | ||
('--market_share', float, 0.00001, 1.0, "Hospital Market Share (0.00001 - 1.0)"), | ||
('--n-days', int, 0, None, "Nuber of days to project >= 0"), | ||
('--relative-contact-rate', float, 0.0, 1.0, "Social Distancing Reduction Rate: 0.0 - 1.0"), | ||
('--susceptible', int, 1, None, "Regional Population >= 1"), | ||
('--ventilated-los', int, 0, None, "Hospitalized Length of Stay (days)"), | ||
('--ventilated-rate', float, 0.0, 1.0, "Ventilated Rate: 0.0 - 1.0"), | ||
): | ||
parser.add_argument(arg, type=validator(cast, min_value, max_value)) | ||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
"""Main.""" | ||
a = parse_args() | ||
|
||
p = Parameters( | ||
current_hospitalized=a.current_hospitalized, | ||
doubling_time=a.doubling_time, | ||
known_infected=a.known_infected, | ||
market_share=a.market_share, | ||
relative_contact_rate=a.relative_contact_rate, | ||
susceptible=a.susceptible, | ||
n_days=a.n_days, | ||
hospitalized=RateLos(a.hospitalized_rate, a.hospitalized_los), | ||
icu=RateLos(a.icu_rate, a.icu_los), | ||
ventilated=RateLos(a.ventilated_rate, a.ventilated_los), | ||
) | ||
|
||
raw_df = DataFrame({ | ||
"Susceptible": p.susceptible_v, | ||
"Infected": p.infected_v, | ||
"Recovered": p.recovered_v, | ||
}) | ||
admits_df = build_admissions_df(p.n_days, *p.dispositions) | ||
census_df = build_census_df(admits_df, *p.lengths_of_stay) | ||
|
||
prefix = a.prefix | ||
for df, name in ( | ||
(raw_df, 'raw'), | ||
(admits_df, 'admits'), | ||
(census_df, 'census'), | ||
): | ||
df.to_csv(prefix + name + '.csv') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--current-hospitalized 6 | ||
--doubling-time 6.0 | ||
--known-infected 157 | ||
--relative-contact-rate 0.0 | ||
--hospitalized-los 7 | ||
--hospitalized-rate 0.05 | ||
--icu-los 9 | ||
--icu-rate 0.02 | ||
--market_share 0.15 | ||
--n-days 60 | ||
--susceptible 4119405 | ||
--ventilated-los 10 | ||
--ventilated-rate 0.01 |