variable renaming for the exposure and inhaled_exposure

This commit is contained in:
Luis Aleixo 2021-09-02 16:19:32 +02:00
parent 70bde2f3fe
commit cb334cbafa
3 changed files with 15 additions and 15 deletions

View file

@ -114,7 +114,7 @@ def calculate_report_data(model: models.ExposureModel):
exposed_occupants = model.exposed.number
expected_new_cases = np.array(model.expected_new_cases()).mean()
cumulative_doses = [
np.array(model.cumulated_exposure_vs_time(float(time))).mean()
np.array(model.inhaled_exposure_between_bounds(float(time))).mean()
for time in times
]
@ -276,7 +276,7 @@ def comparison_plot(scenarios: typing.Dict[str, dict], sample_times: typing.List
concentrations = statistics['concentrations']
#See CERN-OPEN-2021-004, p. 15, eq. 16. - Cumulative Dose
qds = [np.mean(model.cumulated_exposure_vs_time(t)) for t in sample_times]
qds = [np.mean(model.inhaled_exposure_between_bounds(t)) for t in sample_times]
# Plot concentrations and cumulative dose
if name in dash_styled_scenarios:

View file

@ -877,8 +877,8 @@ class ExposureModel:
#: The fraction of viruses actually deposited in the respiratory tract
fraction_deposited: _VectorisedFloat = 0.6
def exposure_vs_time(self, time: float) -> _VectorisedFloat:
"""The number of virus per meter^3 integrated until time."""
def exposure_between_bounds(self, time: float) -> _VectorisedFloat:
"""The cumulative number of virions per meter^3 from model start to the given time."""
exposure = 0.0
for start, stop in self.exposed.presence.boundaries():
@ -896,13 +896,13 @@ class ExposureModel:
def exposure(self) -> _VectorisedFloat:
"""The number of virions per meter^3 for the full simulation time."""
if self.exposed.presence.transition_times():
return self.exposure_vs_time(max(self.exposed.presence.transition_times()))
return self.exposure_between_bounds(max(self.exposed.presence.transition_times()))
else:
return 0
def cumulated_exposure_vs_time(self, time: float) -> _VectorisedFloat:
def inhaled_exposure_between_bounds(self, time: float) -> _VectorisedFloat:
exposure = self.exposure_vs_time(time)
exposure = self.exposure_between_bounds(time)
return (
self.exposed.activity.inhalation_rate *
@ -910,14 +910,14 @@ class ExposureModel:
exposure * self.fraction_deposited
)
def cumulated_exposure(self) -> _VectorisedFloat:
def inhaled_exposure(self) -> _VectorisedFloat:
if self.exposed.presence.transition_times():
return self.cumulated_exposure_vs_time(max(self.exposed.presence.transition_times()))
return self.inhaled_exposure_between_bounds(max(self.exposed.presence.transition_times()))
else:
return 0
def infection_probability(self) -> _VectorisedFloat:
inf_aero = self.cumulated_exposure()
inf_aero = self.inhaled_exposure()
# Probability of infection.
return (1 - np.exp(-(inf_aero/self.concentration_model.virus.infectious_dose))) * 100

View file

@ -70,7 +70,7 @@ def known_concentrations(func):
@pytest.mark.parametrize(
"population, cm, f_dep, expected_exposure, expected_cumulated_exposure, expected_probability",[
"population, cm, f_dep, expected_exposure, expected_inhaled_exposure, expected_probability",[
[populations[1], known_concentrations(lambda t: 36.), 1.,
np.array([432, 432]), np.array([172.368, 160.056]), np.array([99.6803184113, 99.5181053773])],
@ -87,7 +87,7 @@ def known_concentrations(func):
864, np.array([123.12, 246.24]), np.array([98.3493482895, 99.9727534893])],
])
def test_exposure_model_ndarray(population, cm, f_dep,
expected_exposure, expected_cumulated_exposure, expected_probability):
expected_exposure, expected_inhaled_exposure, expected_probability):
model = ExposureModel(cm, population, fraction_deposited=f_dep)
np.testing.assert_almost_equal(
model.exposure(), expected_exposure
@ -96,15 +96,15 @@ def test_exposure_model_ndarray(population, cm, f_dep,
model.infection_probability(), expected_probability, decimal=10
)
np.testing.assert_almost_equal(
model.cumulated_exposure(), expected_cumulated_exposure, decimal=10
model.inhaled_exposure(), expected_inhaled_exposure, decimal=10
)
assert isinstance(model.infection_probability(), np.ndarray)
assert isinstance(model.expected_new_cases(), np.ndarray)
assert isinstance(model.cumulated_exposure(), np.ndarray)
assert isinstance(model.inhaled_exposure(), np.ndarray)
assert model.infection_probability().shape == (2,)
assert model.expected_new_cases().shape == (2,)
assert model.cumulated_exposure().shape == (2,)
assert model.inhaled_exposure().shape == (2,)
@pytest.mark.parametrize("population", populations)