Ejemplo n.º 1
0
def test_mitigation_statement():
    st.cleanup()
    expected_doubling = "outbreak **reduces the doubling time to 7.8** days"
    display_header(st, MODEL, PARAM)
    assert [s for s in st.render_store if expected_doubling in s]
    # assert len((list(filter(lambda s: expected_doubling in s, st.render_store))))
    st.cleanup()
    expected_halving = "outbreak **halves the infections every 51.9** days"
    halving_params = Parameters(
        current_hospitalized=100,
        doubling_time=6.0,
        known_infected=5000,
        market_share=0.05,
        relative_contact_rate=0.7,
        susceptible=500000,
        hospitalized=RateLos(0.05, 7),
        icu=RateLos(0.02, 9),
        ventilated=RateLos(0.01, 10),
        n_days=60,
    )
    halving_model = SimSirModel(halving_params)
    display_header(st, halving_model, halving_params)
    assert [s for s in st.render_store if expected_halving in s]
    #assert len((list(filter(lambda s: expected_halving in s, st.render_store))))
    st.cleanup()
Ejemplo n.º 2
0
def test_parameters():
    param = Parameters(
        current_hospitalized=100,
        doubling_time=6.0,
        known_infected=5000,
        market_share=0.05,
        relative_contact_rate=0.15,
        susceptible=500000,
        hospitalized=RateLos(0.05, 7),
        icu=RateLos(0.02, 9),
        ventilated=RateLos(0.01, 10),
        n_days=60,
    )

    # test the Parameters

    # hospitalized, icu, ventilated
    assert param.rates == (0.05, 0.02, 0.01)
    assert param.lengths_of_stay == (7, 9, 10)

    assert param.infected == 40000.0
    assert isinstance(param.infected, float)  # based off note in models.py

    # test the class-calculated attributes
    assert param.detection_probability == 0.125
    assert param.intrinsic_growth_rate == 0.12246204830937302
    assert param.beta == 3.2961405355450555e-07
    assert param.r_t == 2.307298374881539
    assert param.r_naught == 2.7144686763312222
    assert param.doubling_time_t == 7.764405988534983

    # test the things n_days creates, which in turn tests sim_sir, sir, and get_dispositions
    assert (len(param.susceptible_v) == len(param.infected_v) == len(
        param.recovered_v) == param.n_days + 1 == 61)

    assert param.susceptible_v[0] == 500000.0
    assert round(param.susceptible_v[-1], 0) == 67202
    assert round(param.infected_v[1], 0) == 43735
    assert round(param.recovered_v[30], 0) == 224048
    assert [d[0] for d in param.dispositions] == [100.0, 40.0, 20.0]
    assert [round(d[-1], 0)
            for d in param.dispositions] == [1182.0, 473.0, 236.0]

    # change n_days, make sure it cascades
    param.n_days = 2
    assert (len(param.susceptible_v) == len(param.infected_v) == len(
        param.recovered_v) == param.n_days + 1 == 3)

    # test that admissions are being properly calculated (thanks @PhilMiller)
    admissions = build_admissions_df(param)
    cumulative_admissions = admissions.cumsum()
    diff = cumulative_admissions["Hospitalized"][1:-1] - (
        0.05 * 0.05 * (param.infected_v[1:-1] + param.recovered_v[1:-1]) - 100)
    assert (diff.abs() < 0.1).all()
    assert len(param.susceptible_v) == len(param.infected_v) == len(
        param.recovered_v) == param.n_days + 1 == 3
def halving_param():
    return Parameters(
        current_date=datetime(year=2020, month=3, day=28),
        current_hospitalized=100,
        doubling_time=6.0,
        market_share=0.05,
        relative_contact_rate=0.7,
        population=500000,
        hospitalized=Disposition(0.05, 7),
        icu=Disposition(0.02, 9),
        ventilated=Disposition(0.01, 10),
        n_days=60,
    )
Ejemplo n.º 4
0
def halving_param():
    return Parameters(
        current_date=datetime(year=2020, month=3, day=28),
        current_hospitalized=100,
        doubling_time=6.0,
        hospitalized=Disposition.create(rate=0.05, days=7),
        icu=Disposition.create(rate=0.02, days=9),
        infectious_days=14,
        market_share=0.05,
        mitigation_date=datetime(year=2020, month=3, day=28),
        n_days=60,
        population=500000,
        recovered=0,
        relative_contact_rate=0.7,
        ventilated=Disposition.create(rate=0.01, days=10),
    )
def DEFAULTS():
    return Parameters(
        region=Regions(
            delaware=564696,
            chester=519293,
            montgomery=826075,
            bucks=628341,
            philly=1581000,
        ),
        current_date=datetime(year=2020, month=3, day=28),
        current_hospitalized=14,
        date_first_hospitalized=datetime(year=2020, month=3, day=7),
        doubling_time=4.0,
        n_days=60,
        market_share=0.15,
        relative_contact_rate=0.3,
        hospitalized=Disposition(0.025, 7),
        icu=Disposition(0.0075, 9),
        ventilated=Disposition(0.005, 10),
    )
Ejemplo n.º 6
0
def defaults():
    return Parameters(
        region=Regions(
            delaware=564696,
            chester=519293,
            montgomery=826075,
            bucks=628341,
            philly=1581000,
        ),
        current_date=datetime(year=2020, month=3, day=28),
        current_hospitalized=14,
        date_first_hospitalized=datetime(year=2020, month=3, day=7),
        doubling_time=4.0,
        hospitalized=Disposition.create(rate=0.025, days=7),
        icu=Disposition.create(rate=0.0075, days=9),
        infectious_days=14,
        n_days=60,
        market_share=0.15,
        mitigation_date=datetime(year=2020, month=3, day=28),
        recovered=0,
        relative_contact_rate=0.3,
        ventilated=Disposition.create(rate=0.005, days=10),
    )
Ejemplo n.º 7
0
import pandas as pd  # type: ignore
import numpy as np  # type: ignore
import altair as alt  # type: ignore

from src.penn_chime.charts import new_admissions_chart, admitted_patients_chart
from src.penn_chime.models import sir, sim_sir
from src.penn_chime.parameters import Parameters
from src.penn_chime.presentation import display_header
from src.penn_chime.settings import DEFAULTS
from src.penn_chime.defaults import RateLos

PARAM = Parameters(current_hospitalized=100,
                   doubling_time=6.0,
                   known_infected=5000,
                   market_share=0.05,
                   relative_contact_rate=0.15,
                   susceptible=500000,
                   hospitalized=RateLos(0.05, 7),
                   icu=RateLos(0.02, 9),
                   ventilated=RateLos(0.01, 10),
                   n_days=60)

# set up


# we just want to verify that st _attempted_ to render the right stuff
# so we store the input, and make sure that it matches what we expect
class MockStreamlit:
    def __init__(self):
        self.render_store = []
        self.markdown = self.just_store_instead_of_rendering
        self.latex = self.just_store_instead_of_rendering
Ejemplo n.º 8
0
)
from src.penn_chime.presentation import display_header

EPSILON = 1.e-7

# The defaults in settings will change and break the tests
DEFAULTS = Parameters(
    region=Regions(
        delaware=564696,
        chester=519293,
        montgomery=826075,
        bucks=628341,
        philly=1581000,
    ),
    current_date=datetime(year=2020, month=3, day=28),
    current_hospitalized=14,
    date_first_hospitalized=datetime(year=2020, month=3, day=7),
    doubling_time=4.0,
    n_days=60,
    market_share=0.15,
    relative_contact_rate=0.3,
    hospitalized=RateDays(0.025, 7),
    icu=RateDays(0.0075, 9),
    ventilated=RateDays(0.005, 10),
)

PARAM = Parameters(
    current_hospitalized=100,
    doubling_time=6.0,
    market_share=0.05,
    relative_contact_rate=0.15,