Skip to content

Commit

Permalink
Merge pull request #42 from eco4cast/main
Browse files Browse the repository at this point in the history
Main to prod
  • Loading branch information
jzwart authored Feb 12, 2024
2 parents 6a4e460 + 07cbf10 commit c870d3a
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 2,466 deletions.
16 changes: 8 additions & 8 deletions baseline_models/R/fablePersistenceModelFunction.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Function carry out a random walk forecast
RW_daily_forecast <- function(site, var, h,
bootstrap = FALSE, boot_number = 200,
bootstrap = FALSE, boot_number = 200,
transformation = 'none', verbose = TRUE,...) {
# Work out when the forecast should start
forecast_starts <- targets %>%
Expand All @@ -10,7 +10,7 @@ RW_daily_forecast <- function(site, var, h,
dplyr::summarise(start_date = max(datetime) + lubridate::days(1)) %>% # Date
dplyr::mutate(h = (Sys.Date() - start_date) + h) %>% # Horizon value
dplyr::ungroup()

if (verbose == T) {
message(
site,
Expand All @@ -22,7 +22,7 @@ RW_daily_forecast <- function(site, var, h,
bootstrap
)
}

# filter the targets data set to the site_var pair
targets_use <- targets %>%
dplyr::filter(site_id == site,
Expand All @@ -33,7 +33,7 @@ RW_daily_forecast <- function(site, var, h,
# Remove the NA's put at the end, so that the forecast starts from the last day with an observation,
# rather than today
dplyr::filter(datetime < forecast_starts$start_date)

if (nrow(targets_use) == 0) {
message('no targets available, no forecast run')
empty_df <- data.frame('variable' = character(),
Expand All @@ -42,9 +42,9 @@ RW_daily_forecast <- function(site, var, h,
'datetime' = lubridate::ymd(),
'.rep' = character(),
'.sim' = numeric())

return(empty_df)

} else {
if (transformation == 'log') {
RW_model <- targets_use %>%
Expand All @@ -62,7 +62,7 @@ RW_daily_forecast <- function(site, var, h,
RW_model <- targets_use %>%
fabletools::model(RW = fable::RW(sqrt(observation)))
}

if (bootstrap == T) {
forecast <- RW_model %>% fabletools::generate(
h = as.numeric(forecast_starts$h),
Expand All @@ -74,5 +74,5 @@ RW_daily_forecast <- function(site, var, h,
message('forecast finished')
return(forecast)
}

}
272 changes: 0 additions & 272 deletions catalog/forecasts/Aquatics/Daily_Chlorophyll_a/collection.json

This file was deleted.

Loading

0 comments on commit c870d3a

Please sign in to comment.