From a9221c558bae78aa212c1bc3e0bfccbe828bbfc3 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Tue, 10 Nov 2020 17:25:19 +0100 Subject: [PATCH] Implement an emission_rate_when_present method on InfectedPopulation, so that we don't have to keep guessing a time when they are present. --- cara/apps/calculator/report_generator.py | 2 +- cara/apps/expert.py | 2 +- cara/models.py | 38 ++++++++++++------------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cara/apps/calculator/report_generator.py b/cara/apps/calculator/report_generator.py index 816b48fb..49a51920 100644 --- a/cara/apps/calculator/report_generator.py +++ b/cara/apps/calculator/report_generator.py @@ -23,7 +23,7 @@ def calculate_report_data(model: models.ExposureModel): concentrations = [model.concentration_model.concentration(time) for time in times] highest_const = max(concentrations) prob = model.infection_probability() - er = model.concentration_model.infected.emission_rate(0.1) + er = model.concentration_model.infected.emission_rate_when_present() exposed_occupants = model.exposed.number r0 = model.reproduction_rate() diff --git a/cara/apps/expert.py b/cara/apps/expert.py index 560b3fbf..0d8009ba 100644 --- a/cara/apps/expert.py +++ b/cara/apps/expert.py @@ -112,7 +112,7 @@ class WidgetView: self.out.clear_output() with self.out: P = model.infection_probability() - print(f'Emission rate (quanta/hr): {model.concentration_model.infected.emission_rate(0.1)}') + print(f'Emission rate (quanta/hr): {model.concentration_model.infected.emission_rate_when_present()}') print(f'Probability of infection: {np.round(P, 0)}%') print(f'Number of exposed: {model.exposed.number}') diff --git a/cara/models.py b/cara/models.py index 9d9a4747..533e8e75 100644 --- a/cara/models.py +++ b/cara/models.py @@ -419,31 +419,13 @@ class InfectedPopulation(Population): #: The type of expiration that is being emitted whilst doing the activity. expiration: Expiration - def emission_rate_if_present(self): + def emission_rate_when_present(self) -> float: """ The emission rate if the infected population is present. Note that the rate is not currently time-dependent. """ - - - def individual_emission_rate(self, time) -> float: - """ - The emission rate of a single individual in the population. - - """ - # Note: The original model avoids time dependence on the emission rate - # at the cost of implementing a piecewise (on time) concentration function. - - if not self.person_present(time): - return 0 - - # Note: It is essential that the value of the emission rate is not - # itself a function of time. Any change in rate must be accompanied - # with a declaration of state change time, as is the case for things - # like Ventilation. - # Emission Rate (infectious quantum / h) aerosols = self.expiration.aerosols(self.mask) if np.isinf(aerosols): @@ -457,6 +439,24 @@ class InfectedPopulation(Population): aerosols) return ER + def individual_emission_rate(self, time) -> float: + """ + The emission rate of a single individual in the population. + + """ + # Note: The original model avoids time dependence on the emission rate + # at the cost of implementing a piecewise (on time) concentration function. + + if not self.person_present(time): + return 0. + + # Note: It is essential that the value of the emission rate is not + # itself a function of time. Any change in rate must be accompanied + # with a declaration of state change time, as is the case for things + # like Ventilation. + + return self.emission_rate_when_present() + @functools.lru_cache() def emission_rate(self, time) -> float: """