cara/caimira/tests/test_expiration.py

60 lines
1.8 KiB
Python
Raw Normal View History

2021-05-27 10:33:12 +00:00
import re
import numpy as np
import numpy.testing as npt
import pytest
from retry import retry
2021-05-27 10:33:12 +00:00
from caimira import models
from caimira.monte_carlo.data import expiration_distribution
2021-05-27 10:33:12 +00:00
def test_multiple_wrong_weight_size():
weights = (1., 2., 3.)
e_base = models.Expiration(2.5)
2021-05-27 10:33:12 +00:00
with pytest.raises(
ValueError,
2022-01-27 14:38:25 +00:00
match=re.escape("expirations and weigths must contain the"
2021-05-27 10:33:12 +00:00
"same number of elements")
):
e = models.MultipleExpiration([e_base, e_base], weights)
def test_multiple_wrong_diameters():
weights = (1., 2., 3.)
e1 = models.Expiration(np.array([1., 1.]))
e2 = models.Expiration(1.)
e3 = models.Expiration(2.)
with pytest.raises(
ValueError,
2022-01-27 14:38:25 +00:00
match=re.escape("diameters must all be scalars")
):
e = models.MultipleExpiration([e1, e2, e3], weights)
2021-05-27 10:33:12 +00:00
def test_multiple():
2021-05-27 16:17:59 +00:00
weights = (1., 1.)
mask = models.Mask.types['Type I']
e1 = models.Expiration.types['Breathing']
e2 = models.Expiration.types['Singing']
aerosol_expected = (e1.aerosols(mask) + e2.aerosols(mask))/2.
e = models.MultipleExpiration([e1, e2], weights)
npt.assert_almost_equal(aerosol_expected, e.aerosols(mask))
@retry(tries=10)
2022-06-09 07:46:31 +00:00
# Expected values obtained from analytical formulas
@pytest.mark.parametrize(
2021-09-22 06:55:39 +00:00
"BLO_weights, expected_aerosols",
[
2021-09-22 06:55:39 +00:00
[(1.,0.,0.), 8.33551e-13],
[(1.,1.,1.), 2.20071e-11],
[(1.,5.,5.), 1.06701e-10],
],
)
def test_expiration_aerosols(data_registry, BLO_weights, expected_aerosols):
mask = models.Mask.types['No mask']
e = expiration_distribution(data_registry, BLO_weights)
2021-09-22 06:55:39 +00:00
npt.assert_allclose(e.build_model(100000).aerosols(mask).mean(),
expected_aerosols, rtol=1e-2)