From 44f4280660701a8f245f46583b46dbc3ee26f152 Mon Sep 17 00:00:00 2001 From: AFg6K7h4fhy2 <127630341+AFg6K7h4fhy2@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:50:11 -0400 Subject: [PATCH] ignore extraneous comments --- model_comparison/compare.R | 175 +++++++++++++++++++++++++ pyrenew_flu_light/__init__.py | 2 - pyrenew_flu_light/checks.py | 6 +- pyrenew_flu_light/comp_inf.py | 6 +- pyrenew_flu_light/comp_obs.py | 4 +- pyrenew_flu_light/comp_tran.py | 10 +- pyrenew_flu_light/compare.py | 4 +- pyrenew_flu_light/filtered_data_NY | 164 +++++++++++++++++++++++ pyrenew_flu_light/model.py | 6 +- pyrenew_flu_light/pad.py | 2 - pyrenew_flu_light/plot.py | 8 +- pyrenew_flu_light/post.py | 2 - pyrenew_flu_light/pre.py | 2 - pyrenew_flu_light/run.py | 6 +- pyrenew_flu_light/tut_epim_port_msr.py | 44 +++---- 15 files changed, 377 insertions(+), 64 deletions(-) create mode 100644 model_comparison/compare.R create mode 100644 pyrenew_flu_light/filtered_data_NY diff --git a/model_comparison/compare.R b/model_comparison/compare.R new file mode 100644 index 0000000..ba91bad --- /dev/null +++ b/model_comparison/compare.R @@ -0,0 +1,175 @@ +library(dplyr) +library(tidyr) +library(readr) +library(lubridate) +library(forecasttools) + +read_posterior_samples <- function(file_path) { + posterior_samples <- read_csv(file_path) + return(posterior_samples) +} + +pivot_forecast_to_long <- function( + posterior_samples, + signal_name = "hosp", + time_name = "date" +) { + draws_wide <- tibble::tibble(as.data.frame(posterior_samples)) + names(draws_wide) <- posterior_samples$time + draws_long <- draws_wide %>% + dplyr::mutate(.draw = dplyr::row_number()) %>% + tidyr::pivot_longer(cols = -.draw, names_to = time_name, values_to = signal_name) + return(draws_long) +} +aggregate_to_epiweekly <- function(tidy_daily_trajectories) { + epiweekly_forecasts <- forecasttools::daily_to_epiweekly( + tidy_daily_trajectories, + value_col = "hosp", + id_cols = c(".draw"), + weekly_value_name = "weekly_hosp" + ) + return(epiweekly_forecasts) +} + +output_flusight_table <- function( + weekly_forecasts, + reference_date, + horizons, + output_path +) { + formatted_output <- forecasttools::trajectories_to_quantiles( + weekly_forecasts, + timepoint_cols = c("epiweek", "epiyear"), + value_col = "weekly_hosp" + ) %>% + dplyr::mutate( + location = forecasttools::loc_abbr_to_flusight_code(state) + ) %>% + forecasttools::get_flusight_table( + reference_date, + horizons = horizons + ) + + readr::write_csv(formatted_output, output_path) + return(formatted_output) +} + +generate_flusight_output <- function(file_paths, reference_date, horizons, output_path) { + for (file_path in file_paths) { + posterior_samples <- read_posterior_samples(file_path) + daily_forecasts <- pivot_forecast_to_long(posterior_samples) + weekly_forecasts <- aggregate_to_epiweekly(daily_forecasts) + formatted_output <- output_flusight_table(weekly_forecasts, reference_date, horizons, output_path) + } +} + + +file_paths <- c( + "posterior_predictive_forecasts_test_NY_2024-01-20.csv") +reference_date <- "2024-01-20" +horizons <- -1:3 +output_path <- "flusight_forecast_output_PFL_test_NY_2024-01-20.csv" + +generate_flusight_output( + file_paths, + reference_date, + horizons, + output_path) + + + + + + + +# library(forecasttools) +# library(tibble) +# library(dplyr) +# library(readr) +# library(lubridate) + +# pyrenew_flusight_forecast_from_csv <- function( +# spread_draws_csv, +# fitting_data_csv, +# output_path, +# reference_date, +# horizons = -1:3, +# seed = NULL +# ) { +# set.seed(seed) +# # read data from pyrenew-flu-light run +# spread_draws <- read_csv(spread_draws_csv) +# fitting_data <- read_csv(fitting_data_csv) +# # retrieve locations from fitting data +# locations <- unique(fitting_data$location) +# # parse over and collect forecasts and fitting data +# state_daily_forecast_list <- list() +# for (loc in locations) { +# state_fitting_data <- fitting_data %>% filter(location == loc) +# state_forecast <- spread_draws %>% filter(negbinom_rv_dim_0_index == loc) +# # forecasttools convert spread draws tiddy +# state_forecast_long <- state_forecast %>% +# dplyr::mutate(.draw = draw) %>% +# dplyr::select(.draw, date = negbinom_rv_dim_0_index, hosp = negbinom_rv) +# # go to epiweekly from daily +# state_weekly_forecasts <- forecasttools::daily_to_epiweekly( +# tidy_daily_trajectories = state_forecast_long, +# value_col = "hosp", +# date_col = "date", +# id_cols = ".draw" +# ) +# state_daily_forecast_list[[loc]] <- state_weekly_forecasts +# } +# cli::cli_inform("Formatting output for FluSight...") +# # flusight formatting +# state_flusight_tables <- list() +# full_table <- tibble::tibble() +# for (state in names(state_daily_forecast_list)) { +# state_flusight_table <- forecasttools::trajectories_to_quantiles( +# state_daily_forecast_list[[state]], +# timepoint_cols = c("epiweek", "epiyear"), +# value_col = "weekly_hosp" +# ) %>% +# dplyr::mutate( +# location = forecasttools::loc_abbr_to_flusight_code(state) +# ) %>% +# forecasttools:::get_flusight_table( +# reference_date, +# horizons = horizons +# ) + +# full_table <- dplyr::bind_rows( +# full_table, +# state_flusight_table +# ) +# } +# full_table <- full_table %>% +# dplyr::arrange( +# location, +# reference_date, +# horizon, +# output_type, +# output_type_id +# ) +# # save +# readr::write_csv( +# full_table, +# output_path +# ) +# return(full_table) +# } + +# spread_draws_csv <- "AL_2024-03-30_28_NegBinRv.csv" +# fitting_data_csv <- "filtered_data_AL.csv" +# output_path <- "flusight_output_AL.csv" +# reference_date <- "2024-03-30" +# horizons <- -1:3 + +# run_forecast_with_csvs( +# spread_draws_csv, +# fitting_data_csv, +# output_path, +# reference_date, +# horizons, +# seed = 62352 +# ) diff --git a/pyrenew_flu_light/__init__.py b/pyrenew_flu_light/__init__.py index 1e3a2c3..52a708b 100644 --- a/pyrenew_flu_light/__init__.py +++ b/pyrenew_flu_light/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from checks import ( assert_historical_data_files_exist, check_file_path_valid, diff --git a/pyrenew_flu_light/checks.py b/pyrenew_flu_light/checks.py index e49f6b2..191facb 100644 --- a/pyrenew_flu_light/checks.py +++ b/pyrenew_flu_light/checks.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ Methods to verify pathing and existence of certain files for use of pyrenew-flu-light. @@ -62,7 +60,7 @@ def load_config(config_path: str) -> dict[str, any]: return config -def ensure_output_directory(args: dict[str, any]): # numpydoc ignore=GL08 +def ensure_output_directory(args: dict[str, any]): output_directory = "./output/" if not os.path.exists(output_directory): os.makedirs(output_directory) @@ -79,7 +77,7 @@ def ensure_output_directory(args: dict[str, any]): # numpydoc ignore=GL08 def assert_historical_data_files_exist( reporting_date: str, -): # numpydoc ignore=GL08 +): data_directory = f"../model_comparison/data/{reporting_date}/" assert os.path.exists( data_directory diff --git a/pyrenew_flu_light/comp_inf.py b/pyrenew_flu_light/comp_inf.py index 3073f47..f04f91e 100644 --- a/pyrenew_flu_light/comp_inf.py +++ b/pyrenew_flu_light/comp_inf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ The infections process component in pyrenew-flu-light. """ @@ -36,7 +34,7 @@ def __init__( self, I0: ArrayLike, susceptibility_prior: numpyro.distributions, - ): # numpydoc ignore=GL08 + ): logging.info("Initializing CFAEPIM_Infections") self.I0 = I0 @@ -138,7 +136,7 @@ def sample( # calculate initial susceptible population S_{v-1} init_S = init_S_proportion * P - def update_infections(carry, Rt): # numpydoc ignore=GL08 + def update_infections(carry, Rt): S_t, I_recent = carry # compute raw infections diff --git a/pyrenew_flu_light/comp_obs.py b/pyrenew_flu_light/comp_obs.py index 26c6c70..59f1bae 100644 --- a/pyrenew_flu_light/comp_obs.py +++ b/pyrenew_flu_light/comp_obs.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ The observation process component in pyrenew-flu-light. """ @@ -44,7 +42,7 @@ def __init__( alpha_prior_dist, coefficient_priors, nb_concentration_prior, - ): # numpydoc ignore=GL08 + ): logging.info("Initializing CFAEPIM_Observation") # CFAEPIM_Observation.validate( diff --git a/pyrenew_flu_light/comp_tran.py b/pyrenew_flu_light/comp_tran.py index 0069aa1..5d170b1 100644 --- a/pyrenew_flu_light/comp_tran.py +++ b/pyrenew_flu_light/comp_tran.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ The transmission process (Rt) component in pyrenew-flu-light. """ @@ -18,14 +16,14 @@ from pyrenew.randomvariable import DistributionalVariable, TransformedVariable -class CFAEPIM_Rt(RandomVariable): # numpydoc ignore=GL08 +class CFAEPIM_Rt(RandomVariable): def __init__( self, intercept_RW_prior: numpyro.distributions, max_rt: float, gamma_RW_prior_scale: float, week_indices: ArrayLike, - ): # numpydoc ignore=GL08 + ): """ Initialize the CFAEPIM_Rt class. @@ -55,7 +53,7 @@ def validate( max_rt: any, gamma_RW_prior_scale: any, week_indices: any, - ) -> None: # numpydoc ignore=GL08 + ) -> None: """ Validate the parameters of the CFAEPIM_Rt class. @@ -85,7 +83,7 @@ def validate( f"week_indices must be an array-like structure; was type {type(week_indices)}" ) - def sample(self, n_steps: int, **kwargs) -> tuple: # numpydoc ignore=GL08 + def sample(self, n_steps: int, **kwargs) -> tuple: """ Sample the Rt values using a random walk process and broadcast them to daily values. diff --git a/pyrenew_flu_light/compare.py b/pyrenew_flu_light/compare.py index bc6e1de..3c1bb31 100644 --- a/pyrenew_flu_light/compare.py +++ b/pyrenew_flu_light/compare.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ Comparisons made between posterior samples. """ @@ -18,7 +16,7 @@ def quantilize_forecasts( fitting_data, output_path, reference_date, -): # numpydoc ignore=GL08 +): pandas2ri.activate() forecasttools = importr("forecasttools") # dplyr = importr("dplyr") diff --git a/pyrenew_flu_light/filtered_data_NY b/pyrenew_flu_light/filtered_data_NY new file mode 100644 index 0000000..527a158 --- /dev/null +++ b/pyrenew_flu_light/filtered_data_NY @@ -0,0 +1,164 @@ +location,date,hosp,epiweek,epiyear,day_of_week,is_weekend,is_holiday,is_post_holiday,recency,week,location_code,population,first_week_hosp,nonobservation_period +NY,2023-09-01,0,35,2023,Fri,false,false,false,0,3,36,19835913,2,true +NY,2023-09-02,0,35,2023,Sat,true,false,false,0,3,36,19835913,2,true +NY,2023-09-03,0,36,2023,Sun,true,false,false,0,3,36,19835913,2,true +NY,2023-09-04,0,36,2023,Mon,false,false,false,0,3,36,19835913,2,true +NY,2023-09-05,0,36,2023,Tue,false,false,false,0,3,36,19835913,2,true +NY,2023-09-06,0,36,2023,Wed,false,false,false,0,3,36,19835913,2,true +NY,2023-09-07,0,36,2023,Thu,false,false,false,0,3,36,19835913,2,true +NY,2023-09-08,0,36,2023,Fri,false,false,false,0,3,36,19835913,2,true +NY,2023-09-09,0,36,2023,Sat,true,false,false,0,3,36,19835913,2,true +NY,2023-09-10,0,37,2023,Sun,true,false,false,0,3,36,19835913,2,true +NY,2023-09-11,0,37,2023,Mon,false,false,false,0,3,36,19835913,2,true +NY,2023-09-12,0,37,2023,Tue,false,false,false,0,3,36,19835913,2,true +NY,2023-09-13,0,37,2023,Wed,false,false,false,0,3,36,19835913,2,true +NY,2023-09-14,0,37,2023,Thu,false,false,false,0,3,36,19835913,2,true +NY,2023-09-15,1,37,2023,Fri,false,false,false,0,3,36,19835913,2,false +NY,2023-09-16,1,37,2023,Sat,true,false,false,0,3,36,19835913,2,false +NY,2023-09-17,2,38,2023,Sun,true,false,false,0,4,36,19835913,2,false +NY,2023-09-18,2,38,2023,Mon,false,false,false,0,4,36,19835913,2,false +NY,2023-09-19,2,38,2023,Tue,false,false,false,0,4,36,19835913,2,false +NY,2023-09-20,4,38,2023,Wed,false,false,false,0,4,36,19835913,2,false +NY,2023-09-21,4,38,2023,Thu,false,false,false,0,4,36,19835913,2,false +NY,2023-09-22,2,38,2023,Fri,false,false,false,0,4,36,19835913,2,false +NY,2023-09-23,3,38,2023,Sat,true,false,false,0,4,36,19835913,2,false +NY,2023-09-24,9,39,2023,Sun,true,false,false,0,5,36,19835913,2,false +NY,2023-09-25,4,39,2023,Mon,false,false,false,0,5,36,19835913,2,false +NY,2023-09-26,5,39,2023,Tue,false,false,false,0,5,36,19835913,2,false +NY,2023-09-27,7,39,2023,Wed,false,false,false,0,5,36,19835913,2,false +NY,2023-09-28,10,39,2023,Thu,false,false,false,0,5,36,19835913,2,false +NY,2023-09-29,7,39,2023,Fri,false,false,false,0,5,36,19835913,2,false +NY,2023-09-30,6,39,2023,Sat,true,false,false,0,5,36,19835913,2,false +NY,2023-10-01,1,40,2023,Sun,true,false,false,0,6,36,19835913,2,false +NY,2023-10-02,5,40,2023,Mon,false,false,false,0,6,36,19835913,2,false +NY,2023-10-03,8,40,2023,Tue,false,false,false,0,6,36,19835913,2,false +NY,2023-10-04,4,40,2023,Wed,false,false,false,0,6,36,19835913,2,false +NY,2023-10-05,8,40,2023,Thu,false,false,false,0,6,36,19835913,2,false +NY,2023-10-06,4,40,2023,Fri,false,false,false,0,6,36,19835913,2,false +NY,2023-10-07,7,40,2023,Sat,true,false,false,0,6,36,19835913,2,false +NY,2023-10-08,6,41,2023,Sun,true,false,false,0,7,36,19835913,2,false +NY,2023-10-09,4,41,2023,Mon,false,false,false,0,7,36,19835913,2,false +NY,2023-10-10,2,41,2023,Tue,false,false,false,0,7,36,19835913,2,false +NY,2023-10-11,5,41,2023,Wed,false,false,false,0,7,36,19835913,2,false +NY,2023-10-12,2,41,2023,Thu,false,false,false,0,7,36,19835913,2,false +NY,2023-10-13,4,41,2023,Fri,false,false,false,0,7,36,19835913,2,false +NY,2023-10-14,3,41,2023,Sat,true,false,false,0,7,36,19835913,2,false +NY,2023-10-15,4,42,2023,Sun,true,false,false,0,8,36,19835913,2,false +NY,2023-10-16,3,42,2023,Mon,false,false,false,0,8,36,19835913,2,false +NY,2023-10-17,5,42,2023,Tue,false,false,false,0,8,36,19835913,2,false +NY,2023-10-18,8,42,2023,Wed,false,false,false,0,8,36,19835913,2,false +NY,2023-10-19,8,42,2023,Thu,false,false,false,0,8,36,19835913,2,false +NY,2023-10-20,5,42,2023,Fri,false,false,false,0,8,36,19835913,2,false +NY,2023-10-21,4,42,2023,Sat,true,false,false,0,8,36,19835913,2,false +NY,2023-10-22,7,43,2023,Sun,true,false,false,0,9,36,19835913,2,false +NY,2023-10-23,3,43,2023,Mon,false,false,false,0,9,36,19835913,2,false +NY,2023-10-24,9,43,2023,Tue,false,false,false,0,9,36,19835913,2,false +NY,2023-10-25,6,43,2023,Wed,false,false,false,0,9,36,19835913,2,false +NY,2023-10-26,6,43,2023,Thu,false,false,false,0,9,36,19835913,2,false +NY,2023-10-27,9,43,2023,Fri,false,false,false,0,9,36,19835913,2,false +NY,2023-10-28,8,43,2023,Sat,true,false,false,0,9,36,19835913,2,false +NY,2023-10-29,6,44,2023,Sun,true,false,false,0,10,36,19835913,2,false +NY,2023-10-30,9,44,2023,Mon,false,false,false,0,10,36,19835913,2,false +NY,2023-10-31,6,44,2023,Tue,false,false,false,0,10,36,19835913,2,false +NY,2023-11-01,10,44,2023,Wed,false,false,false,0,10,36,19835913,2,false +NY,2023-11-02,12,44,2023,Thu,false,false,false,0,10,36,19835913,2,false +NY,2023-11-03,9,44,2023,Fri,false,false,false,0,10,36,19835913,2,false +NY,2023-11-04,5,44,2023,Sat,true,false,false,0,10,36,19835913,2,false +NY,2023-11-05,14,45,2023,Sun,true,false,false,0,11,36,19835913,2,false +NY,2023-11-06,10,45,2023,Mon,false,false,false,0,11,36,19835913,2,false +NY,2023-11-07,14,45,2023,Tue,false,false,false,0,11,36,19835913,2,false +NY,2023-11-08,15,45,2023,Wed,false,false,false,0,11,36,19835913,2,false +NY,2023-11-09,11,45,2023,Thu,false,false,false,0,11,36,19835913,2,false +NY,2023-11-10,14,45,2023,Fri,false,false,false,0,11,36,19835913,2,false +NY,2023-11-11,10,45,2023,Sat,true,false,false,0,11,36,19835913,2,false +NY,2023-11-12,9,46,2023,Sun,true,false,false,0,12,36,19835913,2,false +NY,2023-11-13,9,46,2023,Mon,false,false,false,0,12,36,19835913,2,false +NY,2023-11-14,23,46,2023,Tue,false,false,false,0,12,36,19835913,2,false +NY,2023-11-15,21,46,2023,Wed,false,false,false,0,12,36,19835913,2,false +NY,2023-11-16,22,46,2023,Thu,false,false,false,0,12,36,19835913,2,false +NY,2023-11-17,22,46,2023,Fri,false,false,false,0,12,36,19835913,2,false +NY,2023-11-18,17,46,2023,Sat,true,false,false,0,12,36,19835913,2,false +NY,2023-11-19,20,47,2023,Sun,true,false,false,0,13,36,19835913,2,false +NY,2023-11-20,25,47,2023,Mon,false,false,false,0,13,36,19835913,2,false +NY,2023-11-21,20,47,2023,Tue,false,false,false,0,13,36,19835913,2,false +NY,2023-11-22,24,47,2023,Wed,false,false,false,0,13,36,19835913,2,false +NY,2023-11-23,18,47,2023,Thu,false,true,false,0,13,36,19835913,2,false +NY,2023-11-24,27,47,2023,Fri,false,false,true,0,13,36,19835913,2,false +NY,2023-11-25,44,47,2023,Sat,true,false,false,0,13,36,19835913,2,false +NY,2023-11-26,39,48,2023,Sun,true,false,false,0,14,36,19835913,2,false +NY,2023-11-27,36,48,2023,Mon,false,false,false,0,14,36,19835913,2,false +NY,2023-11-28,54,48,2023,Tue,false,false,false,0,14,36,19835913,2,false +NY,2023-11-29,56,48,2023,Wed,false,false,false,0,14,36,19835913,2,false +NY,2023-11-30,55,48,2023,Thu,false,false,false,0,14,36,19835913,2,false +NY,2023-12-01,57,48,2023,Fri,false,false,false,0,14,36,19835913,2,false +NY,2023-12-02,48,48,2023,Sat,true,false,false,0,14,36,19835913,2,false +NY,2023-12-03,58,49,2023,Sun,true,false,false,0,15,36,19835913,2,false +NY,2023-12-04,57,49,2023,Mon,false,false,false,0,15,36,19835913,2,false +NY,2023-12-05,78,49,2023,Tue,false,false,false,0,15,36,19835913,2,false +NY,2023-12-06,76,49,2023,Wed,false,false,false,0,15,36,19835913,2,false +NY,2023-12-07,71,49,2023,Thu,false,false,false,0,15,36,19835913,2,false +NY,2023-12-08,84,49,2023,Fri,false,false,false,0,15,36,19835913,2,false +NY,2023-12-09,85,49,2023,Sat,true,false,false,0,15,36,19835913,2,false +NY,2023-12-10,92,50,2023,Sun,true,false,false,0,16,36,19835913,2,false +NY,2023-12-11,98,50,2023,Mon,false,false,false,0,16,36,19835913,2,false +NY,2023-12-12,101,50,2023,Tue,false,false,false,0,16,36,19835913,2,false +NY,2023-12-13,117,50,2023,Wed,false,false,false,0,16,36,19835913,2,false +NY,2023-12-14,116,50,2023,Thu,false,false,false,0,16,36,19835913,2,false +NY,2023-12-15,132,50,2023,Fri,false,false,false,0,16,36,19835913,2,false +NY,2023-12-16,88,50,2023,Sat,true,false,false,0,16,36,19835913,2,false +NY,2023-12-17,105,51,2023,Sun,true,false,false,0,17,36,19835913,2,false +NY,2023-12-18,134,51,2023,Mon,false,false,false,0,17,36,19835913,2,false +NY,2023-12-19,153,51,2023,Tue,false,false,false,0,17,36,19835913,2,false +NY,2023-12-20,143,51,2023,Wed,false,false,false,0,17,36,19835913,2,false +NY,2023-12-21,144,51,2023,Thu,false,false,false,0,17,36,19835913,2,false +NY,2023-12-22,131,51,2023,Fri,false,false,false,0,17,36,19835913,2,false +NY,2023-12-23,125,51,2023,Sat,true,false,false,0,17,36,19835913,2,false +NY,2023-12-24,147,52,2023,Sun,true,false,false,0,18,36,19835913,2,false +NY,2023-12-25,142,52,2023,Mon,false,true,false,0,18,36,19835913,2,false +NY,2023-12-26,161,52,2023,Tue,false,false,true,0,18,36,19835913,2,false +NY,2023-12-27,217,52,2023,Wed,false,false,false,0,18,36,19835913,2,false +NY,2023-12-28,211,52,2023,Thu,false,false,false,0,18,36,19835913,2,false +NY,2023-12-29,237,52,2023,Fri,false,false,false,0,18,36,19835913,2,false +NY,2023-12-30,230,52,2023,Sat,true,false,false,0,18,36,19835913,2,false +NY,2023-12-31,195,1,2024,Sun,true,true,false,0,19,36,19835913,2,false +NY,2024-01-01,186,1,2024,Mon,false,true,false,0,19,36,19835913,2,false +NY,2024-01-02,191,1,2024,Tue,false,false,true,0,19,36,19835913,2,false +NY,2024-01-03,211,1,2024,Wed,false,false,false,0,19,36,19835913,2,false +NY,2024-01-04,191,1,2024,Thu,false,false,false,0,19,36,19835913,2,false +NY,2024-01-05,146,1,2024,Fri,false,false,false,0,19,36,19835913,2,false +NY,2024-01-06,129,1,2024,Sat,true,false,false,0,19,36,19835913,2,false +NY,2024-01-07,120,2,2024,Sun,true,false,false,0,20,36,19835913,2,false +NY,2024-01-08,124,2,2024,Mon,false,false,false,0,20,36,19835913,2,false +NY,2024-01-09,167,2,2024,Tue,false,false,false,0,20,36,19835913,2,false +NY,2024-01-10,140,2,2024,Wed,false,false,false,0,20,36,19835913,2,false +NY,2024-01-11,137,2,2024,Thu,false,false,false,0,20,36,19835913,2,false +NY,2024-01-12,135,2,2024,Fri,false,false,false,1,20,36,19835913,2,false +NY,2024-01-13,112,2,2024,Sat,true,false,false,2,20,36,19835913,2,false +NY,2024-01-14,-9999,3,2024,Sun,true,false,false,0,21,36,19835913,2,false +NY,2024-01-15,-9999,3,2024,Mon,false,false,false,0,21,36,19835913,2,false +NY,2024-01-16,-9999,3,2024,Tue,false,false,false,0,21,36,19835913,2,false +NY,2024-01-17,-9999,3,2024,Wed,false,false,false,0,21,36,19835913,2,false +NY,2024-01-18,-9999,3,2024,Thu,false,false,false,0,21,36,19835913,2,false +NY,2024-01-19,-9999,3,2024,Fri,false,false,false,0,21,36,19835913,2,false +NY,2024-01-20,-9999,3,2024,Sat,true,false,false,0,21,36,19835913,2,false +NY,2024-01-21,-9999,4,2024,Sun,true,false,false,0,22,36,19835913,2,false +NY,2024-01-22,-9999,4,2024,Mon,false,false,false,0,22,36,19835913,2,false +NY,2024-01-23,-9999,4,2024,Tue,false,false,false,0,22,36,19835913,2,false +NY,2024-01-24,-9999,4,2024,Wed,false,false,false,0,22,36,19835913,2,false +NY,2024-01-25,-9999,4,2024,Thu,false,false,false,0,22,36,19835913,2,false +NY,2024-01-26,-9999,4,2024,Fri,false,false,false,0,22,36,19835913,2,false +NY,2024-01-27,-9999,4,2024,Sat,true,false,false,0,22,36,19835913,2,false +NY,2024-01-28,-9999,5,2024,Sun,true,false,false,0,23,36,19835913,2,false +NY,2024-01-29,-9999,5,2024,Mon,false,false,false,0,23,36,19835913,2,false +NY,2024-01-30,-9999,5,2024,Tue,false,false,false,0,23,36,19835913,2,false +NY,2024-01-31,-9999,5,2024,Wed,false,false,false,0,23,36,19835913,2,false +NY,2024-02-01,-9999,5,2024,Thu,false,false,false,0,23,36,19835913,2,false +NY,2024-02-02,-9999,5,2024,Fri,false,false,false,0,23,36,19835913,2,false +NY,2024-02-03,-9999,5,2024,Sat,true,false,false,0,23,36,19835913,2,false +NY,2024-02-04,-9999,6,2024,Sun,true,false,false,0,24,36,19835913,2,false +NY,2024-02-05,-9999,6,2024,Mon,false,false,false,0,24,36,19835913,2,false +NY,2024-02-06,-9999,6,2024,Tue,false,false,false,0,24,36,19835913,2,false +NY,2024-02-07,-9999,6,2024,Wed,false,false,false,0,24,36,19835913,2,false +NY,2024-02-08,-9999,6,2024,Thu,false,false,false,0,24,36,19835913,2,false +NY,2024-02-09,-9999,6,2024,Fri,false,false,false,0,24,36,19835913,2,false +NY,2024-02-10,-9999,6,2024,Sat,true,false,false,0,24,36,19835913,2,false diff --git a/pyrenew_flu_light/model.py b/pyrenew_flu_light/model.py index 99a94ca..464a6e2 100644 --- a/pyrenew_flu_light/model.py +++ b/pyrenew_flu_light/model.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ The re-instantiated cfaepim model, with transmission, observation, and infection @@ -28,7 +26,7 @@ ) -class CFAEPIM_Model_Sample(NamedTuple): # numpydoc ignore=GL08 +class CFAEPIM_Model_Sample(NamedTuple): Rts: SampledValue | None = None latent_infections: SampledValue | None = None susceptibles: SampledValue | None = None @@ -76,7 +74,7 @@ def __init__( week_indices: ArrayLike, first_week_hosp: int, predictors: list[int], - ): # numpydoc ignore=GL08 + ): self.population = population self.week_indices = week_indices self.first_week_hosp = first_week_hosp diff --git a/pyrenew_flu_light/pad.py b/pyrenew_flu_light/pad.py index 9bc79a2..158c502 100644 --- a/pyrenew_flu_light/pad.py +++ b/pyrenew_flu_light/pad.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from datetime import datetime, timedelta import polars as pl diff --git a/pyrenew_flu_light/plot.py b/pyrenew_flu_light/plot.py index bec4c6e..0e996e9 100644 --- a/pyrenew_flu_light/plot.py +++ b/pyrenew_flu_light/plot.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ Plotting utilities for using pyrenew-flu-light. """ @@ -8,7 +6,7 @@ import matplotlib.pyplot as plt -def plot_lm_arviz_fit(idata): # numpydoc ignore=GL08 +def plot_lm_arviz_fit(idata): fig, ax = plt.subplots() az.plot_lm( "negbinom_rv", @@ -24,14 +22,14 @@ def plot_lm_arviz_fit(idata): # numpydoc ignore=GL08 plt.show() -def compute_eti(dataset, eti_prob): # numpydoc ignore=GL08 +def compute_eti(dataset, eti_prob): eti_bdry = dataset.quantile( ((1 - eti_prob) / 2, 1 / 2 + eti_prob / 2), dim=("chain", "draw") ) return eti_bdry.values.T -def plot_hdi_arviz_for(idata, forecast_days): # numpydoc ignore=GL08 +def plot_hdi_arviz_for(idata, forecast_days): x_data = idata.posterior_predictive["negbinom_rv_dim_0"] + forecast_days y_data = idata.posterior_predictive["negbinom_rv"] fig, axes = plt.subplots(figsize=(6, 5)) diff --git a/pyrenew_flu_light/post.py b/pyrenew_flu_light/post.py index 42a1d84..6db6228 100644 --- a/pyrenew_flu_light/post.py +++ b/pyrenew_flu_light/post.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ Save information regarding model performance and nature of model input and output. diff --git a/pyrenew_flu_light/pre.py b/pyrenew_flu_light/pre.py index 5e0874d..443e9b8 100644 --- a/pyrenew_flu_light/pre.py +++ b/pyrenew_flu_light/pre.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ ETL system for pyrenew-flu-light. """ diff --git a/pyrenew_flu_light/run.py b/pyrenew_flu_light/run.py index a59244c..9807e5a 100644 --- a/pyrenew_flu_light/run.py +++ b/pyrenew_flu_light/run.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import argparse import logging import os @@ -12,7 +10,7 @@ import pyrenew_flu_light -def process_jurisdictions(value): # numpydoc ignore=GL08 +def process_jurisdictions(value): if value.lower() == "all": return pyrenew_flu_light.JURISDICTIONS elif value.lower().startswith("not:"): @@ -304,7 +302,7 @@ def spread_draws( return df -def main(args): # numpydoc ignore=GL08 +def main(args): """ pyrenew-flu-light; to run: diff --git a/pyrenew_flu_light/tut_epim_port_msr.py b/pyrenew_flu_light/tut_epim_port_msr.py index 8dadf8c..b91099d 100644 --- a/pyrenew_flu_light/tut_epim_port_msr.py +++ b/pyrenew_flu_light/tut_epim_port_msr.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ Porting `cfa-forecast-renewal-epidemia` over to MSR. Validated on NHSN influenza @@ -272,7 +270,7 @@ def load_config(config_path: str) -> dict[str, any]: return config -def ensure_output_directory(args: dict[str, any]): # numpydoc ignore=GL08 +def ensure_output_directory(args: dict[str, any]): output_directory = "./output/" if not os.path.exists(output_directory): os.makedirs(output_directory) @@ -289,7 +287,7 @@ def ensure_output_directory(args: dict[str, any]): # numpydoc ignore=GL08 def assert_historical_data_files_exist( reporting_date: str, -): # numpydoc ignore=GL08 +): data_directory = f"../data/{reporting_date}/" assert os.path.exists( data_directory @@ -318,7 +316,7 @@ def plot_utils( filename: str = "delete_me", save_as_img: bool = False, save_to_pdf: bool = False, -) -> None | plt.Figure: # numpydoc ignore=GL08 +) -> None | plt.Figure: if use_legend: axes.legend(loc="best") if use_log: @@ -537,7 +535,7 @@ def __init__( self, I0: ArrayLike, susceptibility_prior: numpyro.distributions, - ): # numpydoc ignore=GL08 + ): logging.info("Initializing CFAEPIM_Infections") self.I0 = I0 @@ -639,7 +637,7 @@ def sample( # calculate initial susceptible population S_{v-1} init_S = init_S_proportion * P - def update_infections(carry, Rt): # numpydoc ignore=GL08 + def update_infections(carry, Rt): S_t, I_recent = carry # compute raw infections @@ -699,7 +697,7 @@ def __init__( alpha_prior_dist, coefficient_priors, nb_concentration_prior, - ): # numpydoc ignore=GL08 + ): logging.info("Initializing CFAEPIM_Observation") # CFAEPIM_Observation.validate( @@ -825,14 +823,14 @@ def sample( return alpha_samples, expected_hosp -class CFAEPIM_Rt(RandomVariable): # numpydoc ignore=GL08 +class CFAEPIM_Rt(RandomVariable): def __init__( self, intercept_RW_prior: numpyro.distributions, max_rt: float, gamma_RW_prior_scale: float, week_indices: ArrayLike, - ): # numpydoc ignore=GL08 + ): """ Initialize the CFAEPIM_Rt class. @@ -862,7 +860,7 @@ def validate( max_rt: any, gamma_RW_prior_scale: any, week_indices: any, - ) -> None: # numpydoc ignore=GL08 + ) -> None: """ Validate the parameters of the CFAEPIM_Rt class. @@ -892,7 +890,7 @@ def validate( f"week_indices must be an array-like structure; was type {type(week_indices)}" ) - def sample(self, n_steps: int, **kwargs) -> tuple: # numpydoc ignore=GL08 + def sample(self, n_steps: int, **kwargs) -> tuple: """ Sample the Rt values using a random walk process and broadcast them to daily values. @@ -940,7 +938,7 @@ def sample(self, n_steps: int, **kwargs) -> tuple: # numpydoc ignore=GL08 return broadcasted_rt_samples -class CFAEPIM_Model_Sample(NamedTuple): # numpydoc ignore=GL08 +class CFAEPIM_Model_Sample(NamedTuple): Rts: SampledValue | None = None latent_infections: SampledValue | None = None susceptibles: SampledValue | None = None @@ -988,7 +986,7 @@ def __init__( week_indices: ArrayLike, first_week_hosp: int, predictors: list[int], - ): # numpydoc ignore=GL08 + ): self.population = population self.week_indices = week_indices self.first_week_hosp = first_week_hosp @@ -1351,7 +1349,7 @@ def add_pre_observation_period( return merged_data -def process_jurisdictions(value): # numpydoc ignore=GL08 +def process_jurisdictions(value): if value.lower() == "all": return JURISDICTIONS elif value.lower().startswith("not:"): @@ -1367,7 +1365,7 @@ def process_jurisdictions(value): # numpydoc ignore=GL08 # config: dict[str, any], # forecasting: bool = False, # n_post_observation_days: int = 0, -# ): # numpydoc ignore=GL08 +# ): # """ # Originally separated to support `model_render`; # possibly reintegrated w/ `run_single_jurisdiction`. @@ -1585,7 +1583,7 @@ def save_numpyro_model( config: dict[str, any], forecasting: bool = False, n_post_observation_days: int = 0, -): # numpydoc ignore=GL08 +): # check if the file exists if os.path.exists(save_path): pass @@ -1604,7 +1602,7 @@ def save_numpyro_model( def template_save_file( title: str, save_path: str, figure_and_descriptions: list[tuple[str, str]] -): # numpydoc ignore=GL08 +): header_p1 = f""" --- title: "{title}" @@ -1623,7 +1621,7 @@ def template_save_file( f.close() -def convert_markdown_output_files_to_pdf(): # numpydoc ignore=GL08 +def convert_markdown_output_files_to_pdf(): markdown_files = glob.glob("*.md") print(markdown_files) pass @@ -1636,7 +1634,7 @@ def save_inference_content(): pass -def plot_lm_arviz_fit(idata): # numpydoc ignore=GL08 +def plot_lm_arviz_fit(idata): fig, ax = plt.subplots() az.plot_lm( "negbinom_rv", @@ -1652,14 +1650,14 @@ def plot_lm_arviz_fit(idata): # numpydoc ignore=GL08 plt.show() -def compute_eti(dataset, eti_prob): # numpydoc ignore=GL08 +def compute_eti(dataset, eti_prob): eti_bdry = dataset.quantile( ((1 - eti_prob) / 2, 1 / 2 + eti_prob / 2), dim=("chain", "draw") ) return eti_bdry.values.T -def plot_hdi_arviz_for(idata, forecast_days): # numpydoc ignore=GL08 +def plot_hdi_arviz_for(idata, forecast_days): x_data = idata.posterior_predictive["negbinom_rv_dim_0"] + forecast_days y_data = idata.posterior_predictive["negbinom_rv"] fig, axes = plt.subplots(figsize=(6, 5)) @@ -1699,7 +1697,7 @@ def plot_hdi_arviz_for(idata, forecast_days): # numpydoc ignore=GL08 plt.show() -def main(args): # numpydoc ignore=GL08 +def main(args): """ The `cfaepim` model required a configuration file and a dataset. The configuration file must