Closed AnujTiwari closed 3 years ago
Memo: I saved the data as "input/Barbour.csv" in my PC and raised the error with the following codes.
from datetime import timedelta
import pandas as pd
import numpy as np
import covsirphy as cs
loader = cs.DataLoader(update_interval=None)
loader.read_csv("input/Barbour.csv", parse_dates=["date"], dayfirst=False)
loader.assign(country="US")
loader.lock(
date="date", country="country", province="county",
confirmed="confirmed", fatal="fatal", recovered="recovered",
population="population",
)
jhu_data = loader.jhu()
snl = cs.Scenario(country="US", province="Barbour")
snl.register(jhu_data)
snl.records(variables="CIFR")
current_date = snl.today
fourteen_days_before = pd.to_datetime(current_date) - timedelta(days=14)
snl.clear(include_past=True)
snl.add(end_date=fourteen_days_before)
snl.add(end_date=current_date)
snl.estimate(cs.SIRF)
snl.summary()
snl.simulate()
Details of the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../covid19-sir/covsirphy/analysis/scenario.py", line 833, in simulate
sim_df = tracker.simulate().set_index(self.DATE).loc[start:end, variables]
File ".../covid19-sir/covsirphy/analysis/phase_tracker.py", line 376, in simulate
sim_df = handler.simulate()
File ".../covid19-sir/covsirphy/ode/ode_handler.py", line 91, in simulate
raise UnExecutedError("ODEHandler.add()")
covsirphy.util.error.UnExecutedError: Please execute ODEHandler.add() in advance.
Memo:
Internal variable PhaseTracker._track_df
is a dataframe with time index (Date) and many columns, including estimated parameter values and estimated DAY parameter values (1/beta [day] etc.). Simulation needs parameter values saved in this dataframe.
At the previous version 2.21.0-lambda-fu1, all rows which have any NA cells are ignored by .dropna()
. When DAY parameters are NAs, this implementation lead to empty data for simulation unexpectedly and raised the error covsirphy.util.error.UnExecutedError: Please execute ODEHandler.add() in advance.
With pull request #896, only rows which have NAs as parameter values will be ignored. NAs of parameter values are not acceptable in simulation, but NAs of DAY parameter values are acceptable in simulation because DAY parameter values are not used for simulation.
Dear @AnujTiwari ,
I think this was solved with #896 (version 2.21.0-mu) and we can use Scenario.simulate()
and Scenario.estimate_accuracy()
method as expected. Please confirm this.
https://gist.github.com/lisphilar/1816d3677a836de61452d443207e9e47
Hi Lisphilar, Thanks for the update. I confirm that this function works well.
Thank you, I will close this issue.
Summary
When we run "snl.estimate_accuracy()" without snl.trend(), such as in case of manually adding change points and estiamting SIR-F values. CovSirPhy shows an error message Please` execute ODEHandler.add() in advance
Codes
loader = cs.DataLoader(update_interval=None) loader.read_csv("Barbour.csv", parse_dates=["date"], dayfirst=False) loader.local
loader.assign(country="US").local.columns
loader.lock( date="date", country="country", province="county", confirmed="confirmed", fatal="fatal", recovered="recovered", population="population", ) loader.locked
jhu_data = loader.jhu() snl = cs.Scenario(country="US", province="Barbour") snl.register(jhu_data) snl.records(variables="CIFR");
current_date = snl.today pd.to_datetime(current_date) fourteen_days_before = pd.to_datetime(current_date) - timedelta(days=14) fourteen_days_before
snl.clear(include_past=True) snl.add(end_date=fourteen_days_before) snl.add(end_date=current_date) snl.summary()
snl.estimate(cs.SIRF) snl.summary()
snl.simulate()
Outputs
UnExecutedError: Please execute ODEHandler.add() in advance.
Environment