-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added plotting functions, tracks in (x, y, z, t ) space, cleaned up code
- Loading branch information
Showing
15 changed files
with
464 additions
and
258 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: rerddapXtracto | ||
Type: Package | ||
Title: Extracts Environmental Data from ERD's ERDDAP Web Service | ||
Version: 0.2.0 | ||
Version: 0.3.0 | ||
Authors@R: person("Roy", "Mendelssohn", email = "[email protected]", role = c("aut","cre")) | ||
Description: The xtractomatic package contains three functions that access | ||
environmental data from ERD's ERDDAP service. The rxtracto function extracts | ||
|
@@ -15,25 +15,19 @@ Description: The xtractomatic package contains three functions that access | |
to be extracted. | ||
URL: https://github.com/rmendels/rerddapXtracto | ||
BugReports: https://github.com/rmendels/rerddapXtracto/issues | ||
Depends: | ||
R (>= 3.3.0) | ||
License: CC0 | ||
LazyData: TRUE | ||
Imports: | ||
abind, | ||
methods, | ||
ncdf4, | ||
parsedate, | ||
plotdap, | ||
rerddap, | ||
sp, | ||
stats | ||
Suggests: | ||
akima, | ||
dplyr, | ||
ggfortify, | ||
ggplot2, | ||
knitr, | ||
lubridate, | ||
mapdata, | ||
xts | ||
RoxygenNote: 5.0.1 | ||
RoxygenNote: 6.0.1 |
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,84 @@ | ||
#' plot result of xtracto_3D or rxtracto_3D | ||
#' | ||
#' \code{plotBox} is a function to plot the results from | ||
#' rxtracto() and xtracto() | ||
#' | ||
#' @export | ||
#' @param resp data frame returned from rxtracto() or xtracto() | ||
#' @param plotColor the color to use in plot from rerddap | ||
#' @param time a function to map multi-time to one, or else identity for animation | ||
#' @param animate if multiple times, if TRUE will animate the maps | ||
#' @param myFunc function of one argument to transform the data | ||
#' @param maxpixels maximum numbe rof pixels to use in making the map - controls resolution | ||
#' @return a plotdap plot | ||
#' | ||
#' @examples | ||
#' tagData <- Marlintag38606 | ||
#' xpos <- tagData$lon | ||
#' ypos <- tagData$lat | ||
#' tpos <- tagData$date | ||
#' zpos <- rep(0., length(xpos)) | ||
#' urlbase <- 'http://upwell.pfeg.noaa.gov/erddap' | ||
#' swchlInfo <- rerddap::info('erdSWchla8day') | ||
#' swchl <- rxtracto(swchlInfo, parameter = 'chlorophyll', xcoord = xpos, ycoord = ypos, tcoord = tpos, zcoord = zpos, xlen = .2, ylen = .2) | ||
#' plotBox(xpos, ypos, swchl, plotColor = 'chlorophyll') | ||
|
||
plotBox <- function(resp, plotColor = 'viridis', time = NA, animate = FALSE, name = NA, myFunc = NA, maxpixels = 10000){ | ||
require(rerddap) | ||
require(plotdap) | ||
if (!is.function(time)) { | ||
time <- function(x) mean(x, na.rm = TRUE) | ||
} | ||
if (is.function(myFunc)) { | ||
resp[[1]] <- myFunc(resp[[1]]) | ||
} | ||
if (!is.na(name)) { | ||
names(resp)[1] <- name | ||
} | ||
paramName = names(resp)[1] | ||
myStruct <- meltnc(resp) | ||
myStruct <- structure( | ||
myStruct, | ||
class = c("griddap_nc", "nc", "data.frame") | ||
) | ||
p <- plotdap::plotdap() | ||
parameter1 <- as.formula(paste('~', paramName)) | ||
myList <- list(p, myStruct, parameter1, plotColor, time, animate, maxpixels ) | ||
names(myList) <- c('plot', 'grid', 'var', 'fill', 'time', 'animate', 'maxpixels') | ||
myplot <- do.call(plotdap::add_griddap, myList) | ||
myplot | ||
} | ||
|
||
meltnc <- function(resp ){ | ||
## modified from rerddap::ncdf4_get | ||
rows = length(resp[[1]]) | ||
if (is.null(resp$time)) { | ||
exout <- do.call("expand.grid", list(longitude = resp$longtiude, latitude = resp$latitude)) | ||
meta <- dplyr::arrange_(exout, names(exout)[1]) | ||
} else { | ||
time <- as.character(resp$time) | ||
time <- suppressWarnings(rep(time, each = rows/length(resp$time))) | ||
lat <- rep(rep(resp$latitude, each = length(resp$longitude)), | ||
length(resp$time)) | ||
lon <- rep(rep(resp$longitude, times = length(resp$latitude)), | ||
times = length(resp$time)) | ||
meta <- data.frame(time, lat, lon, stringsAsFactors = FALSE) | ||
} | ||
|
||
# make data.frame | ||
df <- as.vector(resp[[1]]) | ||
df <- data.frame(df) | ||
names(df) <- names(resp)[1] | ||
alldf <- if (NROW(meta) > 0) cbind(meta, df) else df | ||
|
||
# Fool plotdap that there is a summary | ||
summary_time = list(vals = as.numeric(resp$time)) | ||
summary_lons <- list(vals = resp$longitude) | ||
summary_lats <- list(vals = resp$latitude) | ||
dims <- list(time = summary_time, longitude = summary_lons, latitude = summary_lats) | ||
summary <- list(dims) | ||
names(summary) <- 'dim' | ||
# output | ||
list(summary = summary, data = alldf) | ||
} | ||
|
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,53 @@ | ||
#' plot result of xtracto or rxtracto | ||
#' | ||
#' \code{plotTrack} is a function to plot the results from | ||
#' rxtracto() and xtracto() | ||
#' @export | ||
#' @param xcoord passed to rxtracto() or xtracto() | ||
#' @param ycoord passed to rxtracto() or xtracto() | ||
#' @param resp data frame returned from rxtracto() or xtracto() | ||
#' @param plotColor the color to use in plot from rerddap | ||
#' @param myFunc function of one argument to transform the data | ||
#' @return a plotdap plot | ||
#' | ||
#' @examples | ||
#' tagData <- Marlintag38606 | ||
#' xpos <- tagData$lon | ||
#' ypos <- tagData$lat | ||
#' tpos <- tagData$date | ||
#' zpos <- rep(0., length(xpos)) | ||
#' urlbase <- 'http://upwell.pfeg.noaa.gov/erddap' | ||
#' swchlInfo <- rerddap::info('erdSWchla8day') | ||
#' swchl <- rxtracto(swchlInfo, parameter = 'chlorophyll', xcoord = xpos, ycoord = ypos, tcoord = tpos, zcoord = zpos, xlen = .2, ylen = .2) | ||
#' plotTrack(xpos, ypos, swchl, plotColor = 'chlorophyll') | ||
|
||
plotTrack <- function(xcoord, ycoord, resp, plotColor = 'viridis', name = NA, myFunc = NA, shape = 20, size = .5){ | ||
require(rerddap) | ||
require(plotdap) | ||
ind <- which(xcoord > 180) | ||
xcoord[ind] <- xcoord[ind] - 360 | ||
if (is.function(myFunc)) { | ||
resp[[1]] <- myFunc(resp[[1]]) | ||
} | ||
myDataFrame = data.frame(xcoord, ycoord, resp[[1]]) | ||
nameLen <- nchar(names(resp)) | ||
if (is.na(name)) { | ||
paramName <- substr(names(resp)[1], 6, nameLen) | ||
}else{ | ||
paramName = name | ||
} | ||
names(myDataFrame) <- c('longitude', 'latitude', paramName) | ||
myStruct <- structure( | ||
myDataFrame, | ||
class = c("tabledap", "data.frame") | ||
) | ||
p <- plotdap::plotdap() | ||
paramName1 <- as.formula(paste('~', paramName)) | ||
myList <- list(p, myStruct, paramName1, plotColor, shape, size) | ||
names(myList) <- c('plot', 'table', 'var', 'color', 'shape', 'size') | ||
#plotCmd <- paste0('add_tabledap(plotdap(), myStruct, ~', paramName, | ||
# ', color = ', deparse(plotColor), ', shape =20, size= .5)') | ||
#myPlot <- eval(parse(text = plotCmd)) | ||
myPlot <- do.call(plotdap::add_tabledap, myList) | ||
myPlot | ||
} |
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
Oops, something went wrong.