From 1d78c1e4c66b7d6bf8d592c12567baecf1f8f72d Mon Sep 17 00:00:00 2001 From: Jogi Date: Tue, 22 Aug 2023 10:52:32 -0500 Subject: [PATCH] close #1486 --- covsirphy/dynamics/sewirf.py | 6 +++--- covsirphy/dynamics/sird.py | 6 +++--- covsirphy/dynamics/sirf.py | 6 +++--- tests/test_dynamics/test_model.py | 5 ++++- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/covsirphy/dynamics/sewirf.py b/covsirphy/dynamics/sewirf.py index 0afc0abad..8199f8fb1 100644 --- a/covsirphy/dynamics/sewirf.py +++ b/covsirphy/dynamics/sewirf.py @@ -163,7 +163,7 @@ def dimensional_parameters(self) -> dict[str, float | int]: """Calculate dimensional parameter values. Raises: - ZeroDivisionError: either kappa or rho_i for i=1,2,3 or sigma value was over 0 + ZeroDivisionError: rho_i for i=1,2,3 or sigma value was 0 Returns: dictionary of dimensional parameter values @@ -177,7 +177,7 @@ def dimensional_parameters(self) -> dict[str, float | int]: try: return { "alpha1 [-]": round(self._theta, 3), - "1/alpha2 [day]": round(self._tau / 24 / 60 / self._kappa), + "1/alpha2 [day]": round(self._tau / 24 / 60 / self._kappa) if self._kappa != 0 else np.NaN, "1/beta1 [day]": round(self._tau / 24 / 60 / self._rho1), "1/beta2 [day]": round(self._tau / 24 / 60 / self._rho2), "1/beta3 [day]": round(self._tau / 24 / 60 / self._rho3), @@ -185,7 +185,7 @@ def dimensional_parameters(self) -> dict[str, float | int]: } except ZeroDivisionError: raise ZeroDivisionError( - f"Kappa, rho_i for i=1,2,3 and sigma must be over 0 to calculate dimensional parameters with {self._NAME}.") from None + f"Rho_i for i=1,2,3 and sigma must be over 0 to calculate dimensional parameters with {self._NAME}.") from None @classmethod def from_data_with_quantile(cls, *args, **kwargs) -> NoReturn: diff --git a/covsirphy/dynamics/sird.py b/covsirphy/dynamics/sird.py index 5c2ebfb8a..a85dedf94 100644 --- a/covsirphy/dynamics/sird.py +++ b/covsirphy/dynamics/sird.py @@ -139,7 +139,7 @@ def dimensional_parameters(self) -> dict[str, int]: """Calculate dimensional parameter values. Raises: - ZeroDivisionError: either kappa or rho or sigma value was over 0 + ZeroDivisionError: either rho or sigma value was 0 Returns: dict of {str: int}: dictionary of dimensional parameter values @@ -149,13 +149,13 @@ def dimensional_parameters(self) -> dict[str, int]: """ try: return { - "1/alpha2 [day]": round(self._tau / 24 / 60 / self._kappa), + "1/alpha2 [day]": round(self._tau / 24 / 60 / self._kappa) if self._kappa != 0 else np.NaN, "1/beta [day]": round(self._tau / 24 / 60 / self._rho), "1/gamma [day]": round(self._tau / 24 / 60 / self._sigma) } except ZeroDivisionError: raise ZeroDivisionError( - f"Kappa, rho and sigma must be over 0 to calculate dimensional parameters with {self._NAME}.") from None + f"Rho and sigma must be over 0 to calculate dimensional parameters with {self._NAME}.") from None @classmethod def _param_quantile(cls, data: pd.DataFrame, q: float | pd.Series = 0.5) -> dict[str, float | pd.Series]: diff --git a/covsirphy/dynamics/sirf.py b/covsirphy/dynamics/sirf.py index f23186be3..7b1ff3284 100644 --- a/covsirphy/dynamics/sirf.py +++ b/covsirphy/dynamics/sirf.py @@ -80,7 +80,7 @@ def dimensional_parameters(self) -> dict[str, float | int]: """Calculate dimensional parameter values. Raises: - ZeroDivisionError: either kappa or rho or sigma value was over 0 + ZeroDivisionError: either rho or sigma value was 0 Returns: dictionary of dimensional parameter values @@ -92,13 +92,13 @@ def dimensional_parameters(self) -> dict[str, float | int]: try: return { "alpha1 [-]": round(self._theta, 3), - "1/alpha2 [day]": round(self._tau / 24 / 60 / self._kappa), + "1/alpha2 [day]": round(self._tau / 24 / 60 / self._kappa) if self._kappa != 0 else np.NaN, "1/beta [day]": round(self._tau / 24 / 60 / self._rho), "1/gamma [day]": round(self._tau / 24 / 60 / self._sigma) } except ZeroDivisionError: raise ZeroDivisionError( - f"Kappa, rho and sigma must be over 0 to calculate dimensional parameters with {self._NAME}.") from None + f"Rho and sigma must be over 0 to calculate dimensional parameters with {self._NAME}.") from None @classmethod def _param_quantile(cls, data: pd.DataFrame, q: float | pd.Series = 0.5) -> dict[str, float | pd.Series]: diff --git a/tests/test_dynamics/test_model.py b/tests/test_dynamics/test_model.py index bf49ac454..49adfb9af 100644 --- a/tests/test_dynamics/test_model.py +++ b/tests/test_dynamics/test_model.py @@ -74,8 +74,11 @@ def test_r0(model_class): def test_dimensional_parameters(model_class): model = model_class.from_sample() assert model.dimensional_parameters() - with pytest.raises(ZeroDivisionError): + if not isinstance(model, SIRModel): _dict = model.settings() + _dict.update(param_dict={'_kappa': 0}) + assert model_class(**_dict).dimensional_parameters() is not None + with pytest.raises(ZeroDivisionError): _dict.update(param_dict={param: 0 for param in _dict["param_dict"].keys()}) model_class(**_dict).dimensional_parameters()