def roi_df(args, model_name, roi): if args.fixed_t: args.roi = roi # Temporary 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) global_start = datetime.strptime('01/22/20', '%m/%d/%y') frame_start = datetime.strptime(t0, '%m/%d/%y') day_offset = (frame_start - global_start).days else: day_offset = 0 model_path = ncs.get_model_path(args.models_path, model_name) extension = ['csv', 'pkl'][args.fit_format] rois = ncs.list_rois(args.fits_path, model_name, extension) if args.rois: rois = list(set(rois).intersection(args.rois)) fit_path = ncs.get_fit_path(args.fits_path, model_name, roi) if args.fit_format == 1: fit = ncs.load_fit(fit_path, model_path) stats = ncs.get_waic_and_loo(fit) samples = fit.to_dataframe() elif args.fit_format == 0: samples = ncs.extract_samples(args.fits_path, args.models_path, model_name, roi, args.fit_format) stats = ncs.get_waic(samples) df = ncs.make_table(roi, samples, args.params, stats, quantiles=args.quantiles, day_offset=day_offset) return model_name, roi, df
def get_weeks(args, rois): """Build dataframe containing roi and number of weeks of data per roi. Need this to calculate number of parameters per model to then calulate AIC. Return dataframe, then merge on roi on big table. """ # Create lists: rois, and num weeks. roi_weeks = {} 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 if not args.totwk: stan_data, t0, num_weeks = ncs.get_stan_data(csv, args) if args.totwk: stan_data, t0, num_weeks = ncs.get_stan_data_weekly_total( csv, args) roi_weeks[roi] = num_weeks df_numweek = pd.DataFrame(roi_weeks.items(), columns=['roi', 'num weeks']) df_numweek = df_numweek.set_index('roi').sort_index() return df_numweek
default=0, help=('Use a fixed time base (where 1/22/20 is t=0)' 'rather than a time base that is relative to the ' 'beginning of the data for each region')) args = parser.parse_args() 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)
default=1, help=('Number of iterations for eta adaptation (ADVI).')) args = parser.parse_args() 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 if not args.totwk: stan_data, t0, num_weeks = ncs.get_stan_data(csv, args) if args.totwk: stan_data, t0, num_weeks = ncs.get_stan_data_weekly_total(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 if not args.advi: