From 9712ffc8ae464b59f9674e0973952d9d6a8893b2 Mon Sep 17 00:00:00 2001 From: Nicolas Mounet Date: Tue, 3 Oct 2023 12:05:31 +0200 Subject: [PATCH] Adapting zero removal rate case to case when RR is an array --- caimira/models.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/caimira/models.py b/caimira/models.py index db62293f..7a14f33f 100644 --- a/caimira/models.py +++ b/caimira/models.py @@ -1055,8 +1055,15 @@ class _ConcentrationModelBase: """ V = self.room.volume RR = self.removal_rate(time) - - return (self.population.people_present(time) / (RR * V) + + + if isinstance(RR, np.ndarray): + invRR = np.empty(RR.shape, dtype=np.float64) + invRR[RR == 0.] = np.nan + invRR[RR != 0.] = 1. / RR[RR != 0.] + else: + invRR = np.nan if RR == 0. else 1. / RR + + return (self.population.people_present(time) * invRR / V + self.min_background_concentration()/self.normalization_factor()) @method_cache @@ -1139,11 +1146,16 @@ class _ConcentrationModelBase: delta_time = time - t_last_state_change fac = np.exp(-RR * delta_time) - - if isinstance(RR, float) and RR == 0: - curr_conc_state = delta_time * self.population.people_present(time) / self.room.volume + if isinstance(RR, np.ndarray): + curr_conc_state = np.empty(RR.shape, dtype=np.float64) + curr_conc_state[RR == 0.] = delta_time * self.population.people_present(time) / ( + self.room.volume[RR == 0.] if isinstance(self.room.volume,np.ndarray) else self.room.volume) + curr_conc_state[RR != 0.] = self._normed_concentration_limit(next_state_change_time)[RR != 0.] * (1 - fac[RR != 0.]) else: - curr_conc_state = self._normed_concentration_limit(next_state_change_time) * (1 - fac) + if RR == 0.: + curr_conc_state = delta_time * self.population.people_present(time) / self.room.volume + else: + curr_conc_state = self._normed_concentration_limit(next_state_change_time) * (1 - fac) return curr_conc_state + conc_at_last_state_change * fac