Skip to content

Commit 425f69f

Browse files
committed
Added import_remote function, tweak to ecometab function to format all columns as numeric
1 parent 13824df commit 425f69f

7 files changed

Lines changed: 111 additions & 6 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: SWMPr
22
Type: Package
33
Title: SWMPr package for estuarine monitoring data
4-
Version: 1.8.1
5-
Date: 2015-3-20
4+
Version: 1.9.0
5+
Date: 2015-3-23
66
Author: Marcus Beck
77
Maintainer: Marcus Beck <mbafs2012@gmail.com>
88
Description: This packages provides functions for retrieving, organizing, and

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export(decomp_cj.swmpr)
1818
export(ecometab)
1919
export(hist.swmpr)
2020
export(import_local)
21+
export(import_remote)
2122
export(lines.swmpr)
2223
export(map_reserve)
2324
export(metab_day)

R/swmpr_analyze.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,13 @@ ecometab.swmpr <- function(swmpr_in, depth_val = NULL, metab_units = 'mmol', tra
10681068
'wspd', 'bp')
10691069
dat <- dat[,names(dat) %in% to_keep]
10701070

1071+
# all vals as numeric
1072+
dat[, 2:ncol(dat)] <- apply(
1073+
dat[, 2:ncol(dat), drop = FALSE],
1074+
2,
1075+
function(x) suppressWarnings(as.numeric(x))
1076+
)
1077+
10711078
#convert do from mg/L to mmol/m3
10721079
dat$do <- dat[, 'do_mgl'] / 32 * 1000
10731080

@@ -1077,7 +1084,7 @@ ecometab.swmpr <- function(swmpr_in, depth_val = NULL, metab_units = 'mmol', tra
10771084
# take diff of each column, divide by 2, add original value
10781085
datetimestamp <- diff(dat$datetimestamp)/2 + dat$datetimestamp[-c(nrow(dat))]
10791086
dat <- apply(
1080-
dat[,2:ncol(dat)],
1087+
dat[,2:ncol(dat), drop = FALSE],
10811088
2,
10821089
function(x) diff(x)/2 + x[1:(length(x) -1)]
10831090
)

R/swmpr_retrieval.R

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,59 @@ import_local <- function(path, station_code, trace = FALSE){
400400
# return data frame
401401
return(out)
402402

403-
}
403+
}
404+
405+
406+
407+
######
408+
#' Import SWMP data from Amazon web services
409+
#'
410+
#' Import SWMP data that are stored on Amazon web services as .RData files. Data include almost all available data from 1994 to 2014 for every SWMP station.
411+
#'
412+
#' @param station_code chr string of station to import, i.e., 7 or 8 characters indicating the reserve, site, and data type. Do not include years.
413+
#'
414+
#' @export
415+
#'
416+
#' @return Returns a swmpr object.
417+
#'
418+
#' @details
419+
#' This function allows quick retrieval of .RData files for all data at a single SwMP site. It differs from the other data retrieval functions in that the raw data are downloaded from an independent remote server. Retrieval time is much faster because the files are in binary format for quick import. However, the data are only available up to December 2014 and may not be regularly updated. Always use the CDMO for current data. The data have also been pre-processed using the \code{\link{qaqc}} and setstep functions.
420+
#'
421+
#' The files are available here: \url{https://s3.amazonaws.com/swmpalldata/}. Files can be obtained using the function or by copying the URL to a web browser with the station name appended to the address, including the .RData file extenssion. For example, \url{https://s3.amazonaws.com/swmpalldata/acebbnut.RData}.
422+
#'
423+
#' @seealso \code{\link{import_local}}
424+
#'
425+
#' @examples
426+
#' ## see the available files on the server
427+
#' library(XML)
428+
#' library(httr)
429+
#' files_s3 <- GET('https://s3.amazonaws.com/swmpalldata/')$content
430+
#' files_s3 <- rawToChar(files_s3)
431+
#' files_s3 <- htmlTreeParse(files_s3, useInternalNodes = T)
432+
#' files_s3 <- xpathSApply(files_s3, '//contents//key', xmlValue)
433+
#'
434+
#' ## import a file
435+
#' dat <- import_remote('acebbnut')
436+
#'
437+
#' head(dat)
438+
#'
439+
#' attributes(dat)
440+
import_remote <- function(station_code){
441+
442+
# download
443+
raw_content <- paste0(
444+
'https://s3.amazonaws.com/swmpalldata/',
445+
station_code,
446+
'.RData'
447+
)
448+
raw_content <- httr::GET(raw_content)$content
449+
connect <- rawConnection(raw_content)
450+
load(connect)
451+
wq <- get(station_code)
452+
close(connect)
453+
454+
# return
455+
return(wq)
456+
457+
}
458+

man/ecometab.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Input data include both water quality and weather time series, which are typical
4242

4343
The open-water method is a common approach to quantify net ecosystem metabolism using a mass balance equation that describes the change in dissolved oxygen over time from the balance between photosynthetic and respiration processes, corrected using an empirically constrained air-sea gas diffusion model (see Ro and Hunt 2006, Thebault et al. 2008). The diffusion-corrected DO flux estimates are averaged separately over each day and night of the time series. The nighttime average DO flux is used to estimate respiration rates, while the daytime DO flux is used to estimate net primary production. To generate daily integrated rates, respiration rates are assumed constant such that hourly night time DO flux rates are multiplied by 24. Similarly, the daytime DO flux rates are multiplied by the number of daylight hours, which varies with location and time of year, to yield net daytime primary production. Respiration rates are subtracted from daily net production estimates to yield gross production rates. The metabolic day is considered the 24 hour period between sunsets on two adjacent calendar days.
4444

45-
Aereal rates for gross production and total respiration are based on volumetric rates normalized to the depth of the water column at the sampling location, which is assumed to be well-mixed, such that the DO sensor is reflecting the integrated processes in the entire water column (including the benthos). Water column depth is calculated as the mean value of the depth variable across the time series in the \code{\link{swmpr}} object. Depth values are floored at one meter for very shallow stations and 0.5 meters is also added to reflect the practice of placing sensors slightly off of the bottom. Additionally, the air-sea gas exchange model is calibrated with wind data either collected at, or adjusted to, wind speed at 10 m above the surface. The metadata should be consulted for exact height. The value can be changed manually using a \code{height} argument, which is passed to \code{\link{calckl}}.
45+
Areal rates for gross production and total respiration are based on volumetric rates normalized to the depth of the water column at the sampling location, which is assumed to be well-mixed, such that the DO sensor is reflecting the integrated processes in the entire water column (including the benthos). Water column depth is calculated as the mean value of the depth variable across the time series in the \code{\link{swmpr}} object. Depth values are floored at one meter for very shallow stations and 0.5 meters is also added to reflect the practice of placing sensors slightly off of the bottom. Additionally, the air-sea gas exchange model is calibrated with wind data either collected at, or adjusted to, wind speed at 10 m above the surface. The metadata should be consulted for exact height. The value can be changed manually using a \code{height} argument, which is passed to \code{\link{calckl}}.
4646

4747
A minimum of three records are required for both day and night periods to calculate daily metabolism estimates. Occasional missing values for air temperature, barometric pressure, and wind speed are replaced with the climatological means (hourly means by month) for the period of record using adjacent data within the same month as the missing data.
4848

man/import_remote.Rd

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
% Generated by roxygen2 (4.1.0): do not edit by hand
2+
% Please edit documentation in R/swmpr_retrieval.R
3+
\name{import_remote}
4+
\alias{import_remote}
5+
\title{Import SWMP data from Amazon web services}
6+
\usage{
7+
import_remote(station_code)
8+
}
9+
\arguments{
10+
\item{station_code}{chr string of station to import, i.e., 7 or 8 characters indicating the reserve, site, and data type. Do not include years.}
11+
}
12+
\value{
13+
Returns a swmpr object.
14+
}
15+
\description{
16+
Import SWMP data that are stored on Amazon web services as .RData files. Data include almost all available data from 1994 to 2014 for every SWMP station.
17+
}
18+
\details{
19+
This function allows quick retrieval of .RData files for all data at a single SwMP site. It differs from the other data retrieval functions in that the raw data are downloaded from an independent remote server. Retrieval time is much faster because the files are in binary format for quick import. However, the data are only available up to December 2014 and may not be regularly updated. Always use the CDMO for current data. The data have also been pre-processed using the \code{\link{qaqc}} and setstep functions.
20+
21+
The files are available here: \url{https://s3.amazonaws.com/swmpalldata/}. Files can be obtained using the function or by copying the URL to a web browser with the station name appended to the address, including the .RData file extenssion. For example, \url{https://s3.amazonaws.com/swmpalldata/acebbnut.RData}.
22+
}
23+
\examples{
24+
## see the available files on the server
25+
library(XML)
26+
library(httr)
27+
files_s3 <- GET('https://s3.amazonaws.com/swmpalldata/')$content
28+
files_s3 <- rawToChar(files_s3)
29+
files_s3 <- htmlTreeParse(files_s3, useInternalNodes = T)
30+
files_s3 <- xpathSApply(files_s3, '//contents//key', xmlValue)
31+
32+
## import a file
33+
dat <- import_remote('acebbnut')
34+
35+
head(dat)
36+
37+
attributes(dat)
38+
}
39+
\seealso{
40+
\code{\link{import_local}}
41+
}
42+

man/plot_summary.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ data(apacpnut)
3333
dat <- qaqc(apacpnut)
3434

3535
## plot
36-
plot_summary(dat, param = 'chla_n')
36+
plot_summary(dat, param = 'chla_n', years = c(2007, 2013))
3737
}
3838
\seealso{
3939
\code{\link[ggplot2]{ggplot}}

0 commit comments

Comments
 (0)