Skip to content

Commit

Permalink
Merge pull request #2 from jread-usgs/master
Browse files Browse the repository at this point in the history
v0.1.0 release changes
  • Loading branch information
Jordan S Read committed Jul 10, 2014
2 parents cbb6591 + b6cbb6f commit b8dbf43
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 30 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(MAD)
export(block_stats)
export(build_flags)
export(clean.data)
export(error_code)
export(get.outliers)
export(load.sensor)
Expand Down
6 changes: 3 additions & 3 deletions R/build.flags.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ flatten_flags <- function(flag.bool){
return(data.flags)
}

#'compresses boolean flags into int matrix padded with NAs
#'flags are compressed because it is assumed that they don't happen incredibly frequently
#'example: flag.bool <- matrix(nrow=3,ncol=4,data=c(F,F,F,F,F,F,T,T,F,F,F,F))
# compresses boolean flags into int matrix padded with NAs
# flags are compressed because it is assumed that they don't happen incredibly frequently
# example: flag.bool <- matrix(nrow=3,ncol=4,data=c(F,F,F,F,F,F,T,T,F,F,F,F))
compress_flags <- function(flag.bool){
# find longest j dimension of T
num.row <- max(colSums(flag.bool))
Expand Down
39 changes: 33 additions & 6 deletions R/clean.data.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
clean.data <- function(deploy='pellerin'){
#'@title cleans sensor data with user-specified routines
#'@description
#'cleans sensor data according to details within the user-specified config (*yml) file \cr
#'
#'@param deploy a string for the *.yml file name
#'@param folder a string which specifies the folder of the *.yml file
#'@param plot.diagnostic a boolean for creating a diagnostic plot
#'@param write.file a boolean for creating a timeseries file output
#'@return An optional plot and optional file output handle
#'@keywords methods
#'@author
#'Jordan S. Read
#'@examples
#'\dontrun{
#'clean.data(deploy='pellerin',folder='/[User]/Desktop/Science Projects/sensorQC/',plot.diagnostic=FALSE)
#'clean.data(deploy='pellerin',folder='/[User]/Desktop/Science Projects/sensorQC/',plot.diagnostic=TRUE,write.file=TRUE)
#'}
#'@export
clean.data <- function(deploy='pellerin',folder='../examples/',plot.diagnostic=TRUE, write.file= FALSE){
#is an example wrapper for sensorQC calls

#
cnfg <- load.sqc(deploy.name=deploy,folder='../examples/')
cnfg <- load.sqc(deploy.name=deploy,folder=folder)

sensor.file <- paste(cnfg$data_source[[1]]$folder_name,cnfg$data_source[[1]]$file_name,sep='')

Expand All @@ -22,11 +40,20 @@ clean.data <- function(deploy='pellerin'){
old.inst.flags <- build_flags(data.in=windowed.data,sqc=simple.sqc$outlier_removal,verbose=F)
old.sensor <- block_stats(windowed.data=windowed.data,old.inst.flags)

plot_summary(inst.data=windowed.data,inst.flags,block.data=sensor.stats,block.flags,compare.data=old.sensor,sqc=cnfg)
if (plot.diagnostic){
plot_summary(inst.data=windowed.data,inst.flags,block.data=sensor.stats,block.flags,
compare.data=old.sensor,sqc=cnfg)
}

if (write.file){
output = paste0(folder,deploy,"_sqc_out.tsv")
flat.block <- flatten_flags(block.flags)
write.out <- sensor.stats[!flat.block, ]
write.table(write.out,file=output,col.names=TRUE, quote=FALSE, row.names=FALSE, sep="\t")
}





}


#
2 changes: 1 addition & 1 deletion R/load.sensor.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ read.wide_burst <- function(filename,date.type){

fileLines <- readLines(c)
close(c)
cat('num lines:');cat(length(fileLines));cat('\n')
cat('number of observations:');cat(length(fileLines)*30);cat('\n')
sens.vec <- vector(mode="numeric",length=length(fileLines)*60)
date.vec <- rep(as.POSIXct('1900-01-01'),length(fileLines)*60)

Expand Down
7 changes: 2 additions & 5 deletions R/plot_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ plot_summary <- function(inst.data,inst.flags,block.data,block.flags,compare.dat

xlm = c(min(inst.data[, 1]), max(inst.data[, 1]))
ylm = c(0,1.1*max(block.data[, 2]))
plot(inst.data[, 1],rep(NA,nrow(inst.data)),ylim=ylm,
ylab="SUNA nitrate concentration (micromoles)",
xlab="",xlim=xlm)

layout(panels)
par(mai=c(0,1.5,.1, .5),omi=c(0,0,0,0))
Expand All @@ -32,7 +29,7 @@ plot_summary <- function(inst.data,inst.flags,block.data,block.flags,compare.dat
points(inst.data[use.i,1],rep(i-.5,length(use.i)),pch=15,cex=2.5,
col=rgb(0, 0, 0, .2, maxColorValue = 1))
abline(h = i)
nme <- cnfg$outlier_removal[[i]]$alias
nme <- sqc$outlier_removal[[i]]$alias
ynames <- c(ynames,nme)
}
ix = i
Expand All @@ -42,7 +39,7 @@ plot_summary <- function(inst.data,inst.flags,block.data,block.flags,compare.dat
points(block.data[flags,1],rep(ix-.5,sum(flags)),pch=15,cex=2.5,
col=rgb(1, 0, 0, .4, maxColorValue = 1))
abline(h = ix)
nme <- cnfg$block_stats[[k]]$alias
nme <- sqc$block_stats[[k]]$alias
ynames <- c(ynames,nme)
}

Expand Down
34 changes: 34 additions & 0 deletions man/clean.data.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{clean.data}
\alias{clean.data}
\title{cleans sensor data with user-specified routines}
\usage{
clean.data(deploy = "pellerin", folder = "../examples/",
plot.diagnostic = TRUE, write.file = FALSE)
}
\arguments{
\item{deploy}{a string for the *.yml file name}

\item{folder}{a string which specifies the folder of the *.yml file}

\item{plot.diagnostic}{a boolean for creating a diagnostic plot}

\item{write.file}{a boolean for creating a timeseries file output}
}
\value{
An optional plot and optional file output handle
}
\description{
cleans sensor data according to details within the user-specified config (*yml) file \cr
}
\examples{
\dontrun{
clean.data(deploy='pellerin',folder='/[User]/Desktop/Science Projects/sensorQC/',plot.diagnostic=FALSE)
clean.data(deploy='pellerin',folder='/[User]/Desktop/Science Projects/sensorQC/',plot.diagnostic=TRUE,write.file=TRUE)
}
}
\author{
Jordan S. Read
}
\keyword{methods}

15 changes: 0 additions & 15 deletions man/compress_flags.Rd

This file was deleted.

0 comments on commit b8dbf43

Please sign in to comment.