Ejemplo n.º 1
0
 def test_ode(self, model):
     # Setting
     eg_tau = 1440
     area = {"country": "Full", "province": model.NAME}
     # Population
     population_data = PopulationData(filename=None)
     population_data.update(model.EXAMPLE["population"], **area)
     # Simulation
     example_data = ExampleData(tau=eg_tau, start_date="01Jan2020")
     example_data.add(model, **area)
     # Model-specialized records
     spe_df = example_data.specialized(**area)
     assert set(spe_df.columns) == set(
         [*Term.STR_COLUMNS, *model.VARIABLES])
     # Non-dimensional records
     nondim_df = example_data.non_dim(**area)
     assert set(nondim_df.columns) == set(
         [Term.TS, *list(model.VAR_DICT.keys())])
     # JHU-type records
     jhu_df = example_data.subset(**area)
     assert set(jhu_df.columns) == set(Term.NLOC_COLUMNS)
     # Calculate Rt/day parameters when parameters are None
     param_dict = {p: 0 for p in model.PARAMETERS}
     model_instance = model(population_data.value(**area), **param_dict)
     model_instance.calc_r0()
     model_instance.calc_days_dict(eg_tau)
Ejemplo n.º 2
0
 def test_ode(self, model):
     # Setting
     eg_tau = 1440
     # Simulation
     example_data = ExampleData(tau=eg_tau)
     example_data.add(model)
     nondim_df = example_data.non_dim(model)
     assert isinstance(nondim_df, pd.DataFrame)
     nondim_cols = [Term.TS, *list(model.VAR_DICT.keys())]
     assert set(nondim_df.columns) == set(nondim_cols)
     clean_df = example_data.cleaned()
     assert isinstance(clean_df, pd.DataFrame)
     assert set(clean_df.columns) == set(Term.COLUMNS)
     dim_df = example_data.subset(model)
     assert isinstance(dim_df, pd.DataFrame)
     assert set(dim_df.columns) == set(Term.NLOC_COLUMNS)
     # Estimation
     population = model.EXAMPLE["population"]
     estimator = Estimator(example_data,
                           model=model,
                           population=population,
                           country=model.NAME,
                           province=Term.UNKNOWN,
                           tau=eg_tau)
     estimator.run()
     estimated_df = estimator.summary(name=model.NAME)
     assert isinstance(estimated_df, pd.DataFrame)
     estimator.history(show_figure=False)
     estimator.accuracy(show_figure=False)
Ejemplo n.º 3
0
 def test_error(self, model):
     # Setting
     eg_tau = 1440
     # Simulation
     example_data = ExampleData(tau=eg_tau, start_date="01Jan2020")
     with pytest.raises(KeyError):
         assert not example_data.specialized(model=model).empty
     with pytest.raises(KeyError):
         assert not example_data.non_dim(model=model).empty
     example_data.add(model)
     # Model-specialized records
     with pytest.raises(ValueError):
         assert not example_data.specialized().empty
Ejemplo n.º 4
0
 def test_one_phase(self, model):
     example_data = ExampleData()
     example_data.add(model)
     with pytest.raises(ValueError):
         example_data.subset()
     # Subset
     subset_df = example_data.subset(model=model)
     assert subset_df.columns.tolist() == Term.SUB_COLUMNS
     example_data.subset(country=model.NAME)
     example_data.subset_complement(model=model)
     example_data.records(model=model)
     # Specialized
     specialized_df = example_data.specialized(model=model)
     assert specialized_df.columns.tolist() == [Term.DATE, *model.VARIABLES]
     # Non-dimensional
     nondim_df = example_data.non_dim(model=model)
     assert nondim_df.columns.tolist() == model.VARIABLES
     assert round(nondim_df.sum().sum()) == len(nondim_df)
Ejemplo n.º 5
0
 def test_ode_two_phases(self, population_data):
     # Setting
     eg_tau = 1440
     # Simulation
     example_data = ExampleData(tau=eg_tau)
     example_data.add(SIRF, step_n=30)
     example_data.add(SIRD, step_n=30)
     nondim_df = example_data.non_dim(SIRF)
     assert isinstance(nondim_df, pd.DataFrame)
     nondim_cols = [Term.TS, *list(SIRF.VAR_DICT.keys())]
     assert set(nondim_df.columns) == set(nondim_cols)
     clean_df = example_data.cleaned()
     assert isinstance(clean_df, pd.DataFrame)
     assert set(clean_df.columns) == set(Term.COLUMNS)
     dim_df = example_data.subset(SIRF)
     assert isinstance(dim_df, pd.DataFrame)
     assert set(dim_df.columns) == set(Term.NLOC_COLUMNS)
     # Scenario analysis
     population = SIRF.EXAMPLE["population"]
     population_data.update(population, country=SIRF.NAME)
     scenario = Scenario(example_data, population_data, country=SIRF.NAME)
     scenario.trend()