-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #366 from henrykironde/portalforecast
Point to the new PortalPredictions, portal-forecasts
- Loading branch information
Showing
109 changed files
with
350 additions
and
10,765 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ testing_dir/* | |
/Meta/ | ||
inst/app/models.knit.md | ||
*.DS_Store* | ||
.Rproj.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: portalcasting | ||
Title: Model and Forecast Portal Rodent Dynamics | ||
Version: 0.60.1 | ||
Version: 0.60.2 | ||
Authors@R: c( | ||
person(c("Juniper", "L."), "Simonis", | ||
email = "[email protected]", role = c("aut", "cre"), | ||
|
@@ -21,7 +21,7 @@ Authors@R: c( | |
comment = c(ORCID = "0000-0001-6728-7745")), | ||
person(c("S. K.", "Morgan"), "Ernest", role = c("aut"), | ||
comment = c(ORCID = "0000-0002-6026-8530"))) | ||
Description: Create a directory, populate it with data, build models, forecast rodent populations, and visualize the results. The user can spin-up a local lightweight sandbox or full-scale production environment from the same code underlying the continuously deployed Portal Predictions Project continuous integration system <https://github.com/weecology/portalpredictions> and website <https://portal.naturecast.org>. | ||
Description: Create a directory, populate it with data, build models, forecast rodent populations, and visualize the results. The user can spin-up a local lightweight sandbox or full-scale production environment from the same code underlying the continuously deployed Portal Predictions Project continuous integration system <https://github.com/weecology/portal-forecasts> and website <https://portal.naturecast.org>. | ||
URL: https://weecology.github.io/portalcasting/, https://github.com/weecology/portalcasting | ||
BugReports: https://github.com/weecology/portalcasting/issues | ||
Depends: | ||
|
@@ -48,7 +48,8 @@ Imports: | |
shiny, | ||
stats, | ||
viridis, | ||
yaml | ||
yaml, | ||
utils | ||
Suggests: | ||
pkgdown, | ||
testthat | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#' Zip and unzip forecasts by forecast date | ||
#' | ||
#' @param type either zip or unzip | ||
#' @param forecast_path location of forecast directory | ||
#' @param date forecast date to use while zipping | ||
#' | ||
#' @export | ||
#' | ||
zip_unzip <- function(type = NULL, | ||
forecast_path = "forecasts/", | ||
date = NULL) { | ||
# Function to zip a list of files | ||
zip_files <- function(zipfile, files) { | ||
zipfile <- normalizePath(zipfile, mustWork = FALSE) | ||
if (file.exists(zipfile)) { | ||
# First remove old zip file if exists | ||
unlink(zipfile) | ||
} | ||
# Zip all files in the list | ||
utils::zip(zipfile, files) | ||
unlink(files) | ||
} | ||
|
||
messageq("Preparing forecasts files") | ||
proj_path <- forecast_path | ||
forecasts_metadata <- paste0(proj_path, "/forecasts_metadata.csv") | ||
|
||
proj_path <- normalizePath(proj_path, mustWork = FALSE) | ||
forecasts_metadata <- normalizePath(forecasts_metadata, mustWork = FALSE) | ||
metadata <- read.csv(forecasts_metadata) | ||
unique_dates <- sort(unique(metadata$"forecast_date")) | ||
|
||
if (type == "zip") { | ||
csv_file <- "_forecast_table.csv" | ||
yaml_file <- "_metadata.yaml" | ||
json_file <- "_model_forecast.json" | ||
|
||
if (!is.null(date)) { | ||
unique_dates <- c(date) | ||
messageq(paste0("Zipping forecasts files for ", date)) | ||
} | ||
|
||
for (forecast_day in unique_dates) { | ||
id_date_files <- c() | ||
zipfile <- paste0(proj_path, "/forecast_id_", forecast_day, ".zip") | ||
|
||
# Get all the values of that particular day in a data frame | ||
newdata <- subset(metadata, | ||
forecast_date == forecast_day, | ||
select = c("forecast_id", "forecast_date") | ||
) | ||
|
||
# For each forecast_id get 3 files | ||
All_ids <- newdata$"forecast_id" | ||
for (id in All_ids) { | ||
csv_file_path <- paste0(proj_path, "/forecast_id_", id, csv_file) | ||
if (file.exists(csv_file_path)) { | ||
id_date_files <- c(id_date_files, csv_file_path) | ||
} | ||
yaml_file_path <- paste0(proj_path, "/forecast_id_", id, yaml_file) | ||
if (file.exists(yaml_file_path)) { | ||
id_date_files <- c(id_date_files, yaml_file_path) | ||
} | ||
json_file_path <- paste0(proj_path, "/forecast_id_", id, json_file) | ||
if (file.exists(json_file_path)) { | ||
id_date_files <- c(id_date_files, json_file_path) | ||
} | ||
} | ||
|
||
if (length(id_date_files)) { | ||
# Zip forecast files for the current date | ||
zip_files(zipfile, id_date_files) | ||
} | ||
} | ||
|
||
# Zip forecasts_evaluations.csv | ||
eval_file <- paste0(proj_path, "/forecasts_evaluations.csv") | ||
zipfile <- paste0(proj_path, "/forecasts_evaluations.zip") | ||
zip_files(zipfile, eval_file) | ||
} | ||
|
||
if (type == "unzip") { | ||
messageq("Unzipping forecasts files") | ||
|
||
# Unzip files based on unique_dates | ||
for (forecast_day in unique_dates) { | ||
zipfile <- paste0(proj_path, "/forecast_id_", forecast_day, ".zip") | ||
zipfile <- normalizePath(zipfile, mustWork = FALSE) | ||
if (file.exists(zipfile)) { | ||
unzip(zipfile, exdir = proj_path, junkpaths = TRUE) | ||
unlink(zipfile) | ||
} | ||
} | ||
|
||
# Unzip forecasts_evaluations.csv | ||
eval_zip <- paste0(proj_path, "/forecasts_evaluations.zip") | ||
eval_zip <- normalizePath(eval_zip, mustWork = FALSE) | ||
if (file.exists(eval_zip)) { | ||
unzip(eval_zip, exdir = proj_path, junkpaths = TRUE) | ||
unlink(eval_zip) | ||
} | ||
} | ||
} |
Oops, something went wrong.