Skip to content

Commit

Permalink
removed two coops egs that were leading to no results
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Oct 22, 2016
1 parent 7448dc9 commit 83ac413
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 59 deletions.
74 changes: 33 additions & 41 deletions R/coops.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#' @param end_date (numeric) Date in yyyymmdd format. Required
#' @param product (character) Specify the data type. See below for Details. Required
#' @param datum (character) See below for Details. Required for all water level products.
#' @param units (character) Specify metric or english (imperial) units, one of 'metric', 'english'.
#' @param units (character) Specify metric or english (imperial) units, one of 'metric', 'english'.
#' @param time_zone (character) Time zone, one of 'gmt', 'lst', 'lst_ldt'.
#' @param application (character) If called within an external package, set to the name of your
#' organization. Optional
#' @param ... Curl options passed on to \code{\link[httr]{GET}}. Optional
#'
#' @details
#'
#' @details
#' Options for the product paramter. One of:
#' \itemize{
#' \item water_level - Preliminary or verified water levels, depending on availability
Expand All @@ -23,7 +23,7 @@
#' \item air_pressure - Barometric pressure as measured at the station
#' \item air_gap - Air Gap (distance between a bridge and the water's surface) at the station
#' \item conductivity - The water's conductivity as measured at the station
#' \item visibility - Visibility from the station's visibility sensor. A measure of
#' \item visibility - Visibility from the station's visibility sensor. A measure of
#' atmospheric clarity
#' \item humidity - Relative humidity as measured at the station
#' \item salinity - Salinity and specific gravity data for the station
Expand All @@ -36,7 +36,7 @@
#' \item datums - datums data for the stations
#' \item currents - Currents data for currents stations
#' }
#'
#'
#' Options for the datum paramter. One of:
#' \itemize{
#' \item MHHW - Mean higher high water
Expand All @@ -49,12 +49,12 @@
#' \item STND - Station datum
#' }
#'
#' @references
#' @references
#' \url{http://co-ops.nos.noaa.gov/api/}
#'
#'
#' \url{http://tidesandcurrents.noaa.gov/map/}
#'
#' @return List, of length one or two.
#'
#' @return List, of length one or two.
#' \itemize{
#' \item metadata A list of metadata with slots id, name, lat, lon
#' \item data A data.frame with data
Expand All @@ -63,79 +63,71 @@
#' # Get monthly mean sea level data at Vaca Key (8723970)
#' coops_search(station_name = 8723970, begin_date = 19820301, end_date = 20141001,
#' datum = "stnd", product = "monthly_mean")
#'
#'
#' # Get verified water level data at Vaca Key (8723970)
#' coops_search(station_name = 8723970, begin_date = 20140927, end_date = 20140928,
#' datum = "stnd", product = "water_level")
#'
#'
#' # Get daily mean water level data at Fairport, OH (9063053)
#' coops_search(station_name = 9063053, begin_date = 20150927, end_date = 20150928,
#' product = "daily_mean", datum = "stnd", time_zone = "lst")
#'
#'
#' # Get air temperature at Vaca Key (8723970)
#' coops_search(station_name = 8723970, begin_date = 20140927, end_date = 20140928,
#' product = "air_temperature")
#'
#'
#' # Get water temperature at Vaca Key (8723970)
#' coops_search(station_name = 8723970, begin_date = 20140927, end_date = 20140928,
#' product = "water_temperature")
#'
#'
#' # Get air pressure at Vaca Key (8723970)
#' coops_search(station_name = 8723970, begin_date = 20140927, end_date = 20140928,
#' product = "air_pressure")
#'
#' # Get conductivity at Eugene Island, LA (8764314)
#' coops_search(station_name = 8764314, begin_date = 20151223, end_date = 20151224,
#' product = "conductivity")
#'
#' # Get salinity at Eugene Island, LA (8764314)
#' coops_search(station_name = 8764314, begin_date = 20150927, end_date = 20150928,
#' product = "salinity")
#'
#'
#' # Get humidity at Eugene Island, LA (8764314)
#' coops_search(station_name = 8764314, begin_date = 20150927, end_date = 20150928,
#' product = "humidity")
#'
#' # Get wind at Vaca Key (8723970)
#' coops_search(station_name = 8723970, begin_date = 20140927, end_date = 20140928,
#' product = "wind")
#'
#'
#' # Get hourly water level height at Key West (8724580)
#' coops_search(station_name = 8724580, begin_date = 20140927, end_date = 20140928,
#' product = "hourly_height", datum = "stnd")
#'
#'
#' # Get high-low water level at Key West (8724580)
#' coops_search(station_name = 8724580, begin_date = 20140927, end_date = 20140928,
#' product = "high_low", datum = "stnd")
#'
#'
#' # Get currents data at Pascagoula Harbor (ps0401)
#' coops_search(station_name = "ps0401", begin_date = 20151221, end_date = 20151222,
#' product = "currents")
#'
#'
#' # Get one-minute water level at Vaca Key (8723970)
#' coops_search(station_name = 8723970, begin_date = 20140927, end_date = 20140928,
#' datum = "stnd", product = "one_minute_water_level")
#'
#'
#' # Get datums at Fort Myers, FL (8725520)
#' coops_search(station_name = 8725520, product = "datums")
#'
#'
#' # Get water level predictions at Vaca Key (8723970)
#' coops_search(station_name = 8723970, begin_date = 20140928, end_date = 20140929,
#' datum = "stnd", product = "predictions")
#'
#'
#' }
coops_search <- function(begin_date = NULL, end_date = NULL, station_name = NULL,
product, datum = NULL, units = "metric", time_zone = "gmt",
coops_search <- function(begin_date = NULL, end_date = NULL, station_name = NULL,
product, datum = NULL, units = "metric", time_zone = "gmt",
application = "rnoaa", ...){

water_level_products <- c("water_level", "hourly_height", "high_low", "daily_mean", "monthly_mean", "one_minute_water_level", "predictions")
if(product %in% water_level_products & length(datum) < 1){
stop("Must specify a datum for water level products", call. = FALSE)
}
args <- noaa_compact(list(begin_date = begin_date, end_date = end_date,
station = station_name, product = product, datum = datum,
units = units, time_zone = time_zone, application = application,

args <- noaa_compact(list(begin_date = begin_date, end_date = end_date,
station = station_name, product = product, datum = datum,
units = units, time_zone = time_zone, application = application,
format = "json"))

res <- coops_GET(coops_base(), args, ...)
Expand All @@ -144,22 +136,22 @@ coops_search <- function(begin_date = NULL, end_date = NULL, station_name = NULL
& is.null(nrow(res$datums))) {
stop("No data was found", call. = FALSE)
}

if(!(product %in% c("monthly_mean", "datums"))){
res[[length(res)]][,1] <- as.POSIXct(res[[length(res)]][,1])
}

if(product == "monthly_mean"){
res[[length(res)]] <- data.frame(apply(res[[length(res)]], 2, as.numeric))
}

res[[length(res)]][,2] <- as.numeric(res[[length(res)]][,2])

res
}

coops_base <- function() "http://tidesandcurrents.noaa.gov/api/datagetter"

coops_GET <- function(url, args, ...) {
res <- httr::GET(url, query = args, ...)
httr::stop_for_status(res)
Expand Down
28 changes: 10 additions & 18 deletions man/coops.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 83ac413

Please sign in to comment.