Skip to content

Commit

Permalink
merged tests (custom and fixed)
Browse files Browse the repository at this point in the history
  • Loading branch information
lrdossan committed Nov 22, 2023
1 parent 11cbc85 commit 8bd53e5
Showing 1 changed file with 5 additions and 49 deletions.
54 changes: 5 additions & 49 deletions caimira/tests/models/test_fitting_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
['Light activity', [8, 12, 17], [1.25, 0.25]],
['Moderate activity', [8, 13, 15, 16, 17], [2.25, 0.25, 3.45, 0.25]],
['Heavy exercise', [8, 17], [0.25]],
['Seated', [8, 17], [0.25]],
['Standing', [8, 17], [2.45]],
]
)
def test_fitting_algorithm_custom_ventilation(activity_type, ventilation_active, air_exch):
def test_fitting_algorithm(activity_type, ventilation_active, air_exch):
conc_model = models.CO2ConcentrationModel(
room=models.Room(
volume=75, inside_temp=models.PiecewiseConstant((0., 24.), (293,))),
Expand Down Expand Up @@ -48,54 +50,8 @@ def test_fitting_algorithm_custom_ventilation(activity_type, ventilation_active,
fit_parameters = data_model.CO2_fit_params()
exhalation_rate = fit_parameters['exhalation_rate']
npt.assert_almost_equal(
round(exhalation_rate, 2), conc_model.CO2_emitters.activity.exhalation_rate)
exhalation_rate, conc_model.CO2_emitters.activity.exhalation_rate, decimal=2)

ventilation_values = fit_parameters['ventilation_values']
npt.assert_allclose([round(vent, 2) for vent in ventilation_values], air_exch)


@pytest.mark.parametrize(
"activity_type, air_exch", [
['Seated', 0.25],
['Standing', 2.45],
]
)
def test_fitting_algorithm_fixed_ventilation(activity_type, air_exch):
conc_model = models.CO2ConcentrationModel(
room=models.Room(
volume=75, inside_temp=models.PiecewiseConstant((0., 24.), (293,))),
ventilation=models.AirChange(active=models.PeriodicInterval(120, 120), air_exch=air_exch),
CO2_emitters=models.SimplePopulation(
number=models.IntPiecewiseConstant(transition_times=tuple(
[8, 12, 13, 17]), values=tuple([2, 1, 2])),
presence=None,
activity=models.Activity.types[activity_type]
),
)

times = np.linspace(8, 17, 100)
CO2_concentrations = [
conc_model.concentration(float(time))
for time in times
]

# Generate CO2DataModel
data_model = models.CO2DataModel(
room_volume=75,
number=models.IntPiecewiseConstant(transition_times=tuple(
[8, 12, 13, 17]), values=tuple([2, 1, 2])),
presence=None,
ventilation_transition_times=tuple([8, 17]),
times=times,
CO2_concentrations=CO2_concentrations
)

fit_parameters = data_model.CO2_fit_params()

exhalation_rate = fit_parameters['exhalation_rate']
npt.assert_almost_equal(
round(exhalation_rate, 2), conc_model.CO2_emitters.activity.exhalation_rate)

ventilation_values = fit_parameters['ventilation_values']
npt.assert_almost_equal(round(ventilation_values[0], 2), air_exch)
npt.assert_allclose(ventilation_values, air_exch, rtol=1e-2)

0 comments on commit 8bd53e5

Please sign in to comment.