Skip to content

Commit

Permalink
fix: update download_signals.R to work with evalcast==0.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dshemetov committed Apr 5, 2024
1 parent 92b633f commit e43de7a
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions forecast/code/download_signals/download_signals.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ library(covidcast)
library(evalcast)
library(here)

# Set the Delphi API key from an environment variable
options(covidcast.auth = Sys.getenv("DELPHI_EPIDATA_KEY"))

# Parameters for determining which data (and how much) we need --------
geo_type <- "hrr"
ntrain = 21
Expand Down Expand Up @@ -65,18 +68,16 @@ start_day_download <- function(forecast_date) {

# Download honest data ----------------------------------------------------


signals_df = honest_as_of_signals
offline_signal_dir = here("data", "offline_signals", "honest_as_of")
if (!dir.exists(offline_signal_dir)) dir.create(offline_signal_dir)
if (!dir.exists(offline_signal_dir)) dir.create(offline_signal_dir, recursive = TRUE)
for (idx in 1:nrow(honest_as_of_signals)) {
forecast_dates <- seq(as.Date(signals_df$start_forecast_date[idx]),
as.Date(end_forecast_date), by = "day")
signals_download = tibble::tibble(
data_source = signals_df$data_source[idx],
signal = signals_df$signal[idx],
start_day = list(start_day_download),
as_of = list(function(x) x),
geo_values='*',
geo_type='hrr')
preds = get_predictions(signal_downloader,
Expand All @@ -86,14 +87,13 @@ for (idx in 1:nrow(honest_as_of_signals)) {
incidence_period = 'day',
forecaster_args = list(
offline_signal_dir=offline_signal_dir
)
),
honest_as_of = TRUE
)
}


# Download "finalized" data -----------------------------------------------


signals_df = dishonest_as_of_signals
offline_signal_dir = here("data", "offline_signals", "dishonest_as_of")
if (!dir.exists(offline_signal_dir)) dir.create(offline_signal_dir)
Expand All @@ -112,17 +112,16 @@ for (idx in 1:nrow(dishonest_as_of_signals)) {
signals_download,
forecast_dates,
incidence_period='day',
forecaster_args=list(
offline_signal_dir=offline_signal_dir
)
forecaster_args = list(
offline_signal_dir=offline_signal_dir
),
honest_as_of = FALSE
)
}



# Copy finalized google to honest -----------------------------------------
# See the manuscript for a discussion of why we use finalized google

google_sigs <- list.files(offline_signal_dir, "google-symptoms")
file.copy(google_sigs, here("data", "offline_signals", "honest_as_of"))

Expand All @@ -144,4 +143,3 @@ saveRDS(df[[1]] %>%
saveRDS(df[[1]] %>%
select(geo_value, time_value, value),
here("data", "confirmed_7dav_incidence_num.RDS"))

0 comments on commit e43de7a

Please sign in to comment.