コード例 #1
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
コード例 #2
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)
コード例 #3
0
 def test_r0(self, model):
     eg_dict = model.EXAMPLE.copy()
     # Calculate r0
     model_ins = model(eg_dict["population"], **eg_dict["param_dict"])
     eg_r0 = model_ins.calc_r0()
     # Set-up example dataset (from 01Jan2020 to 31Jan2020)
     area = {"country": "Theoretical"}
     example_data = ExampleData(tau=1440, start_date="01Jan2020")
     example_data.add(model, step_n=180, **area)
     # Check the nature of r0
     df = example_data.specialized(model, **area)
     x_max = df.loc[df[Term.CI].idxmax(), Term.S] / eg_dict["population"]
     assert round(x_max, 2) == round(1 / eg_r0, 2)
コード例 #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)