Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
karanjogi committed Aug 24, 2023
1 parent 95a0424 commit fce33c4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions covsirphy/dynamics/sewirf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -177,15 +177,15 @@ 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),
"1/gamma [day]": round(self._tau / 24 / 60 / self._sigma)
}
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:
Expand Down
6 changes: 3 additions & 3 deletions covsirphy/dynamics/sird.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]:
Expand Down
6 changes: 3 additions & 3 deletions covsirphy/dynamics/sirf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_dynamics/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit fce33c4

Please sign in to comment.