Beispiel #1
0
 def test_records(self, jhu_data, population_data):
     scenario = Scenario(jhu_data, population_data, country="Italy")
     record_df = scenario.records(show_figure=False)
     warnings.filterwarnings("ignore", category=UserWarning)
     record_df = scenario.records(show_figure=True)
     assert isinstance(record_df, pd.DataFrame)
     assert set(record_df.columns) == set(Term.NLOC_COLUMNS)
 def test_interactive(self, jhu_data, population_data, country):
     with pytest.raises(ValueError):
         Scenario()
     # Setting
     scenario = Scenario(country=country)
     scenario.register(jhu_data, population_data)
     # Force interactive
     scenario._interactive = True
     warnings.filterwarnings("ignore", category=UserWarning)
     scenario.records(show_figure=True)
 def test_records(self, jhu_data, population_data, country):
     warnings.simplefilter("ignore", category=UserWarning)
     # Setting
     snl = Scenario(jhu_data, population_data, country)
     snl.first_date = "01Apr2020"
     snl.last_date = "01Aug2020"
     # Test
     df = snl.records(show_figure=False)
     assert isinstance(df, pd.DataFrame)
     assert set(df.columns) == set(Term.NLOC_COLUMNS)
     dates = df[Term.DATE]
     assert dates.min() == Term.date_obj(snl.first_date)
     assert dates.max() == Term.date_obj(snl.last_date)
     df2 = snl.records(show_figure=True)
     assert isinstance(df2, pd.DataFrame)
     assert set(df2.columns) == set(Term.NLOC_COLUMNS)
Beispiel #4
0
 def test_complement(self, jhu_data, population_data, country):
     max_ignored = 100
     # Auto complement
     snl = Scenario(jhu_data,
                    population_data,
                    country,
                    auto_complement=True)
     recovered = snl.records(show_figure=False)[Term.R]
     assert recovered[recovered > max_ignored].value_counts().max() == 1
     # Restore the raw data
     snl.complement_reverse()
     recovered = snl.records(show_figure=False)[Term.R]
     assert recovered[recovered > max_ignored].value_counts().max() != 1
     # Complement
     snl.complement()
     recovered = snl.records(show_figure=False)[Term.R]
     assert recovered[recovered > max_ignored].value_counts().max() == 1
Beispiel #5
0
 def test_scenario(self):
     area = {"country": "Theoretical"}
     # Set-up example dataset (from 01Jan2020 to 31Jan2020)
     example_data = ExampleData(tau=1440, start_date="01Jan2020")
     example_data.add(SIRF, step_n=30, **area)
     # Population value
     population_data = PopulationData(filename=None)
     population_data.update(SIRF.EXAMPLE["population"], **area)
     # Set-up Scenario instance
     snl = Scenario(tau=1440, **area)
     snl.register(example_data, population_data)
     # Check records
     record_df = snl.records(variables="CFR")
     assert set(record_df.columns) == set(
         [Term.DATE, Term.C, Term.F, Term.R])
     # Add a past phase to 31Jan2020 with parameter values
     snl.add(model=SIRF, **SIRF.EXAMPLE["param_dict"])
     # Check summary
     df = snl.summary()
     assert not df.empty
     assert len(df) == 1
     assert Term.RT in df
     # Main scenario
     snl.add(end_date="31Dec2020", name="Main")
     assert snl.get(Term.RT, phase="last", name="Main") == 2.50
     # Lockdown scenario
     snl.clear(name="Lockdown")
     rho_lock = snl.get("rho", phase="0th") * 0.5
     snl.add(end_date="31Dec2020", name="Lockdown", rho=rho_lock)
     assert snl.get(Term.RT, phase="last", name="Lockdown") == 1.25
     # Medicine scenario
     snl.clear(name="Medicine")
     kappa_med = snl.get("kappa", phase="0th") * 0.5
     sigma_med = snl.get("sigma", phase="0th") * 2
     snl.add(end_date="31Dec2020",
             name="Medicine",
             kappa=kappa_med,
             sigma=sigma_med)
     assert snl.get(Term.RT, phase="last", name="Medicine") == 1.31
     # Add vaccine scenario
     snl.clear(name="Vaccine")
     rho_vac = snl.get("rho", phase="0th") * 0.8
     kappa_vac = snl.get("kappa", phase="0th") * 0.6
     sigma_vac = snl.get("sigma", phase="0th") * 1.2
     snl.add(end_date="31Dec2020",
             name="Vaccine",
             rho=rho_vac,
             kappa=kappa_vac,
             sigma=sigma_vac)
     assert snl.get(Term.RT, phase="last", name="Vaccine") == 1.72
     # Description
     snl.describe()
     # History
     snl.history("Rt")
     snl.history("rho")
     snl.history("Infected")
     snl.history_rate(name="Medicine")
     snl.simulate(name="Vaccine")
 def test_records(self, jhu_data, population_data):
     scenario = Scenario(jhu_data, population_data, country="Italy")
     record_df = scenario.records(show_figure=False)
     assert isinstance(record_df, pd.DataFrame)
     assert set(record_df.columns) == set(Term.NLOC_COLUMNS)