diff --git a/CRAN-RELEASE b/CRAN-RELEASE index 3799a6f..326b8a2 100644 --- a/CRAN-RELEASE +++ b/CRAN-RELEASE @@ -1,2 +1,2 @@ -This package was submitted to CRAN on 2019-05-29. +This package was submitted to CRAN on 2019-06-03. Once it is accepted, delete this file and tag the release (commit 4c2ea05e5e). diff --git a/DESCRIPTION b/DESCRIPTION index d7be8bc..d851e56 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,32 +1,40 @@ Package: rerddapXtracto Type: Package -Title: Extracts Environmental Data from ERD's ERDDAP Web Service -Version: 0.3.5.900 +Title: Extracts Environmental Data from 'ERDDAP' Web Services +Version: 0.3.5 Authors@R: person("Roy", "Mendelssohn", email = "roy.mendelssohn@noaa.gov", role = c("aut","cre")) -Description: The xtractomatic package contains three functions that access - environmental data from ERD's ERDDAP service. The rxtracto function extracts +Description: Contains three functions that access + environmental data from any 'ERDDAP' data web service. The rxtracto() function extracts data along a trajectory for a given "radius" around the point. The - rxtracto_3D function extracts data in a box. The rxtractogon function - extracts data in a polygon. There are also two helper functions to obtain - information about available data. - These functions differ from those in the xtractomatic package in that they - use the `rerddap` package to access gridded data on any ERDDAP server, but - they require the user to provide initial information about the data - to be extracted. + rxtracto_3D() function extracts data in a box. The rxtractogon() function + extracts data in a polygon. All of those three function use the 'rerddap' package + to extract the data, and should work with any 'ERDDAP' server. + There are also two functions, plotBBox() and plotTrack() that use the 'plotdap' + package to simplify the creation of maps of the data. URL: https://github.com/rmendels/rerddapXtracto BugReports: https://github.com/rmendels/rerddapXtracto/issues +Depends: + R(>= 3.5.0) License: CC0 -LazyData: TRUE Imports: abind, + dplyr, + ggplot2, + httr, methods, ncdf4, parsedate, - rerddap, + plotdap, + readr, + rerddap (>= 0.6.0), sp, - stats + stats, Suggests: - ggplot2, + gganimate, knitr, mapdata, -RoxygenNote: 6.0.1 + rmarkdown +RoxygenNote: 6.1.1 +Encoding: UTF-8 +LazyData: TRUE +VignetteBuilder: knitr diff --git a/R/rxtracto.R b/R/rxtracto.R index 48e11a1..50b2a86 100644 --- a/R/rxtracto.R +++ b/R/rxtracto.R @@ -1,9 +1,9 @@ -#' Extract environmental data along a trajectory from an ERDDAP server using rerddap. +#' Extract environmental data along a trajectory from an 'ERDDAP' server using 'rerddap'. #' -#' \code{rxtracto} uses the R program rerddap to extract environmental -#' data from an ERDDAP server along a (x,y,z, time) trajectory. +#' \code{rxtracto} uses the R program 'rerddap' to extract environmental +#' data from an 'ERDDAP' server along a (x,y,z, time) trajectory. #' @export -#' @param dataInfo - the return from an rerddap "info" call to an ERDDAP server +#' @param dataInfo - the return from an 'rerddap::info' call to an 'ERDDAP' server #' @param parameter - character string containing the name of the parameter to extract #' @param xcoord - a real array with the x-coordinates of the trajectory (if longitude in #' decimal degrees East, either 0-360 or -180 to 180) #' @param ycoord - a real array with the y-coordinate of the trajectory (if latitude in @@ -14,11 +14,10 @@ #' @param xlen - real array defining the longitude box around the given point (xlen/2 around the point) #' @param ylen - real array defining the latitude box around the given point (ylen/2 around the point) #' @param zlen - real array defining the depth or altitude box around the given point (zlen/2 around the point) -#' @param xName - character string with name of the xcoord in the ERDDAP dataset (default "longitude") -#' @param yName - character string with name of the ycoord in the ERDDAP dataset (default "latitude") -#' @param zName - character string with name of the zcoord in the ERDDAP dataset (default "altitude") -#' @param tName - character string with name of the tcoord in the ERDDAP dataset (default "time") -#' @param urlbase - base URL of the ERDDAP server being accessed - default "http://upwell.pfeg.noaa.gov/erddap" +#' @param xName - character string with name of the xcoord in the 'ERDDAP' dataset (default "longitude") +#' @param yName - character string with name of the ycoord in the 'ERDDAP' dataset (default "latitude") +#' @param zName - character string with name of the zcoord in the 'ERDDAP' dataset (default "altitude") +#' @param tName - character string with name of the tcoord in the 'ERDDAP' dataset (default "time") #' @param verbose - logical variable (default FALSE) #' if the the URL request should be verbose #' @return A dataframe containing: @@ -36,42 +35,28 @@ #' \item column 11 = median absolute deviation of data within search radius #' } #' @examples -#' urlbase <- 'https://upwell.pfeg.noaa.gov/erddap' -#' dataInfo <- rerddap::info('erdMBsstd8day') +#' # toy example to show use +#' # but keep execution time down +#' \donttest{ +#' dataInfo <- rerddap::info('erdHadISST') +#' } #' parameter <- 'sst' -#' xcoord <- c(230, 231) -#' ycoord <- c(40, 41) -#' tcoord <- c('2006-01-15', '2006-01-20') -#' zcoord <- c(0., 0.) -#' xlen <- 0.5 -#' ylen <- 0.5 +#' xcoord <- c(-130.5) +#' ycoord <- c(40.5) +#' tcoord <- c('2006-01-16') +#' xlen <- 0.01 +#' ylen <- 0.01 #' extract <- rxtracto(dataInfo, parameter = parameter, xcoord = xcoord, -#' ycoord = ycoord, tcoord= tcoord, zcoord = zcoord, +#' ycoord = ycoord, tcoord= tcoord, #' xlen = xlen, ylen = ylen) +#' \donttest{ #' # 2-D example getting bathymetry #' dataInfo <- rerddap::info('etopo360') #' parameter <- 'altitude' #' extract <- rxtracto(dataInfo, parameter, xcoord = xcoord, ycoord = ycoord, #' xlen = xlen, ylen = ylen) +#' } #' -#' # Example where grid is not latitude-longitude -#' dataInfo <- rerddap::info('glos_tds_5912_ca66_3f41') -#' parameter <- 'temp' -#' xName <- 'nx' -#' yName <- 'ny' -#' zName <- 'nsigma' -#' xcoord <- c(10, 11) -#' ycoord <- c(10, 11) -#' zcoord <- c(1, 1) -#' # time span changes in this dataset - get last three times -#' myURL <- "https://upwell.pfeg.noaa.gov/erddap/griddap/glos_tds_5912_ca66_3f41.csv0?time[last - 2:1:last]" -#' myTimes <- utils::read.csv(utils::URLencode(myURL), header = FALSE, stringsAsFactors = FALSE)[[1]] -#' tcoord <- c(myTimes[1], myTimes[3]) -#' xlen <- 0 -#' ylen <- 0 -#' extract <- rxtracto(dataInfo, parameter, xcoord = xcoord, ycoord = ycoord, -#' zcoord = zcoord, tcoord = tcoord, xlen = xlen, -#' ylen = ylen, xName = xName, yName = yName, zName = zName) @@ -80,7 +65,6 @@ rxtracto <- function(dataInfo, parameter = NULL, xcoord=NULL, ycoord = NULL, zcoord = NULL, tcoord = NULL, xlen = 0., ylen = 0., zlen = 0., xName = 'longitude', yName = 'latitude', zName = 'altitude', tName = 'time', - urlbase = 'https://upwell.pfeg.noaa.gov/erddap', verbose = FALSE) { # Check Passed Info ------------------------------------------------------- @@ -88,7 +72,7 @@ rxtracto <- function(dataInfo, parameter = NULL, xcoord=NULL, ycoord = NULL, callDims <- list(xcoord, ycoord, zcoord, tcoord) names(callDims) <- c(xName, yName, zName, tName) dataInfo1 <- dataInfo - + urlbase <- dataInfo1$base_url # Check that the non-null input vectors are the same length dimLengths <- lapply(callDims, length) dimLengths[dimLengths == 0] <- NULL @@ -243,7 +227,6 @@ oldDataFrame <- out_dataframe[1, ] # will try 5 times, if failure will stop and save data tryn <- 0 goodtry <- -1 - options(warn = 2) while ((tryn <= numtries) & (goodtry == -1)) { tryn <- tryn + 1 extract <- try(do.call(rerddap::griddap, griddapCmd )) @@ -254,7 +237,9 @@ oldDataFrame <- out_dataframe[1, ] # extract <- do.call(rerddap::griddap, griddapCmd ) if (goodtry == -1) { print(griddapCmd) - print("There was an error in the url call, perhaps a time out. See message on screen and URL called") + text1 <- "There was an error in the url call, perhaps a time out." + text2 <- "See message on screen and URL called" + print(paste(text1, text2)) print("Returning incomplete download") out_dataframe <- out_dataframe[1:(i - 1), ] remove('paramdata') @@ -297,7 +282,7 @@ oldDataFrame <- out_dataframe[1, ] oldDataFrame <- out_dataframe[i,] } -out_dataframe <- structure(out_dataframe, class = 'rxtractoTrack') +out_dataframe <- structure(out_dataframe, class = c('list', 'rxtractoTrack')) return(out_dataframe) } diff --git a/R/rxtracto_3D.R b/R/rxtracto_3D.R index 2865093..ef6dd16 100644 --- a/R/rxtracto_3D.R +++ b/R/rxtracto_3D.R @@ -1,11 +1,11 @@ -#' Extract environmental data in a 3-dimnesional box from an ERDDAP server using rerddap. +#' Extract environmental data in a 3-dimensional box from an 'ERDDAP' server using 'rerddap'. #' -#' \code{rxtracto_3D} uses the R program rerddap to extract environmental data -#' from an ERDDAP server in an (x,y,z, time) bounding box. +#' \code{rxtracto_3D} uses the R program 'rerddap' to extract environmental data +#' from an 'ERDDAP' server in an (x,y,z, time) bounding box. #' The same call could be made directly in rerddap, #' but function is maintained as it is used in the polygon routine. #' @export -#' @param dataInfo - the return from an rerddap "info" call to an ERDDAP server +#' @param dataInfo - the return from an 'rerddap:info' call to an 'ERDDAP' server #' @param parameter - character string containing the name of the parameter to extract #' @param xcoord - a real array with the x-coordinates of the trajectory (if longitude in #' decimal degrees East, either 0-360 or -180 to 180) #' @param ycoord - a real array with the y-coordinate of the trajectory (if latitude in @@ -13,12 +13,12 @@ #' @param zcoord - a real array with the z-coordinate (usually altitude or depth) #' @param tcoord - a character array with the times of the trajectory in #' "YYYY-MM-DD" - for now restricted to be time. -#' @param xName - character string with name of the xcoord in the ERDDAP dataset (default "longitude") -#' @param yName - character string with name of the ycoord in the ERDDAP dataset (default "latitude") -#' @param zName - character string with name of the zcoord in the ERDDAP dataset (default "altitude") -#' @param tName - character string with name of the tcoord in the ERDDAP dataset (default "time") -#' @param urlbase - base URL of the ERDDAP server being accessed - default "http://upwell.pfeg.noaa.gov/erddap" +#' @param xName - character string with name of the xcoord in the 'ERDDAP' dataset (default "longitude") +#' @param yName - character string with name of the ycoord in the 'ERDDAP' dataset (default "latitude") +#' @param zName - character string with name of the zcoord in the 'ERDDAP' dataset (default "altitude") +#' @param tName - character string with name of the tcoord in the 'ERDDAP' dataset (default "time") #' @param verbose - logical variable (default FALSE) if the the URL request should be verbose +#' @param cache_remove - logical variable (default TRUE) whether to delete 'rerddap' cache #' @return structure with data and dimensions: #' \itemize{ #' \item extract$data - the data array dimensioned (lon,lat,time) @@ -29,38 +29,23 @@ #' \item extract$time - the times of the extracts #' } #' @examples -#' urlbase <- 'https://upwell.pfeg.noaa.gov/erddap' -#' dataInfo <- rerddap::info('erdMBsstd8day') +#' # toy example to show use +#' # and keep execution time low +#' \donttest{ +#' dataInfo <- rerddap::info('erdHadISST') +#' } #' parameter <- 'sst' -#' xcoord <- c(230, 235) -#' ycoord <- c(40, 45) -#' tcoord <- c('2006-01-15', '2006-01-20') -#' zcoord <- c(0., 0.) +#' xcoord <- c(-130.5, -130.5) +#' ycoord <- c(40.5, 40.5) +#' tcoord <- c('2006-01-16', '2006-01-16') #' extract <- rxtracto_3D(dataInfo, parameter, xcoord = xcoord, ycoord = ycoord, -#' tcoord = tcoord, zcoord = zcoord) +#' tcoord = tcoord) #' +#' \donttest{ #' # 2-D example getting bathymetry #' dataInfo <- rerddap::info('etopo360') #' parameter <- 'altitude' #' extract <- rxtracto_3D(dataInfo, parameter, xcoord = xcoord, ycoord = ycoord) -#' -#' # Example where grid is not latitude-longitude -#' dataInfo <- rerddap::info('glos_tds_5912_ca66_3f41') -#' parameter = 'temp' -#' xName <- 'nx' -#' yName <- 'ny' -#' zName <- 'nsigma' -#' xcoord <- c(10, 11) -#' ycoord <- c(10, 11) -#' zcoord <- c(1, 1) -#' # time span changes in this dataset - get last three times -#' myURL <- "https://upwell.pfeg.noaa.gov/erddap/griddap/glos_tds_5912_ca66_3f41.csv0?time[last - 2:1:last]" -#' myTimes <- utils::read.csv(utils::URLencode(myURL), header = FALSE, stringsAsFactors = FALSE)[[1]] -#' tcoord <- c(myTimes[1], myTimes[3]) -#' extract <- rxtracto_3D(dataInfo, parameter, xcoord = xcoord, ycoord = ycoord, -#' zcoord = zcoord, tcoord = tcoord, xName = xName, -#' yName = yName, zName = zName) -#' #' # Dataset that has depth also #' # 3 months of subsurface temperature at 70m depth from SODA 2.2.4 #' dataInfo <- rerddap::info('erdSoda331oceanmday') @@ -75,9 +60,14 @@ #' extract <- rxtracto_3D(dataInfo, parameter, xcoord = xcoord, ycoord = ycoord, #' zcoord = zcoord, tcoord = tcoord, xName = xName, #' yName = yName, zName = zName) +#' } #' -rxtracto_3D <- function(dataInfo, parameter = NULL, xcoord = NULL, ycoord = NULL, zcoord = NULL, tcoord = NULL, xName = 'longitude', yName = 'latitude', zName = 'altitude', tName = 'time', urlbase = 'https://upwell.pfeg.noaa.gov/erddap/', verbose=FALSE) { +rxtracto_3D <- function(dataInfo, parameter = NULL, xcoord = NULL, + ycoord = NULL, zcoord = NULL, tcoord = NULL, + xName = 'longitude', yName = 'latitude', + zName = 'altitude', tName = 'time', + verbose=FALSE, cache_remove = TRUE) { # Check Passed Info ------------------------------------------------------- @@ -85,6 +75,7 @@ rxtracto_3D <- function(dataInfo, parameter = NULL, xcoord = NULL, ycoord = NULL callDims <- list(xcoord, ycoord, zcoord, tcoord) names(callDims) <- c(xName, yName, zName, tName) dataInfo1 <- dataInfo + urlbase <- dataInfo1$base_url urlbase <- checkInput(dataInfo1, parameter, urlbase, callDims) @@ -217,20 +208,11 @@ if (grepl('etopo',extract[[2]])) { } -# copy netcdf file from cache to the present directory and rename -copyFile <- paste0(getwd(), '/', parameter, '.nc') -iFile <- 1 -while (file.exists(copyFile)) { - copyFile <- paste0(getwd(), '/', parameter, '_', iFile, '.nc') - iFile <- iFile + 1 -} -fcopy <- file.copy(griddapExtract$summary$filename, copyFile) -if (!fcopy) { - print('copying and renaming downloaded file from default ~/.rerddap failed') -} # remove netcdf file from cache -rerddap::cache_delete(griddapExtract) -extract <- structure(extract, class = 'rxtracto3D') +if (cache_remove) { + rerddap::cache_delete(griddapExtract) +} +extract <- structure(extract, class = c('list', 'rxtracto3D')) return(extract) } diff --git a/R/rxtractogon.R b/R/rxtractogon.R index 039fb57..0c32cd1 100644 --- a/R/rxtractogon.R +++ b/R/rxtractogon.R @@ -1,10 +1,9 @@ -#' Extract environmental data in a polygon using ERDDAP. +#' Extract environmental data in a polygon using 'ERDDAP' and 'rerddap'. #' -#' \code{rxtractogon} uses the ERD ERDDAP data web service to extact -#' environmental data inside a polygon defined by vectors of -#' latitudes and longitudes +#' \code{rxtractogon} uses the R program 'rerddap' to extract environmental data +#' from an 'ERDDAP' server in a polygon through time. #' @export -#' @param dataInfo - the return from an rerddap "info" call to an ERDDAP server +#' @param dataInfo - the return from an 'rerddap:info' call to an 'ERDDAP' server #' @param parameter - character string containing the name of the parameter to extract #' @param xcoord - array giving longitudes (in decimal #' degrees East, either 0-360 or -180 to 180) of polygon @@ -12,11 +11,10 @@ #' degrees N; -90 to 90)of polygon #' @param tcoord - 2-array of minimum and maximum times as 'YYYY-MM-DD' #' @param zcoord - a real number with the z-coordinate(usually altitude or depth) -#' @param xName - character string with name of the xcoord in the ERDDAP dataset (default "longitude") -#' @param yName - character string with name of the ycoord in the ERDDAP dataset (default "latitude") -#' @param zName - character string with name of the zcoord in the ERDDAP dataset (default "altitude") -#' @param tName - character string with name of the tcoord in the ERDDAP dataset (default "time") -#' @param urlbase - base URL of the ERDDAP server being accessed - default "http://upwell.pfeg.noaa.gov/erddap" +#' @param xName - character string with name of the xcoord in the 'ERDDAP' dataset (default "longitude") +#' @param yName - character string with name of the ycoord in the 'ERDDAP' dataset (default "latitude") +#' @param zName - character string with name of the zcoord in the 'ERDDAP' dataset (default "altitude") +#' @param tName - character string with name of the tcoord in the 'ERDDAP' dataset (default "time") #' @param verbose - logical variable (default FALSE) if the the URL request should be verbose #' @return structure with data and dimensions #' \itemize{ @@ -28,13 +26,18 @@ #' \item extract$time - the times of the extracts #' } #' @examples -#' dataInfo <- rerddap::info('erdVH3chlamday') -#' parameter <- 'chla' -#' tcoord <- c("2016-06-15", "2016-06-15") -#' xcoord <- mbnms$Longitude -#' ycoord <- mbnms$Latitude -#' sanctchl <- rxtractogon (dataInfo, parameter=parameter, xcoord = xcoord, +#' # toy example to show use +#' # and keep execution time low +#' \donttest{ +#' dataInfo <- rerddap::info('erdHadISST') +#' } +#' parameter <- 'sst' +#' tcoord <- c("2016-06-15") +#' xcoord <- mbnms$Longitude[1:3] +#' ycoord <- mbnms$Latitude[1:3] +#' sanctSST <- rxtractogon (dataInfo, parameter=parameter, xcoord = xcoord, #' ycoord = ycoord, tcoord= tcoord) +#' \donttest{ #' xcoord <- mbnms$Longitude #' ycoord <- mbnms$Latitude #' dataInfo <- rerddap::info('etopo180') @@ -43,17 +46,22 @@ #' yName <- 'latitude' #' bathy <- rxtractogon (dataInfo, parameter = parameter, xcoord = xcoord, #' ycoord = ycoord) +#' } #' @section Details: #' rxtractogon extracts the data from the smallest bounding box that contains #' the polygon, and then uses the function "point.in.polygon" from the "sp" -#' package to mask out the areas outside of the polygon. rxtractogon only works with -#' datasets defined on a latitude and longitude grid. +#' package to mask out the areas outside of the polygon. +#' rxtractogon only works with datasets defined +#' on a latitude and longitude grid. -rxtractogon <- function(dataInfo, parameter, xcoord = NULL, ycoord = NULL, zcoord = NULL, tcoord = NULL, xName = 'longitude', yName = 'latitude', zName = 'altitude', tName = 'time', urlbase = 'https://upwell.pfeg.noaa.gov/erddap', verbose = FALSE) { +rxtractogon <- function(dataInfo, parameter, xcoord = NULL, ycoord = NULL, + zcoord = NULL, tcoord = NULL, xName = 'longitude', + yName = 'latitude', zName = 'altitude', tName = 'time', + verbose = FALSE) { rerddap::cache_setup(temp_dir = TRUE) @@ -85,7 +93,10 @@ xcoord1 <- c(min(xcoord), max(xcoord)) ycoord1 <- c(min(ycoord), max(ycoord)) # call xtracto to get data -extract <- rxtracto_3D(dataInfo, parameter = parameter, xcoord = xcoord1, ycoord = ycoord1, zcoord = zcoord, tcoord = tcoord1, xName = xName, yName = yName, zName = zName, urlbase = urlbase, verbose = verbose) +extract <- rxtracto_3D(dataInfo, parameter = parameter, xcoord = xcoord1, + ycoord = ycoord1, zcoord = zcoord, tcoord = tcoord1, + xName = xName, yName = yName, zName = zName, + verbose = verbose) # extract <- xtracto_3D(xcoord1,ycoord1,tpos1,dtype, verbose) if (length(dim(extract[[1]])) == 2) { extract[[1]] <- array(extract[[1]], c(dim(extract[[1]]), 1)) @@ -97,16 +108,17 @@ if (length(dim(extract[[1]])) == 4) { # make sure polygon is closed; if not, close it. - if ((mypoly[length(mypoly[, 1]), 1] != mypoly[1, 1]) | (mypoly[length(mypoly[, 2]), 2] != mypoly[1, 2])) { + if ((mypoly[length(mypoly[, 1]), 1] != mypoly[1, 1]) | + (mypoly[length(mypoly[, 2]), 2] != mypoly[1, 2])) { mypoly <- rbind(mypoly, c(mypoly[1, 1], mypoly[1, 2])) } #Parse grid lats and longs -# x.vals <- matrix(rep(as.numeric(substr(dimnames(extract)[[1]], 1, nchar(dimnames(extract)[[1]])-1)),length(dimnames(extract)[[2]])), ncol = length(dimnames(extract)[[2]])) -# y.vals <- matrix(sort(rep(as.numeric(substr(dimnames(extract)[[2]], 1, nchar(dimnames(extract)[[2]])-1)),length(dimnames(extract)[[1]]))), ncol = length(dimnames(extract)[[1]])) -x.vals <- matrix(rep(extract$longitude, length(extract$latitude)), ncol = length(extract$latitude)) +x.vals <- matrix(rep(extract$longitude, length(extract$latitude)), + ncol = length(extract$latitude)) y.vals <- sort(rep(extract$latitude, length(extract$longitude))) -y.vals <- matrix(y.vals, nrow = length(extract$latitude), ncol = length(extract$longitude)) +y.vals <- matrix(y.vals, nrow = length(extract$latitude), + ncol = length(extract$longitude)) # deal with polygon crossing 180 ew.sign <- sign(mypoly$x) if (length(unique(ew.sign)) > 1) { @@ -116,8 +128,8 @@ if (length(unique(ew.sign)) > 1) { } # create new array masked by polygon -# in.poly <- matrix(point.in.polygon(x.vals, y.vals, poly$x, poly$y), ncol = length(dimnames(extract)[[1]])) -in.poly <- matrix(sp::point.in.polygon(x.vals, y.vals, mypoly$x, mypoly$y), ncol = length(extract$longitude)) +in.poly <- matrix(sp::point.in.polygon(x.vals, y.vals, mypoly$x, mypoly$y), + ncol = length(extract$longitude)) in.poly[in.poly > 1] <- 1 in.poly[in.poly == 0] <- NA dim(in.poly) <- dim(extract[[1]][, , 1]) diff --git a/cran-comments.md b/cran-comments.md index a4aee77..a1bd0cd 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,11 +1,16 @@ ## Test environments * local OS X install, R 3.6.0 -* rhub check_for_cran Windows Server +* rhub check_for_cran Windows Server and Fedora * win-builder (devel and release) ## Resubmission -Problem with keywords fixed. +Comments given on last submission: + +1. Don't quote function names in Description - fixed +2. change \dontrun{} to \donttest{} - fixed +3. Don't set user option - fixed +4. Don't write to user space - fixed Timings have been reduced as much as possible. 'rxtracto()', 'rxtracto_3D()', and 'rxtractogon()' all are functions that perform subsetting @@ -31,6 +36,9 @@ On rhub Windows Server I get: rxtracto 0.21 0.04 7.10 rxtracto_3D 0.04 0.02 6.40 +On rhub Fedora I get: + +new submission On winbuilder-release I get: diff --git a/man/rxtracto.Rd b/man/rxtracto.Rd index 47ef4b2..7453850 100644 --- a/man/rxtracto.Rd +++ b/man/rxtracto.Rd @@ -2,16 +2,15 @@ % Please edit documentation in R/rxtracto.R \name{rxtracto} \alias{rxtracto} -\title{Extract environmental data along a trajectory from an ERDDAP server using rerddap.} +\title{Extract environmental data along a trajectory from an 'ERDDAP' server using 'rerddap'.} \usage{ rxtracto(dataInfo, parameter = NULL, xcoord = NULL, ycoord = NULL, zcoord = NULL, tcoord = NULL, xlen = 0, ylen = 0, zlen = 0, xName = "longitude", yName = "latitude", zName = "altitude", - tName = "time", urlbase = "https://upwell.pfeg.noaa.gov/erddap", - verbose = FALSE) + tName = "time", verbose = FALSE) } \arguments{ -\item{dataInfo}{- the return from an rerddap "info" call to an ERDDAP server} +\item{dataInfo}{- the return from an 'rerddap::info' call to an 'ERDDAP' server} \item{parameter}{- character string containing the name of the parameter to extract} @@ -31,15 +30,13 @@ decimal degrees N; -90 to 90)} \item{zlen}{- real array defining the depth or altitude box around the given point (zlen/2 around the point)} -\item{xName}{- character string with name of the xcoord in the ERDDAP dataset (default "longitude")} +\item{xName}{- character string with name of the xcoord in the 'ERDDAP' dataset (default "longitude")} -\item{yName}{- character string with name of the ycoord in the ERDDAP dataset (default "latitude")} +\item{yName}{- character string with name of the ycoord in the 'ERDDAP' dataset (default "latitude")} -\item{zName}{- character string with name of the zcoord in the ERDDAP dataset (default "altitude")} +\item{zName}{- character string with name of the zcoord in the 'ERDDAP' dataset (default "altitude")} -\item{tName}{- character string with name of the tcoord in the ERDDAP dataset (default "time")} - -\item{urlbase}{- base URL of the ERDDAP server being accessed - default "http://upwell.pfeg.noaa.gov/erddap"} +\item{tName}{- character string with name of the tcoord in the 'ERDDAP' dataset (default "time")} \item{verbose}{- logical variable (default FALSE) if the the URL request should be verbose} @@ -61,44 +58,30 @@ A dataframe containing: } } \description{ -\code{rxtracto} uses the R program rerddap to extract environmental -data from an ERDDAP server along a (x,y,z, time) trajectory. +\code{rxtracto} uses the R program 'rerddap' to extract environmental +data from an 'ERDDAP' server along a (x,y,z, time) trajectory. } \examples{ -urlbase <- 'https://upwell.pfeg.noaa.gov/erddap' -dataInfo <- rerddap::info('erdMBsstd8day') +# toy example to show use +# but keep execution time down +\donttest{ +dataInfo <- rerddap::info('erdHadISST') +} parameter <- 'sst' -xcoord <- c(230, 231) -ycoord <- c(40, 41) -tcoord <- c('2006-01-15', '2006-01-20') -zcoord <- c(0., 0.) -xlen <- 0.5 -ylen <- 0.5 +xcoord <- c(-130.5) +ycoord <- c(40.5) +tcoord <- c('2006-01-16') +xlen <- 0.01 +ylen <- 0.01 extract <- rxtracto(dataInfo, parameter = parameter, xcoord = xcoord, - ycoord = ycoord, tcoord= tcoord, zcoord = zcoord, + ycoord = ycoord, tcoord= tcoord, xlen = xlen, ylen = ylen) +\donttest{ # 2-D example getting bathymetry dataInfo <- rerddap::info('etopo360') parameter <- 'altitude' extract <- rxtracto(dataInfo, parameter, xcoord = xcoord, ycoord = ycoord, xlen = xlen, ylen = ylen) +} -# Example where grid is not latitude-longitude -dataInfo <- rerddap::info('glos_tds_5912_ca66_3f41') -parameter <- 'temp' -xName <- 'nx' -yName <- 'ny' -zName <- 'nsigma' -xcoord <- c(10, 11) -ycoord <- c(10, 11) -zcoord <- c(1, 1) - # time span changes in this dataset - get last three times - myURL <- "https://upwell.pfeg.noaa.gov/erddap/griddap/glos_tds_5912_ca66_3f41.csv0?time[last - 2:1:last]" -myTimes <- utils::read.csv(utils::URLencode(myURL), header = FALSE, stringsAsFactors = FALSE)[[1]] -tcoord <- c(myTimes[1], myTimes[3]) -xlen <- 0 -ylen <- 0 -extract <- rxtracto(dataInfo, parameter, xcoord = xcoord, ycoord = ycoord, - zcoord = zcoord, tcoord = tcoord, xlen = xlen, - ylen = ylen, xName = xName, yName = yName, zName = zName) } diff --git a/man/rxtracto_3D.Rd b/man/rxtracto_3D.Rd index ff9d328..0e81815 100644 --- a/man/rxtracto_3D.Rd +++ b/man/rxtracto_3D.Rd @@ -2,15 +2,15 @@ % Please edit documentation in R/rxtracto_3D.R \name{rxtracto_3D} \alias{rxtracto_3D} -\title{Extract environmental data in a 3-dimnesional box from an ERDDAP server using rerddap.} +\title{Extract environmental data in a 3-dimensional box from an 'ERDDAP' server using 'rerddap'.} \usage{ rxtracto_3D(dataInfo, parameter = NULL, xcoord = NULL, ycoord = NULL, - zcoord = NULL, tcoord = NULL, xName = "longitude", yName = "latitude", - zName = "altitude", tName = "time", - urlbase = "https://upwell.pfeg.noaa.gov/erddap/", verbose = FALSE) + zcoord = NULL, tcoord = NULL, xName = "longitude", + yName = "latitude", zName = "altitude", tName = "time", + verbose = FALSE, cache_remove = TRUE) } \arguments{ -\item{dataInfo}{- the return from an rerddap "info" call to an ERDDAP server} +\item{dataInfo}{- the return from an 'rerddap:info' call to an 'ERDDAP' server} \item{parameter}{- character string containing the name of the parameter to extract} @@ -24,17 +24,17 @@ decimal degrees N; -90 to 90)} \item{tcoord}{- a character array with the times of the trajectory in "YYYY-MM-DD" - for now restricted to be time.} -\item{xName}{- character string with name of the xcoord in the ERDDAP dataset (default "longitude")} +\item{xName}{- character string with name of the xcoord in the 'ERDDAP' dataset (default "longitude")} -\item{yName}{- character string with name of the ycoord in the ERDDAP dataset (default "latitude")} +\item{yName}{- character string with name of the ycoord in the 'ERDDAP' dataset (default "latitude")} -\item{zName}{- character string with name of the zcoord in the ERDDAP dataset (default "altitude")} +\item{zName}{- character string with name of the zcoord in the 'ERDDAP' dataset (default "altitude")} -\item{tName}{- character string with name of the tcoord in the ERDDAP dataset (default "time")} - -\item{urlbase}{- base URL of the ERDDAP server being accessed - default "http://upwell.pfeg.noaa.gov/erddap"} +\item{tName}{- character string with name of the tcoord in the 'ERDDAP' dataset (default "time")} \item{verbose}{- logical variable (default FALSE) if the the URL request should be verbose} + +\item{cache_remove}{- logical variable (default TRUE) whether to delete 'rerddap' cache} } \value{ structure with data and dimensions: @@ -48,44 +48,29 @@ structure with data and dimensions: } } \description{ -\code{rxtracto_3D} uses the R program rerddap to extract environmental data -from an ERDDAP server in an (x,y,z, time) bounding box. +\code{rxtracto_3D} uses the R program 'rerddap' to extract environmental data +from an 'ERDDAP' server in an (x,y,z, time) bounding box. The same call could be made directly in rerddap, but function is maintained as it is used in the polygon routine. } \examples{ -urlbase <- 'https://upwell.pfeg.noaa.gov/erddap' -dataInfo <- rerddap::info('erdMBsstd8day') +# toy example to show use +# and keep execution time low +\donttest{ +dataInfo <- rerddap::info('erdHadISST') +} parameter <- 'sst' -xcoord <- c(230, 235) -ycoord <- c(40, 45) -tcoord <- c('2006-01-15', '2006-01-20') -zcoord <- c(0., 0.) +xcoord <- c(-130.5, -130.5) +ycoord <- c(40.5, 40.5) +tcoord <- c('2006-01-16', '2006-01-16') extract <- rxtracto_3D(dataInfo, parameter, xcoord = xcoord, ycoord = ycoord, - tcoord = tcoord, zcoord = zcoord) + tcoord = tcoord) +\donttest{ # 2-D example getting bathymetry dataInfo <- rerddap::info('etopo360') parameter <- 'altitude' extract <- rxtracto_3D(dataInfo, parameter, xcoord = xcoord, ycoord = ycoord) - -# Example where grid is not latitude-longitude -dataInfo <- rerddap::info('glos_tds_5912_ca66_3f41') -parameter = 'temp' -xName <- 'nx' -yName <- 'ny' -zName <- 'nsigma' -xcoord <- c(10, 11) -ycoord <- c(10, 11) -zcoord <- c(1, 1) - # time span changes in this dataset - get last three times - myURL <- "https://upwell.pfeg.noaa.gov/erddap/griddap/glos_tds_5912_ca66_3f41.csv0?time[last - 2:1:last]" -myTimes <- utils::read.csv(utils::URLencode(myURL), header = FALSE, stringsAsFactors = FALSE)[[1]] -tcoord <- c(myTimes[1], myTimes[3]) -extract <- rxtracto_3D(dataInfo, parameter, xcoord = xcoord, ycoord = ycoord, - zcoord = zcoord, tcoord = tcoord, xName = xName, - yName = yName, zName = zName) - # Dataset that has depth also # 3 months of subsurface temperature at 70m depth from SODA 2.2.4 dataInfo <- rerddap::info('erdSoda331oceanmday') @@ -100,5 +85,6 @@ tcoord <- c('2010-10-15', '2010-12-15') extract <- rxtracto_3D(dataInfo, parameter, xcoord = xcoord, ycoord = ycoord, zcoord = zcoord, tcoord = tcoord, xName = xName, yName = yName, zName = zName) +} } diff --git a/man/rxtractogon.Rd b/man/rxtractogon.Rd index 9b8914a..12b3794 100644 --- a/man/rxtractogon.Rd +++ b/man/rxtractogon.Rd @@ -2,15 +2,15 @@ % Please edit documentation in R/rxtractogon.R \name{rxtractogon} \alias{rxtractogon} -\title{Extract environmental data in a polygon using ERDDAP.} +\title{Extract environmental data in a polygon using 'ERDDAP' and 'rerddap'.} \usage{ rxtractogon(dataInfo, parameter, xcoord = NULL, ycoord = NULL, - zcoord = NULL, tcoord = NULL, xName = "longitude", yName = "latitude", - zName = "altitude", tName = "time", - urlbase = "https://upwell.pfeg.noaa.gov/erddap", verbose = FALSE) + zcoord = NULL, tcoord = NULL, xName = "longitude", + yName = "latitude", zName = "altitude", tName = "time", + verbose = FALSE) } \arguments{ -\item{dataInfo}{- the return from an rerddap "info" call to an ERDDAP server} +\item{dataInfo}{- the return from an 'rerddap:info' call to an 'ERDDAP' server} \item{parameter}{- character string containing the name of the parameter to extract} @@ -24,15 +24,13 @@ degrees N; -90 to 90)of polygon} \item{tcoord}{- 2-array of minimum and maximum times as 'YYYY-MM-DD'} -\item{xName}{- character string with name of the xcoord in the ERDDAP dataset (default "longitude")} +\item{xName}{- character string with name of the xcoord in the 'ERDDAP' dataset (default "longitude")} -\item{yName}{- character string with name of the ycoord in the ERDDAP dataset (default "latitude")} +\item{yName}{- character string with name of the ycoord in the 'ERDDAP' dataset (default "latitude")} -\item{zName}{- character string with name of the zcoord in the ERDDAP dataset (default "altitude")} +\item{zName}{- character string with name of the zcoord in the 'ERDDAP' dataset (default "altitude")} -\item{tName}{- character string with name of the tcoord in the ERDDAP dataset (default "time")} - -\item{urlbase}{- base URL of the ERDDAP server being accessed - default "http://upwell.pfeg.noaa.gov/erddap"} +\item{tName}{- character string with name of the tcoord in the 'ERDDAP' dataset (default "time")} \item{verbose}{- logical variable (default FALSE) if the the URL request should be verbose} } @@ -48,26 +46,31 @@ structure with data and dimensions } } \description{ -\code{rxtractogon} uses the ERD ERDDAP data web service to extact -environmental data inside a polygon defined by vectors of -latitudes and longitudes +\code{rxtractogon} uses the R program 'rerddap' to extract environmental data +from an 'ERDDAP' server in a polygon through time. } \section{Details}{ rxtractogon extracts the data from the smallest bounding box that contains the polygon, and then uses the function "point.in.polygon" from the "sp" - package to mask out the areas outside of the polygon. rxtractogon only works with - datasets defined on a latitude and longitude grid. + package to mask out the areas outside of the polygon. + rxtractogon only works with datasets defined + on a latitude and longitude grid. } \examples{ -dataInfo <- rerddap::info('erdVH3chlamday') -parameter <- 'chla' -tcoord <- c("2016-06-15", "2016-06-15") -xcoord <- mbnms$Longitude -ycoord <- mbnms$Latitude -sanctchl <- rxtractogon (dataInfo, parameter=parameter, xcoord = xcoord, +# toy example to show use +# and keep execution time low +\donttest{ +dataInfo <- rerddap::info('erdHadISST') +} +parameter <- 'sst' +tcoord <- c("2016-06-15") +xcoord <- mbnms$Longitude[1:3] +ycoord <- mbnms$Latitude[1:3] +sanctSST <- rxtractogon (dataInfo, parameter=parameter, xcoord = xcoord, ycoord = ycoord, tcoord= tcoord) +\donttest{ xcoord <- mbnms$Longitude ycoord <- mbnms$Latitude dataInfo <- rerddap::info('etopo180') @@ -77,3 +80,4 @@ yName <- 'latitude' bathy <- rxtractogon (dataInfo, parameter = parameter, xcoord = xcoord, ycoord = ycoord) } +} diff --git a/rerddapXtracto.Rproj b/rerddapXtracto.Rproj index 497f8bf..270314b 100644 --- a/rerddapXtracto.Rproj +++ b/rerddapXtracto.Rproj @@ -18,3 +18,4 @@ StripTrailingWhitespace: Yes BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace