Skip to content

Commit

Permalink
handling 366
Browse files Browse the repository at this point in the history
  • Loading branch information
emmamendelsohn committed Nov 4, 2023
1 parent b022163 commit fc4a9d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 10 additions & 3 deletions R/calculate_forecasts_anomalies.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,16 @@ calculate_forecasts_anomalies <- function(ecmwf_forecasts_transformed,
summarize(lead_mean = sum(mean * weight)/ sum(weight)) |>
ungroup()

# get historical means for lead period
doy_start <- yday(lead_start_date)
doy_end <- yday(lead_end_date)
# get historical means for lead period, removing doy 366
lead_dates <- seq(lead_start_date, lead_end_date, by = "day")
lead_doys <- yday(lead_dates)
if(366 %in% lead_doys) {
lead_doys <- lead_doys[lead_doys!=366]
lead_doys <- c(lead_doys, tail(lead_doys, 1) + 1)
}

doy_start <- head(lead_doys, 1)
doy_end <- tail(lead_doys, 1)
doy_start_frmt <- str_pad(doy_start, width = 3, side = "left", pad = "0")
doy_end_frmt <- str_pad(doy_end, width = 3, side = "left", pad = "0")
doy_range <- glue::glue("{doy_start_frmt}_to_{doy_end_frmt}")
Expand Down
5 changes: 4 additions & 1 deletion R/calculate_weather_anomalies.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ calculate_weather_anomalies <- function(nasa_weather_transformed,
# get lag dates, removing doy 366
lag_dates <- seq(date_selected - end, date_selected - start, by = "day")
lag_doys <- yday(lag_dates)
if(366 %in% lag_doys) lag_doys <- c(head(lag_doys, 1) - 1, lag_doys[lag_doys!=366])
if(366 %in% lag_doys){
lag_doys <- lag_doys[lag_doys!=366]
lag_doys <- c(head(lag_doys, 1) - 1, lag_doys)
}

# Get historical means for lag period
doy_start <- head(lag_doys, 1)
Expand Down

0 comments on commit fc4a9d5

Please sign in to comment.