Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated load_data.R #1592 #2771

Merged
merged 14 commits into from
Mar 1, 2021
1 change: 1 addition & 0 deletions docker/depends/pecan.depends.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ wanted <- c(
'binaryLogic',
'BioCro',
'bit64',
'BrownDog',
'coda',
'corrplot',
'data.table',
Expand Down
25 changes: 14 additions & 11 deletions modules/benchmark/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,29 @@ Description: The Predictive Ecosystem Carbon Analyzer (PEcAn) is a scientific
streamline the interaction between data and models, and to improve the
efficacy of scientific investigation.
Imports:
dbplyr,
dplyr,
ggplot2,
gridExtra,
lubridate (>= 1.6.0),
magrittr,
ncdf4 (>= 1.15),
PEcAn.DB,
PEcAn.logger,
PEcAn.remote,
PEcAn.settings,
PEcAn.utils,
lubridate (>= 1.6.0),
ncdf4 (>= 1.15),
udunits2 (>= 0.11),
XML (>= 3.98-1.4),
dplyr,
ggplot2,
gridExtra,
reshape2,
dbplyr,
SimilarityMeasures,
zoo,
stringr
stringr,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
stringr,
stringr,
tidyselect,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@infotroph ill get on this ASAP. also, the pleasure was mine, got to learn so much from you guys. thanks for being patient with me hehe.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also please suggest any error fix that I can start working on after this.

udunits2 (>= 0.11),
XML (>= 3.98-1.4),
zoo

ashiklom marked this conversation as resolved.
Show resolved Hide resolved
Suggests:
PEcAn.data.land,
testthat (>= 2.0.0)
testthat (>= 2.0.0),
BrownDog
License: BSD_3_clause + file LICENSE
Copyright: Authors
LazyLoad: yes
Expand Down
1 change: 1 addition & 0 deletions modules/benchmark/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ importFrom(ggplot2,geom_path)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,labs)
importFrom(magrittr,"%>%")
22 changes: 8 additions & 14 deletions modules/benchmark/R/load_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
##' @author Betsy Cowdery, Istem Fer, Joshua Mantooth
##' Generic function to convert input files containing observational data to
##' a common PEcAn format.
#' @importFrom magrittr %>%

load_data <- function(data.path, format, start_year = NA, end_year = NA, site = NA,
vars.used.index=NULL, ...) {
Expand All @@ -30,12 +31,6 @@ load_data <- function(data.path, format, start_year = NA, end_year = NA, site =
vars.used.index <- setdiff(seq_along(format$vars$variable_id), format$time.row)
}

library(PEcAn.utils)
library(PEcAn.benchmark)
library(lubridate)
library(udunits2)
library(dplyr)

# Determine the function that should be used to load the data
mimetype <- gsub("-", "_", format$mimetype)
fcn1 <- paste0("load_", format$file_name)
Expand All @@ -44,13 +39,13 @@ load_data <- function(data.path, format, start_year = NA, end_year = NA, site =
fcn <- match.fun(fcn1)
} else if (exists(fcn2)) {
fcn <- match.fun(fcn2)
} else if (!exists(fcn1) & !exists(fcn2) & require(bd)) {
} else if (!exists(fcn1) & !exists(fcn2) & requireNamespace(bd, quietly = TRUE)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (!exists(fcn1) & !exists(fcn2) & requireNamespace(bd, quietly = TRUE)) {
} else if (!exists(fcn1) & !exists(fcn2) & requireNamespace("BrownDog", quietly = TRUE)) {

#To Do: call to DAP to see if conversion to csv is possible
#Brown Dog API call through BDFiddle, requires username and password
key <- get_key("https://bd-api.ncsa.illinois.edu",username,password)
token <- get_token("https://bd-api.ncsa.illinois.edu",key)
key <- BrownDog::get_key("https://bd-api.ncsa.illinois.edu",username,password)
token <- BrownDog::get_token("https://bd-api.ncsa.illinois.edu",key)
#output_path = where are we putting converted file?
converted.data.path <- convert_file(url = "https://bd-api.ncsa.illinois.edu", input_filename = data.path,
converted.data.path <- BrownDog::convert_file(url = "https://bd-api.ncsa.illinois.edu", input_filename = data.path,
output = "csv", output_path = output_path, token = token)
if (is.na(converted.data.path)){
PEcAn.logger::logger.error("Converted file was not returned from Brown Dog")
Expand Down Expand Up @@ -94,11 +89,11 @@ load_data <- function(data.path, format, start_year = NA, end_year = NA, site =
vars_used$pecan_name[i], vars_used$pecan_units[i]))
out[col] <- udunits2::ud.convert(as.numeric(x), u1, u2)
colnames(out)[col] <- vars_used$pecan_name[i]
} else if (misc.are.convertible(u1, u2)) {
} else if (PEcAn.utils::misc.are.convertible(u1, u2)) {
print(sprintf("convert %s %s to %s %s",
vars_used$input_name[i], u1,
vars_used$pecan_name[i], u2))
out[col] <- as.vector(misc.convert(x, u1, u2)) # Betsy: Adding this because misc.convert returns vector with attributes original agrument x, which causes problems later
out[col] <- as.vector(PEcAn.utils::misc.convert(x, u1, u2)) # Betsy: Adding this because misc.convert returns vector with attributes original agrument x, which causes problems later
colnames(out)[col] <- vars_used$pecan_name[i]
} else {
PEcAn.logger::logger.warn(paste("Units cannot be converted. Removing variable. please check the units of",vars_used$input_name[i]))
Expand All @@ -115,7 +110,7 @@ load_data <- function(data.path, format, start_year = NA, end_year = NA, site =
names(out)[col] <- format$vars$pecan_name[time.row]

# Need a much more spohisticated approach to converting into time format.
y <- dplyr::select(out, one_of(format$vars$pecan_name[time.row]))
y <- dplyr::select(out, tidyselect::one_of(format$vars$pecan_name[time.row]))

if(!is.null(site$time_zone)){
tz = site$time_zone
Expand Down Expand Up @@ -145,4 +140,3 @@ load_data <- function(data.path, format, start_year = NA, end_year = NA, site =

return(out)
} # load_data