diff --git a/cara/models.py b/cara/models.py index ec81b37c..291dcfc1 100644 --- a/cara/models.py +++ b/cara/models.py @@ -526,8 +526,8 @@ Expiration.types = { @dataclass(frozen=True) class Activity: - inhalation_rate: float - exhalation_rate: float + inhalation_rate: _VectorisedFloat + exhalation_rate: _VectorisedFloat #: Pre-populated examples of activities. types: typing.ClassVar[typing.Dict[str, "Activity"]] diff --git a/cara/tests/models/test_exposure_model.py b/cara/tests/models/test_exposure_model.py index 34ed03af..464f25a9 100644 --- a/cara/tests/models/test_exposure_model.py +++ b/cara/tests/models/test_exposure_model.py @@ -46,20 +46,37 @@ populations = [ 10, halftime, models.Mask(0.95, 0.15, np.array([0.3, 0.35])), models.Activity.types['Standing'], ), + # A population with some array component for inhalation_rate. + models.Population( + 10, halftime, models.Mask.types['Type I'], + models.Activity(np.array([0.51,0.57]), 0.57), + ), ] @pytest.mark.parametrize( - "population, cm, expected_exposure",[ - [populations[1], KnownConcentrations(lambda t: 1.2), np.array([14.4, 14.4])], - [populations[0], KnownConcentrations(lambda t: np.array([1.2, 2.4])), np.array([14.4, 28.8])], - [populations[1], KnownConcentrations(lambda t: np.array([1.2, 2.4])), np.array([14.4, 28.8])], + "population, cm, expected_exposure, expected_probability",[ + [populations[1], KnownConcentrations(lambda t: 1.2), + np.array([14.4, 14.4]), np.array([99.6803184113, 99.5181053773])], + + [populations[2], KnownConcentrations(lambda t: 1.2), + np.array([14.4, 14.4]), np.array([99.4146994564, 99.6803184113])], + + [populations[0], KnownConcentrations(lambda t: np.array([1.2, 2.4])), + np.array([14.4, 28.8]), np.array([99.6803184113, 99.9989780368])], + + [populations[1], KnownConcentrations(lambda t: np.array([1.2, 2.4])), + np.array([14.4, 28.8]), np.array([99.6803184113, 99.9976777757])], ]) -def test_exposure_model_ndarray(population, cm, expected_exposure): +def test_exposure_model_ndarray(population, cm, + expected_exposure, expected_probability): model = ExposureModel(cm, population) np.testing.assert_almost_equal( model.quanta_exposure(), expected_exposure ) + np.testing.assert_almost_equal( + model.infection_probability(), expected_probability, decimal=10 + ) assert isinstance(model.infection_probability(), np.ndarray) assert isinstance(model.expected_new_cases(), np.ndarray) diff --git a/cara/tests/test_infected_population.py b/cara/tests/test_infected_population.py index ab9e36d3..39fbc039 100644 --- a/cara/tests/test_infected_population.py +++ b/cara/tests/test_infected_population.py @@ -3,13 +3,14 @@ import pytest import cara.models + @pytest.mark.parametrize( "override_params", [ {'viral_load_in_sputum': np.array([5e8, 1e9])}, {'coefficient_of_infectivity': np.array([0.02, 0.05])}, {'η_exhale': np.array([0.92, 0.95])}, {'η_leaks': np.array([0.15, 0.20])}, - + {'exhalation_rate': np.array([0.75, 0.81])}, ] ) def test_infected_population_vectorisation(override_params): @@ -19,6 +20,7 @@ def test_infected_population_vectorisation(override_params): 'coefficient_of_infectivity': 0.02, 'η_exhale': 0.95, 'η_leaks': 0.15, + 'exhalation_rate': 0.75, } defaults.update(override_params) @@ -33,7 +35,7 @@ def test_infected_population_vectorisation(override_params): ), activity=cara.models.Activity( 0.51, - 0.75, + defaults['exhalation_rate'], ), virus=cara.models.Virus( halflife=defaults['virus_halflife'],