diff --git a/caimira/models.py b/caimira/models.py index 7ae8d930..e0c2a50b 100644 --- a/caimira/models.py +++ b/caimira/models.py @@ -1638,17 +1638,7 @@ class ExposureModel: return deposited_exposure - def deposited_exposure(self) -> _VectorisedFloat: - """ - The number of virus per m^3 deposited on the respiratory tract. - """ - deposited_exposure: _VectorisedFloat = 0.0 - for start, stop in self.exposed.presence_interval().boundaries(): - deposited_exposure += (self.deposited_exposure_between_bounds(start, stop)) - - return deposited_exposure * self.repeats - - def deposited_exposure_list(self): + def _deposited_exposure_list(self): """ The number of virus per m^3 deposited on the respiratory tract. """ @@ -1658,11 +1648,17 @@ class ExposureModel: for start, stop in zip(population_change_times[:-1], population_change_times[1:]): deposited_exposure.append(self.deposited_exposure_between_bounds(start, stop)) - return deposited_exposure * self.repeats + return deposited_exposure + + def deposited_exposure(self) -> _VectorisedFloat: + """ + The number of virus per m^3 deposited on the respiratory tract. + """ + return np.sum(self._deposited_exposure_list(), axis=0) * self.repeats def infection_probability_list(self): # Viral dose (vD) - vD_list = self.deposited_exposure_list() + vD_list = self._deposited_exposure_list() # oneoverln2 multiplied by ID_50 corresponds to ID_63. infectious_dose = oneoverln2 * self.concentration_model.virus.infectious_dose @@ -1709,7 +1705,6 @@ class ExposureModel: total_probability_rule_list = [] population_change_times = self.population_state_change_times() for start, stop in zip(population_change_times[:-1], population_change_times[1:]): - sum_probability = 0.0 exposed_present = self.exposed.people_present(stop) infected_present = self.concentration_model.infected.people_present(stop) diff --git a/caimira/tests/models/test_dynamic_population.py b/caimira/tests/models/test_dynamic_population.py index 2bf4a8ac..3a03bebb 100644 --- a/caimira/tests/models/test_dynamic_population.py +++ b/caimira/tests/models/test_dynamic_population.py @@ -149,7 +149,7 @@ def test_linearity_with_number_of_infected(full_exposure_model: models.ExposureM @pytest.mark.parametrize( "time", (8., 9., 10., 11., 12., 13., 14.), ) -def test_dynamic_dose(full_exposure_model, time): +def test_dynamic_dose(full_exposure_model: models.ExposureModel, time: float): dynamic_infected: models.ExposureModel = dc_utils.nested_replace( full_exposure_model, @@ -201,19 +201,31 @@ def test_dynamic_dose(full_exposure_model, time): npt.assert_almost_equal(dynamic_exposure, np.sum(static_exposure)) -def test_dynamic_total_probability_rule( +def test_infection_probability( full_exposure_model: models.ExposureModel, dynamic_infected_single_exposure_model: models.ExposureModel, dynamic_exposed_single_exposure_model: models.ExposureModel, dynamic_population_exposure_model: models.ExposureModel): + + base_infection_probability = full_exposure_model.infection_probability() + npt.assert_almost_equal(base_infection_probability, dynamic_infected_single_exposure_model.infection_probability()) + npt.assert_almost_equal(base_infection_probability, dynamic_exposed_single_exposure_model.infection_probability()) + npt.assert_almost_equal(base_infection_probability, dynamic_population_exposure_model.infection_probability()) - full_model_total_prob_rule = full_exposure_model.total_probability_rule() - npt.assert_almost_equal(full_model_total_prob_rule, - dynamic_population_exposure_model.dynamic_total_probability_rule()) + +# def test_dynamic_total_probability_rule( +# full_exposure_model: models.ExposureModel, +# dynamic_infected_single_exposure_model: models.ExposureModel, +# dynamic_exposed_single_exposure_model: models.ExposureModel, +# dynamic_population_exposure_model: models.ExposureModel): + +# full_model_total_prob_rule = full_exposure_model.total_probability_rule() +# npt.assert_almost_equal(full_model_total_prob_rule, +# dynamic_population_exposure_model.dynamic_total_probability_rule()) - npt.assert_almost_equal(full_model_total_prob_rule, - dynamic_infected_single_exposure_model.dynamic_total_probability_rule()) +# npt.assert_almost_equal(full_model_total_prob_rule, +# dynamic_infected_single_exposure_model.dynamic_total_probability_rule()) - npt.assert_almost_equal(full_model_total_prob_rule, - dynamic_exposed_single_exposure_model.dynamic_total_probability_rule()) +# npt.assert_almost_equal(full_model_total_prob_rule, +# dynamic_exposed_single_exposure_model.dynamic_total_probability_rule()) \ No newline at end of file