diff --git a/NAMESPACE b/NAMESPACE index 9368108..3cc46b1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,7 @@ export(MAD) export(block_stats) export(build_flags) +export(clean.data) export(error_code) export(get.outliers) export(load.sensor) diff --git a/R/build.flags.R b/R/build.flags.R index 1002a29..dbd8d2a 100644 --- a/R/build.flags.R +++ b/R/build.flags.R @@ -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)) diff --git a/R/clean.data.R b/R/clean.data.R index cc5a80b..ff21812 100644 --- a/R/clean.data.R +++ b/R/clean.data.R @@ -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='') @@ -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") + } + + } - - -# \ No newline at end of file diff --git a/R/load.sensor.R b/R/load.sensor.R index 0bf742e..05396bc 100644 --- a/R/load.sensor.R +++ b/R/load.sensor.R @@ -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) diff --git a/R/plot_summary.R b/R/plot_summary.R index 19a531b..9db2b71 100644 --- a/R/plot_summary.R +++ b/R/plot_summary.R @@ -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)) @@ -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 @@ -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) } diff --git a/man/clean.data.Rd b/man/clean.data.Rd new file mode 100644 index 0000000..3655fbd --- /dev/null +++ b/man/clean.data.Rd @@ -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} + diff --git a/man/compress_flags.Rd b/man/compress_flags.Rd deleted file mode 100644 index 0b8ba86..0000000 --- a/man/compress_flags.Rd +++ /dev/null @@ -1,15 +0,0 @@ -% Generated by roxygen2 (4.0.1): do not edit by hand -\name{compress_flags} -\alias{compress_flags} -\title{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))} -\usage{ -compress_flags(flag.bool) -} -\description{ -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)) -} -