if args.n_threads == 0: args.n_threads = args.n_chains if args.n_iter < args.n_warmups: args.n_warmups = int(args.n_iter / 2) csv = Path(args.data_path) / ("covidtimeseries_%s.csv" % args.roi) csv = csv.resolve() assert csv.exists(), "No such csv file: %s" % csv stan_data, t0 = ncs.get_stan_data(csv, args) if stan_data is None: print("No data for %s; skipping fit." % args.roi) sys.exit(0) if args.n_data_only: print(ncs.get_n_data(stan_data)) sys.exit(0) init_fun = ncs.get_init_fun(args, stan_data) model_path = Path(args.models_path) / ('%s.stan' % args.model_name) model_path = model_path.resolve() assert model_path.is_file(), "No such .stan file: %s" % model_path control = {'adapt_delta': args.adapt_delta} stanrunmodel = ncs.load_or_compile_stan_model( args.model_name, args.models_path, force_recompile=args.force_recompile) # Fit Stan # fit = stanrunmodel.sampling(data=stan_data, init=init_fun, control=control, # chains=args.n_chains, # chain_id=np.arange(args.n_chains),
import pandas as pd from pathlib import Path import niddk_covid_sicr as ncs # Parse all the command-line arguments parser = argparse.ArgumentParser(description='') parser.add_argument('-dp', '--data-path', default='./data', help='Path to directory containing the data files') parser.add_argument('-ld', '--last-date', help=('Last date to use in the data; dates past this ' 'will be ignored')) args = parser.parse_args() # Get all model_names, roi combinations rois = ncs.list_rois(args.data_path, 'covidtimeseries', '.csv') df = pd.DataFrame(index=rois, columns=['n_data_pts'], dtype=int) for roi in rois: csv = Path(args.data_path) / ("covidtimeseries_%s.csv" % roi) csv = csv.resolve() assert csv.exists(), "No such csv file: %s" % csv stan_data, t0 = ncs.get_stan_data(csv, args) n_data = ncs.get_n_data(stan_data) df.loc[roi, 'n_data_pts'] = int(n_data) df.loc[roi, 't0'] = t0 df.index.name = 'roi' df['n_data_pts'] = df['n_data_pts'].astype(int) df['t0'] = df['t0'].astype('datetime64') df.to_csv('n_data.csv')