lisphilar / covid19-sir

CovsirPhy: Python library for COVID-19 analysis with phase-dependent SIR-derived ODE models.

Home Page:https://lisphilar.github.io/covid19-sir/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] how to set data range with `Dynamics()` and `Dynamics.from_data()`

shik-design opened this issue · comments

Checkbox

  • I agree to follow code of conduct and to engage in discussion actively.
  • I agree to create a new issue with the other templates if developers request.

Question

dyn_act = cs.Dynamics.from_data(model=cs.SIRModel, data=actual_df, name="None")
dyn_act.register().tail()

where will I run the above codes with date_range=("01Jan2022", "30Jun2022")

What tried

import covsirphy as cs
print(cs.__version__)


dyn_act = cs.Dynamics.from_data(model=cs.SIRModel, date_range=("01Jan2022", "30Jun2022"), data=actual_df, name="None")
dyn_act.register().tail()


### Additional Context

_No response_

We have two solutions.

  1. Subset actual_df with pandas.DatetimeIndex
dyn_act = cs.Dynamics.from_data(model=cs.SIRModel, data=actual_df["2022-01-01":"2022-06-30"], name=None)
dyn_act.register().tail()
  1. Initialize Dynamics instance without .from_data() class method
dyn_act = cs.Dynamics(model=cs.SIRModel, date_range=("01Jan2022", "30Jun2022"), name=None)
dyn_act.register(data=actual_df).tail()

Note that Dynamics.from_data() calls Dynamics(...) and Dynamics.register(...), setting the min/max dates of actual_df as the date range automaticallly.

@classmethod
def from_data(cls, model: ODEModel, data: pd.DataFrame, tau: int | None = 1440, name: str | None = None) -> Self:
"""Initialize model with data.
Args:
data: new data to overwrite the current information
Index
Date (pandas.Timestamp): Observation dates
Columns
Susceptible (int): the number of susceptible cases
Infected (int): the number of currently infected cases
Fatal (int): the number of fatal cases
Recovered (int): the number of recovered cases
(numpy.float64): ODE parameter values defined with the ODE model (optional)
tau: tau value [min] or None (un-set)
name: name of dynamics to show in figures (e.g. "baseline") or None (un-set)
Returns:
initialized model
Note:
Regarding @date_range, refer to covsirphy.ODEModel.from_sample().
"""
Validator(model, "model", accept_none=False).subclass(ODEModel)
Validator(data, "data").dataframe(time_index=True)
instance = cls(model=model, date_range=(data.index.min(), data.index.max()), tau=tau, name=name)
instance.register(data=data)
return instance

Thanks a lot