Implement an emission_rate_when_present method on InfectedPopulation, so that we don't have to keep guessing a time when they are present.

This commit is contained in:
Phil Elson 2020-11-10 17:25:19 +01:00
parent 7b43eb0ea5
commit a9221c558b
3 changed files with 21 additions and 21 deletions

View file

@ -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()

View file

@ -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}')

View file

@ -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:
"""