def test_add_phase_dep(self, jhu_data, population_data, country): # Setting snl = Scenario(jhu_data, population_data, country) snl.first_date = "01Apr2020" snl.last_date = "01Aug2020" # Test warnings.simplefilter("error") with pytest.raises(DeprecationWarning): snl.add_phase(end_date="01May2020") warnings.simplefilter("ignore") snl.add_phase(end_date="01May2020")
def test_analysis(self, jhu_data, population_data): scenario = Scenario(jhu_data, population_data, country="Italy") with pytest.raises(KeyError): scenario.simulate(name="Main", show_figure=False) with pytest.raises(ValueError): scenario.estimate(model=SIRF) # S-R trend analysis scenario.trend(show_figure=False) warnings.filterwarnings("ignore", category=UserWarning) scenario.trend(show_figure=True) # Parameter estimation of SIR-F model with pytest.raises(ValueError): scenario.param_history(targets=["Rt"], show_figure=False) with pytest.raises(ValueError): scenario.estimate(model=SIRF, tau=1440) scenario.estimate(model=SIRF) # History of estimation scenario.estimate_history(phase="1st") with pytest.raises(KeyError): scenario.estimate_history(phase="0th") # Accuracy of estimation scenario.estimate_accuracy(phase="1st") with pytest.raises(KeyError): scenario.estimate_accuracy(phase="0th") # Prediction scenario.add(name="Main", days=100) scenario.simulate(name="Main", show_figure=False) scenario.simulate(name="Main", show_figure=True) scenario.param_history(targets=["Rt"], show_figure=False) scenario.param_history(targets=["Rt"], divide_by_first=False) scenario.param_history(targets=["Rt"], show_box_plot=False) with pytest.raises(KeyError): scenario.param_history(targets=["Rt", "Value"]) with pytest.raises(KeyError): scenario.param_history(targets=["Rt"], box_plot=False) # New scenario sigma_new = scenario.get("sigma", phase="last") * 2 with pytest.raises(KeyError): scenario.get("value") warnings.filterwarnings("ignore", category=DeprecationWarning) scenario.add_phase(name="New medicines", days=100, sigma=sigma_new) # Summarize scenarios summary_df = scenario.summary() assert isinstance(summary_df, pd.DataFrame) desc_df = scenario.describe() assert isinstance(desc_df, pd.DataFrame) # Estimation errors with pytest.raises(TypeError): scenario.estimate(SIRF, phases="1st") with pytest.raises(KeyError): scenario.estimate(SIRF, phases=["100th"])
def test_analysis(self, jhu_data, population_data): scenario = Scenario(jhu_data, population_data, country="Italy") # S-R trend analysis scenario.trend(show_figure=False) # Parameter estimation of SIR-F model scenario.estimate(model=SIRF) # Prediction scenario.add_phase(name="Main", days=100) scenario.simulate(name="Main", show_figure=False) scenario.param_history(targets=["Rt"], name="Main", show_figure=False) # New scenario sigma_new = scenario.get("sigma", phase="last") * 2 scenario.add_phase(name="New medicines", days=100, sigma=sigma_new) # Summarize scenarios summary_df = scenario.summary() assert isinstance(summary_df, pd.DataFrame) desc_df = scenario.describe() assert isinstance(desc_df, pd.DataFrame)
def test_add_past_phases(self, jhu_data, population_data): scenario = Scenario(jhu_data, population_data, country="Italy") # With specified end date scenario.remove() scenario.add_phase(end_date="01May2020") scenario.add_phase(end_date="01Jun2020") scenario.add_phase() date_df = scenario.summary() assert len(date_df) == 3 # with specified length of the phase scenario.remove() scenario.add_phase(days=30) scenario.add_phase(days=30) scenario.add_phase() length_df = scenario.summary() assert len(length_df) == 3