From 87584908f137652f63cf899a227c494fccca0207 Mon Sep 17 00:00:00 2001 From: stefanmet Date: Thu, 26 Jul 2018 04:02:32 +0000 Subject: [PATCH 001/168] def.base.ec.R: boundary condition fix --- pack/eddy4R.base/R/def.base.ec.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/def.base.ec.R b/pack/eddy4R.base/R/def.base.ec.R index 44bef917..df0346a2 100644 --- a/pack/eddy4R.base/R/def.base.ec.R +++ b/pack/eddy4R.base/R/def.base.ec.R @@ -53,7 +53,7 @@ if(AlgBase == "mean") { # linear trend: if(AlgBase == "trnd") { - var<-approx(idxTime, var, xout=idxTime)[[2]] #get rid of NAs in var + var <- stats::approx(x = idxTime, y = var, xout = idxTime, method = "linear", rule = 2)[[2]] #get rid of NAs in var trnd<-lm(var~idxTime) varBase<- fitted.values(trnd) #coefficients(trnd)[1]+ From 3f628d8a89382addf14bd535a5031d7deaee2eae Mon Sep 17 00:00:00 2001 From: stefanmet Date: Sun, 17 Nov 2019 00:56:33 +0000 Subject: [PATCH 002/168] merge remaining changes --- pack/eddy4R.base/DESCRIPTION | 9 +- pack/eddy4R.base/R/def.hdf5.read.qfqm.R | 20 +- pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R | 148 ++++------ pack/eddy4R.base/R/def.mtch.out.refe.R | 17 +- pack/eddy4R.base/R/wrap.hdf5.read.R | 203 +++++++------ pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R | 10 + pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.api.R | 31 +- pack/eddy4R.base/R/wrap.irga.vali.R | 103 +++---- pack/eddy4R.base/R/wrap.unit.conv.out.ec.R | 291 ++++++++++--------- pack/eddy4R.qaqc/DESCRIPTION | 2 + pack/eddy4R.qaqc/R/def.dspk.br86.R | 191 ++++++------ pack/eddy4R.qaqc/R/def.dspk.wndw.R | 150 +++++----- 12 files changed, 599 insertions(+), 576 deletions(-) diff --git a/pack/eddy4R.base/DESCRIPTION b/pack/eddy4R.base/DESCRIPTION index 717f0f1e..1b62c212 100644 --- a/pack/eddy4R.base/DESCRIPTION +++ b/pack/eddy4R.base/DESCRIPTION @@ -11,7 +11,9 @@ Description: Contains basic commonalities for the eddy4R family of R-packages Depends: R (>= 3.4.0) Imports: - BiocInstaller (>= 1.26.0), + BiocManager (>= 1.30.7), + DataCombine (>= 0.2.21), + deming (>= 1.4), downloader (>= 0.4), EMD (>= 1.5.7), ff (>= 2.2-13), @@ -20,7 +22,10 @@ Imports: rhdf5 (>= 2.20.0), robfilter (>= 4.1), signal (>= 0.7-6), - zoo (>= 1.8-1) + zoo (>= 1.8-1), + neonUtilities (>= 1.3.1) +Suggests: + NEONprocIS.base License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 LazyData: true RoxygenNote: 6.1.1 diff --git a/pack/eddy4R.base/R/def.hdf5.read.qfqm.R b/pack/eddy4R.base/R/def.hdf5.read.qfqm.R index a67c5cca..93d3ec88 100644 --- a/pack/eddy4R.base/R/def.hdf5.read.qfqm.R +++ b/pack/eddy4R.base/R/def.hdf5.read.qfqm.R @@ -4,7 +4,7 @@ #' @author #' David Durden \email{ddurden@battelleecology.org} -#' @description definition function. Reads an HDF5 input file in NEON standard format from \code{DirInpLoca}. +#' @description definition function. Reads an HDF5 input file in NEON standard format from \code{DirInpLoca}. #' @param DirInpLoca Character: Input directory. #' @param SiteLoca Character: Site location. @@ -14,7 +14,7 @@ #' @param FreqLoca Integer: Measurement frequency. #' @param MethMeas A vector of class "character" containing the name of measurement method (eddy-covariance turbulent exchange or storage exchange), MethMeas = c("ecte", "ecse"). Defaults to "ecte". -#' @return +#' @return #' Named list \code{qfqm} containing time-series of quality flags. #' @references @@ -35,9 +35,9 @@ # Natchaya Pingintha-Durden (2017-06-21) # adding parameter MethMeas to distinguish different cases for ecte and ecse # David Durden (2017-12-12) -# Removing rev number from dp0p data product HDF5 group levels +# Removing rev number from dp0p data product HDF5 group levels # Natchaya P-Durden (2018-01-19) -# Updating to remove rev numbers from ECSE dp0p HDF5 data product group level +# Updating to remove rev numbers from ECSE dp0p HDF5 data product group level # Natchaya P-Durden (2018-03-30) # applied term name convention; replaced Levl by Lvl # Natchaya P-Durden (2018-05-22) @@ -53,8 +53,8 @@ def.hdf5.read.qfqm <- function( FreqLoca, MethMeas = c("ecte", "ecse")[1] ){ - -#Read in the flags from the HDF5 file + +#Read in the flags from the HDF5 file if (MethMeas == "ecte") { qfqm <- rhdf5::h5read(file = base::paste0(DirInpLoca, "/ECTE_dp0p_", SiteLoca, "_", DateLoca, ".h5"), name = base::paste0("/", SiteLoca, "/dp0p/qfqm/", VarLoca, "/",LvlTowr), read.attributes = TRUE) @@ -64,13 +64,13 @@ if (MethMeas == "ecse") { qfqm <- rhdf5::h5read(file = base::paste0(DirInpLoca, "/ECSE_dp0p_", SiteLoca, "_", DateLoca, ".h5"), name = base::paste0("/", SiteLoca, "/dp0p/qfqm/", VarLoca, "/",LvlTowr), read.attributes = TRUE) } - -#Convert each flag to a vector from a 1D array + +#Convert each flag to a vector from a 1D array for(idx in base::names(qfqm)) qfqm[[idx]] <- base::as.vector(qfqm[[idx]]); base::rm(idx) #Apply units to each flag -lapply(seq_len(length(qfqm)), function(x){ - print(x) +lapply(seq_len(length(qfqm)), function(x){ + tryCatch({rlog$debug(x)}, error=function(cond){print(x)}) attributes(qfqm[[x]])$Unit <<- attributes(qfqm)$Unit[[x]] }) diff --git a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R index 032fb3b4..aeb55a15 100755 --- a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R +++ b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R @@ -4,8 +4,8 @@ #' @author #' David Durden \email{ddurden@battelleecology.org} -#' @description -#' Definition function. To write NEON Level 1 data product descriptive statistics (mean, minimum, maximum, variance, number of non-NA points), quality flags and quality metrics, and uncertainty values gathered from via the API to an output HDF5 file. +#' @description +#' Definition function. To write NEON Level 1 data product descriptive statistics (mean, minimum, maximum, variance, number of non-NA points), quality flags and quality metrics, and uncertainty values gathered from via the API to an output HDF5 file. #' @param date Character: The date for the data to be gathered. #' @param FileOut Character: The file name for the output HDF5 file @@ -15,7 +15,7 @@ #' @param TimeAgr Integer: The time aggregation index in minutes (i.e. 30) #' @return An updated dp0p HDF5 file with dp01 data, qfqm, and uncertainty written - + #' @references #' License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007. @@ -28,7 +28,7 @@ #' @export -# changelog and author contributions / copyrights +# changelog and author contributions / copyrights # David Durden (2018-02-24) # original creation # Natchaya P-Durden (2018-03-28) @@ -39,11 +39,14 @@ # fix for missing timeEnd; # David Durden (2018-04-12) # add failsafe for missing data in API; -# #TODO: +# #TODO: # - Create check if group level exists and create if not # - Add other dp01's and remove hardcoded units # Natchaya P-Durden (2019-06-10) # adding additional data products +# Natchaya P-Durden (2019-09-12) +# get information of existing dp01 hor and ver from dp0p hdf5 file +# convert qmBeta and qmAlph to fraction ############################################################################################## def.hdf5.wrte.dp01.api <- function( @@ -59,7 +62,8 @@ def.hdf5.wrte.dp01.api <- function( #Needed library library(rhdf5) -#TODO: +library(neonUtilities) +#TODO: #Create check if group level exists and create if not #Add other dp01's and remove hardcoded units ############################################################################ @@ -70,7 +74,7 @@ yearMnth <- as.character.Date(date, format = "%Y-%m") timeBgn <- date - lubridate::seconds(1) -timeEnd <- date + lubridate::days(1) +timeEnd <- date + lubridate::days(1) #assign data unit attributes outAttr <- base::list() @@ -109,7 +113,8 @@ if(DpName == "h2oSoilVol") TblName <- c("ionSoilVol", "h2oSoilVol") if(DpName == "presBaro") TblName <- c("presCor", "presAtm") #Grab 30 minute data to be written -print(paste0(format(Sys.time(), "%F %T"), " downloading ", TimeAgr, " min data from the portal")) +msg <- paste0("downloading ", TimeAgr, " min data from the portal") +tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) data <- try(expr = Noble::pull.date(site = SiteLoca, dpID = DpNum, bgn.date = timeBgn, end.date = timeEnd, package = "expanded", time.agr = TimeAgr), silent = TRUE) #Currently requires to subtract 1 minute otherwise (1 index will be cut from the beginning) #Failsafe test if API pull produced an error @@ -117,87 +122,54 @@ if(class(data) == "try-error"){ #Initialize lists rpt <- list(data = list(), qfqm = list(), ucrt = list()) #get sensor HOR and VER - if (DpName %in% "radiNet"){ - LvlMeas <- LvlTowr} else{ - #assign downloading directory - DirDnld <- paste0(dirname(FileOut), "/",DpName) - #Check if download directory exists and create if not - if(dir.exists(DirDnld) == FALSE) dir.create(DirDnld, recursive = TRUE) - - #download data from dataportal - neonUtilities::getPackage(dpID = DpNum, site_code = SiteLoca, year_month = yearMnth, package = "basic",savepath = DirDnld) - - #get the list of download zip file - fileList <- list.files(path = DirDnld, pattern= ".zip", all.files=FALSE, - full.names=FALSE) - #unzip the download zip file - utils::unzip(zipfile = paste0(DirDnld,"/", fileList), exdir = DirDnld, overwrite = TRUE) - - #get sensor position file name - fileName <- list.files(path = DirDnld, pattern = paste0("sensor_positions")) - - #read in .csv file - sensLoc <- read.csv(paste0(DirDnld,"/", fileName), header=TRUE) - #get vertical and horizontal measurement location - tmpLoc <- strsplit(as.character(sensLoc$HOR.VER),split='.', fixed=TRUE) - hor <- unlist(lapply(1:length(tmpLoc), function(x) { - if (nchar(tmpLoc[[x]][1]) == 1) {as.character(paste0("00",tmpLoc[[x]][1]))} else{as.character(tmpLoc[[x]][1])} - })) - ver <- unlist(lapply(1:length(tmpLoc), function(x) { - if (nchar(tmpLoc[[x]][2]) == 2) {as.character(paste0(tmpLoc[[x]][2],"0"))} else{as.character(tmpLoc[[x]][2])} - })) - #merge hor.ver and hor_ver - LocMeas <- as.character(paste0(hor,".",ver)) - LvlMeas <- as.character(paste0(hor,"_",ver)) - #delete download folder - print(unlink(DirDnld, recursive=TRUE)) - }#end else - + LocMeas <- gsub("\\_", ".", LvlTowr[[DpName]]) + LvlMeas <- LvlTowr[[DpName]] + #Determine the output levels LvlMeasOut <- LocMeas #Name for HDF5 output names(LvlMeasOut) <- LvlMeas - + #Create the timeBgn vector for aggregation period specified (1, 30 minutes) timeBgnOut <- seq(from = lubridate::ymd_hms(timeBgn) + lubridate::seconds(1), to = base::as.POSIXlt(timeEnd) - lubridate::minutes(TimeAgr), by = paste(TimeAgr, "mins", sep = " ")) - + #Create the timeEnd vector for aggregation period specified (1, 30 minutes) timeEndOut <- seq(from = lubridate::ymd_hms(timeBgn) + lubridate::minutes(TimeAgr)+ lubridate::seconds(1), to = base::as.POSIXlt(timeEnd), by = paste(TimeAgr, "mins", sep = " ")) - + #Creating a vector of NaN's to fill data.frames dataNa <- rep(x = NaN, length = length(timeBgnOut)) - + #Create the output dataframe for data values - dataOut <- data.frame("timeBgn" = strftime(as.character(timeBgnOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(timeEndOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "max" = dataNa, "mean" = dataNa, "min" = dataNa, "numSamp" = dataNa, "vari"= dataNa, stringsAsFactors = FALSE) - + dataOut <- data.frame("timeBgn" = strftime(as.character(timeBgnOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(timeEndOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "max" = dataNa, "mean" = dataNa, "min" = dataNa, "numSamp" = dataNa, "vari"= dataNa, stringsAsFactors = FALSE) + #Adding unit attributes and naming them attributes(dataOut)$unit <- outAttr$data[[DpName]] names(attributes(dataOut)$unit) <- names(dataOut) - + #Create the output dataframe for qfqm values - qfqmOut <- data.frame("timeBgn" = strftime(as.character(timeBgnOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(timeEndOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "qmAlph" = rep(x = 0.0, length = length(timeBgnOut)), "qmBeta" = rep(x = 1.0, length = length(timeBgnOut)), "qfFinl" = rep(x = 1L, length = length(timeBgnOut)), "qfSci" = rep(x = 0L, length = length(timeBgnOut)), stringsAsFactors = FALSE) - + qfqmOut <- data.frame("timeBgn" = strftime(as.character(timeBgnOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(timeEndOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "qmAlph" = rep(x = 0.0, length = length(timeBgnOut)), "qmBeta" = rep(x = 1.0, length = length(timeBgnOut)), "qfFinl" = rep(x = 1L, length = length(timeBgnOut)), "qfSci" = rep(x = 0L, length = length(timeBgnOut)), stringsAsFactors = FALSE) + #Setting attributes attributes(qfqmOut)$unit <- base::rep_len(x = "NA", length.out = ncol(qfqmOut)) names(attributes(qfqmOut)$unit) <- names(qfqmOut) - - #Create the output dataframe for ucrt values - ucrtOut <- data.frame("timeBgn" = strftime(as.character(timeBgnOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(timeEndOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "ucrtCal95" = dataNa, "se" = dataNa, stringsAsFactors = FALSE) - + + #Create the output dataframe for ucrt values + ucrtOut <- data.frame("timeBgn" = strftime(as.character(timeBgnOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(timeEndOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "ucrtCal95" = dataNa, "se" = dataNa, stringsAsFactors = FALSE) + #Adding unit attributes and naming them attributes(ucrtOut)$unit <- outAttr$ucrt[[DpName]] names(attributes(ucrtOut)$unit) <- names(ucrtOut) - + #Create list structure for the return output (type>>HOR_VER>>output_dataframes) lapply(LvlMeas, function(x) { lapply (TblName, function(y) { if (y %in% "presCor"){ #Create the output dataframe for data values - dataOut <- data.frame("timeBgn" = strftime(as.character(timeBgnOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(timeEndOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "mean" = dataNa, stringsAsFactors = FALSE) + dataOut <- data.frame("timeBgn" = strftime(as.character(timeBgnOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(timeEndOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "mean" = dataNa, stringsAsFactors = FALSE) #Create the output dataframe for qfqm values - qfqmOut <- data.frame("timeBgn" = strftime(as.character(timeBgnOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(timeEndOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "qfDew" = rep(x = -1.0, length = length(timeBgnOut)), "qfFinl" = rep(x = 1L, length = length(timeBgnOut)), "qfSci" = rep(x = 0L, length = length(timeBgnOut)), "qfTemp" = rep(x = -1.0, length = length(timeBgnOut)), stringsAsFactors = FALSE) - #Create the output dataframe for ucrt values - ucrtOut <- data.frame("timeBgn" = strftime(as.character(timeBgnOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(timeEndOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "ucrtCal95" = dataNa, stringsAsFactors = FALSE) + qfqmOut <- data.frame("timeBgn" = strftime(as.character(timeBgnOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(timeEndOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "qfDew" = rep(x = 1L, length = length(timeBgnOut)), "qfFinl" = rep(x = 1L, length = length(timeBgnOut)), "qfSci" = rep(x = 0L, length = length(timeBgnOut)), "qfTemp" = rep(x = 1L, length = length(timeBgnOut)), stringsAsFactors = FALSE) + #Create the output dataframe for ucrt values + ucrtOut <- data.frame("timeBgn" = strftime(as.character(timeBgnOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(timeEndOut), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "ucrtCal95" = dataNa, stringsAsFactors = FALSE) } rpt$data[[x]][[y]] <<- dataOut rpt$qfqm[[x]][[y]] <<- qfqmOut @@ -249,7 +221,7 @@ if (DpName %in% "presBaro"){ #Grab the names of variables for data nameVar$Data <- grep(pattern = "mean|variance|minimum|maximum|numpts|corPres", x = names(data), ignore.case = TRUE, value = TRUE) #Exclude corPres qfqm and ucrt from data - nameVar$Data <- nameVar$Data[!nameVar$Data %in% nameVar$Ucrt] + nameVar$Data <- nameVar$Data[!nameVar$Data %in% nameVar$Ucrt] nameVar$Data <- nameVar$Data[!nameVar$Data %in% nameVar$Qfqm] } else{ nameVar$Qfqm <- grep(pattern = "alphaqm|betaqm|finalqf", x = names(data), ignore.case = TRUE, value = TRUE) @@ -278,21 +250,15 @@ if (DpName %in% "presBaro"){ } nameVar$TimeOut <- sort(nameVar$Time) -names(nameVar$TimeOut) <- c("timeEnd", "timeBgn") +names(nameVar$TimeOut) <- c("timeEnd", "timeBgn") #Grabbing the tower measurement levels for a given dp01 product ############################################################################### #get vertical and horizontal measurement location -if (DpName %in% "radiNet"){ - LocMeas <- gsub("\\_", ".", LvlTowr) - LvlMeas <- LvlTowr -} else { - tmpLoc <- subset(names(data), grepl("Maximum",names(data))) - LocMeas <- gsub("[a-zA-Z]", "", tmpLoc) - LocMeas <- substring(LocMeas, 2) - LocMeas <- LocMeas[!duplicated(LocMeas)] - LvlMeas <- gsub("\\.", "_", LocMeas) } +#get sensor HOR and VER +LocMeas <- gsub("\\_", ".", LvlTowr[[DpName]]) +LvlMeas <- LvlTowr[[DpName]] #Determine the output levels LvlMeasOut <- LocMeas @@ -303,7 +269,7 @@ names(LvlMeasOut) <- LvlMeas #Sort output data and apply eddy4R naming conventions tmp$data <- lapply(LvlMeasOut, function(x){ - #Grab just the columns to be output + #Grab just the columns to be output tmp <- data[,grep(pattern = paste(nameVar$DataOut, collapse = "|"), x = names(data))] if(DpName %in% "presBaro"){ tmp <- tmp[,-grep(pattern = "QF|Uncert", x = colnames(tmp))]} @@ -352,7 +318,7 @@ for (idxLvl in names(tmp$data)){ } tmp$qfqm <- lapply(LvlMeasOut, function(x){ - #Grab just the columns to be output + #Grab just the columns to be output tmp <- data[,grep(pattern = paste(nameVar$QfqmOut, collapse = "|"), x = names(data))] #Sort the output columns to grab the HOR_VER level as separate lists of dataframes tmp <- tmp[,grep(pattern = x, x = names(tmp))] @@ -374,13 +340,24 @@ for (idxLvl in names(tmp$qfqm)){ for (idxSupDp in 1:length(TblName)){ #determine begin and end columns bgn <- (idxSupDp*4 - 3) - end <- idxSupDp*4 + end <- idxSupDp*4 rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]] <- data.frame("timeBgn" = strftime(as.character(data$startDateTime), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), "timeEnd" = strftime(as.character(data$endDateTime), format= "%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), tmp$qfqm[[idxLvl]][,bgn:end], stringsAsFactors = FALSE) #Adding unit attributes and naming them attributes(rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]])$unit <- base::rep_len(x = "NA", length.out = ncol(rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]])) names(attributes(rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]])$unit) <- names(rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]]) #Convert all NaNs in the qfSci to 0 rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]][is.nan(rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]]$qfSci),"qfSci"] <- 0L + if (!(TblName[idxSupDp] %in% "presCor")){ + #Convert all NaNs in the qmAlph and qmBeta to 100 + rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]][is.nan(rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]]$qmAlph),"qmAlph"] <- 0L + rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]][is.nan(rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]]$qmBeta),"qmBeta"] <- 100L + #Convert unit of qmAlph and qmBeta to fraction + rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]]$qmAlph <- (rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]]$qmAlph)/100 + rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]]$qmBeta <- (rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]]$qmBeta)/100 + } else { + rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]][is.nan(rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]]$qfDew),"qfDew"] <- 1L + rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]][is.nan(rpt$qfqm[[idxLvl]][[TblName[idxSupDp]]]$qfTemp),"qfTemp"] <- 1L + } } } # #Convert all NaNs in the qfSci to 0 @@ -389,7 +366,7 @@ for (idxLvl in names(tmp$qfqm)){ # }) tmp$ucrt <- lapply(LvlMeasOut, function(x){ - #Grab just the columns to be output + #Grab just the columns to be output tmp <- data[,grep(pattern = paste(nameVar$UcrtOut, collapse = "|"), x = names(data))] #Sort the output columns to grab the HOR_VER level as separate lists of dataframes tmp <- tmp[,grep(pattern = x, x = names(tmp))] @@ -402,7 +379,7 @@ tmp$ucrt <- lapply(LvlMeasOut, function(x){ #Adding unit attributes and naming them #attributes(tmp)$unit <- outAttr$ucrt[[DpName]] #names(attributes(tmp)$unit) <- names(tmp) - + #Return output return(tmp) }) @@ -441,7 +418,7 @@ for (idxLvl in names(tmp$ucrt)){ idFile <- rhdf5::H5Fopen(FileOut) #Create a group level for site -idSite <- rhdf5::H5Gopen(idFile, SiteLoca) +idSite <- rhdf5::H5Gopen(idFile, SiteLoca) #Open dp01 level idDp01 <- rhdf5::H5Gopen(idSite,"dp01") @@ -472,25 +449,25 @@ for (idxSupDp in TblName){ #Write output data rhdf5::h5writeDataset.data.frame(obj = rpt$data[[names(LvlMeasOut[idx])]][[idxSupDp]], h5loc = idLvlMeasData, name = idxSupDp, DataFrameAsCompound = TRUE) # Writing attributes to the data -if(!is.null(attributes(rpt$data[[names(LvlMeasOut[idx])]][[idxSupDp]])$unit) == TRUE){ +if(!is.null(attributes(rpt$data[[names(LvlMeasOut[idx])]][[idxSupDp]])$unit) == TRUE){ dgid <- rhdf5::H5Dopen(idLvlMeasData, idxSupDp) rhdf5::h5writeAttribute(attributes(rpt$data[[names(LvlMeasOut[idx])]][[idxSupDp]])$unit, h5obj = dgid, name = "unit") } #Write output data rhdf5::h5writeDataset.data.frame(obj = rpt$qfqm[[names(LvlMeasOut[idx])]][[idxSupDp]], h5loc = idLvlMeasQfqm, name = idxSupDp, DataFrameAsCompound = TRUE) - + # Writing attributes to the qfqm -if(!is.null(attributes(rpt$qfqm[[names(LvlMeasOut[idx])]][[idxSupDp]])$unit) == TRUE){ +if(!is.null(attributes(rpt$qfqm[[names(LvlMeasOut[idx])]][[idxSupDp]])$unit) == TRUE){ dgid <- rhdf5::H5Dopen(idLvlMeasQfqm, idxSupDp) rhdf5::h5writeAttribute(attributes(rpt$qfqm[[names(LvlMeasOut[idx])]][[idxSupDp]])$unit, h5obj = dgid, name = "unit") } - + #Write output data rhdf5::h5writeDataset.data.frame(obj = rpt$ucrt[[names(LvlMeasOut[idx])]][[idxSupDp]], h5loc = idLvlMeasUcrt, name = idxSupDp, DataFrameAsCompound = TRUE) - + # Writing attributes to the data - if(!is.null(attributes(rpt$ucrt[[names(LvlMeasOut[idx])]][[idxSupDp]])$unit) == TRUE){ + if(!is.null(attributes(rpt$ucrt[[names(LvlMeasOut[idx])]][[idxSupDp]])$unit) == TRUE){ dgid <- rhdf5::H5Dopen(idLvlMeasUcrt, idxSupDp) rhdf5::h5writeAttribute(attributes(rpt$ucrt[[names(LvlMeasOut[idx])]][[idxSupDp]])$unit, h5obj = dgid, name = "unit") } @@ -498,7 +475,6 @@ if(!is.null(attributes(rpt$qfqm[[names(LvlMeasOut[idx])]][[idxSupDp]])$unit) == } #End of for loop around measurement levels - #Close all the HDF5 connections h5closeAll() diff --git a/pack/eddy4R.base/R/def.mtch.out.refe.R b/pack/eddy4R.base/R/def.mtch.out.refe.R index 8c4a846d..5f5fd4fd 100644 --- a/pack/eddy4R.base/R/def.mtch.out.refe.R +++ b/pack/eddy4R.base/R/def.mtch.out.refe.R @@ -5,9 +5,9 @@ #' David Durden \email{ddurden@battelleecology.org} \cr #' Cove Sturtevant \email{eddy4R.info@gmail.com} -#' @description +#' @description #' Function definition. A function to compare the file output from a workflow to a reference output file -#' to ensure that changes during development to functions called by the workflow have not impacted the +#' to ensure that changes during development to functions called by the workflow have not impacted the #' results.\cr #' The function reads in the new data produced in the tmp directory and compares the first 10 lines to the reference output data. @@ -46,18 +46,21 @@ def.mtch.out.refe <- function( fileRefe, Head = FALSE, NumLine = 10) { - + # Read in the output file dataOut <- utils::read.csv(fileOut) - + # Read in the reference file dataRefe <- utils::read.csv(fileRefe) - + #Compare the first numLine lines of the data between the output and reference if(!isTRUE(base::all.equal(dataOut[1:NumLine,],dataRefe[1:NumLine,]))){ base::stop("Bummer! The current output DOES NOT MATCH the reference output :(") } else { - base::print("Yay! The current output MATCHES the reference output :)") + tryCatch({rlog$debug("Yay! The current output MATCHES the reference output :)")}, + error=function(cond){ + print("Yay! The current output MATCHES the reference output :)") + }) } - + } diff --git a/pack/eddy4R.base/R/wrap.hdf5.read.R b/pack/eddy4R.base/R/wrap.hdf5.read.R index b9ffef44..35b46efd 100644 --- a/pack/eddy4R.base/R/wrap.hdf5.read.R +++ b/pack/eddy4R.base/R/wrap.hdf5.read.R @@ -14,10 +14,10 @@ #' @param FreqLoca Integer: Measurement frequency. #' @param RngLoca List of named ingegers: Thresholds for range test. #' @param DespLoca List of integers: De-spiking parameters -#' @param MethMeas A vector of class "character" containing the name of measurement method (eddy-covariance turbulent exchange or storage exchange), MethMeas = c("ecte", "ecse"). Defaults to "ecte". +#' @param MethMeas A vector of class "character" containing the name of measurement method (eddy-covariance turbulent exchange or storage exchange), MethMeas = c("ecte", "ecse"). Defaults to "ecte". -#' @return +#' @return #' Named list containing pre-processed time-series $time and $data. #' @references @@ -45,9 +45,9 @@ # Ke Xu (2017-05-22) # adding parameter MethMeas to distinguish different cases for ecte and ecse # David Durden (2017-12-12) -# Updating to remove rev numbers from ECTE dp0p HDF5 data product group levels +# Updating to remove rev numbers from ECTE dp0p HDF5 data product group levels # Natchaya P-Durden (2018-01-19) -# Updating to remove rev numbers from ECSE dp0p HDF5 data product group levels +# Updating to remove rev numbers from ECSE dp0p HDF5 data product group levels # Updating to remove rev numbers from ECTE dp0p HDF5 data product group levels # Stefan Metzger (2018-01-30) # move ECSE de-spiking from wrap.neon.read.hdf5.eddy() to wrap.prd.day.ecse() @@ -68,7 +68,7 @@ # Natchaya P-Durden (2019-02-14) # adding to write out DfSd of gasRefe ############################################################################################## - + wrap.hdf5.read <- function( DirInpLoca, SiteLoca, @@ -83,7 +83,7 @@ wrap.hdf5.read <- function( DespLoca, MethMeas = c("ecte", "ecse")[1] ) { - + # create regular time dimension # POSIX is rounding down, add time increment after last significant digit time <- seq.POSIXt( @@ -96,15 +96,15 @@ time <- seq.POSIXt( # get available files from directory structure file <- list.files(DirInpLoca) - + # exclude files and subfolder with formats different from target file format file <- file[which(sapply(1:length(file), function(x) strsplit(file[x], "_")[[1]][3] == SiteLoca))] - + # extract dates in ISO format - + # first split file name from extension file <- sapply(1:length(file), function(x) strsplit(file[x], "[.]")[[1]][1]) - + # then split date from remainder of filename file <- sapply(1:length(file), function(x) strsplit(file[x], "_")[[1]][4]) @@ -118,7 +118,7 @@ if(!(DateLoca %in% file)) { # irgaTurb if(VarLoca == "irgaTurb") { - + data <- data.frame(matrix(data = NaN, ncol = 21, nrow = length(time))) names(data) <- c("asrpCo2", "asrpH2o", "densMoleCo2", "densMoleH2o", "potCool", "powrCo2Refe", "powrCo2Samp", "powrH2oRefe", "powrH2oSamp", "presAtm", "presDiff","presSum", "rtioMoleDryCo2", "rtioMoleDryH2o", "ssiCo2", "ssiH2o", "tempIn", "tempMean", @@ -127,57 +127,58 @@ if(!(DateLoca %in% file)) { attributes(data)$unit <- c("-", "-", "molCo2 m-3", "molH2o m-3", "V", "W", "W", "W", "W", "Pa", "Pa", "Pa", "molCo2 mol-1Dry", "molH2o mol-1Dry", "-", "-", "K", "K", "K", "K", "YYYY-MM-DD hh:mm:ss.sss") names(attributes(data)$unit) <- names(data) - + } # irgaTurb MFC if(VarLoca == "mfcSampTurb") { - + data <- data.frame(matrix(data = NaN, ncol = 6, nrow = length(time))) names(data) <- c("frt", "frt00", "frtSet00", "presAtm", "temp", "time") data$time <- time attributes(data)$unit <- c("litersPerMinute", "litersPerMinute", "litersPerMinute", "Pa", "K", "YYYY-MM-DD hh:mm:ss.sss") names(attributes(data)$unit) <- names(data) - + } # irgaTurb Solenoids in NEMA enclosure if(VarLoca == "valvValiNemaTurb") { - + data <- data.frame(matrix(data = NaN, ncol = 6, nrow = length(time))) names(data) <- c("qfGas01", "qfGas02", "qfGas03", "qfGas04", "qfGas05", "time") data$time <- time attributes(data)$unit <- c("NA", "NA", "NA", "NA", "NA", "YYYY-MM-DD hh:mm:ss.sss") names(attributes(data)$unit) <- names(data) - + } # soni if(VarLoca == "soni") { - + data <- data.frame(matrix(data = NaN, ncol = 7, nrow = length(time))) names(data) <- c("idx", "tempSoni", "time", "veloSoni", "veloXaxs", "veloYaxs", "veloZaxs") data$time <- time attributes(data)$unit <- c("NA", "K", "YYYY-MM-DD hh:mm:ss.sss", "m s-1", "m s-1", "m s-1", "m s-1") names(attributes(data)$unit) <- names(data) - + } # amrs if(VarLoca == "amrs") { - + data <- data.frame(matrix(data = NaN, ncol = 14, nrow = length(time))) - names(data) <- c("accXaxs", "accXaxsDiff", "accYaxs", "accYaxsDiff", "accZaxs", "accZaxsDiff", "angXaxs", "angYaxs", "angZaxs", + names(data) <- c("accXaxs", "accXaxsDiff", "accYaxs", "accYaxsDiff", "accZaxs", "accZaxsDiff", "angXaxs", "angYaxs", "angZaxs", "avelXaxs", "avelYaxs", "avelZaxs", "idx", "time" ) data$time <- time - attributes(data)$unit <- c("m s-2", "m s-2", "m s-2", "m s-2", "m s-2", "m s-2", "rad", "rad", "rad", "rad s-1", "rad s-1", + attributes(data)$unit <- c("m s-2", "m s-2", "m s-2", "m s-2", "m s-2", "m s-2", "rad", "rad", "rad", "rad s-1", "rad s-1", "rad s-1", "NA", "YYYY-MM-DD hh:mm:ss.sss") names(attributes(data)$unit) <- names(data) - + } # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " hdf5 file not available, NaNs substituted")) - + msg<-paste0("dataset ", DateLoca, ": ", VarLoca, " hdf5 file not available, NaNs substituted") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) + ### # mid data availability # case "dataset is available": start read data from hdf5 file @@ -185,50 +186,51 @@ if(!(DateLoca %in% file)) { ### # read-in data - + # read-in hdf5 data from the specified sensor # options via open connection: fid <- H5Fopen(paste0(DirInpLoca, "/ECSE_L0_", SiteLoca, "_", DateLoca, ".h5")); h5ls(fid) - - + + if(MethMeas == "ecte") data <- rhdf5::h5read(file = base::paste0(DirInpLoca, "/ECTE_dp0p_", SiteLoca, "_", DateLoca, ".h5"), name = base::paste0("/", SiteLoca, "/dp0p/data/", VarLoca, "/",LvlTowr), read.attributes = TRUE) - - + + if(MethMeas == "ecse") data <- rhdf5::h5read(file = base::paste0(DirInpLoca, "/ECSE_dp0p_", SiteLoca, "_", DateLoca, ".h5"), name = base::paste0("/", SiteLoca, "/dp0p/data/", VarLoca, "/",LvlTowr), read.attributes = TRUE) - + # convert 1-d array list-elements to vector list-elements # can be omitted once Dave figures out to store h5 data tables as vector list-elements for(idx in base::names(data)) data[[idx]] <- base::as.vector(data[[idx]]); base::rm(idx) - + # convert list to data.frame data <- base::as.data.frame(data, stringsAsFactors = FALSE) # base::attributes(data)$row.names <- NULL - + # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " hdf5 read-in complete")) + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " hdf5 read-in complete") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) # convert type of variable time data$time <- base::as.POSIXct(data$time, format="%Y-%m-%dT%H:%M:%OSZ", tz="UTC") + 0.0001 # assign hdf5 attributes - + # read attributes - + if(MethMeas == "ecte") attr <- rhdf5::h5readAttributes(file = base::paste0(DirInpLoca, "/ECTE_dp0p_", SiteLoca, "_", DateLoca, ".h5"), name = base::paste0("/", SiteLoca, "/dp0p/data/", VarLoca, "/", LvlTowr)) - - + + if(MethMeas == "ecse") attr <- rhdf5::h5readAttributes(file = base::paste0(DirInpLoca, "/ECSE_dp0p_", SiteLoca, "_", DateLoca, ".h5"), name = base::paste0("/", SiteLoca, "/dp0p/data/", VarLoca, "/", LvlTowr)) - + #########This section not needed after moving the names and units to the data table level########################### - # which attributes are of type character? + # which attributes are of type character? # Set01 <- base::names(attr)[base::sapply(base::names(attr), function(x) base::is.character(attr[[x]]))] - + # split characters by comma separator and trim white spaces # if(base::length(Set01) > 0) attr[Set01] <- base::sapply(Set01, function(x) base::trimws(base::unlist(base::strsplit(x = attr[[x]], split = ",")))) @@ -237,26 +239,27 @@ if(!(DateLoca %in% file)) { # sort and assign unit descriptions in same order as data base::attributes(data)$unit <- attr$Unit[base::names(data)] - + # sd assign attribute to gasRefe if (VarLoca == "gasRefe"){ base::names(attr$Sd) <- attr$Name base::names(attr$DfSd) <- attr$Name - base::attributes(data)$sd <- attr$Sd[base::names(data)] - base::attributes(data)$DfSd <- attr$DfSd[base::names(data)] + base::attributes(data)$sd <- attr$Sd[base::names(data)] + base::attributes(data)$DfSd <- attr$DfSd[base::names(data)] } - rm(attr) - + rm(attr) + # replacement statement for assigning units to individual variables in data # # assign units to variables in data # for(idx in base::names(data)) base::attr(x = data[[idx]], which = "unit") <- attr$Unit[[idx]] # rm(idx) # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " hdf5 attributes complete")) + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " hdf5 attributes complete") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) # unit conversion - + # perform unit conversion data <- base::suppressWarnings(eddy4R.base::def.unit.conv(data = data, unitFrom = attributes(data)$unit, @@ -265,21 +268,22 @@ if(!(DateLoca %in% file)) { # replacement statement for performing unit conversion over individual variables in data # # perform unit conversion: loop around variables in data # for(idx in base::names(data)) { - # + # # data[[idx]] <- base::suppressWarnings( # eddy4R.base::def.unit.conv(data = base::as.vector(data[[idx]]), # unitFrom = attributes(data[[idx]])$unit, # unitTo = "intl") # ) - # + # # }; rm(idx) # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " unit conversion complete")) + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " unit conversion complete") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) # regularization if(Rglr) { - + # perform regularization data <- eddy4R.base::def.rglr( timeMeas = base::as.POSIXlt(data$time, format="%Y-%m-%dT%H:%M:%OSZ", tz="UTC"), @@ -294,18 +298,20 @@ if(!(DateLoca %in% file)) { )$dataRglr # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " regularization complete")) + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " regularization complete") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) } else { - + # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " regularization not selected")) - + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " regularization not selected") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) + } - + # discard data with bad sensor diagnostic flag if(Diag) { - + # for selected sensors if(VarLoca %in% base::names(RngLoca)) { @@ -316,7 +322,7 @@ if(!(DateLoca %in% file)) { whr <- which(data$dataRglr$diag != 8191) if(length(whr) > 0) data$dataRglr[whr, c("asrpCO2", "asrpH2O", "rhoMoleCO2", "densMoleH2o", "fdMoleCO2", "rtioMoleDryH2o")] <- NaN rm(whr) - + # #determine binary representations for integers up to 2^32-1 # #https://stat.ethz.ch/pipermail/r-help/2000-February/010141.html # #truncate leading zeroes in strings @@ -330,7 +336,7 @@ if(!(DateLoca %in% file)) { # #determine decimal value of binary string # #http://stackoverflow.com/questions/12892348/in-r-how-to-convert-binary-string-to-binary-or-decimal-value # base2deci <- function(base_number, base = 2) { - # sapply(1:length(base_number), function(x) + # sapply(1:length(base_number), function(x) # sum(base^(which(rev(unlist(strsplit(as.character(base_number[x]), "")) == 1))-1)) # ) # } @@ -343,10 +349,10 @@ if(!(DateLoca %in% file)) { # rm(whr_not) } - + # soni if(VarLoca == "soni") { - + # discard sonic data with invalid quality flag idx <- which(data$diag != 0) if(length(idx) > 0) data[idx, names(RngLoca$soni)] <- NaN @@ -355,54 +361,60 @@ if(!(DateLoca %in% file)) { } # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " sensor diagnostics complete")) - + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " sensor diagnostics complete") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) + } else { - + # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " sensor diagnostics not performed")) - + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " sensor diagnostics not performed") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) + } - + } else { - + # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " sensor diagnostics not selected")) - + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " sensor diagnostics not selected") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) + } # range test if(Rng) { - + # perform range test if(VarLoca %in% base::names(RngLoca)) { # loop around variables for(idx in base::names(RngLoca[[VarLoca]])) { - + whr <- which(data[,idx] < RngLoca[[VarLoca]][1,idx] | data[,idx] > RngLoca[[VarLoca]][2,idx]) if(length(whr > 0)) data[whr,idx] <- NaN - + }; rm(idx, whr) # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " range test complete")) - + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " range test complete") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) + } else { - + # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " range test not performed")) - + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " range test not performed") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) + } - + } else { - + # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " range test not selected")) - + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " range test not selected") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) + } - + # de-spiking # for ECSE, do not perform here; already migrated to eddy4R.base::wrap.prd.day.ecse() # TODO: similarly adjust for ECTE @@ -410,7 +422,7 @@ if(!(DateLoca %in% file)) { # perform range test if(VarLoca %in% base::names(RngLoca)) { - + # loop around variables for(idx in base::names(RngLoca[[VarLoca]])) { @@ -425,29 +437,30 @@ if(!(DateLoca %in% file)) { # resolution threshold ThshReso = DespLoca$rest )$dataOut - + } - + # clean up rm(idx) - + # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " de-spiking complete")) - + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " de-spiking complete") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) + } else { - + # print message to screen - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", DateLoca, ": ", VarLoca, " de-spiking not performed")) - + msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " de-spiking not performed") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) } - + } ### } -# end data availability +# end data availability ### - + # return data return(list(time = time, data = data)) diff --git a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R index 6b9b8318..eb0b85ba 100755 --- a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R +++ b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R @@ -62,6 +62,8 @@ # deleted dp04 of fluxCor and fluxRaw out when writing the basic file # David Durden (2019-05-30) # Adding dp04 low resolution output on top of validation code +# Natchaya P-Durden (2019-09-30) +# only write qfFinl out in basic file ############################################################################################## @@ -243,6 +245,14 @@ if(MethDp04 == TRUE){ #Write dp04 QFQM output ######################################################################################################################## + #write out only qfFinl in basic file + if (MethExpd == FALSE){ + lapply(names(inpList$dp04$qfqm[[idxDp04]]$turb), function(x){ + if (!(x %in% "qfFinl")) { + inpList$dp04$qfqm[[idxDp04]]$turb[[x]] <<- NULL + } + }) + } #Adding time to output dataframe rptDp04Qfqm <- cbind(timeBgn = outList$data$soni$veloXaxsErth$timeBgn, timeEnd = outList$data$soni$veloXaxsErth$timeEnd, inpList$dp04$qfqm[[idxDp04]]$turb, stringsAsFactors = FALSE) diff --git a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.api.R b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.api.R index 6501cf41..4dfb1cef 100644 --- a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.api.R +++ b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.api.R @@ -4,8 +4,8 @@ #' @author #' David Durden \email{ddurden@battelleecology.org} -#' @description -#' Definition function. To write NEON Level 1 data product descriptive statistics (mean, minimum, maximum, variance, number of non-NA points), quality flags and quality metrics, and uncertainty values gathered from via the API to an output HDF5 file. +#' @description +#' Definition function. To write NEON Level 1 data product descriptive statistics (mean, minimum, maximum, variance, number of non-NA points), quality flags and quality metrics, and uncertainty values gathered from via the API to an output HDF5 file. #' @param date Character: The date for the data to be gathered in ISO format ("YYYYmmdd"). #' @param FileOut Character: The file name for the output HDF5 file @@ -13,9 +13,9 @@ #' @param Dp01 Character: A vector of data product names for the data to be gathered. #' @param LvlTowr Character: The tower level that the sensor data is being collected in NEON data product convention (HOR_VER). #' @param TimeAgr Integer: The time aggregation index in minutes (i.e. 30) -#' +#' #' @return An updated dp0p HDF5 file with dp01 data, qfqm, and uncertainty written -#' +#' #' @references #' License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007. @@ -28,7 +28,7 @@ #' @export -# changelog and author contributions / copyrights +# changelog and author contributions / copyrights # David Durden (2018-02-28) # original creation # Natchaya P-Durden (2018-03-30) @@ -38,15 +38,15 @@ ############################################################################################## # date <- "20170901" -# +# # SiteLoca <- "CPER" -# +# # DpName <- "tempAirLvl" #"DP1.00002.001" #SAAT # #DpName <- "tempAirTop" "DP1.00003.001" #TRAAT # FileOut <- "/home/ddurden/eddy/data/dev_tests/dp01/ECSE_dp0p_CPER_2017-09-01.h5" -# -# LvlTowr <- "000_040" -# +# +# LvlTowr <- "000_040" +# # TimeAgr <- c(1,30) wrap.hdf5.wrte.dp01.api <- function( @@ -57,20 +57,21 @@ wrap.hdf5.wrte.dp01.api <- function( LvlTowr, TimeAgr = c(1,30) ){ - + #Initialize the reporting data list - rpt <- list() - + rpt <- list() + #Loop around data products for(idxDp in DpName){ #print screen - print(paste0(format(Sys.time(), "%F %T"), " Begin to re-ingest ", idxDp, " dp01 data")) + msg<-paste0("Begin to re-ingest ", idxDp, " dp01 data") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) #Call the definition function for all the data product rpt[[idxDp]] <- lapply(TimeAgr, function(x) { #Use the definition function to grab reingest data eddy4R.base::def.hdf5.wrte.dp01.api(date = date, SiteLoca = SiteLoca, FileOut = FileOut, DpName = idxDp, LvlTowr = LvlTowr, TimeAgr = x) })# End of lapply function } #End of for loop around dp01 data products - + return(rpt) } #End of wrap.hdf5.wrte.dp01.api function diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index 37210268..4fbe4980 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -8,10 +8,10 @@ #' @param data List consisting of \code{ff::ffdf} file-backed objects containing the dp0p input IRGA. #' @param qfqmFlag List consisting of \code{ff::ffdf} file-backed objects containing the IRGA quality flags. -#' @param gasRefe List containing the values of the reference gases. [mol mol-1] +#' @param gasRefe List containing the values of the reference gases. [mol mol-1] #' @param DateProc A vector of class "character" containing the processing date. -#' @return +#' @return #' The returned object consists of:\cr #' \code{rtioMoleDryCo2Vali} scriptive statistics (mean, min, max, vari, numSamp, se) of CO2 dry mole concentration during performing validation and CO2 dry mole concentration of reference gases.\cr #' \code{rtioMoleDryCo2Mlf} linear regression coefficients resulted from the maximum-likelihood fitting of a functional relationship. \cr @@ -32,14 +32,14 @@ # changelog and author contributions / copyrights # Natchaya P-Durden (2018-11-14) # original creation -# Natchaya P-Durden (2018-11-27) -# including the reference gases into the output -# Natchaya P-Durden (2018-11-28) +# Natchaya P-Durden (2018-11-27) +# including the reference gases into the output +# Natchaya P-Durden (2018-11-28) # removing standard error from report value # adding unit attributes # Natchaya P-Durden (2018-12-04) # adding standard deviation calculation -# adding maximum-likelihood fitting of a functional relationship (MLFR) +# adding maximum-likelihood fitting of a functional relationship (MLFR) # Natchaya P-Durden (2019-01-03) # adding logic when coefficients are NAs # Natchaya P-Durden (2019-01-04) @@ -79,23 +79,24 @@ wrap.irga.vali <- function( gasRefe, DateProc ) { + #adding library #library(deming) #library(zoo) - + #assign list rpt <- list() valiData <- list() #create temporary place to host coeficience values tmpCoef <- list() - + #dates that will be used in determination of slope and offset Date <- c(base::as.Date(DateProc) - 1, base::as.Date(DateProc), base::as.Date(DateProc) + 1) Date <- as.character(Date) Freq <- 20 #measurement frequency (20 Hz) #standard error of zero gas (unit in mol mol-1) zeroRefeSe <- 1*10^(-6) - + #calculation for each date in Date for (idxDate in Date){ #idxDate <- Date[1] @@ -105,12 +106,12 @@ wrap.irga.vali <- function( DatePre <- base::as.Date(idxDate) - 1 #post-processing date DatePost <- base::as.Date(idxDate) + 1 - #define 3 days which data will be used + #define 3 days which data will be used allDate <- c(base::as.Date(DatePre), base::as.Date(DateBgn), base::as.Date(DatePost)) - + #grab 3 days window of irga data and qfqmFlag (pre-processing, processing, and post-processing date) numDate <- 0 - + for (idxAllDate in allDate){ numDate <- numDate + 1 idxAllDate <- as.Date(idxAllDate, origin = "1970-01-01") @@ -124,7 +125,7 @@ wrap.irga.vali <- function( colnames(subQfqmFlag) <- names(qfqmFlag$irgaTurb) #add time #output time - options(digits.secs=3) + options(digits.secs=3) subTimeBgn <- base::as.POSIXlt(paste(base::as.Date(idxAllDate, origin = "1970-01-01"), " ", "00:00:00.0001", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") subTimeEnd <- base::as.POSIXlt(paste(base::as.Date(idxAllDate, origin = "1970-01-01"), " ", "23:59:59.9502", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") time <- as.POSIXlt(seq.POSIXt( @@ -152,22 +153,22 @@ wrap.irga.vali <- function( };rm(subData, subQfqmFlag, subTime)#end loop for of idxAllDate #define qf for each gas cylinder nameQf <- c("qfIrgaTurbValiGas01", "qfIrgaTurbValiGas02", "qfIrgaTurbValiGas03", "qfIrgaTurbValiGas04", "qfIrgaTurbValiGas05") - + #statistical names (will be used when no validation occured at all) NameStat <- c("mean", "min", "max", "vari", "numSamp", "se") - + #assign list tmp <- list() rptTmp <- list() - + #calculate statistical for each gas for (idxNameQf in nameQf){ #idxNameQf <- nameQf[2] - print(idxNameQf) + tryCatch({rlog$debug(idxNameQf)}, error=function(cond){print(idxNameQf)}) #preparing the qfIrgaTurbValiGas01 to 05 data for def.idx.agr() #replace NA to the qf which are not equal to 1 allSubQfqm[[idxNameQf]][] <- ifelse(allSubQfqm[[idxNameQf]][] != 1, NA, allSubQfqm[[idxNameQf]][]) - + #determine when validation occur #if there is at least one measurement if(length(which(!is.na(allSubQfqm[[idxNameQf]][]))) > 0){ @@ -177,11 +178,11 @@ wrap.irga.vali <- function( idxVali <- idxVali[rowSums(is.na(idxVali)) != 2,] #if last timeEnd is NA, replce that time to the last time value in data$time idxVali$timeEnd <- as.POSIXct(ifelse(is.na(idxVali$timeEnd), allSubData$time[length(allSubData$time)], idxVali$timeEnd), origin = "1970-01-01", tz = "UTC") - + for (idxAgr in 1:length(idxVali$timeBgn)){ #idxAgr <- 1 - inpTmp <- data.frame(rtioMoleDryCo2 = allSubData$rtioMoleDryCo2[idxVali$idxBgn[idxAgr]:idxVali$idxEnd[idxAgr]]) - + inpTmp <- data.frame(rtioMoleDryCo2 = allSubData$rtioMoleDryCo2[idxVali$idxBgn[idxAgr]:idxVali$idxEnd[idxAgr]]) + #statistical processing tmp[[idxNameQf]][[idxAgr]] <- eddy4R.base::wrap.dp01(data = inpTmp) #report data @@ -201,12 +202,12 @@ wrap.irga.vali <- function( rptTmp[[idxNameQf]][[1]]$timeEnd <- data.frame(rtioMoleDryCo2 = base::as.POSIXlt(paste(DateBgn, " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC")) } }#end of each qf in nameQf - + #return results as dataframe outTmp00 <-list() outTmp01 <- list() outTmp02 <- list() - + #Transform rptTmp into report dataframe format for (idxGas in names(rptTmp)){ #for (idxGas in c("qfIrgaTurbValiGas02", "qfIrgaTurbValiGas03", "qfIrgaTurbValiGas04")){ @@ -220,32 +221,32 @@ wrap.irga.vali <- function( } outTmp02[[idxGas]] <- do.call(rbind, outTmp01) outTmp02[[idxGas]]$gasType <- idxGas - + #empty lists outTmp00 <-list() outTmp01 <- list() - + } - + #combine row and save statistical outputs into rpt[[idxDate]]$rtioMoleDryCo2Vali rpt[[idxDate]]$rtioMoleDryCo2Vali <- do.call(rbind, outTmp02) - + #assign column names colnames(rpt[[idxDate]]$rtioMoleDryCo2Vali) <- c("mean", "min", "max", "vari", "numSamp", "se", "timeBgn", "timeEnd", "gasType") - + #remove row names rownames(rpt[[idxDate]]$rtioMoleDryCo2Vali) <- NULL - + #remove unuse objects rm(outTmp00, outTmp01, outTmp02, rptTmp, idxGas) - + #select only data fall in DateProc - #assign time window + #assign time window timeMin <- base::as.POSIXlt(paste(DateBgn, " ", "00:01:29.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") timeMax <- base::as.POSIXlt(paste(DatePost, " ", "00:01:29.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") #determine index when timeEnd fall in DateProc rpt[[idxDate]]$rtioMoleDryCo2Vali <- rpt[[idxDate]]$rtioMoleDryCo2Vali[which(rpt[[idxDate]]$rtioMoleDryCo2Vali$timeEnd >= timeMin & rpt[[idxDate]]$rtioMoleDryCo2Vali$timeBgn < timeMax),] - + #fail safe: fill in dataframe with NaN values when there is only qfIrgaTurbValiGas01 or no validation at all if (length(rpt[[idxDate]]$rtioMoleDryCo2Vali$mean) <= 1){ if(length(rpt[[idxDate]]$rtioMoleDryCo2Vali$mean) == 1 & rpt[[idxDate]]$rtioMoleDryCo2Vali$gasType[1] == "qfIrgaTurbValiGas01"){ @@ -268,7 +269,7 @@ wrap.irga.vali <- function( } } } - + #add gasRefe values into rpt #create temporary dataframe tmpGasRefe <- data.frame(matrix(ncol = 3, nrow = 5)) @@ -317,7 +318,7 @@ wrap.irga.vali <- function( } } }; rm(idxRow)# end for loop - + #replace the rtioMoleDryCo2RefeSe of zero gas to 0.1 ppm tmpGasRefe$rtioMoleDryCo2RefeSe[2] <- zeroRefeSe #add gas type @@ -328,7 +329,7 @@ wrap.irga.vali <- function( rpt[[idxDate]]$rtioMoleDryCo2Vali$rtioMoleDryCo2Refe[idxRow] <- tmpGasRefe$rtioMoleDryCo2Refe[locGas] rpt[[idxDate]]$rtioMoleDryCo2Vali$rtioMoleDryCo2RefeSe[idxRow] <- tmpGasRefe$rtioMoleDryCo2RefeSe[locGas] } - + #preparing data tables for calculating the regression #check if there are more than one validation occurred within one day if (length(which(rpt[[idxDate]]$rtioMoleDryCo2Vali$gasType == "qfIrgaTurbValiGas02")) == 2 & @@ -339,12 +340,12 @@ wrap.irga.vali <- function( } else{ valiCrit <- FALSE } - + #if valiCrit = TRUE, separate the data into 2 table if (valiCrit == TRUE){ locGas <- which(rpt[[idxDate]]$rtioMoleDryCo2Vali$gasType == "qfIrgaTurbValiGas02") #defined the critical time by adding 30 min after the end of running zero gas - timeCrit00 <- as.POSIXlt(rpt[[idxDate]]$rtioMoleDryCo2Vali$timeEnd[locGas[1]] + 30*60,format="%Y-%m-%d %H:%M:%OS", tz="UTC") + timeCrit00 <- as.POSIXlt(rpt[[idxDate]]$rtioMoleDryCo2Vali$timeEnd[locGas[1]] + 30*60,format="%Y-%m-%d %H:%M:%OS", tz="UTC") #timeCrit01 <- as.POSIXlt(rpt[[idxDate]]$rtioMoleDryCo2Vali$timeEnd[locGas[2]] + 30*60,format="%Y-%m-%d %H:%M:%OS", tz="UTC") #get rid of archive gas valiData[[idxDate]]$data00 <- rpt[[idxDate]]$rtioMoleDryCo2Vali[-which(rpt[[idxDate]]$rtioMoleDryCo2Vali$gasType == "qfIrgaTurbValiGas01"),] @@ -353,7 +354,7 @@ wrap.irga.vali <- function( valiData[[idxDate]]$data00 <- valiData[[idxDate]]$data00[which(valiData[[idxDate]]$data00$timeEnd < timeCrit00),] valiData[[idxDate]]$data01 <- valiData[[idxDate]]$data01[which(valiData[[idxDate]]$data01$timeEnd > timeCrit00),] }; rm (locGas, timeCrit00, timeCrit01) - + subVali <- list() subVali01 <- list() if (valiCrit == FALSE){ @@ -369,9 +370,9 @@ wrap.irga.vali <- function( locGas00 <- locGas00[length(locGas00)] } #defined the critical time by adding 30 min after the end of running zero gas - timeCrit00 <- as.POSIXlt(valiData[[idxDate]]$data00$timeEnd[locGas00[1]] + 30*60,format="%Y-%m-%d %H:%M:%OS", tz="UTC") + timeCrit00 <- as.POSIXlt(valiData[[idxDate]]$data00$timeEnd[locGas00[1]] + 30*60,format="%Y-%m-%d %H:%M:%OS", tz="UTC") #select data within timeCrit - valiData[[idxDate]]$data00 <- valiData[[idxDate]]$data00[which(valiData[[idxDate]]$data00$timeEnd >= valiData[[idxDate]]$data00$timeEnd[locGas00[1]] & + valiData[[idxDate]]$data00 <- valiData[[idxDate]]$data00[which(valiData[[idxDate]]$data00$timeEnd >= valiData[[idxDate]]$data00$timeEnd[locGas00[1]] & valiData[[idxDate]]$data00$timeEnd < timeCrit00),] #check if there are all data as expected if (length(valiData[[idxDate]]$data00$timeBgn) <= 4){ @@ -393,17 +394,17 @@ wrap.irga.vali <- function( }#end else valiData[[idxDate]]$data01 <- valiData[[idxDate]]$data00 } - + #calculate linear regression between validation gas standard and sensor reading values #using maximum-likelihood fitting of a functional relationship (MLFR) #calculate linear regression for each of valiData[[idxDate]]$data01 and valiData[[idxDate]]$data00 #test if all inputs are NA for (idxData in names(valiData[[idxDate]])){ #create empty dataframe to keep intercept and slope output from MLFR - tmpCoef[[idxDate]][[idxData]] <- data.frame(matrix(ncol = 3, nrow = 2)) + tmpCoef[[idxDate]][[idxData]] <- data.frame(matrix(ncol = 3, nrow = 2)) #assign column name colnames(tmpCoef[[idxDate]][[idxData]]) <- c("coef", "se", "scal") - + if (length(valiData[[idxDate]][[idxData]]$mean) < 4 | sum(is.na(valiData[[idxDate]][[idxData]]$mean)) > 0 | sum(is.na(valiData[[idxDate]][[idxData]]$se)) >0 | sum(is.na(valiData[[idxDate]][[idxData]]$rtioMoleDryCo2Refe)) > 0 | sum(is.na(valiData[[idxDate]][[idxData]]$rtioMoleDryCo2RefeSe)) > 1){ @@ -411,7 +412,7 @@ wrap.irga.vali <- function( } else{ #x are sensor readings; y are reference gas values rtioMoleDryCo2Mlfr <- deming::deming(rtioMoleDryCo2Refe[1:4] ~ mean[1:4], data = valiData[[idxDate]][[idxData]], - xstd = se[1:4], ystd = rtioMoleDryCo2RefeSe[1:4]) + xstd = se[1:4], ystd = rtioMoleDryCo2RefeSe[1:4]) #write output to table #intercept tmpCoef[[idxDate]][[idxData]][1,1] <- rtioMoleDryCo2Mlfr$coefficients[[1]] @@ -423,25 +424,25 @@ wrap.irga.vali <- function( tmpCoef[[idxDate]][[idxData]][1,3] <- rtioMoleDryCo2Mlfr$sigma } }#end of for loop of idxData - + #report output rpt[[idxDate]]$rtioMoleDryCo2Mlf <- tmpCoef[[idxDate]]$data00 #reorder column rpt[[idxDate]]$rtioMoleDryCo2Vali <- rpt[[idxDate]]$rtioMoleDryCo2Vali[,c(1:5, 10, 7, 8)] #unit attributes unitRtioMoleDryCo2Vali <- attributes(data$irgaTurb$rtioMoleDryCo2)$unit - + attributes(rpt[[idxDate]]$rtioMoleDryCo2Vali)$unit <- c(unitRtioMoleDryCo2Vali, #"mean" unitRtioMoleDryCo2Vali, #"min" - unitRtioMoleDryCo2Vali, #"max" + unitRtioMoleDryCo2Vali, #"max" unitRtioMoleDryCo2Vali,#"vari" "NA", #"numSamp" attributes(gasRefe$rtioMoleDryCo2Refe01[[idxDate]]$`702_000`)$unit,#"rtioMoleDryCo2Refe" "NA", #"timeBgn" "NA")#"timeEnd" - + }; rm(valiCrit, allSubData, allSubQfqm, allSubTime)#end of idxDate - + invisible(gc()) #check if there are more than one validation occurred in DateProc if (length(which(rpt[[DateProc]]$rtioMoleDryCo2Vali$gasType == "qfIrgaTurbValiGas02")) == 2 & @@ -452,11 +453,11 @@ wrap.irga.vali <- function( } else{ valiCrit <- FALSE } - + #applying the calculated coefficients to measured data #Calculate time-series (20Hz) of slope and zero offset rpt[[DateProc]]$rtioMoleDryCo2Cor <- eddy4R.base::def.irga.vali.cor(data = data, DateProc = DateProc, coef = tmpCoef, valiData = valiData, valiCrit = valiCrit, ScalMax = 20, FracSlpMax = 0.1, Freq = 20) - + #return results return(rpt) } diff --git a/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R b/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R index 8e03306f..763e0df6 100644 --- a/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R +++ b/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R @@ -1,14 +1,14 @@ ############################################################################################## -#' @title Wrapper function: Output unit conversion for ECTE +#' @title Wrapper function: Output unit conversion for ECTE -#' @author +#' @author #' David Durden \email{eddy4R.info@gmail.com} -#' @description Function wrapper. Convert a list of data to eddy4r output units using def.unit.conv function, with special attention to variable with the mean removed that are translated between units (i.e. variance for temperature when converting K to C). +#' @description Function wrapper. Convert a list of data to eddy4r output units using def.unit.conv function, with special attention to variable with the mean removed that are translated between units (i.e. variance for temperature when converting K to C). #' @param inpList Required. A named list of data frames of type numeric, containing the data to be converted. #' @param MethMeas A vector of class "character" containing the name of measurement method (eddy-covariance turbulent exchange or storage exchange), MethMeas = c("ecte", "ecse"). Defaults to "ecse". [-] -#' @param MethType Required. A character string containing the type of data to be converted. Defauts to \code{MethType} = c("Data"). +#' @param MethType Required. A character string containing the type of data to be converted. Defauts to \code{MethType} = c("Data"). #' @return A list, \code{rpt}, with data, qfqm, or uncertainty output with the correct output units @@ -23,7 +23,7 @@ #' @export -# changelog and author contributions / copyrights +# changelog and author contributions / copyrights # David Durden (2018-02-12) # original creation # Natchaya P-Durden (2018-03-28) @@ -48,8 +48,8 @@ wrap.unit.conv.out.ec <- function( #Putting MethType to lowercase always MethType <- base::tolower(MethType) - -rpt <- inpList + +rpt <- inpList #working and output attribute lists wrkAttr <- base::list() outAttr <- base::list() @@ -58,102 +58,102 @@ outAttr <- base::list() if(MethMeas == "ecte"){ if(MethType == "data"){ outAttr$soni <- base::list( - "veloXaxsErth"= c("mean" = "m s-1", "min" = "m s-1", "max" = "m s-1", "vari" = "m s-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "veloYaxsErth"= c("mean" = "m s-1", "min" = "m s-1", "max" = "m s-1", "vari" = "m s-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "veloZaxsErth"= c("mean" = "m s-1", "min" = "m s-1", "max" = "m s-1", "vari" = "m s-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "veloXaxsYaxsErth"= c("mean" = "m s-1", "min" = "m s-1", "max" = "m s-1", "vari" = "m s-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "angZaxsErth"= c("mean" = "deg", "min" = "deg", "max" = "deg", "vari" = "deg", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "tempSoni"= c("mean" = "C", "min" = "C", "max" = "C", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "veloXaxsErth"= c("mean" = "m s-1", "min" = "m s-1", "max" = "m s-1", "vari" = "m s-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "veloYaxsErth"= c("mean" = "m s-1", "min" = "m s-1", "max" = "m s-1", "vari" = "m s-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "veloZaxsErth"= c("mean" = "m s-1", "min" = "m s-1", "max" = "m s-1", "vari" = "m s-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "veloXaxsYaxsErth"= c("mean" = "m s-1", "min" = "m s-1", "max" = "m s-1", "vari" = "m s-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "angZaxsErth"= c("mean" = "deg", "min" = "deg", "max" = "deg", "vari" = "deg", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "tempSoni"= c("mean" = "C", "min" = "C", "max" = "C", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), "tempAir"= c("mean" = "C", "min" = "C", "max" = "C", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA")) outAttr$amrs <- base::list( - "angNedXaxs"= c("mean" = "deg", "min" = "deg", "max" = "deg", "vari" = "deg", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "angNedYaxs"= c("mean" = "deg", "min" = "deg", "max" = "deg", "vari" = "deg", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "angNedXaxs"= c("mean" = "deg", "min" = "deg", "max" = "deg", "vari" = "deg", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "angNedYaxs"= c("mean" = "deg", "min" = "deg", "max" = "deg", "vari" = "deg", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), "angNedZaxs"= c("mean" = "deg", "min" = "deg", "max" = "deg", "vari" = "deg", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA")) outAttr$co2Turb <- base::list( - "rtioMoleDryCo2"= c("mean" = "umolCo2 mol-1Dry", "min" = "umolCo2 mol-1Dry", "max" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "rtioMoleDryCo2"= c("mean" = "umolCo2 mol-1Dry", "min" = "umolCo2 mol-1Dry", "max" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), "rtioMoleDryCo2Cor"= c("mean" = "umolCo2 mol-1Dry", "min" = "umolCo2 mol-1Dry", "max" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), "rtioMoleDryCo2Raw"= c("mean" = "umolCo2 mol-1Dry", "min" = "umolCo2 mol-1Dry", "max" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "densMoleCo2"= c("mean" = "umolCo2 m-3", "min" = "umolCo2 m-3", "max" = "umolCo2 m-3", "vari" = "umolCo2 m-3", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "presAtm"= c("mean" = "kPa", "min" = "kPa", "max" = "kPa", "vari" = "kPa", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "presSum"= c("mean" = "kPa", "min" = "kPa", "max" = "kPa", "vari" = "kPa", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "frt00Samp"= c("mean" = "dm3 min-1", "min" = "dm3 min-1", "max" = "dm3 min-1", "vari" = "dm3 min-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "densMoleCo2"= c("mean" = "umolCo2 m-3", "min" = "umolCo2 m-3", "max" = "umolCo2 m-3", "vari" = "umolCo2 m-3", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "presAtm"= c("mean" = "kPa", "min" = "kPa", "max" = "kPa", "vari" = "kPa", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "presSum"= c("mean" = "kPa", "min" = "kPa", "max" = "kPa", "vari" = "kPa", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "frt00Samp"= c("mean" = "dm3 min-1", "min" = "dm3 min-1", "max" = "dm3 min-1", "vari" = "dm3 min-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), "tempAve"= c("mean" = "C", "min" = "C", "max" = "C", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA")) outAttr$h2oTurb <- base::list( - "rtioMoleDryH2o"= c("mean" = "mmolH2o mol-1Dry", "min" = "mmolH2o mol-1Dry", "max" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "densMoleH2o"= c("mean" = "mmolH2o m-3", "min" = "mmolH2o m-3", "max" = "mmolH2o m-3", "vari" = "mmolH2o m-3", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "rtioMoleDryH2o"= c("mean" = "mmolH2o mol-1Dry", "min" = "mmolH2o mol-1Dry", "max" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "densMoleH2o"= c("mean" = "mmolH2o m-3", "min" = "mmolH2o m-3", "max" = "mmolH2o m-3", "vari" = "mmolH2o m-3", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), "tempDew"= c("mean" = "C", "min" = "C", "max" = "C", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "presAtm"= c("mean" = "kPa", "min" = "kPa", "max" = "kPa", "vari" = "kPa", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "presSum"= c("mean" = "kPa", "min" = "kPa", "max" = "kPa", "vari" = "kPa", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), - "frt00Samp"= c("mean" = "dm3 min-1", "min" = "dm3 min-1", "max" = "dm3 min-1", "vari" = "dm3 min-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "presAtm"= c("mean" = "kPa", "min" = "kPa", "max" = "kPa", "vari" = "kPa", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "presSum"= c("mean" = "kPa", "min" = "kPa", "max" = "kPa", "vari" = "kPa", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "frt00Samp"= c("mean" = "dm3 min-1", "min" = "dm3 min-1", "max" = "dm3 min-1", "vari" = "dm3 min-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), "tempAve"= c("mean" = "C", "min" = "C", "max" = "C", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA")) } if(MethType == "ucrt"){ outAttr$soni <- base::list( - "veloXaxsErth"= c("mean" = "m s-1", "vari" = "m s-1", "se" = "m s-1", "timeBgn" = "NA", "timeEnd" = "NA"), - "veloYaxsErth"= c("mean" = "m s-1", "vari" = "m s-1", "se" = "m s-1", "timeBgn" = "NA", "timeEnd" = "NA"), + "veloXaxsErth"= c("mean" = "m s-1", "vari" = "m s-1", "se" = "m s-1", "timeBgn" = "NA", "timeEnd" = "NA"), + "veloYaxsErth"= c("mean" = "m s-1", "vari" = "m s-1", "se" = "m s-1", "timeBgn" = "NA", "timeEnd" = "NA"), "veloZaxsErth"= c("mean" = "m s-1", "vari" = "m s-1", "se" = "m s-1", "timeBgn" = "NA", "timeEnd" = "NA"), - "veloXaxsYaxsErth"= c("mean" = "m s-1", "vari" = "m s-1", "se" = "m s-1", "timeBgn" = "NA", "timeEnd" = "NA"), - "angZaxsErth"= c("mean" = "deg", "vari" = "deg", "se" = "deg", "timeBgn" = "NA", "timeEnd" = "NA"), - "tempSoni"= c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA"), + "veloXaxsYaxsErth"= c("mean" = "m s-1", "vari" = "m s-1", "se" = "m s-1", "timeBgn" = "NA", "timeEnd" = "NA"), + "angZaxsErth"= c("mean" = "deg", "vari" = "deg", "se" = "deg", "timeBgn" = "NA", "timeEnd" = "NA"), + "tempSoni"= c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA"), "tempAir"= c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA")) - + outAttr$amrs <- base::list( - "angNedXaxs"= c("mean" = "deg", "vari" = "deg", "se" = "deg", "timeBgn" = "NA", "timeEnd" = "NA"), - "angNedYaxs"= c("mean" = "deg", "vari" = "deg", "se" = "deg", "timeBgn" = "NA", "timeEnd" = "NA"), + "angNedXaxs"= c("mean" = "deg", "vari" = "deg", "se" = "deg", "timeBgn" = "NA", "timeEnd" = "NA"), + "angNedYaxs"= c("mean" = "deg", "vari" = "deg", "se" = "deg", "timeBgn" = "NA", "timeEnd" = "NA"), "angNedZaxs"= c("mean" = "deg", "vari" = "deg", "se" = "deg", "timeBgn" = "NA", "timeEnd" = "NA")) - + outAttr$co2Turb <- base::list( - "rtioMoleDryCo2"= c("mean" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "se" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA"), - "rtioMoleDryCo2Cor"= c("mean" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "se" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA"), - "rtioMoleDryCo2Raw"= c("mean" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "se" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA"), - "densMoleCo2"= c("mean" = "umolCo2 m-3", "vari" = "umolCo2 m-3", "se" = "umolCo2 m-3", "timeBgn" = "NA", "timeEnd" = "NA"), - "presAtm"= c("mean" = "kPa", "vari" = "kPa", "se" = "kPa", "timeBgn" = "NA", "timeEnd" = "NA"), - "presSum"= c("mean" = "kPa", "vari" = "kPa", "se" = "kPa", "timeBgn" = "NA", "timeEnd" = "NA"), - "frt00Samp"= c("mean" = "dm3 min-1", "vari" = "dm3 min-1", "se" = "dm3 min-1", "timeBgn" = "NA", "timeEnd" = "NA"), + "rtioMoleDryCo2"= c("mean" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "se" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA"), + "rtioMoleDryCo2Cor"= c("mean" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "se" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA"), + "rtioMoleDryCo2Raw"= c("mean" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "se" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA"), + "densMoleCo2"= c("mean" = "umolCo2 m-3", "vari" = "umolCo2 m-3", "se" = "umolCo2 m-3", "timeBgn" = "NA", "timeEnd" = "NA"), + "presAtm"= c("mean" = "kPa", "vari" = "kPa", "se" = "kPa", "timeBgn" = "NA", "timeEnd" = "NA"), + "presSum"= c("mean" = "kPa", "vari" = "kPa", "se" = "kPa", "timeBgn" = "NA", "timeEnd" = "NA"), + "frt00Samp"= c("mean" = "dm3 min-1", "vari" = "dm3 min-1", "se" = "dm3 min-1", "timeBgn" = "NA", "timeEnd" = "NA"), "tempAve"= c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA")) - + outAttr$h2oTurb <- base::list( - "rtioMoleDryH2o"= c("mean" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "se" = "mmolH2o mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA"), - "densMoleH2o"= c("mean" = "mmolH2o m-3", "vari" = "mmolH2o m-3", "se" = "mmolH2o m-3", "timeBgn" = "NA", "timeEnd" = "NA"), + "rtioMoleDryH2o"= c("mean" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "se" = "mmolH2o mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA"), + "densMoleH2o"= c("mean" = "mmolH2o m-3", "vari" = "mmolH2o m-3", "se" = "mmolH2o m-3", "timeBgn" = "NA", "timeEnd" = "NA"), "tempDew"= c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA"), - "presAtm"= c("mean" = "kPa", "vari" = "kPa", "se" = "kPa", "timeBgn" = "NA", "timeEnd" = "NA"), - "presSum"= c("mean" = "kPa", "vari" = "kPa", "se" = "kPa", "timeBgn" = "NA", "timeEnd" = "NA"), - "frt00Samp"= c("mean" = "dm3 min-1", "vari" = "dm3 min-1", "se" = "dm3 min-1", "timeBgn" = "NA", "timeEnd" = "NA"), + "presAtm"= c("mean" = "kPa", "vari" = "kPa", "se" = "kPa", "timeBgn" = "NA", "timeEnd" = "NA"), + "presSum"= c("mean" = "kPa", "vari" = "kPa", "se" = "kPa", "timeBgn" = "NA", "timeEnd" = "NA"), + "frt00Samp"= c("mean" = "dm3 min-1", "vari" = "dm3 min-1", "se" = "dm3 min-1", "timeBgn" = "NA", "timeEnd" = "NA"), "tempAve"= c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA")) } if(MethType == "vali"){ outAttr$co2Turb <- base::list( - "rtioMoleDryCo2Vali"= c("mean" = "umolCo2 mol-1Dry", "min" = "umolCo2 mol-1Dry", "max" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "numSamp" = "NA", "rtioMoleDryCo2Refe" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA")) + "rtioMoleDryCo2Vali"= c("mean" = "umolCo2 mol-1Dry", "min" = "umolCo2 mol-1Dry", "max" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "numSamp" = "NA", "rtioMoleDryCo2Refe" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA")) } #assign output attributes outAttr$vari <- base::list( - "veloXaxsErth"= "m2 s-2", - "veloYaxsErth"= "m2 s-2", + "veloXaxsErth"= "m2 s-2", + "veloYaxsErth"= "m2 s-2", "veloZaxsErth"= "m2 s-2", - "veloXaxsYaxsErth"= "m2 s-2", - "angZaxsErth"= "deg2", - "tempSoni"= "C2", - "tempAir"= "C2", - "angNedXaxs"= "deg2", - "angNedYaxs"= "deg2", + "veloXaxsYaxsErth"= "m2 s-2", + "angZaxsErth"= "deg2", + "tempSoni"= "C2", + "tempAir"= "C2", + "angNedXaxs"= "deg2", + "angNedYaxs"= "deg2", "angNedZaxs"= "deg2", - "rtioMoleDryCo2"= "umol2Co2 mol-2Dry", + "rtioMoleDryCo2"= "umol2Co2 mol-2Dry", "rtioMoleDryCo2Cor"= "umol2Co2 mol-2Dry", "rtioMoleDryCo2Raw"= "umol2Co2 mol-2Dry", - "rtioMoleDryCo2Vali"= "umol2Co2 mol-2Dry", - "densMoleCo2"= "umol2Co2 m-6", - "presAtm"= "kPa2", - "presSum"= "kPa2", - "frt00Samp"= "dm6 min-2", + "rtioMoleDryCo2Vali"= "umol2Co2 mol-2Dry", + "densMoleCo2"= "umol2Co2 m-6", + "presAtm"= "kPa2", + "presSum"= "kPa2", + "frt00Samp"= "dm6 min-2", "tempAve"= "C2", - "rtioMoleDryH2o"= "mmol2H2o mol-2Dry", - "densMoleH2o"= "mmol2H2o m-6", + "rtioMoleDryH2o"= "mmol2H2o mol-2Dry", + "densMoleH2o"= "mmol2H2o m-6", "tempDew"= "C2" ) @@ -167,20 +167,20 @@ for(idxDp in base::names(rpt)){ baseAttr <- base::attributes(rpt[[idxDp]][[idxVar]])$unit} else{ baseAttr <- base::attributes(rpt[[idxDp]][[idxVar]])$unit[1] } - + if(MethType == "data"){ wrkAttr[[idxDp]][[idxVar]] <- c("mean"= baseAttr, "min" = baseAttr, "max" = baseAttr, "vari" = baseAttr, "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") - + #Only variables with conversion factors (i.e. multiplied differences should be converted using the unit conversion tool. Temp has an offset applied, this should not be performed for any variable with the mean removed, i.e. vari, se, etc.) if(base::grepl(pattern = "temp", x = idxVar)){wrkAttr[[idxDp]][[idxVar]]["vari"] <- "C"} } - + if(MethType == "ucrt"){ wrkAttr[[idxDp]][[idxVar]] <- c("mean"= baseAttr, "vari" = baseAttr, "se" = baseAttr, "timeBgn" = "NA", "timeEnd" = "NA") #Only variables with conversion factors (i.e. multiplied differences should be converted using the unit conversion tool. Temp has an offset applied, this should not be performed for any variable with the mean removed, i.e. vari, se, etc.) if(base::grepl(pattern = "temp", x = idxVar)){wrkAttr[[idxDp]][[idxVar]][wrkAttr[[idxDp]][[idxVar]] == baseAttr] <- "C"} } - + if(MethType == "qfqm"){ # Create qfqm list of units wrkAttr[[idxDp]][[idxVar]] <- base::rep_len(baseAttr, length.out = length(rpt[[idxDp]][[idxVar]])) @@ -190,12 +190,12 @@ for(idxDp in base::names(rpt)){ wrkAttr[[idxDp]][[idxVar]][base::grep(pattern = "qf|time", x = names(wrkAttr[[idxDp]][[idxVar]]))] <- "NA" #Apply dimensionless fraction for all qm variables wrkAttr[[idxDp]][[idxVar]][base::grep(pattern = "qm", x = names(wrkAttr[[idxDp]][[idxVar]]))] <- "-" - + # Apply output attributes outAttr[[idxDp]][[idxVar]] <- wrkAttr[[idxDp]][[idxVar]] - + } - + if(MethType == "vali"){ #refeName <- names(outAttr[[idxDp]][[idxVar]][6]) nameAttr <- c("mean", "min", "max", "vari", "numSamp" , names(outAttr[[idxDp]][[idxVar]][6]), "timeBgn", "timeEnd" ) @@ -203,19 +203,19 @@ for(idxDp in base::names(rpt)){ wrkAttr[[idxDp]][[idxVar]] <- c(baseAttr, baseAttr, baseAttr, baseAttr, baseAttr, baseAttr, "NA", "NA") names(wrkAttr[[idxDp]][[idxVar]]) <- nameAttr } - + #To apply unit conversion to variance, we need to take sqrt first base::try(rpt[[idxDp]][[idxVar]]$vari <- base::sqrt(rpt[[idxDp]][[idxVar]]$vari), silent = TRUE) base::attributes(rpt[[idxDp]][[idxVar]])$unit <- wrkAttr[[idxDp]][[idxVar]] #Applying unit conversion# rpt[[idxDp]][[idxVar]] <- base::suppressWarnings(eddy4R.base::def.unit.conv(data = rpt[[idxDp]][[idxVar]], unitFrom = attributes(rpt[[idxDp]][[idxVar]])$unit, unitTo = outAttr[[idxDp]][[idxVar]], MethGc = FALSE)) - + #Convert units values back to variance base::try(rpt[[idxDp]][[idxVar]]$vari <- (rpt[[idxDp]][[idxVar]]$vari)^2, silent = TRUE) - + # Apply variance units base::try(attributes(rpt[[idxDp]][[idxVar]])$unit[names(attributes(rpt[[idxDp]][[idxVar]])$unit) == "vari"] <- outAttr$vari[[idxVar]], silent = TRUE) - + } #End loop around idxVar } #End loop around idxDp }#End of ecte @@ -224,28 +224,28 @@ for(idxDp in base::names(rpt)){ if(MethMeas == "ecse"){ #unit for vari outAttr$vari <- c("frt00" = "dm6 min-2", - "pres" = "kPa2", - "presEnvHut" = "kPa2", - "rhEnvHut" = "%", - "rtioMoleDryCo2" = "umol2Co2 mol-2", - "rtioMoleWetCo2" = "umol2Co2 mol-2", - "rtioMoleDryCo2Refe" = "umol2Co2 mol-2", - "temp" = "C2", - "tempEnvHut" = "C2", - "rtioMoleDryH2o" = "mmol2H2o mol-2", - "rtioMoleWetH2o" = "mmol2H2o mol-2", - "rtioMoleWetH2oEnvHut" = "mmol2H2o mol-2", - "rtioMoleWet12CCo2" = "umol2Co2 mol-2", - "rtioMoleDry12CCo2" = "umol2Co2 mol-2", - "rtioMoleWet13CCo2" = "umol2Co2 mol-2", - "rtioMoleDry13CCo2" = "umol2Co2 mol-2", - "dlta13CCo2" = "permill2", - "dlta13CCo2Refe" = "permill2", - "dlta18OH2o" = "permill2", - "dlta2HH2o" = "permill2", - "dlta18OH2oRefe" = "permill2", - "dlta2HH2oRefe" = "permill2") - + "pres" = "kPa2", + "presEnvHut" = "kPa2", + "rhEnvHut" = "%", + "rtioMoleDryCo2" = "umol2Co2 mol-2", + "rtioMoleWetCo2" = "umol2Co2 mol-2", + "rtioMoleDryCo2Refe" = "umol2Co2 mol-2", + "temp" = "C2", + "tempEnvHut" = "C2", + "rtioMoleDryH2o" = "mmol2H2o mol-2", + "rtioMoleWetH2o" = "mmol2H2o mol-2", + "rtioMoleWetH2oEnvHut" = "mmol2H2o mol-2", + "rtioMoleWet12CCo2" = "umol2Co2 mol-2", + "rtioMoleDry12CCo2" = "umol2Co2 mol-2", + "rtioMoleWet13CCo2" = "umol2Co2 mol-2", + "rtioMoleDry13CCo2" = "umol2Co2 mol-2", + "dlta13CCo2" = "permill2", + "dlta13CCo2Refe" = "permill2", + "dlta18OH2o" = "permill2", + "dlta2HH2o" = "permill2", + "dlta18OH2oRefe" = "permill2", + "dlta2HH2oRefe" = "permill2") + if(MethType == "data"){ #define working unit attributes #dp01 @@ -283,7 +283,7 @@ if(MethMeas == "ecse"){ wrkAttr$fluxCo2 <- c("mean" = "molCo2 mol-1 m s-1", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$fluxH2o <- c("mean" = "molH2o mol-1 m s-1", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$fluxTemp <- c("mean" = "K m s-1", "timeBgn" = "NA", "timeEnd" = "NA") - + #define output unit attributes #dp01 outAttr$frt00 <- c("mean" = "dm3 min-1", "min" = "dm3 min-1", "max" = "dm3 min-1", "vari" = "dm3 min-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") @@ -320,12 +320,13 @@ if(MethMeas == "ecse"){ outAttr$fluxCo2 <- c("mean" = "umolCo2 mol-1 m s-1", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$fluxH2o <- c("mean" = "mmolH2o mol-1 m s-1", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$fluxTemp <- c("mean" = "K m s-1", "timeBgn" = "NA", "timeEnd" = "NA") - + #performing dp01 unit conversion - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", Date, ": performing dp01 unit conversion")) + msg <- paste0("dataset ", Date, ": performing dp01 unit conversion") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) for(idxDp in base::names(rpt$dp01$data)[which(!(names(rpt$dp01$data) %in% c("tempAirTop", "tempAirLvl")))]) { #idxDp <- base::names(rpt$dp01$data)[1] - + for(idxLvl in base::names(rpt$dp01$data[[idxDp]])){ #idxLvl <- base::names(rpt$dp01$data[[idxDp]])[1] for(idxVar in base::names(rpt$dp01$data[[idxDp]][[idxLvl]])){ @@ -342,7 +343,7 @@ if(MethMeas == "ecse"){ unitFrom = attributes(rpt$dp01$data[[idxDp]][[idxLvl]][[idxVar]])$unit, unitTo = outAttr[[idxVar]], MethGc = FALSE)) - + #calculate variance rpt$dp01$data[[idxDp]][[idxLvl]][[idxVar]]$vari <- (rpt$dp01$data[[idxDp]][[idxLvl]][[idxVar]]$vari)^2 #format time @@ -353,17 +354,18 @@ if(MethMeas == "ecse"){ attributes(rpt$dp01$data[[idxDp]][[idxLvl]][[idxVar]])$unit #apply variance units base::try(attributes(rpt$dp01$data[[idxDp]][[idxLvl]][[idxVar]])$unit[names(attributes(rpt$dp01$data[[idxDp]][[idxLvl]][[idxVar]])$unit) == "vari"] <- outAttr$vari[[idxVar]], silent = TRUE) - + } } - base::gc(verbose=FALSE) # clean up memory + base::gc(verbose=FALSE) # clean up memory }; rm(idxVar) - + #performing dp02 unit conversion - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", Date, ": performing dp02 unit conversion")) + msg<-paste0("dataset ", Date, ": performing dp02 unit conversion") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) for(idxDp in base::names(rpt$dp02$data)) { #idxDp <- base::names(rpt$dp02$data)[1] - + for(idxLvl in base::names(rpt$dp02$data[[idxDp]])){ #idxLvl <- base::names(rpt$dp02$data[[idxDp]])[2] for(idxVar in base::names(rpt$dp02$data[[idxDp]][[idxLvl]])){ @@ -376,26 +378,27 @@ if(MethMeas == "ecse"){ unitFrom = attributes(rpt$dp02$data[[idxDp]][[idxLvl]][[idxVar]])$unit, unitTo = outAttr[[idxVar]], MethGc = FALSE)) - - + + #format time rpt$dp02$data[[idxDp]][[idxLvl]][[idxVar]]$timeBgn <- as.character(rpt$dp02$data[[idxDp]][[idxLvl]][[idxVar]]$timeBgn) rpt$dp02$data[[idxDp]][[idxLvl]][[idxVar]]$timeEnd <- as.character(rpt$dp02$data[[idxDp]][[idxLvl]][[idxVar]]$timeEnd) - + #unit transfer attributes(rpt$dp02$data[[idxDp]][[idxLvl]][[idxVar]])$unit <- attributes(rpt$dp02$data[[idxDp]][[idxLvl]][[idxVar]])$unit - + } } - base::gc(verbose=FALSE) # clean up memory + base::gc(verbose=FALSE) # clean up memory }; rm(idxVar) - + #performing dp03 unit conversion - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", Date, ": performing dp03 unit conversion")) + msg <- paste0("dataset ", Date, ": performing dp03 unit conversion") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) for(idxDp in base::names(rpt$dp03$data)) { #idxDp <- base::names(rpt$dp03$data)[1] - + for(idxVar in base::names(rpt$dp03$data[[idxDp]])){ #idxVar <- base::names(rpt$dp03$data[[idxDp]])[1] #Apply unit attributes to mean, timeBgn, timeEnd @@ -406,26 +409,27 @@ if(MethMeas == "ecse"){ unitFrom = attributes(rpt$dp03$data[[idxDp]][[idxVar]])$unit, unitTo = outAttr$dp03[[idxVar]], MethGc = FALSE)) - - + + #format time rpt$dp03$data[[idxDp]][[idxVar]]$timeBgn <- as.character(rpt$dp03$data[[idxDp]][[idxVar]]$timeBgn) rpt$dp03$data[[idxDp]][[idxVar]]$timeEnd <- as.character(rpt$dp03$data[[idxDp]][[idxVar]]$timeEnd) - + #unit transfer attributes(rpt$dp03$data[[idxDp]][[idxVar]])$unit <- attributes(rpt$dp03$data[[idxDp]][[idxVar]])$unit[1] - + } base::gc(verbose=FALSE) # clean up memory - + }; rm(idxVar) - + #performing dp04 unit conversion - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", Date, ": performing dp04 unit conversion")) + msg <- paste0("dataset ", Date, ": performing dp04 unit conversion") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) for(idxDp in base::names(rpt$dp04$data)) { #idxDp <- base::names(rpt$dp04$data)[3] - + for(idxVar in base::names(rpt$dp04$data[[idxDp]])){ #idxVar <- base::names(rpt$dp04$data[[idxDp]])[1] #Apply unit attributes to mean, timeBgn, timeEnd @@ -436,12 +440,12 @@ if(MethMeas == "ecse"){ unitFrom = attributes(rpt$dp04$data[[idxDp]][[idxVar]])$unit, unitTo = outAttr[[idxDp]], MethGc = FALSE)) - - + + #format time rpt$dp04$data[[idxDp]][[idxVar]]$timeBgn <- as.character(rpt$dp04$data[[idxDp]][[idxVar]]$timeBgn) rpt$dp04$data[[idxDp]][[idxVar]]$timeEnd <- as.character(rpt$dp04$data[[idxDp]][[idxVar]]$timeEnd) - + #unit transfer attributes(rpt$dp04$data[[idxDp]][[idxVar]])$unit <- attributes(rpt$dp04$data[[idxDp]][[idxVar]])$unit @@ -449,10 +453,11 @@ if(MethMeas == "ecse"){ base::gc(verbose=FALSE) # clean up memory } }#end of MethType = "data" - + if(MethType == "qfqm"){ #performing dp01 and dp02 unit transfer - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", Date, ": transfering dp01 and dp02 qfqm unit ")) + msg <- paste0("dataset ", Date, ": transfering dp01 and dp02 qfqm unit ") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) for(idxDataLvl in c("dp01", "dp02")){ for(idxDp in base::names(rpt[[idxDataLvl]]$qfqm)[which(!(names(rpt[[idxDataLvl]]$data) %in% c("tempAirTop", "tempAirLvl")))]) { for(idxLvl in base::names(rpt[[idxDataLvl]]$qfqm[[idxDp]])){ @@ -470,18 +475,19 @@ if(MethMeas == "ecse"){ rpt[[idxDataLvl]]$qfqm[[idxDp]][[idxLvl]][[idxVar]]$timeEnd <- as.character(rpt[[idxDataLvl]]$qfqm[[idxDp]][[idxLvl]][[idxVar]]$timeEnd) } } - base::gc(verbose=FALSE) # clean up memory + base::gc(verbose=FALSE) # clean up memory }; rm(idxVar) }#end of dp01 and dp02 - + #performing dp03 and dp04 unit transfer - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", Date, ": transfering dp03 and dp04 qfqm unit ")) + msg <- paste0("dataset ", Date, ": transfering dp03 and dp04 qfqm unit ") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) for(idxDataLvl in c("dp03", "dp04")){ for(idxDp in base::names(rpt[[idxDataLvl]]$qfqm)) { for(idxVar in base::names(rpt[[idxDataLvl]]$qfqm[[idxDp]])){ #Apply unit attributes to rpt if(idxDataLvl == "dp03"){ - attributes(rpt[[idxDataLvl]]$qfqm[[idxDp]][[idxVar]])$unit <- "NA" + attributes(rpt[[idxDataLvl]]$qfqm[[idxDp]][[idxVar]])$unit <- "NA" }else{ # Create qfqm list of units wrkAttr[[idxVar]] <- c(rep("-", time = length(rpt[[idxDataLvl]]$qfqm[[idxDp]][[idxVar]]))) @@ -496,11 +502,11 @@ if(MethMeas == "ecse"){ rpt[[idxDataLvl]]$qfqm[[idxDp]][[idxVar]]$timeBgn <- as.character(rpt[[idxDataLvl]]$qfqm[[idxDp]][[idxVar]]$timeBgn) rpt[[idxDataLvl]]$qfqm[[idxDp]][[idxVar]]$timeEnd <- as.character(rpt[[idxDataLvl]]$qfqm[[idxDp]][[idxVar]]$timeEnd) } - base::gc(verbose=FALSE) # clean up memory + base::gc(verbose=FALSE) # clean up memory }; rm(idxVar) }#end of dp03 and dp04 }#End of MethType == "qfqm" - + if(MethType == "ucrt"){ #dp01 wrkAttr$frt00 <- c("mean" = "m3 s-1", "vari" = "m3 s-1", "se" = "m3 s-1", "timeBgn" = "NA", "timeEnd" = "NA") @@ -521,7 +527,7 @@ if(MethMeas == "ecse"){ wrkAttr$dlta13CCo2 <- c("mean" = "permill", "vari" = "permill", "se" = "permill", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$dlta18OH2o <- c("mean" = "permill", "vari" = "permill", "se" = "permill", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$dlta2HH2o <- c("mean" = "permill", "vari" = "permill", "se" = "permill", "timeBgn" = "NA", "timeEnd" = "NA") - + #define output unit attributes #dp01 outAttr$frt00 <- c("mean" = "dm3 min-1", "vari" = "dm3 min-1", "se" = "dm3 min-1", "timeBgn" = "NA", "timeEnd" = "NA") @@ -542,13 +548,14 @@ if(MethMeas == "ecse"){ outAttr$dlta13CCo2 <- c("mean" = "permill", "vari" = "permill", "se" = "permill", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$dlta18OH2o <- c("mean" = "permill", "vari" = "permill", "se" = "permill", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$dlta2HH2o <- c("mean" = "permill", "vari" = "permill", "se" = "permill", "timeBgn" = "NA", "timeEnd" = "NA") - + #performing dp01 ucrt unit conversion - print(paste0(format(Sys.time(), "%F %T"), ": dataset ", Date, ": performing dp01 ucrt unit conversion")) + msg <- paste0("dataset ", Date, ": performing dp01 ucrt unit conversion") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) #transfer units for(idxDp in base::names(rpt$dp01$ucrt)) { #idxDp <- base::names(rpt$dp01$ucrt)[1] - + for(idxLvl in base::names(rpt$dp01$ucrt[[idxDp]])){ #idxLvl <- base::names(rpt$dp01$ucrt[[idxDp]])[1] for(idxVar in base::names(rpt$dp01$ucrt[[idxDp]][[idxLvl]])){ @@ -563,8 +570,8 @@ if(MethMeas == "ecse"){ unitFrom = attributes(rpt$dp01$ucrt[[idxDp]][[idxLvl]][[idxVar]])$unit, unitTo = outAttr[[idxVar]], MethGc = FALSE)) - - + + #calculate variance rpt$dp01$ucrt[[idxDp]][[idxLvl]][[idxVar]]$vari <- (rpt$dp01$ucrt[[idxDp]][[idxLvl]][[idxVar]]$vari)^2 #format time @@ -575,10 +582,10 @@ if(MethMeas == "ecse"){ attributes(rpt$dp01$ucrt[[idxDp]][[idxLvl]][[idxVar]])$unit #apply variance units base::try(attributes(rpt$dp01$ucrt[[idxDp]][[idxLvl]][[idxVar]])$unit[names(attributes(rpt$dp01$ucrt[[idxDp]][[idxLvl]][[idxVar]])$unit) == "vari"] <- outAttr$vari[[idxVar]], silent = TRUE) - + } } - base::gc(verbose=FALSE) # clean up memory + base::gc(verbose=FALSE) # clean up memory }; rm(idxVar) }#end of ucrt }#End of ecse diff --git a/pack/eddy4R.qaqc/DESCRIPTION b/pack/eddy4R.qaqc/DESCRIPTION index 2d945427..76d2dbf1 100644 --- a/pack/eddy4R.qaqc/DESCRIPTION +++ b/pack/eddy4R.qaqc/DESCRIPTION @@ -18,6 +18,8 @@ Imports: plyr (>= 1.8.4), reshape2 (>= 1.4.2), Rmisc (>= 1.5) +Suggests: + NEONprocIS.base License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 LazyData: true RoxygenNote: 6.1.1 diff --git a/pack/eddy4R.qaqc/R/def.dspk.br86.R b/pack/eddy4R.qaqc/R/def.dspk.br86.R index cde464ac..a47a8df3 100644 --- a/pack/eddy4R.qaqc/R/def.dspk.br86.R +++ b/pack/eddy4R.qaqc/R/def.dspk.br86.R @@ -1,7 +1,7 @@ ############################################################################################## #' @title Definition function: Median filter de-spiking -#' @author +#' @author #' Stefan Metzger \email{eddy4R.info@gmail.com} \cr #' Cove Sturtevant \email{eddy4R.info@gmail.com} @@ -37,27 +37,27 @@ #' @return \code{numBinFinl} Integer. The final number of histogram bins used. #' @return \code{numSpk} Integer. The number of spikes identified. #' @return \code{dataOut} Numeric vector of input data with spikes removed. -#' @return \code{dataNorm} Numeric vector of input data normalized to mean 0 and standard deviation of 1 -#' @return \code{dataNormDiff} Numeric vector of differences between subsequent values of \code{dataNorm}. Length = 1-length(dataInp) -#' @return \code{resoDataNorm} Numeric value. Measurement resolution (assumed to be smallest recorded change in \code{dataNorm}) -#' @return \code{thshNumData} Numeric value. Minimum number of non-NAs in window to calculate median, otherwise NA is returned. -#' @return \code{dataNormFiltMed} Numeric vector. Median-filtered timeseries of \code{dataNorm}. -#' @return \code{histDiff} Numeric vector. Initial histogram of differences of \code{dataNormFiltMed} -#' @return \code{crit} Logical. Criteria for ending iteration over histogram bins -#' @return \code{locBin} Numeric vector. Bin edges for \code{histDiff} -#' @return \code{histDiffFinl} Numeric vector. Final histogram of differences of \code{dataNormFiltMed} using bin edges in \code{locBin} -#' @return \code{histDiffFinl$counts} Integer vector. Counts within each bin of \code{histDiffFinl} -#' @return \code{histDiffFinl$breaks} Numeric vector. Bin edges for \code{histDiffFinl} -#' @return \code{idxBinMin} Integer. Index of histogram bin within \code{histDiffFinl} with minimum number of counts. -#' @return \code{idxBinMax} Integer. Index of histogram bin within \code{histDiffFinl} with maximum number of counts. -#' @return \code{idxThshBinMin} Integer. Current iteration of minimum threshold index of histogram bin within \code{histDiffFinl} for spike determination -#' @return \code{idxThshBinMax} Integer. Current iteration of maximum threshold index of histogram bin within \code{histDiffFinl} for spike determination -#' @return \code{idxThshBinMinFinl} Integer. Final minimum threshold index of histogram bin within \code{histDiffFinl} for spike determination -#' @return \code{idxThshBinMaxFinl} Integer. Final maximum threshold index of histogram bin within \code{histDiffFinl} for spike determination +#' @return \code{dataNorm} Numeric vector of input data normalized to mean 0 and standard deviation of 1 +#' @return \code{dataNormDiff} Numeric vector of differences between subsequent values of \code{dataNorm}. Length = 1-length(dataInp) +#' @return \code{resoDataNorm} Numeric value. Measurement resolution (assumed to be smallest recorded change in \code{dataNorm}) +#' @return \code{thshNumData} Numeric value. Minimum number of non-NAs in window to calculate median, otherwise NA is returned. +#' @return \code{dataNormFiltMed} Numeric vector. Median-filtered timeseries of \code{dataNorm}. +#' @return \code{histDiff} Numeric vector. Initial histogram of differences of \code{dataNormFiltMed} +#' @return \code{crit} Logical. Criteria for ending iteration over histogram bins +#' @return \code{locBin} Numeric vector. Bin edges for \code{histDiff} +#' @return \code{histDiffFinl} Numeric vector. Final histogram of differences of \code{dataNormFiltMed} using bin edges in \code{locBin} +#' @return \code{histDiffFinl$counts} Integer vector. Counts within each bin of \code{histDiffFinl} +#' @return \code{histDiffFinl$breaks} Numeric vector. Bin edges for \code{histDiffFinl} +#' @return \code{idxBinMin} Integer. Index of histogram bin within \code{histDiffFinl} with minimum number of counts. +#' @return \code{idxBinMax} Integer. Index of histogram bin within \code{histDiffFinl} with maximum number of counts. +#' @return \code{idxThshBinMin} Integer. Current iteration of minimum threshold index of histogram bin within \code{histDiffFinl} for spike determination +#' @return \code{idxThshBinMax} Integer. Current iteration of maximum threshold index of histogram bin within \code{histDiffFinl} for spike determination +#' @return \code{idxThshBinMinFinl} Integer. Final minimum threshold index of histogram bin within \code{histDiffFinl} for spike determination +#' @return \code{idxThshBinMaxFinl} Integer. Final maximum threshold index of histogram bin within \code{histDiffFinl} for spike determination #' @return \code{setSpk} Indices of determined spikes within \code{dataInp} #' @return \code{qfSpk} Integer. Quality flag values [-1,0,1] for despike test, matching same size as \code{dataInp} -#' -#' +#' +#' #' @references #' License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007. \cr #' Brock, F. V. A Nonlinear Filter to Remove Impulse Noise from Meteorological Data. J. Atmos. Oceanic Technol. 3, 51-58 (1986). \cr @@ -74,7 +74,7 @@ #' @seealso Currently none #' @export -#' +#' # changelog and author contributions / copyrights # Stefan Metzger (2014-11-14) # original creation @@ -101,54 +101,54 @@ def.dspk.br86 <- function( ThshReso = 10, # resolution threshold for spike determination FracRealMin = 0.025 # minimum fraction of non-NA values ) { - + # Initialize output rpt <- base::list(dataInp=dataInp,WndwFilt=WndwFilt,NumBin=NumBin,ThshReso=ThshReso,FracRealMin=FracRealMin) - - #Error catching 1: + + #Error catching 1: #fewer non-NAs in dataset than required for 0.5 h out of 24 h of data (default 2.5%) if(base::length(base::which(!base::is.na(rpt$dataInp)))/base::length(rpt$dataInp) < rpt$FracRealMin) { ### - - + + rpt$numBinFinl <- -1 # Set to error code rpt$numSpk <- -1 # Set to error code - rpt$dataOut <- rpt$dataInp - - - + rpt$dataOut <- rpt$dataInp + + + ### #mid error catching 1 #no non-NAs in dataset } else { ### - - + + #normalizing time-series to mean = 0 and sd = 1 - rpt$dataNorm <- (rpt$dataInp - base::mean(rpt$dataInp, na.rm=TRUE)) / stats::sd(rpt$dataInp, na.rm=TRUE) + rpt$dataNorm <- (rpt$dataInp - base::mean(rpt$dataInp, na.rm=TRUE)) / stats::sd(rpt$dataInp, na.rm=TRUE) #determine differences rpt$dataNormDiff <- base::diff(rpt$dataNorm) - - - + + + ### - #Error catching 2: + #Error catching 2: #(i) singular or constant value, or (ii) no consecutive values. #in (i) the first case sd(rpt$dataInp) will return NA, and so rpt$dataNorm will be all NAs #in (ii) all differences are NA if(base::length(base::which(!base::is.na(rpt$dataNormDiff))) == 0) { ### - - - + + + rpt$numBinFinl <- -2 # Set to error code rpt$numSpk <- -2 # Set to error code - rpt$dataOut <- rpt$dataInp - - - + rpt$dataOut <- rpt$dataInp + + + ### #mid intercept 2 #singular or constant value @@ -156,58 +156,60 @@ def.dspk.br86 <- function( ### - + #determine measurement resolution (assumed to be smallest recorded change in data series) rpt$resoDataNorm <- base::min(base::abs(rpt$dataNormDiff[base::which(rpt$dataNormDiff != 0)]), na.rm=TRUE) # plot(rpt$dataInp[1:100], type="l") # min(diff(rpt$dataInp[1:100]), na.rm=TRUE) - + #apply median filter and calculate differences #minimum number of non-NAs in window to calculate median, else return NA rpt$thshNumData <- base::max(c(5, base::floor(1/2 * rpt$WndwFilt))) #calculating median-filtered time-series + base::sink("/dev/null", type = "output") rpt$dataNormFiltMed <- robfilter::med.filter(y=rpt$dataNorm, width=rpt$WndwFilt, minNonNAs=rpt$thshNumData, online=FALSE, extrapolate=FALSE) - + base::sink(type = "output") + #intercept if robfilter returns NA - + if(base::length(rpt$dataNormFiltMed) == 1) { - + rpt$histDiff <- base::rep(0, base::length(rpt$dataInp)) - + } else { - + #calculating histogram of differences rpt$histDiff <- rpt$dataNormFiltMed$y - rpt$dataNormFiltMed$level[,1] - + } - - + + ### - #Error catching 3: + #Error catching 3: #measurement changes so slow that time-series and filter value are identical - #Or: less non-NAs in differences than required for 0.5 h out of 24 h of data (approx 2.5%) + #Or: less non-NAs in differences than required for 0.5 h out of 24 h of data (approx 2.5%) if(base::max(rpt$histDiff, na.rm=TRUE) == 0 | base::length(base::which(!base::is.na(rpt$histDiff)))/base::length(rpt$dataInp) < rpt$FracRealMin | base::length(stats::na.omit(base::unique(rpt$histDiff)))/base::length(rpt$dataInp) < 0.001 ) { ### - - - + + + rpt$numBinFinl <- -3 # Set to error code rpt$numSpk <- -3 # Set to error code - rpt$dataOut <- rpt$dataInp - - - + rpt$dataOut <- rpt$dataInp + + + ### #mid intercept 3 #measurement changes fast enough so that time-series and filter value are not identical } else { ### - - - + + + ### #start while loop around PDF bins rpt$crit <- FALSE @@ -215,15 +217,15 @@ def.dspk.br86 <- function( rpt$numBinFinl <- rpt$NumBin while(rpt$crit == FALSE) { ### - - - + + + #number of histogram bins #rpt$numBinFinl <- rpt$NumBin * rpt$iter + 1 rpt$locBin <- base::seq(base::min(rpt$histDiff, na.rm=TRUE), base::max(rpt$histDiff, na.rm=TRUE), length.out=rpt$numBinFinl) #calculate histogram rpt$histDiffFinl <- graphics::hist(rpt$histDiff, breaks = rpt$locBin, plot=FALSE) - + #determine bin with most values rpt$idxBinMax <- base::which.max(rpt$histDiffFinl$counts) #data needs to have extrema, otherwise it will not identify the zero crossing @@ -231,42 +233,42 @@ def.dspk.br86 <- function( rpt$idxBinMin <- EMD::extrema(y=c(rpt$histDiffFinl$counts, base::sin(1:10)))$minindex[,1] #remove sin(1:10) minima from end rpt$idxBinMin <- rpt$idxBinMin[-base::which(rpt$idxBinMin > (rpt$numBinFinl - 1))] - + #minimum threshold rpt$idxThshBinMin <- base::which(rpt$histDiffFinl$counts[rpt$idxBinMin] == 0 & rpt$idxBinMin < rpt$idxBinMax) #maximum threshold rpt$idxThshBinMax <- base::which(rpt$histDiffFinl$counts[rpt$idxBinMin] == 0 & rpt$idxBinMin > rpt$idxBinMax) - + # #message to screen # print(paste("PDF with ", rpt$numBinFinl, " bins is completed", sep="")) - + #conditional statement for while loop #continue iterating if no bins with zero entries are found below AND above distribution maximum, else calculate thresholds if(base::length(rpt$idxThshBinMin) == 0 | length(rpt$idxThshBinMax) == 0) { - + #rpt$iter <- rpt$iter + 1 rpt$numBinFinl <- 2 * rpt$numBinFinl - + } else { - + #final minimum threshold, i.e. lower break of closest bin with zero observations below distribution maximum rpt$idxThshBinMinFinl <- rpt$histDiffFinl$breaks[rpt$idxBinMin[rpt$idxThshBinMin][base::length(rpt$idxThshBinMin)]] #final maximum threshold, i.e. upper break of closest bin with zero observations above distribution maximum rpt$idxThshBinMaxFinl <- rpt$histDiffFinl$breaks[rpt$idxBinMin[rpt$idxThshBinMax][1] + 1] - + rpt$crit <- TRUE - + } - - - + + + ### } #end while loop around PDF bins ### - - - + + + #determine indices of spikes #considers spikes only if difference larger than measurement resolution x rpt$ThshReso rpt$setSpk <- base::which( @@ -274,44 +276,45 @@ def.dspk.br86 <- function( rpt$histDiff > rpt$idxThshBinMaxFinl & base::abs(rpt$histDiff) > rpt$resoDataNorm * rpt$ThshReso ) rpt$numSpk <- base::length(rpt$setSpk) # Number of spikes found - + #remove spikes rpt$dataOut <- rpt$dataInp if(rpt$numSpk > 0) rpt$dataOut[rpt$setSpk] <- NA - - + + ### } #end intercept 3 #measurement changes fast enough so that time-series and filter value are not identical ### - - - + + + ### } #end intercept 2 #singular or constant value ### - - + + ### } #end intercept 1 #no non-NAs in dataset ### - + # Create vector of quality flag values [-1,0,1] rpt$qfSpk <- dataInp # initialize size of output rpt$qfSpk[] <- 0 # start with all flags not raised rpt$qfSpk[base::is.na(rpt$dataInp)] <- -1 # 'could not evaluate' flag for original NA values rpt$qfSpk[rpt$setSpk] <- 1 # raise flag for determined spikes - + # #print message to screen # print(paste("De-spiking completed, ", rpt$numSpk, " spikes have been removed", sep="")) + #return des-spiked time-series and all additional info return(rpt) diff --git a/pack/eddy4R.qaqc/R/def.dspk.wndw.R b/pack/eddy4R.qaqc/R/def.dspk.wndw.R index e8e7f5f7..ceb04be0 100644 --- a/pack/eddy4R.qaqc/R/def.dspk.wndw.R +++ b/pack/eddy4R.qaqc/R/def.dspk.wndw.R @@ -1,11 +1,11 @@ ############################################################################################## #' @title Definition function: Determine spike locations using window-based statistics -#' @author +#' @author #' Stefan Metzger \email{eddy4R.info@gmail.com} \cr #' Cove Sturtevant \email{eddy4R.info@gmail.com} -#' @description +#' @description #' Function definition. Determines spike locations based on window-based Gaussian statistics (arithmetic mean and standard deviation) and distribution statistics (median, median absolute deviation). #' @param data Required input. A data frame or matrix containing the data to be evaluated. @@ -24,7 +24,7 @@ #' \code{Prnt}: Logical. print results? \cr #' \code{Plot}: Logical. plot results? #' @param Vrbs Optional. Option to output the quality flags (same size as \code{data}) rather than vector positions of failed and na values. Default = FALSE - + #' @return A list of the following: \cr #' \code{data}: the despiked data matrix \cr #' \code{smmy}: a summary of the despike algorithm results, including iterations (\code{iter}), determined spikes (\code{news}), and total resultant NAs (\code{alls}) \cr @@ -59,15 +59,15 @@ # adjusted naming throughout to conform to EC TES coding convention, and added documentation # Cove Sturtevant (2016-01-08) # changed output vector of spike locations to be a list of failed and na (unable to eval) locations -# also added an input parameter NaFracMax specifying the maximum proportion of NA values in a window -# for reliable spike estimation. +# also added an input parameter NaFracMax specifying the maximum proportion of NA values in a window +# for reliable spike estimation. # Cove Sturtevant (2016-02-09) # added loading of required library eddy4R.base # Cove Sturtevant (2016-11-9) -# added verbose option for reporting quality flag values [-1,0,1] as opposed to vector positions +# added verbose option for reporting quality flag values [-1,0,1] as opposed to vector positions # of failed and na values -# adjusted output of vector positions of failed and na spike positions (Vrbs = FALSE) to be nested -# under each variable rather than each variable nested under the lists of failed and na results +# adjusted output of vector positions of failed and na spike positions (Vrbs = FALSE) to be nested +# under each variable rather than each variable nested under the lists of failed and na results # Natchaya P-Durden (2018-04-03) # update @param format # Natchaya P-Durden (2018-04-04) @@ -104,15 +104,15 @@ def.dspk.wndw <- function ( if (!require(eddy4R.base)) { stop("Please install package 'eddy4R.base' before continuing") } - + #data always as matrix mat <- as.matrix(data) numVar <- base::ncol(mat) - + # Initialize output of actual flag values when using verbose option if(Vrbs){ qfSpk <- data - qfSpk[] <- 0 + qfSpk[] <- 0 } @@ -123,34 +123,34 @@ def.dspk.wndw <- function ( for(idxVar in 1:numVar) { #idxVar<-1 trns <- mat[,idxVar] - + # initialize fail and na spike positions for this variable setSpk[[idxVar]] <- list(setQfSpk=list(fail=numeric(0),na=numeric(0))) - + # Store na positions as "unable to evaluate" spikes setSpk[[idxVar]]$setQfSpk$na <- which(is.na(trns)) - + if(Trt$NaTrt == "approx") { trns <- approx(x=index(trns), y=trns, xout=index(trns))$y } - + setNa <- which(is.na(trns)) iter <- 0 setSpkPrlm <- integer(0) ### - - + + ### #start loop around window sizes for(idxNumPtsWndw in 1:length(Trt$NumPtsWndw)) { #idxNumPtsWndw<-1 numPtsWndw <- Trt$NumPtsWndw[idxNumPtsWndw] numSpkNew <- 1 - - + + while(numSpkNew != 0) { iter <- iter + 1 - + #apply spike detection over windows if(Trt$AlgClas == "mean") { #mean and sd (> 1 s per 1e4 entries) @@ -162,7 +162,7 @@ def.dspk.wndw <- function ( } #scale (spread of data) sprdRoll <- zoo::rollapply(data=zoo::zoo(trns), width=numPtsWndw, FUN=sd, by=Trt$NumPtsSlid, na.rm=TRUE, fill = NA) - + } else { #median and mad (> 2 s per 1e4 entries) #location @@ -174,41 +174,41 @@ def.dspk.wndw <- function ( #scale sprdRoll <- zoo::rollapply(data=zoo::zoo(trns), width=numPtsWndw, FUN=mad, by=Trt$NumPtsSlid, na.rm=TRUE, fill = NA) * (numPtsWndw / (numPtsWndw - 0.8)) } - + # Find windows where there were not enough data points to reliably compute statistics naFracRoll <- zoo::rollapply(data=zoo::zoo(trns),width=numPtsWndw,FUN=function(Var){length(which(is.na(Var)))/length(Var)},by=Trt$NumPtsSlid, fill = NA) setNaSpkNew <- which(naFracRoll > Trt$NaFracMax) - + #calculate and match criteria crit <- abs((trns - cntrRoll) / sprdRoll) setSpkNew <- which(crit > (Trt$ThshStd * (1 + (iter - 1) * Trt$Infl))) setNaSpkNew <- intersect(setSpkNew,setNaSpkNew) # record spike positions in which there were too many NAs in the window setSpkNew <- setdiff(setSpkNew,setNaSpkNew) # remove unreliable spikes numSpkNew <- length(setSpkNew) - + #replicate cntrRoll and sprdRoll for untreated indices if sliding increment > 1 if(Trt$NumPtsSlid > 1) { - + setUntr <- which(!is.na(cntrRoll)) setUntrBgn <- sapply(setUntr, function(valu) valu - (Trt$NumPtsWndw/2 - 1)) setUntrEnd <- sapply(setUntr, function(valu) valu + (Trt$NumPtsWndw/2)) - + #assign local variables cntrRollLocl <- cntrRoll sprdRollLocl <- sprdRoll naFracRollLocl <- naFracRoll - + #forward #assignment for(idxUntr in 1:length(setUntr)){ #idxUntr <- 1 - + cntrRollLocl[setUntrBgn[idxUntr]:setUntrEnd[idxUntr]] <- cntrRoll[setUntr[idxUntr]] sprdRollLocl[setUntrBgn[idxUntr]:setUntrEnd[idxUntr]] <- sprdRoll[setUntr[idxUntr]] naFracRollLocl[setUntrBgn[idxUntr]:setUntrEnd[idxUntr]] <- naFracRoll[setUntr[idxUntr]] - + }; rm(idxUntr) - + #calculate and match criteria crit <- abs((trns - cntrRollLocl) / sprdRollLocl) setNaSpkNewFwd <- which(naFracRollLocl > Trt$NaFracMax) @@ -221,13 +221,13 @@ def.dspk.wndw <- function ( #assignment for(idxUntr in length(setUntr):1){ #idxUntr <- 1 - + cntrRollLocl[setUntrBgn[idxUntr]:setUntrEnd[idxUntr]] <- cntrRoll[setUntr[idxUntr]] sprdRollLocl[setUntrBgn[idxUntr]:setUntrEnd[idxUntr]] <- sprdRoll[setUntr[idxUntr]] naFracRollLocl[setUntrBgn[idxUntr]:setUntrEnd[idxUntr]] <- naFracRoll[setUntr[idxUntr]] - + }; rm(idxUntr) - + #calculate and match criteria crit <- abs((trns - cntrRollLocl) / sprdRollLocl) setNaSpkNewBwd <- which(naFracRollLocl > Trt$NaFracMax) @@ -235,76 +235,77 @@ def.dspk.wndw <- function ( setSpkNewBwd <- which(crit > (Trt$ThshStd * (1 + (iter - 1) * Trt$Infl))) setNaSpkNewBwd <- intersect(setSpkNewBwd,setNaSpkNewBwd) # record spike positions in which there were too many NAs in the window setSpkNewBwd <- setdiff(setSpkNewBwd,setNaSpkNewBwd) # remove unreliable spikes - - + + #combine results setSpkNew <- unique(c(setSpkNewFwd, setSpkNewBwd)) setNaSpkNew <- unique(c(setNaSpkNewFwd, setNaSpkNewBwd)) numSpkNew <- length(setSpkNew) - + #clean up rm(setUntrEnd, cntrRollLocl, setUntr, sprdRollLocl, setUntrBgn, setSpkNewFwd, setSpkNewBwd) - + } - - + + #remove spikes and store results if(numSpkNew > 0) { - + #remove spikes trns[setSpkNew] <- NA - + #store results if(iter == 1) { - + setSpkPrlm <- setSpkNew - + } else { - + setSpkPrlm <- base:::sort(unique(c(setSpkPrlm, setSpkNew))) - + } setSpk[[idxVar]]$setQfSpk$na <- base:::sort(unique(c(setSpk[[idxVar]]$setQfSpk$na,setNaSpkNew))) - + } - + #plotting if(Cntl$Plot == TRUE) { par(mar=c(1,1,1,1)) plot(log10(crit), type="p", ylim=c(-10,10), main=paste(dimnames(mat)[[2]][idxVar], ", step ", iter, ", window ", numPtsWndw, sep="")) abline(h=log10(Trt$ThshStd * (1 + (iter - 1) * Trt$Infl))) } - + #how many iterations do we need? if(Cntl$Prnt == TRUE) { - print(paste("Variable ", idxVar, " of ", numVar, ", iteration ", iter, " is finished. ", - numSpkNew, " new spikes, totally ", length(setSpkPrlm), " spikes.", sep="")) + msg <- paste("Variable ", idxVar, " of ", numVar, ", iteration ", iter, " is finished. ", + numSpkNew, " new spikes, totally ", length(setSpkPrlm), " spikes.", sep="") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) } - + #break if maximum number of iterations is reached - if(iter == Trt$IterMax) break - + if(iter == Trt$IterMax) break + #linearly interpolate values if(Trt$NaTrt == "approx") trns <- approx(x=index(trns), y=trns, xout=index(trns))$y - - + + } - - + + ### } #end loop around window sizes ### - - + + # #where have we found spikes # setSpkPrlm <- which(is.na(trns)) # if(length(setNa) > 0 & length(setSpkPrlm) > 0) { # whr_n <- sapply(1:length(setNa), function(valu) which(setSpkPrlm == setNa[valu])) # setSpkPrlm <- setSpkPrlm[-whr_n] # } - - + + #which of them are neighboring? if(is.logical(Trt$NumPtsGrp[1]) & Trt$NumPtsGrp[1] == FALSE) { #omit group considerations? @@ -334,7 +335,7 @@ def.dspk.wndw <- function ( setSpkVar <- integer(0) } } - + #store result setSpk[[idxVar]]$setQfSpk$fail <- setSpkVar mat[setSpkVar,idxVar] <- NA @@ -345,33 +346,34 @@ def.dspk.wndw <- function ( } else { smmyOut <- cbind(smmyOut, smmyOutVar) } - + #how many iterations do we need? if(Cntl$Prnt == TRUE) { - print(paste("Variable ", idxVar, " of ", numVar, " (", dimnames(mat)[[2]][idxVar], ") is finished after ", smmyOut[1,idxVar], " iteration(s). ", - smmyOut[2,idxVar], " spike(s) were detected, totally ", smmyOut[3,idxVar], " NAs.", sep="")) + msg <- paste("Variable ", idxVar, " of ", numVar, " (", dimnames(mat)[[2]][idxVar], ") is finished after ", smmyOut[1,idxVar], " iteration(s). ", + smmyOut[2,idxVar], " spike(s) were detected, totally ", smmyOut[3,idxVar], " NAs.", sep="") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) } - + # For Verbose option, output actual flag values if(Vrbs) { qfSpk[[idxVar]][setSpk[[idxVar]]$setQfSpk$na] <- -1 # flag na values qfSpk[[idxVar]][setSpkVar] <- 1 # flag failed values - } - + } + ### } #end loop around data columns dimnames(smmyOut)[[2]] <- dimnames(mat)[[2]] ### - - + + #make sure that there's no NAs in first and last row of all columns (for interpolation) if(Cntl$NaOmit == TRUE) { allVAL <- which(sapply(1:nrow(mat), function(x) all(!is.na(mat[x,]))) == TRUE) mat <- mat[(allVAL[1]:allVAL[length(allVAL)]),] } - - + + #return results # For Verbose option, output actual flag values, otherwise output vector positions of failed and na values if(Vrbs) { @@ -387,7 +389,7 @@ def.dspk.wndw <- function ( setSpk=setSpk ) } - + return(rpt) - + } From 21f3abc4d514b4bfbac2112e462b4849d3117a4c Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 22 Nov 2019 05:52:27 +0000 Subject: [PATCH 003/168] - updating dependency --- pack/eddy4R.base/DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack/eddy4R.base/DESCRIPTION b/pack/eddy4R.base/DESCRIPTION index 1aea1439..bfbde41a 100644 --- a/pack/eddy4R.base/DESCRIPTION +++ b/pack/eddy4R.base/DESCRIPTION @@ -20,7 +20,7 @@ Imports: ffbase (>= 0.12.3), polynom (>= 1.3-9), rhdf5 (>= 2.20.0), - robfilter (== 4.1), + robfilter (== 4.1.1), signal (>= 0.7-6), zoo (>= 1.8-1), neonUtilities (>= 1.3.1) From c346d1fc60726dc6f853f0ef538f82ca2323ff7e Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 22 Nov 2019 20:06:58 +0000 Subject: [PATCH 004/168] - temporary fix for robfilter changing version specification --- pack/eddy4R.base/DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack/eddy4R.base/DESCRIPTION b/pack/eddy4R.base/DESCRIPTION index bfbde41a..5330ba57 100644 --- a/pack/eddy4R.base/DESCRIPTION +++ b/pack/eddy4R.base/DESCRIPTION @@ -20,7 +20,7 @@ Imports: ffbase (>= 0.12.3), polynom (>= 1.3-9), rhdf5 (>= 2.20.0), - robfilter (== 4.1.1), + robfilter (>=4.1.1), signal (>= 0.7-6), zoo (>= 1.8-1), neonUtilities (>= 1.3.1) From c6c9f5fe32783497e7242705fb5da2da87a14829 Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 22 Nov 2019 21:17:06 +0000 Subject: [PATCH 005/168] - fixing operator format for version --- pack/eddy4R.base/DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack/eddy4R.base/DESCRIPTION b/pack/eddy4R.base/DESCRIPTION index 5330ba57..a09c94b2 100644 --- a/pack/eddy4R.base/DESCRIPTION +++ b/pack/eddy4R.base/DESCRIPTION @@ -20,7 +20,7 @@ Imports: ffbase (>= 0.12.3), polynom (>= 1.3-9), rhdf5 (>= 2.20.0), - robfilter (>=4.1.1), + robfilter (>= 4.1.1), signal (>= 0.7-6), zoo (>= 1.8-1), neonUtilities (>= 1.3.1) From 02a807e6ddee359d7b394a62e8c833b14b617c74 Mon Sep 17 00:00:00 2001 From: ddurden Date: Wed, 27 Nov 2019 04:24:11 +0000 Subject: [PATCH 006/168] - Updating eddy4R Dockerfile to match eddy4R-deve --- Dockerfile | 106 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 33 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6f5b064d..cf4abaa9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,41 +1,81 @@ # start with the ropensci image including debian:testing, r-base, rocker/rstudio, rocker/hadleyverse # https://hub.docker.com/r/rocker/ropensci/ -FROM rocker/ropensci:latest +FROM rocker/rstudio:3.5.2 -# maintainer handle -MAINTAINER "Stefan Metzger" eddy4R.info@gmail.com +WORKDIR /home/eddy/eddy4R +# copy clone of GitHub source repo "NEONScience/NEON-FIU-algorithm" to the Docker image +COPY . . -# install OS-side dependencies +# Build R dependencies using two cpu's worth of resources +ENV MAKEFLAGS='-j3' - # update the list of available packages and their versions - RUN apt-get update +# install OS-side dependencies: EBImage -> fftwtools -> fftw3, REddyProc -> RNetCDF -> udunits - # install dependencies - RUN apt-get install -y \ - # EBImage - fftw3 \ - fftw3-dev \ - libjpeg-dev \ - libtiff-dev \ - # REddyProc - libudunits2-0 \ - libudunits2-dev \ - libnetcdf-dev \ - udunits-bin + # update the list of available packages and their versions + # required starting 2016-11-16T07:53:52Z when rocker/ropensci changed FROM rocker/hadleyverse to FROM rocker/verse + RUN apt-get update \ + && apt-get dist-upgrade -y \ + && RUNDEPS="fftw3 \ + libudunits2-0 \ + udunits-bin \ + hdf5-helpers \ + libhdf5-cpp-100 \ + libnetcdf11 \ + libhdf5-100 \ + libsz2 \ + libmysql++3v5 \ + libmariadbclient18 \ + libpng-tools \ + libproj-dev \ + libssl-dev \ + # Library for git via ssh key + ssh \ + libxml2-dev \ + mysql-common" \ +# libtiff5 \ +# libjpeg62-turbo \ +# libnetcdf11 \ +# libpng16-16 \ +# libhdf5-100 \ +# libhdf5-cpp-100 + && BUILDDEPS="fftw3-dev \ + libudunits2-dev \ + libjpeg-dev \ + libtiff5-dev \ + libnetcdf-dev \ + libpng-dev \ + libhdf5-dev \ + libmysql++-dev \ + " \ + && apt-get install -y $BUILDDEPS $RUNDEPS \ + # create folder for dependencies of eddy4R packages + # create directory + && mkdir -p /home/eddy/depe \ + # provide read, write and executable access to web-hosted installation script + # 777 is just wrong, shouldn't this be a chown? + && chmod -R 777 /home/eddy/depe \ + # eddy4R installation + # install eddy4R packages + # install eddy4R packages from clone + && R -e 'source("https://www.dropbox.com/s/xg8dxtmroo10qmm/flow.inst.eddy4r.R?dl=1")' \ + + # Installing R package dependencies that are only workflow related (including CI combiner) + && install2.r --error \ + Hmisc \ + parsedate \ + rowr \ + urltools \ + + # provide read and write access for default R library location to Rstudio users + # TODO: PERHAPS THIS SHOULD JUST CHOWN TO rstudio instead of setting 777 perms? And at the end of the file -sj + && chmod -R 777 /usr/local/lib/R/site-library \ + # Clean up build dependencies + && apt-get remove --purge -y $BUILDDEPS \ + && apt-get autoremove -y \ + && apt-get autoclean -y \ + && rm -rf /var/lib/apt/lists/* \ + # Clean up the rocker image leftovers + && rm -rf /tmp/rstudio* \ + && rm -rf /tmp/Rtmp* -# eddy4R-Docker example workflow and data - # create directory - RUN mkdir -p /home/eddy - - # provide read and write access to web-hosted installation script - RUN chmod -R 777 /home/eddy - -# install the eddy4R packages via web-hosted installation script -RUN R -e 'source("https://www.dropbox.com/s/xmgsctjbrekfyw8/flow.inst.eddy4r.R?dl=1")' - - # provide read and write access to Rstudio users for example workflow and data location - RUN chmod -R 777 /home/eddy - -# provide read and write access to Rstudio users for default R library location -RUN chmod -R 777 /usr/local/lib/R/site-library From 23560f6cb106c62fc185b82af841c4ffd59198d1 Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 2 Dec 2019 04:51:59 +0000 Subject: [PATCH 007/168] - adding Travis-CI build to eddy4R repo --- .travis.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..a8290ce3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +sudo: required + +language: r + +services: +- docker + +before_install: +- docker build . -t travis +- docker run -d -p 8787:8787 travis +- docker ps -a + +install: true \ No newline at end of file From f1be8292187a001db9e01557bcdb1f7178e60ed6 Mon Sep 17 00:00:00 2001 From: NDurden Date: Tue, 14 Jan 2020 21:19:54 +0000 Subject: [PATCH 008/168] added time when actual validation begin to fill NaN in correction data to get rid of spike --- pack/eddy4R.base/R/def.irga.vali.cor.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.base/R/def.irga.vali.cor.R b/pack/eddy4R.base/R/def.irga.vali.cor.R index 28d3de79..e865da2d 100644 --- a/pack/eddy4R.base/R/def.irga.vali.cor.R +++ b/pack/eddy4R.base/R/def.irga.vali.cor.R @@ -43,6 +43,8 @@ # apply ff object to dataframe to save the memory # Natchaya P-Durden (2019-03-15) # added ScalMax, FracSlpMax, and Freq into input function parameters +# Natchaya P-Durden (2020-01-14) +# added time when the real validation begin ############################################################################################## def.irga.vali.cor <- function( data, @@ -115,10 +117,11 @@ def.irga.vali.cor <- function( } #time when performing of zero gas is started - if (length(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn[which(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$gasType == "qfIrgaTurbValiGas02")]) == 0){ + if (length(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn[which(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$gasType == "qfIrgaTurbValiGas02")]) == 0 || + is.na(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$mean[which(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$gasType == "qfIrgaTurbValiGas02")])){ timeEnd <- as.POSIXlt(paste(dateEnd[idx], " ", "", sep="00:00:00.000"), format="%Y-%m-%d %H:%M:%OS", tz="UTC") } else { - timeEnd <- as.POSIXlt(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn[which(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$gasType == "qfIrgaTurbValiGas02")]) + timeEnd <- as.POSIXlt(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn[which(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$gasType == "qfIrgaTurbValiGas02")]-(60*3.5)) } #output time From 8607a714a4de679414eee2279ed78f07a703dd0e Mon Sep 17 00:00:00 2001 From: NDurden Date: Wed, 15 Jan 2020 17:11:21 +0000 Subject: [PATCH 009/168] reporting the rtioMoleDryH2oVali table --- pack/eddy4R.base/R/wrap.irga.vali.R | 106 ++++++++++++++--------- pack/eddy4R.qaqc/man/def.qf.irga.vali.Rd | 7 +- 2 files changed, 69 insertions(+), 44 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index 4fbe4980..27d29966 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -71,6 +71,8 @@ # Natchaya P-Durden (2019-05-09) # updating logic in fail-safe to fill in dataframe with NaN when there is only archive gas or no validation at all # bug fix on selecting the validation gas based on timeCrit +# Natchaya P-Durden (2020-01-15) +# reporting the rtioMoleDryH2oVali table ############################################################################################## wrap.irga.vali <- function( @@ -156,11 +158,12 @@ wrap.irga.vali <- function( #statistical names (will be used when no validation occured at all) NameStat <- c("mean", "min", "max", "vari", "numSamp", "se") - - #assign list - tmp <- list() - rptTmp <- list() - + + #for each loop of rtioMoleDryCo2 and rtioMoleDryH2o + for (idxVar in c("rtioMoleDryCo2", "rtioMoleDryH2o")) { + #assign list + tmp <- list() + rptTmp <- list() #calculate statistical for each gas for (idxNameQf in nameQf){ #idxNameQf <- nameQf[2] @@ -181,25 +184,31 @@ wrap.irga.vali <- function( for (idxAgr in 1:length(idxVali$timeBgn)){ #idxAgr <- 1 - inpTmp <- data.frame(rtioMoleDryCo2 = allSubData$rtioMoleDryCo2[idxVali$idxBgn[idxAgr]:idxVali$idxEnd[idxAgr]]) - + inpTmp <- data.frame(idxVar = allSubData[[idxVar]][idxVali$idxBgn[idxAgr]:idxVali$idxEnd[idxAgr]]) + colnames(inpTmp) <- idxVar + #statistical processing tmp[[idxNameQf]][[idxAgr]] <- eddy4R.base::wrap.dp01(data = inpTmp) #report data rptTmp[[idxNameQf]][[idxAgr]] <- tmp[[idxNameQf]][[idxAgr]] #report time - rptTmp[[idxNameQf]][[idxAgr]]$timeBgn <- data.frame(rtioMoleDryCo2 = idxVali$timeBgn[[idxAgr]]) - rptTmp[[idxNameQf]][[idxAgr]]$timeEnd <- data.frame(rtioMoleDryCo2 = idxVali$timeEnd[[idxAgr]]) + rptTmp[[idxNameQf]][[idxAgr]]$timeBgn <- data.frame(idxVar = idxVali$timeBgn[[idxAgr]]) + rptTmp[[idxNameQf]][[idxAgr]]$timeEnd <- data.frame(idxVar = idxVali$timeEnd[[idxAgr]]) + colnames(rptTmp[[idxNameQf]][[idxAgr]]$timeBgn) <- idxVar + colnames(rptTmp[[idxNameQf]][[idxAgr]]$timeEnd) <- idxVar }#end for each idxAgr #end for at least there is one measurement } else {#if there is no measurement for(idxStat in NameStat){ #report data - rptTmp[[idxNameQf]][[1]][[idxStat]] <- data.frame(rtioMoleDryCo2 = NaN) + rptTmp[[idxNameQf]][[1]][[idxStat]] <- data.frame(idxVar = NaN) + colnames(rptTmp[[idxNameQf]][[1]][[idxStat]]) <- idxVar }#end idxStat #report time - rptTmp[[idxNameQf]][[1]]$timeBgn <- data.frame(rtioMoleDryCo2 = base::as.POSIXlt(paste(DateBgn, " ", "00:00:00.000", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC")) - rptTmp[[idxNameQf]][[1]]$timeEnd <- data.frame(rtioMoleDryCo2 = base::as.POSIXlt(paste(DateBgn, " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC")) + rptTmp[[idxNameQf]][[1]]$timeBgn <- data.frame(idxVar = base::as.POSIXlt(paste(DateBgn, " ", "00:00:00.000", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC")) + rptTmp[[idxNameQf]][[1]]$timeEnd <- data.frame(idxVar = base::as.POSIXlt(paste(DateBgn, " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC")) + colnames(rptTmp[[idxNameQf]][[1]]$timeBgn) <- idxVar + colnames(rptTmp[[idxNameQf]][[1]]$timeEnd) <- idxVar } }#end of each qf in nameQf @@ -215,7 +224,7 @@ wrap.irga.vali <- function( for (idxLoc in 1:length(rptTmp[[idxGas]])){ for (idxStat in names(rptTmp[[idxGas]][[idxLoc]])){ #idxStat <- names(rptTmp[[idxGas]][[idxLoc]])[1] - outTmp00[[idxStat]] <- data.frame(rptTmp[[idxGas]][[idxLoc]][[idxStat]]$rtioMoleDryCo2) + outTmp00[[idxStat]] <- data.frame(rptTmp[[idxGas]][[idxLoc]][[idxStat]][[idxVar]]) } outTmp01[[idxLoc]] <- do.call(cbind, outTmp00) } @@ -229,13 +238,14 @@ wrap.irga.vali <- function( } #combine row and save statistical outputs into rpt[[idxDate]]$rtioMoleDryCo2Vali - rpt[[idxDate]]$rtioMoleDryCo2Vali <- do.call(rbind, outTmp02) + valiTmp <- paste0(idxVar,"Vali") + rpt[[idxDate]][[valiTmp]] <- do.call(rbind, outTmp02) #assign column names - colnames(rpt[[idxDate]]$rtioMoleDryCo2Vali) <- c("mean", "min", "max", "vari", "numSamp", "se", "timeBgn", "timeEnd", "gasType") + colnames(rpt[[idxDate]][[valiTmp]]) <- c("mean", "min", "max", "vari", "numSamp", "se", "timeBgn", "timeEnd", "gasType") #remove row names - rownames(rpt[[idxDate]]$rtioMoleDryCo2Vali) <- NULL + rownames(rpt[[idxDate]][[valiTmp]]) <- NULL #remove unuse objects rm(outTmp00, outTmp01, outTmp02, rptTmp, idxGas) @@ -245,32 +255,33 @@ wrap.irga.vali <- function( timeMin <- base::as.POSIXlt(paste(DateBgn, " ", "00:01:29.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") timeMax <- base::as.POSIXlt(paste(DatePost, " ", "00:01:29.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") #determine index when timeEnd fall in DateProc - rpt[[idxDate]]$rtioMoleDryCo2Vali <- rpt[[idxDate]]$rtioMoleDryCo2Vali[which(rpt[[idxDate]]$rtioMoleDryCo2Vali$timeEnd >= timeMin & rpt[[idxDate]]$rtioMoleDryCo2Vali$timeBgn < timeMax),] + rpt[[idxDate]][[valiTmp]] <- rpt[[idxDate]][[valiTmp]][which(rpt[[idxDate]][[valiTmp]]$timeEnd >= timeMin & rpt[[idxDate]][[valiTmp]]$timeBgn < timeMax),] #fail safe: fill in dataframe with NaN values when there is only qfIrgaTurbValiGas01 or no validation at all - if (length(rpt[[idxDate]]$rtioMoleDryCo2Vali$mean) <= 1){ - if(length(rpt[[idxDate]]$rtioMoleDryCo2Vali$mean) == 1 & rpt[[idxDate]]$rtioMoleDryCo2Vali$gasType[1] == "qfIrgaTurbValiGas01"){ - rpt[[idxDate]]$rtioMoleDryCo2Vali[2:5,] <- NA - rpt[[idxDate]]$rtioMoleDryCo2Vali$numSamp <- NaN - rpt[[idxDate]]$rtioMoleDryCo2Vali$timeBgn[2:5] <- base::as.POSIXlt(paste(idxDate, " ", "00:00:00.000", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") - rpt[[idxDate]]$rtioMoleDryCo2Vali$timeEnd[2:5] <- base::as.POSIXlt(paste(idxDate, " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") + if (length(rpt[[idxDate]][[valiTmp]]$mean) <= 1){ + if(length(rpt[[idxDate]][[valiTmp]]$mean) == 1 & rpt[[idxDate]][[valiTmp]]$gasType[1] == "qfIrgaTurbValiGas01"){ + rpt[[idxDate]][[valiTmp]][2:5,] <- NA + rpt[[idxDate]][[valiTmp]]$numSamp <- NaN + rpt[[idxDate]][[valiTmp]]$timeBgn[2:5] <- base::as.POSIXlt(paste(idxDate, " ", "00:00:00.000", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") + rpt[[idxDate]][[valiTmp]]$timeEnd[2:5] <- base::as.POSIXlt(paste(idxDate, " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") #replace gasType - rpt[[idxDate]]$rtioMoleDryCo2Vali$gasType <- nameQf + rpt[[idxDate]][[valiTmp]]$gasType <- nameQf }else{ - if(length(rpt[[idxDate]]$rtioMoleDryCo2Vali$mean) == 0){ - rpt[[idxDate]]$rtioMoleDryCo2Vali[1:5,] <- NA - rpt[[idxDate]]$rtioMoleDryCo2Vali$numSamp <- NaN - rpt[[idxDate]]$rtioMoleDryCo2Vali$timeBgn <- base::as.POSIXlt(paste(idxDate, " ", "00:00:00.000", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") - rpt[[idxDate]]$rtioMoleDryCo2Vali$timeEnd <- base::as.POSIXlt(paste(idxDate, " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") + if(length(rpt[[idxDate]][[valiTmp]]$mean) == 0){ + rpt[[idxDate]][[valiTmp]][1:5,] <- NA + rpt[[idxDate]][[valiTmp]]$numSamp <- NaN + rpt[[idxDate]][[valiTmp]]$timeBgn <- base::as.POSIXlt(paste(idxDate, " ", "00:00:00.000", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") + rpt[[idxDate]][[valiTmp]]$timeEnd <- base::as.POSIXlt(paste(idxDate, " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") #replace gasType - rpt[[idxDate]]$rtioMoleDryCo2Vali$gasType <- nameQf + rpt[[idxDate]][[valiTmp]]$gasType <- nameQf }else{ - rpt[[idxDate]]$rtioMoleDryCo2Vali <- rpt[[idxDate]]$rtioMoleDryCo2Vali + rpt[[idxDate]][[valiTmp]] <- rpt[[idxDate]][[valiTmp]] } } } #add gasRefe values into rpt + if (idxVar == "rtioMoleDryCo2") { #create temporary dataframe tmpGasRefe <- data.frame(matrix(ncol = 3, nrow = 5)) #assign column name @@ -424,23 +435,34 @@ wrap.irga.vali <- function( tmpCoef[[idxDate]][[idxData]][1,3] <- rtioMoleDryCo2Mlfr$sigma } }#end of for loop of idxData - #report output rpt[[idxDate]]$rtioMoleDryCo2Mlf <- tmpCoef[[idxDate]]$data00 + #close if idxVar == rtioMoleDryCo2 + }else{ + rpt[[idxDate]]$rtioMoleDryH2oVali$rtioMoleDryH2oRefe <- ifelse(rpt[[idxDate]]$rtioMoleDryH2oVali$gasType == "qfIrgaTurbValiGas02", 0, NA) + } #reorder column - rpt[[idxDate]]$rtioMoleDryCo2Vali <- rpt[[idxDate]]$rtioMoleDryCo2Vali[,c(1:5, 10, 7, 8)] + rpt[[idxDate]][[valiTmp]] <- rpt[[idxDate]][[valiTmp]][,c(1:5, 10, 7, 8)] + #unit attributes - unitRtioMoleDryCo2Vali <- attributes(data$irgaTurb$rtioMoleDryCo2)$unit + unitVali <- attributes(data$irgaTurb[[idxVar]])$unit + #unit attributes for gasRefe + if (idxVar == "rtioMoleDryCo2") { + unitRefe <- attributes(gasRefe$rtioMoleDryCo2Refe01[[idxDate]]$`702_000`)$unit #"rtioMoleDryCo2Refe" + } else{ + unitRefe <- "molH2o mol-1" + } - attributes(rpt[[idxDate]]$rtioMoleDryCo2Vali)$unit <- c(unitRtioMoleDryCo2Vali, #"mean" - unitRtioMoleDryCo2Vali, #"min" - unitRtioMoleDryCo2Vali, #"max" - unitRtioMoleDryCo2Vali,#"vari" - "NA", #"numSamp" - attributes(gasRefe$rtioMoleDryCo2Refe01[[idxDate]]$`702_000`)$unit,#"rtioMoleDryCo2Refe" - "NA", #"timeBgn" - "NA")#"timeEnd" + attributes(rpt[[idxDate]][[valiTmp]])$unit <- c(unitVali, #"mean" + unitVali, #"min" + unitVali, #"max" + unitVali,#"vari" + "NA", #"numSamp" + unitRefe,#gasRefe + "NA", #"timeBgn" + "NA")#"timeEnd" + }#end of for loop of idxVar }; rm(valiCrit, allSubData, allSubQfqm, allSubTime)#end of idxDate invisible(gc()) diff --git a/pack/eddy4R.qaqc/man/def.qf.irga.vali.Rd b/pack/eddy4R.qaqc/man/def.qf.irga.vali.Rd index 0ebc7a60..91896d5e 100644 --- a/pack/eddy4R.qaqc/man/def.qf.irga.vali.Rd +++ b/pack/eddy4R.qaqc/man/def.qf.irga.vali.Rd @@ -4,8 +4,11 @@ \alias{def.qf.irga.vali} \title{Definition function: Validation flag for IRGA} \usage{ -def.qf.irga.vali(data, Sens = c("irgaMfcSamp", "valvValiNemaTurb")[1], - qfGas = NULL) +def.qf.irga.vali( + data, + Sens = c("irgaMfcSamp", "valvValiNemaTurb")[1], + qfGas = NULL +) } \arguments{ \item{data}{A data.frame containing the L0p input IRGA sampling mass flow controller data or the IRGA validation soleniod valves data at native resolution. Of type numeric or integer. [User-defined]} From 081dcaa5d3b116492731424506e8f223b41d55d7 Mon Sep 17 00:00:00 2001 From: NDurden Date: Thu, 16 Jan 2020 17:57:48 +0000 Subject: [PATCH 010/168] generated NA for rtioMoleDryH2oCor --- pack/eddy4R.base/R/def.irga.vali.cor.R | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pack/eddy4R.base/R/def.irga.vali.cor.R b/pack/eddy4R.base/R/def.irga.vali.cor.R index e865da2d..71408e23 100644 --- a/pack/eddy4R.base/R/def.irga.vali.cor.R +++ b/pack/eddy4R.base/R/def.irga.vali.cor.R @@ -45,6 +45,8 @@ # added ScalMax, FracSlpMax, and Freq into input function parameters # Natchaya P-Durden (2020-01-14) # added time when the real validation begin +# Natchaya P-Durden (2020-01-16) +# generated NA for rtioMoleDryH2oCor ############################################################################################## def.irga.vali.cor <- function( data, @@ -173,8 +175,11 @@ def.irga.vali.cor <- function( if (all(is.na(ofstLin)) & all(is.na(slpLin))){ #subData$rtioMoleDryCo2Cor <- as.numeric(subData$rtioMoleDryCo2) subData$rtioMoleDryCo2Cor <- NA + subData$rtioMoleDryH2oCor <- NA } else { subData$rtioMoleDryCo2Cor <- as.numeric(ofstLin + subData$rtioMoleDryCo2*slpLin) + #place holder for future h2o correction + subData$rtioMoleDryH2oCor <- NA } #outSub[[idx]] <- subData @@ -214,16 +219,15 @@ rpt <- eddy4R.base::def.rglr(timeMeas = base::as.POSIXlt(outTmp01$time, format=" #replace time to regularize time rpt$time <- timeRglr #check if rtioMoleDryCo2Cor in rpt if not add them with all NA -if (length(rpt$rtioMoleDryCo2Cor) == 0){ - rpt$rtioMoleDryCo2Cor <- NA -} +if (length(rpt$rtioMoleDryCo2Cor) == 0) {rpt$rtioMoleDryCo2Cor <- NA} +if (length(rpt$rtioMoleDryH2oCor) == 0) {rpt$rtioMoleDryH2oCor <- NA} #Creating the index to organize the variables in alphabetical order idxIrga <- order(names(rpt)) #Changing the order of the variables to alphabetical order using the index rpt <- rpt[,idxIrga] #adding unit attributes attrUnit <- c("-", "-", "molCo2 m-3", "molH2o m-3", "NA", "V", "W", "W", "W", "W", "Pa", "Pa", "Pa", "molCo2 mol-1Dry", "molCo2 mol-1Dry", "molH2o mol-1Dry", - "-", "-", "K", "K", "K", "K", "NA") + "molH2o mol-1Dry", "-", "-", "K", "K", "K", "K", "NA") for(idxVar in 1:length(attrUnit)) { From cd0dbdebe769d7b29ec317de8c401a4d1982e81d Mon Sep 17 00:00:00 2001 From: NDurden Date: Fri, 17 Jan 2020 15:20:11 +0000 Subject: [PATCH 011/168] removed rtioMoleDryH2oCor and rtioMoleDryH2oRaw data and ucrt from the basic file --- pack/eddy4R.base/R/def.hdf5.wrte.dp01.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R index f33bee13..8971229c 100755 --- a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R +++ b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R @@ -48,6 +48,8 @@ # adding linear regression coefficients and its se to the attribute of rtioMoleDryCo2Vali # Natchaya P-Durden (2019-02-21) # adding results from MLF (scale) to the attribute of rtioMoleDryCo2Vali +# Natchaya P-Durden (2019-01-08) +# removed rtioMoleDryH2oCor and rtioMoleDryH2oRaw data and ucrt from the basic file ############################################################################################## @@ -70,6 +72,8 @@ MethExpd <- grepl(pattern = "expanded", x = FileOut) if(MethExpd == FALSE){ inpList$data$co2Turb$rtioMoleDryCo2Cor <- NULL inpList$data$co2Turb$rtioMoleDryCo2Raw <- NULL + inpList$data$h2oTurb$rtioMoleDryH2oCor <- NULL + inpList$data$h2oTurb$rtioMoleDryH2oRaw <- NULL } #Create HDF5 connection to the output file @@ -113,6 +117,8 @@ if(MethSubAgr == TRUE){ if(MethExpd == FALSE){ inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Cor <- NULL inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Raw <- NULL + inpList$dp01AgrSub$data$h2oTurb$rtioMoleDryH2oCor <- NULL + inpList$dp01AgrSub$data$h2oTurb$rtioMoleDryH2oRaw <- NULL } #Writing sub-aggregated (e.g.1-min) data to output HDF5 file lapply(names(inpList$dp01AgrSub$data[[Dp01]]), function(x) rhdf5::h5writeDataset.data.frame(obj = inpList$dp01AgrSub$data[[Dp01]][[x]], h5loc = idData01, name = x, DataFrameAsCompound = TRUE)) @@ -203,6 +209,8 @@ if(MethUcrt == TRUE){ if(MethExpd == FALSE){ inpList$ucrt$co2Turb$rtioMoleDryCo2Cor <- NULL inpList$ucrt$co2Turb$rtioMoleDryCo2Raw <- NULL + inpList$ucrt$h2oTurb$rtioMoleDryH2oCor <- NULL + inpList$ucrt$h2oTurb$rtioMoleDryH2oRaw <- NULL } #Writing 30-min ucrt to output HDF5 file lapply(names(inpList$ucrt[[Dp01]]), function(x) rhdf5::h5writeDataset.data.frame(obj = inpList$ucrt[[Dp01]][[x]], h5loc = idUcrt30, name = x, DataFrameAsCompound = TRUE)) @@ -219,6 +227,8 @@ if(MethSubAgr == TRUE){ if(MethExpd == FALSE){ inpList$dp01AgrSub$ucrt$co2Turb$rtioMoleDryCo2Cor <- NULL inpList$dp01AgrSub$ucrt$co2Turb$rtioMoleDryCo2Raw <- NULL + inpList$dp01AgrSub$ucrt$h2oTurb$rtioMoleDryH2oCor <- NULL + inpList$dp01AgrSub$ucrt$h2oTurb$rtioMoleDryH2oRaw <- NULL } #Writing sub-aggregated (e.g.1-min) ucrt to output HDF5 file lapply(names(inpList$dp01AgrSub$ucrt[[Dp01]]), function(x) rhdf5::h5writeDataset.data.frame(obj = inpList$dp01AgrSub$ucrt[[Dp01]][[x]], h5loc = idUcrt01, name = x, DataFrameAsCompound = TRUE)) From 1cf0f4abeb627340d60115974ddb064d921bb25d Mon Sep 17 00:00:00 2001 From: NDurden Date: Fri, 17 Jan 2020 15:20:47 +0000 Subject: [PATCH 012/168] adding rtioMoleDryH2o during validation --- pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R index eb0b85ba..de841c8b 100755 --- a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R +++ b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R @@ -64,6 +64,8 @@ # Adding dp04 low resolution output on top of validation code # Natchaya P-Durden (2019-09-30) # only write qfFinl out in basic file +# Natchaya P-Durden (2020-01-17) +# adding rtioMoleDryH2o during validation ############################################################################################## @@ -121,11 +123,14 @@ if(MethSubAgr == TRUE){ #adding irgaTurb validation data outList$vali$data$co2Turb <- inpList$vali$data$co2Turb + outList$vali$data$h2oTurb <- inpList$vali$data$h2oTurb #If values come in as Posix, they must first be converted to characters for (idxTime in c("timeBgn", "timeEnd")){ if(!is.character(outList$vali$data$co2Turb$rtioMoleDryCo2Vali[[idxTime]])){ outList$vali$data$co2Turb$rtioMoleDryCo2Vali[[idxTime]] <- strftime(outList$vali$data$co2Turb$rtioMoleDryCo2Vali[[idxTime]], format="%Y-%m-%dT%H:%M:%OSZ", tz="UTC")} + if(!is.character(outList$vali$data$h2oTurb$rtioMoleDryH2oVali[[idxTime]])){ + outList$vali$data$h2oTurb$rtioMoleDryH2oVali[[idxTime]] <- strftime(outList$vali$data$h2oTurb$rtioMoleDryH2oVali[[idxTime]], format="%Y-%m-%dT%H:%M:%OSZ", tz="UTC")} } #Unit conversion for dp01 sub-aggregated irgaTurb validation data @@ -133,6 +138,7 @@ if(MethSubAgr == TRUE){ #adding validation data to dp01AgrSub outList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali <- outList$vali$data$co2Turb$rtioMoleDryCo2Vali + outList$dp01AgrSub$data$h2oTurb$rtioMoleDryH2oVali <- outList$vali$data$h2oTurb$rtioMoleDryH2oVali #Packaging sub-aggregated (e.g.1-min) dp01 qfqm for writing to HDF5 file outList$dp01AgrSub$qfqm <- sapply(names(inpList$dp01AgrSub$qfqm), function(x) eddy4R.base::def.hdf5.pack(inpList = inpList$dp01AgrSub$qfqm, time = inpList$dp01AgrSub$time, Dp = x)) @@ -219,7 +225,7 @@ if(MethDp04 == TRUE){ } else { #output only flux for fluxCo2 in basic file - if (idxDp04 == c("fluxCo2") & MethExpd == FALSE){ + if (idxDp04 %in% c("fluxCo2", "fluxH2o") & MethExpd == FALSE){ inpList$dp04$data[[idxDp04]]$turb$fluxCor <- NULL inpList$dp04$data[[idxDp04]]$turb$fluxRaw <- NULL } From cb2cd266c4c96295af6518c1932bc86750125026 Mon Sep 17 00:00:00 2001 From: NDurden Date: Fri, 17 Jan 2020 15:21:33 +0000 Subject: [PATCH 013/168] adding unit conversion for rtioMoleDryH2o during validation --- pack/eddy4R.base/R/wrap.unit.conv.out.ec.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R b/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R index 763e0df6..03e95ca5 100644 --- a/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R +++ b/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R @@ -38,6 +38,8 @@ # adding units conversion for ecse # Natchaya P-Durden (2019-07-23) # converting time format in ecse qfqm +# Natchaya P-Durden (2020-01-17) +# adding unit conversion for rtioMoleDryH2o during validation ############################################################################################ wrap.unit.conv.out.ec <- function( @@ -83,6 +85,8 @@ outAttr$co2Turb <- base::list( outAttr$h2oTurb <- base::list( "rtioMoleDryH2o"= c("mean" = "mmolH2o mol-1Dry", "min" = "mmolH2o mol-1Dry", "max" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "rtioMoleDryH2oCor"= c("mean" = "mmolH2o mol-1Dry", "min" = "mmolH2o mol-1Dry", "max" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), + "rtioMoleDryH2oRaw"= c("mean" = "mmolH2o mol-1Dry", "min" = "mmolH2o mol-1Dry", "max" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), "densMoleH2o"= c("mean" = "mmolH2o m-3", "min" = "mmolH2o m-3", "max" = "mmolH2o m-3", "vari" = "mmolH2o m-3", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), "tempDew"= c("mean" = "C", "min" = "C", "max" = "C", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), "presAtm"= c("mean" = "kPa", "min" = "kPa", "max" = "kPa", "vari" = "kPa", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA"), @@ -118,6 +122,8 @@ if(MethType == "ucrt"){ outAttr$h2oTurb <- base::list( "rtioMoleDryH2o"= c("mean" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "se" = "mmolH2o mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA"), + "rtioMoleDryH2oCor"= c("mean" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "se" = "mmolH2o mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA"), + "rtioMoleDryH2oRaw"= c("mean" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "se" = "mmolH2o mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA"), "densMoleH2o"= c("mean" = "mmolH2o m-3", "vari" = "mmolH2o m-3", "se" = "mmolH2o m-3", "timeBgn" = "NA", "timeEnd" = "NA"), "tempDew"= c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA"), "presAtm"= c("mean" = "kPa", "vari" = "kPa", "se" = "kPa", "timeBgn" = "NA", "timeEnd" = "NA"), @@ -129,6 +135,8 @@ if(MethType == "ucrt"){ if(MethType == "vali"){ outAttr$co2Turb <- base::list( "rtioMoleDryCo2Vali"= c("mean" = "umolCo2 mol-1Dry", "min" = "umolCo2 mol-1Dry", "max" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "numSamp" = "NA", "rtioMoleDryCo2Refe" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA")) + outAttr$h2oTurb <- base::list( + "rtioMoleDryH2oVali"= c("mean" = "mmolH2o mol-1Dry", "min" = "mmolH2o mol-1Dry", "max" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "numSamp" = "NA", "rtioMoleDryH2oRefe" = "mmolH2o mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA")) } #assign output attributes @@ -153,6 +161,9 @@ outAttr$vari <- base::list( "frt00Samp"= "dm6 min-2", "tempAve"= "C2", "rtioMoleDryH2o"= "mmol2H2o mol-2Dry", + "rtioMoleDryH2oCor"= "mmol2H2o mol-2Dry", + "rtioMoleDryH2oRaw"= "mmol2H2o mol-2Dry", + "rtioMoleDryH2oVali"= "mmol2H2o mol-2Dry", "densMoleH2o"= "mmol2H2o m-6", "tempDew"= "C2" ) From ef4b80000e327a393beeb1588f0df2e5fc9ff281 Mon Sep 17 00:00:00 2001 From: NDurden Date: Thu, 23 Jan 2020 14:08:16 +0000 Subject: [PATCH 014/168] adding timeBgn and timeEnd attributes --- pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R index de841c8b..517042b7 100755 --- a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R +++ b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R @@ -66,6 +66,8 @@ # only write qfFinl out in basic file # Natchaya P-Durden (2020-01-17) # adding rtioMoleDryH2o during validation +# Natchaya P-Durden (2020-01-22) +# adding timeBgn and timeEnd attributes ############################################################################################## @@ -178,6 +180,8 @@ if(MethDp04 == TRUE){ #Writing unit attributes to each variable to the dataframe level attributes(rptDp04)$unit <- attributes(inpList$dp04$data[[idxDp04]]$stat)$unit + #Adding timeBgn and timeEnd attributes + attributes(rptDp04)$unit <- c("NA", "NA", attributes(rptDp04)$unit) #Open connection to dp04 data level idDataDp04 <- rhdf5::H5Gopen(idFile,paste0("/", SiteLoca, "/dp04/data/",idxDp04)) @@ -210,6 +214,11 @@ if(MethDp04 == TRUE){ #Writing unit attributes to each variable to the dataframe level attributes(rptDp04Qfqm)$unit <- sapply(names(inpList$dp04$qfqm[[idxDp04]]$turb), function(x) attributes(inpList$dp04$qfqm[[idxDp04]]$turb[[x]])$unit) + #Adding timeBgn and timeEnd attributes + tmpAttr <- c() + attributes(tmpAttr)$unit[["timeBgn"]] <- "NA" + attributes(tmpAttr)$unit[["timeEnd"]] <- "NA" + attributes(rptDp04Qfqm)$unit <- c(attributes(tmpAttr)$unit, attributes(rptDp04Qfqm)$unit) #Open connection to dp04 data level idQfqmDp04 <- rhdf5::H5Gopen(idFile,paste0("/", SiteLoca, "/dp04/qfqm/",idxDp04)) @@ -236,6 +245,12 @@ if(MethDp04 == TRUE){ #Writing unit attributes to each variable to the dataframe level attributes(rptDp04)$unit <- sapply(names(inpList$dp04$data[[idxDp04]]$turb), function(x) attributes(inpList$dp04$data[[idxDp04]]$turb[[x]])$unit) + #Adding timeBgn and timeEnd attributes + tmpAttr <- c() + attributes(tmpAttr)$unit[["timeBgn"]] <- "NA" + attributes(tmpAttr)$unit[["timeEnd"]] <- "NA" + attributes(rptDp04)$unit <- c(attributes(tmpAttr)$unit, attributes(rptDp04)$unit) + #Open connection to dp04 data level idDataDp04 <- rhdf5::H5Gopen(idFile,paste0("/", SiteLoca, "/dp04/data/",idxDp04)) @@ -265,6 +280,11 @@ if(MethDp04 == TRUE){ #Writing unit attributes to each variable to the dataframe level attributes(rptDp04Qfqm)$unit <- sapply(names(inpList$dp04$qfqm[[idxDp04]]$turb), function(x) attributes(inpList$dp04$qfqm[[idxDp04]]$turb[[x]])$unit) + #Adding timeBgn and timeEnd attributes + tmpAttr <- c() + attributes(tmpAttr)$unit[["timeBgn"]] <- "NA" + attributes(tmpAttr)$unit[["timeEnd"]] <- "NA" + attributes(rptDp04Qfqm)$unit <- c(attributes(tmpAttr)$unit, attributes(rptDp04Qfqm)$unit) #Open connection to dp04 data level idQfqmDp04 <- rhdf5::H5Gopen(idFile,paste0("/", SiteLoca, "/dp04/qfqm/",idxDp04)) From 89a580ee97298a7658461434c2fccc65b0fbda7c Mon Sep 17 00:00:00 2001 From: NDurden Date: Thu, 23 Jan 2020 19:24:43 +0000 Subject: [PATCH 015/168] removed unnecessary dp01 qfqm unit attributes when writing out the basic file --- pack/eddy4R.base/R/def.hdf5.wrte.dp01.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R index 8971229c..8076a8f8 100755 --- a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R +++ b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R @@ -50,6 +50,8 @@ # adding results from MLF (scale) to the attribute of rtioMoleDryCo2Vali # Natchaya P-Durden (2019-01-08) # removed rtioMoleDryH2oCor and rtioMoleDryH2oRaw data and ucrt from the basic file +# Natchaya P-Durden (2020-02-23) +# removed unnecessary qfqm unit attributes when writing the basic file ############################################################################################## @@ -190,7 +192,12 @@ if(MethSubAgr == TRUE){ lapply(names(inpList$qfqm[[Dp01]]), function(x) { if (!is.null(attributes(inpList$qfqm[[Dp01]][[x]])$unit) == TRUE){ dgid <- rhdf5::H5Dopen(idQfqm30, x) + if(MethExpd == FALSE){ + tmpAttr <- attributes(inpList$qfqm[[Dp01]][[x]])$unit[which(names(attributes(inpList$qfqm[[Dp01]][[x]])$unit) %in% c("qfFinl","timeBgn","timeEnd"))] + rhdf5::h5writeAttribute(tmpAttr, h5obj = dgid, name = "unit") + }else{ rhdf5::h5writeAttribute(attributes(inpList$qfqm[[Dp01]][[x]])$unit, h5obj = dgid, name = "unit") + } }}) if(MethSubAgr == TRUE){ @@ -198,7 +205,12 @@ if(MethSubAgr == TRUE){ lapply(names(inpList$dp01AgrSub$qfqm[[Dp01]]), function(x) { if (!is.null(attributes(inpList$dp01AgrSub$qfqm[[Dp01]][[x]])$unit) == TRUE){ dgid <- rhdf5::H5Dopen(idQfqm01, x) + if(MethExpd == FALSE){ + tmpAttr <- attributes(inpList$dp01AgrSub$qfqm[[Dp01]][[x]])$unit[which(names(attributes(inpList$dp01AgrSub$qfqm[[Dp01]][[x]])$unit) %in% c("qfFinl","timeBgn","timeEnd"))] + rhdf5::h5writeAttribute(tmpAttr, h5obj = dgid, name = "unit") + }else{ rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$qfqm[[Dp01]][[x]])$unit, h5obj = dgid, name = "unit") + } }}) } ########################################################################################## From bf59859f3c40de4d9e6a54aaa8fd9daf425c1d54 Mon Sep 17 00:00:00 2001 From: NDurden Date: Fri, 31 Jan 2020 15:18:45 +0000 Subject: [PATCH 016/168] adjust workflow to run MLFR even missing one gas cylinder --- pack/eddy4R.base/R/wrap.irga.vali.R | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index 27d29966..3be00029 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -73,6 +73,8 @@ # bug fix on selecting the validation gas based on timeCrit # Natchaya P-Durden (2020-01-15) # reporting the rtioMoleDryH2oVali table +# Natchaya P-Durden (2020-01-31) +# adjust workflow to run MLFR even missing one gas cylinder ############################################################################################## wrap.irga.vali <- function( @@ -415,15 +417,20 @@ wrap.irga.vali <- function( tmpCoef[[idxDate]][[idxData]] <- data.frame(matrix(ncol = 3, nrow = 2)) #assign column name colnames(tmpCoef[[idxDate]][[idxData]]) <- c("coef", "se", "scal") - - if (length(valiData[[idxDate]][[idxData]]$mean) < 4 | - sum(is.na(valiData[[idxDate]][[idxData]]$mean)) > 0 | sum(is.na(valiData[[idxDate]][[idxData]]$se)) >0 | - sum(is.na(valiData[[idxDate]][[idxData]]$rtioMoleDryCo2Refe)) > 0 | sum(is.na(valiData[[idxDate]][[idxData]]$rtioMoleDryCo2RefeSe)) > 1){ - tmpCoef[[idxDate]][[idxData]][,] <- NA + + #get the temporary valiData table without NA + tmpValiData <- na.omit(valiData[[idxDate]][[idxData]]) + #report NA for regression coefficients if input validation data less than 3 values + if (nrow(tmpValiData) < 3){ + + # if (length(valiData[[idxDate]][[idxData]]$mean) < 4 | + # sum(is.na(valiData[[idxDate]][[idxData]]$mean)) > 0 | sum(is.na(valiData[[idxDate]][[idxData]]$se)) >0 | + # sum(is.na(valiData[[idxDate]][[idxData]]$rtioMoleDryCo2Refe)) > 0 | sum(is.na(valiData[[idxDate]][[idxData]]$rtioMoleDryCo2RefeSe)) > 1){ + tmpCoef[[idxDate]][[idxData]][,] <- NA } else{ #x are sensor readings; y are reference gas values - rtioMoleDryCo2Mlfr <- deming::deming(rtioMoleDryCo2Refe[1:4] ~ mean[1:4], data = valiData[[idxDate]][[idxData]], - xstd = se[1:4], ystd = rtioMoleDryCo2RefeSe[1:4]) + rtioMoleDryCo2Mlfr <- deming::deming(rtioMoleDryCo2Refe[1:nrow(tmpValiData)] ~ mean[1:nrow(tmpValiData)], data = tmpValiData, + xstd = se[1:nrow(tmpValiData)], ystd = rtioMoleDryCo2RefeSe[1:nrow(tmpValiData)]) #write output to table #intercept tmpCoef[[idxDate]][[idxData]][1,1] <- rtioMoleDryCo2Mlfr$coefficients[[1]] From a9634d0d4ed617f1aa432204dc3c1a1ee5d96463 Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 10 Feb 2020 02:47:24 +0000 Subject: [PATCH 017/168] - Grabbing objDesc and Readme from S3, removing dropbox link --- pack/eddy4R.base/R/def.hdf5.crte.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.crte.R b/pack/eddy4R.base/R/def.hdf5.crte.R index 90cc1967..adea1618 100755 --- a/pack/eddy4R.base/R/def.hdf5.crte.R +++ b/pack/eddy4R.base/R/def.hdf5.crte.R @@ -73,6 +73,8 @@ # Adding irga validation system sensors for ECTE (pressure sensors) # Dave Durden (2019-07-14) # Adding irga validation system sensors for ECTE (valve and pump) +# Dave Durden (2020-02-09) +# Grabbing objDesc and Readme from S3, removing dropbox link ############################################################################################################## #Start of function call to generate NEON HDF5 files ############################################################################################################## @@ -102,8 +104,7 @@ def.hdf5.crte <- function( DirTmp <- tempdir() #Download file description readme and object list - eddy4R.base::def.dld.zip(Inp = list(Url = "https://www.dropbox.com/s/dqq3j7epiy98y29/fileDesc.zip?dl=1", - Dir = DirTmp)) + eddy4R.base::def.dld.zip(Inp = list(Url = "https://s3.data.neonscience.org/neon-ec-goldfiles/EC-turbulence-processing/fileDesc.zip", Dir = DirTmp)) #Store the path to the readme file FileNameReadMe <- base::list.files( path = base::paste0(DirTmp,"/fileDesc"), pattern = ".txt", full.names = TRUE) From ca06244dcdd5cdda35e13ff56c7f75b24c7967a4 Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 10 Feb 2020 05:49:15 +0000 Subject: [PATCH 018/168] - Adding vignette to eddy4R repo --- vign/turb.neon.vignette.Rmd | 909 ++++++++++++++++++++++++++++++++++++ 1 file changed, 909 insertions(+) create mode 100755 vign/turb.neon.vignette.Rmd diff --git a/vign/turb.neon.vignette.Rmd b/vign/turb.neon.vignette.Rmd new file mode 100755 index 00000000..3681945b --- /dev/null +++ b/vign/turb.neon.vignette.Rmd @@ -0,0 +1,909 @@ +--- +title: "Example workflow for processing NEON eddy-covariance turbulence data with eddy4R-Docker 1.0.0" +author: "David Durden, Stefan Metzger, Natchaya Pingintha-Durden, Claire Lunch, Megan Jones" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Example workflow for processing NEON eddy-covariance turbulence data with eddy4R-Docker 1.0.0} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r setup, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +## 0. Install and set up + +This vignette assumes you are working with eddy4R within the Docker +environment established by NEON. To get set up in that environment, +follow the instructions here. + +At the end of those instructions, you should have an RStudio +environment running within Docker. Use that workspace for this +vignette. + +## 1. Install packages and set up environment + +First, check for required packages and install any that aren't +already installed. Once all required packages are installed, +load them into the environment. + +Throughout this vignette, we use the `package::function()` +syntax to explicitly refer to functions. This is done to avoid any +possibility of ambiguity, in case there are functions in +different packages with the same name. + + +```{r pack-install} + +packReq <- c("DataCombine", "eddy4R.base", "eddy4R.qaqc", + "ff", "ffbase", "methods", "rhdf5","splus2R") +base::lapply(packReq, function(x) { + print(x) + if(base::require(x, character.only = TRUE) == FALSE) { + utils::install.packages(x) + base::library(x, character.only = TRUE) + }}) +base::rm(packReq) + +``` + + +## 2. Set environment variables + +Here we set file paths and basic input parameters as environment +variables for convenience. + +```{r env-vars} + +# First, we assign a working directory where the input data, output reference data, and workflow will be downloaded to for running the tutorial. This defaults to a temporary directory, but you can change this to any location you like (be aware the downloaded .zip archive is ~ 360 MB) +DirWrk <- tempdir() + +#This is the data download url, we use a permanent URL (PURL) link to ensure the data is always accessible. +UrlDld <- "https://w3id.org/smetzger/Metzger-et-al_2019_NEON-BAMS/tutorial_data/" + +# Download input data and output reference data +eddy4R.base::def.dld.zip(Inp = list(Url = UrlDld, Dir = DirWrk)) + +# File path for the directory containing input L0' data +base::Sys.setenv("DIRINP" = paste0(DirWrk,"/inpExmp")) + +# File path for outputs +base::Sys.setenv("DIROUT" = paste0(DirWrk,"/out")) + +# Date(s) of the input data, specified here for the output file name +base::Sys.setenv("DATEOUT" = "2017-09-01") + +# NEON domain, site, and data product ID of the input data +# for the output file name: +# Domain 10 = D10 +# Central Plains Experimental Range = CPER +# Bundled eddy covariance data = 00200.001 +base::Sys.setenv("FILEOUTBASE" = "NEON.D10.CPER.00200.001") + +# Flag to indicate to the eddy4R.base::def.para.flow() +# function that the variables above can be found as +# environment variables, instead of provided as function +# inputs +base::Sys.setenv("METHPARAFLOW" = "EnvVar") + +``` + +## 3. Read in metadata + +Pass along the environment variables defined in section 2, +then read in additional parameters from the HDF5 file. + +```{r metadata} + +# In this section, define and/or read in a number of terms and +# parameters. + +# Create an empty list for parameters. +Para <- base::list() + +# Use the def.para.flow() function to specify the metadata are stored +# in environment variables, and give file paths to input and output. +# You will see a number of warning messages in response to this line, +# but if you can proceed with the next several commands, don't worry +# about the warnings here. +Para$Flow <- eddy4R.base::def.para.flow(MethParaFlow = "EnvVar") + +# The args() function can be used to see the full list of function +# arguments available in def.para.flow(). +# Additional metadata can be passed to the function as well, by +# assigning a variable name in the functional call. +base::args(eddy4R.base::def.para.flow) + +# Get the NEON-specific 4-letter code for the site location (Loc) +# from the dp0p input file +Para$Flow$Loc <- eddy4R.base::def.para.site(FileInp = Para$Flow$DirFilePara)$Loc + +# Get the level of the tower top (LvlTowr) from the dp0p input file +Para$Flow$LvlTowr <- eddy4R.base::def.para.site(FileInp = Para$Flow$DirFilePara)$LvlTowr + +# Use the def.hdf5.read.para() function to extract parameters +# from the metadata in the input file and assign them to the +# parameter list. + +# For each variable to be written out, set the aggregation +# parameters. +# Variables: +# amrs: Attitude Motion Reference System +# co2turb: Turbulent CO2 flux +# h2oTurb: Turbulent H2O flux +# soni: Windspeed and direction from sonic anemometer +# Parameters: +# PrdIncrAgrDflt: Period Increment Aggregation Default +# PrdWndwAgrDflt: Period Window Aggregation Default +for(idx in c("amrs", "co2Turb", "h2oTurb", "soni")) { + + Para$Flow$dp01[[idx]] <- eddy4R.base::def.hdf5.read.para( + DirFileParaLoca = Para$Flow$DirFilePara, + GrpName = paste0("/", Para$Flow$Loc, "/dp01/data/", idx), + SetPara = c("PrdIncrAgrDflt", "PrdWndwAgrDflt") + ) + +} + +# AngEnuXaxs: Planar fit coefficient of the x axis +# AngEnuYaxs: Planar fit coefficient of the y axis +# Ofst: Planar fit offset +# ZoneTime: Time zone of data collection +# Note that a future release of the eddy4R package will +# include a planar fit function, which will allow you to +# set the planar fit coefficients to NA here, and then +# use the function to estimate them. This workflow will +# require a longer window of input data, on the order of +# days to weeks, be provided to determine a robust +# planar regression for the data. +Para$Sci <- eddy4R.base::def.hdf5.read.para( + DirFileParaLoca = Para$Flow$DirFilePara, + GrpName = Para$Flow$Loc, + SetPara = c("Pf$AngEnuXaxs", "Pf$AngEnuYaxs", "Pf$Ofst", "ZoneTime") +) + +# In the next 5 commands, get the sampling frequency (FreqSamp) +# of each instrument from the parameters in the input file: +# irgaTurb: Turbulent flux gas analyzer +# mfcSampTurb: Mass flow controller +# valvValiNemaTurb: Valve Validation Nema enclosure Turbulence +# soni, amrs: See above +Para$Sci$dp0p$irgaTurb <- def.hdf5.read.para( + DirFileParaLoca = Para$Flow$DirFilePara, + GrpName = paste0("/", Para$Flow$Loc, "/dp0p/data/irgaTurb"), + SetPara = c("FreqSamp") +) + +Para$Sci$dp0p$mfcSampTurb <- def.hdf5.read.para( + DirFileParaLoca = Para$Flow$DirFilePara, + GrpName = paste0("/", Para$Flow$Loc, "/dp0p/data/mfcSampTurb"), + SetPara = c("FreqSamp") +) + +Para$Sci$dp0p$valvValiNemaTurb <- def.hdf5.read.para( + DirFileParaLoca = Para$Flow$DirFilePara, + GrpName = paste0("/", Para$Flow$Loc, "/dp0p/data/valvValiNemaTurb"), + SetPara = c("FreqSamp") +) + +# For the sonic anemometer, also get the angle of the z axis +# relative to the North-East-Down coordinate system used +# for sonic anemometer installation (AngNedZaxs) +Para$Sci$dp0p$soni <- def.hdf5.read.para( + DirFileParaLoca = Para$Flow$DirFilePara, + GrpName = paste0("/", Para$Flow$Loc, "/dp0p/data/soni"), + SetPara = c("AngNedZaxs","FreqSamp") +) + +Para$Sci$dp0p$amrs <- def.hdf5.read.para( + DirFileParaLoca = Para$Flow$DirFilePara, + GrpName = paste0("/", Para$Flow$Loc, "/dp0p/data/amrs"), + SetPara = c("FreqSamp") +) + +# Lag$TimeDiff: The time lag to align gas concentration data +# with wind measurements, allowing for travel time from the inlet +# to the gas analyzer. +# The next two commands create the TimeDiff parameter for CO2 +# and H2O, but leave them set to NA. Lag time is calculated by +# eddy4R.base::def.lag(). If you prefer to set it manually, +# the def.lag() function can also set it. +Para$Sci$dp01$co2Turb$RtioMoleDryCo2 <- def.hdf5.read.para( + DirFileParaLoca = Para$Flow$DirFilePara, + GrpName = paste0("/", Para$Flow$Loc, "/dp01/data/co2Turb/", + Para$Flow$LvlTowr, "_30m/rtioMoleDryCo2"), + SetPara = c("Lag$TimeDiff") +) + +Para$Sci$dp01$h2oTurb$RtioMoleDryH2o <- def.hdf5.read.para( + DirFileParaLoca = Para$Flow$DirFilePara, + GrpName = paste0("/", Para$Flow$Loc, "/dp01/data/h2oTurb/", + Para$Flow$LvlTowr, "_30m/rtioMoleDryH2o"), + SetPara = c("Lag$TimeDiff") +) + +# Create a version label for your outputs, using the +# current system time +Para$Flow$VersDp <- paste0(Para$Flow$VersDp, "_", + format(Sys.time(), "%Y%m%d_%H%M%S_%Z")) + +# Create a list of the sampling frequencies of the essential +# instruments, extracted from the input data above. +FreqSamp <- list( + "irgaTurb" = Para$Sci$dp0p$irgaTurb$FreqSamp, + "mfcSampTurb" = Para$Sci$dp0p$mfcSampTurb$FreqSamp, + "valvValiNemaTurb" = ifelse(length(as.numeric(Para$Sci$dp0p$valvValiNemaTurb$FreqSamp))==0, + 0.2, as.numeric(Para$Sci$dp0p$valvValiNemaTurb$FreqSamp)), + "soni" = Para$Sci$dp0p$soni$FreqSamp, + "amrs" = Para$Sci$dp0p$amrs$FreqSamp +) + +``` + +## 4. Variable ranges + +Set plausible ranges for the input variables, to be tested on ingest. +Then set paths for the working directory. + +```{r range} + +# Create an empty list for range values. +Rng <- list() + +# Set ranges for gas analyzer variables: +# densMoleCo2: CO2 molar density, mol m-3 +# densMoleH2o: H2O molar density, mol m-3 +# presAtm: Atmospheric pressure, Pa +# presDiff: Difference in pressure, Pa +# rtioMoleDryCo2: Mole ratio of CO2 in air, mol mol-1 +# rtioMoleDryH2o: Mole ratio of H2O in air, mol mol-1 +# tempIn: Temperature of air at inlet, K +# tempOut: Temperature of air at outlet, K +Rng$irgaTurb <- data.frame( + "densMoleCo2" = c(0,30) * 1e-3, + "densMoleH2o" = c(0,1500) * 1e-3, + "presAtm" = c(50,120) * 1e3, + "presDiff" = c(-10,1) * 1e3, + "rtioMoleDryCo2" = c(300,450) * 1e-6, + "rtioMoleDryH2o" = c(0,30) * 1e-3, + "tempIn" = c(220,330), + "tempOut" = c(220,330) +) + +# Set ranges for sonic anemometer variables: +# veloXaxs: Velocity on the x axis, m s-1 +# veloYaxs: Velocity on the y axis, m s-1 +# veloZaxs: Velocity on the z axis, m s-1 +# veloSoni: Speed of sound, m s-1 +Rng$soni <- data.frame( + "veloXaxs"=c(-50,50), + "veloYaxs"=c(-50,50), + "veloZaxs"=c(-10,10), + "veloSoni"=c(300,400) +) + +# Set ranges for attitude and motion reference variables: +# angXaxs: Deviation from the x axis, degree +# angYaxs: Deviation from the y axis, degree +# angZaxs: Deviation from the z axis, degree +Rng$amrs <- data.frame( + "angXaxs"=c(-360,360), + "angYaxs"=c(-360,360), + "angZaxs"=c(-360,360) +) + +# Set directories and file paths +# As written, this vignette uses the default paths. To use custom +# paths, assign the file paths you want to use to the parameters +# Para$Flow$DirWrk, Para$Flow$DirInp, and Para$Flow$DirOut before +# proceeding to the code below. + +# Working directory +# Default: use a temporary working directory on Docker filesystem +if(is.na(Para$Flow$DirWrk)) { + Para$Flow$DirWrk <- tempdir() + + # Optional: create a user-specified working directory, e.g. on host filesystem + } else { + dir.create(Para$Flow$DirWrk, recursive = TRUE, showWarnings = FALSE) + } + +# Directory for input data +# Default: use temporary working directory on Docker filesystem +if(is.na(Para$Flow$DirInp)) { + Para$Flow$DirInp <- paste0(Para$Flow$DirWrk, "/inpRefe") + + # Optional: create user-specified input directory + } else { + dir.create(Para$Flow$DirInp, recursive = TRUE, showWarnings = FALSE) + } + +# Directory for output data +# Default: use temporary working directory on Docker filesystem +if(is.na(Para$Flow$DirOut)) { + Para$Flow$DirOut <- paste0(Para$Flow$DirWrk, "/out") + + # Optional: create user-specified input directory + } else { + dir.create(Para$Flow$DirOut, recursive = TRUE, showWarnings = FALSE) + } + + +``` + +## 5. Read in data! + +We have found in testing that this section may run into trouble if +Docker is not assigned sufficient memory in your system. If you +find that this section hangs or errors out, try opening +Docker -> Preferences -> Advanced and increasing the memory +allotment. + +```{r ingest} + +# Create empty lists for data and quality flags +data <- list() +qfqmFlag <- list() + +# Index for the number of days iterated over, and empty list for outputs +numDate <- 0 +out <- list() + +# Loop over days in input data (in the example data here, there is +# only one day) +for(date in Para$Flow$DateOut) { + numDate <- numDate + 1 + + # Begin: read raw data from HDF5 file + if(Para$Flow$Read == "hdf5") { + + # Create directory structure + dir.create(paste(Para$Flow$DirOut, "/", Para$Flow$Loc, "/", + Para$Flow$VersDp, sep=""), + recursive = TRUE, showWarnings = FALSE) + + # Create empty list for inputs + inp <- list() + + # Loop over instruments + for(Var in c("irgaTurb", "mfcSampTurb", "valvValiNemaTurb", "soni", "amrs")){ + + # Use data read function, assigning results to a temporary variable + tmp <- eddy4R.base::wrap.hdf5.read( + DirInpLoca = Para$Flow$DirInp, + SiteLoca = Para$Flow$Loc, + DateLoca = date, + VarLoca = Var, + FreqLoca = FreqSamp[[Var]], + LvlTowr = Para$Flow$LvlTowr, + RngLoca = Rng, + + # Assign de-spiking parameters: + # widt: WndwDspkBr86 de-spiking median filter window width [s] + # nbin: NumDspkBr86Bin de-spiking histogram bins initial number/step size + # rest: ThshDspkBr86Reso de-spiking resolution threshold + DespLoca = list(widt = 9, + nbin = 2, + rest = 10 + ) + ) + + # Read in quality flags from HDF5 file + if(!Var %in% "valvValiNemaTurb"){ + + tmpQfqm <- eddy4R.base::def.hdf5.read.qfqm( + DirInpLoca = Para$Flow$DirInp, + SiteLoca = Para$Flow$Loc, + DateLoca = date, + VarLoca = Var, + FreqLoca = FreqSamp[[Var]], + LvlTowr = Para$Flow$LvlTowr + ) + + # Remove timestamp from flags, since timestamps will be + # saved elsewhere + tmpQfqm <- tmpQfqm[,grep("time",names(tmpQfqm),invert = T)] + } + + # Copy results from temporary variables to inp + + # Time domain, including unit assignment + if(Var == "irgaTurb") { + inp$time <- ff::as.ffdf.data.frame(data.frame(UTC = tmp$time)) + base::attr(x = inp$time$UTC, which = "unit") <- "YYYY-MM-DD hh:mm:ss.sss" + } + + # Sensor data, including unit assignment + inp$data[[Var]] <- ff::as.ffdf.data.frame(tmp$data) + for(idx in base::names(tmp$data)) + base::attr(x = inp$data[[Var]][[idx]], which = "unit") <- + base::attr(x = tmp$data, which = "unit")[[idx]] + + if(exists("tmpQfqm")) inp$qfqm[[Var]] <- ff::as.ffdf.data.frame(tmpQfqm) + + # Remove temporary variables + rm(tmp) + if(exists("tmpQfqm")) + rm(tmpQfqm) + invisible(gc()) + + # End loop over instruments + }; rm(Var) + + # Calculate derived quantities: daily extent, native resolution + inp <- eddy4R.base::wrap.derv.prd.day( + inpList = inp, + ZoneTime = Para$Sci$ZoneTime, + AngZaxsSoniInst = Para$Sci$dp0p$soni$AngNedZaxs + ) + + # Print status message + print(paste0(format(Sys.time(), "%F %T"), ": dataset ", date, + ": derived quantities calculated (daily extent, native resolution)")) + + # End of raw data read + } + + # Assign daily data and attributes to file-backed objects + # to keep RAM footprint small + # If loop is on the first day, create the attributes: + if(numDate == 1) { + + # IRGA + data$irgaTurb <- inp$data$irgaTurb + qfqmFlag$irgaTurb <- inp$qfqm$irgaTurb + + # MFC + data$mfcSampTurb <- inp$data$mfcSampTurb + qfqmFlag$mfcSampTurb <- inp$qfqm$mfcSampTurb + + # Sonic anemometer + data$soni <- inp$data$soni + qfqmFlag$soni <- inp$qfqm$soni + + # AMRS + data$amrs <- inp$data$amrs + qfqmFlag$amrs <- inp$qfqm$amrs + + # Time objects + data$time <- inp$time + qfqmFlag$time <- inp$time + + # If loop is on any day after the first, append the attributes: + } else { + + # IRGA + data$irgaTurb <- ffbase::ffdfappend(x = data$irgaTurb, + dat = inp$data$irgaTurb) + qfqmFlag$irgaTurb <- ffbase::ffdfappend(x =qfqmFlag$irgaTurb, + dat = inp$qfqm$irgaTurb) + + # MFC + data$mfcSampTurb <- ffbase::ffdfappend(x = data$mfcSampTurb, + dat = inp$data$mfcSampTurb) + qfqmFlag$mfcSampTurb <- ffbase::ffdfappend(x = qfqmFlag$mfcSampTurb, + dat = inp$qfqm$mfcSampTurb) + + # valvValiNemaTurb + data$valvValiNemaTurb <- ffbase::ffdfappend(x = data$valvValiNemaTurb, + dat = inp$data$valvValiNemaTurb) + qfqmFlag$valvValiNemaTurb <- ffbase::ffdfappend(x = qfqmFlag$valvValiNemaTurb, + dat = inp$qfqm$valvValiNemaTurb) + + # Sonic anemometer + data$soni <- ffbase::ffdfappend(x = data$soni, dat = inp$data$soni) + qfqmFlag$soni <- ffbase::ffdfappend(x =qfqmFlag$soni, dat = inp$qfqm$soni) + + # AMRS + data$amrs <- ffbase::ffdfappend(x = data$amrs, dat = inp$data$amrs) + qfqmFlag$amrs <- ffbase::ffdfappend(x =qfqmFlag$amrs, dat = inp$qfqm$amrs) + + # Time objects + data$time <- ffbase::ffdfappend(x = data$time, dat = inp$time) + qfqmFlag$time <- ffbase::ffdfappend(x =qfqmFlag$time, dat = inp$time) + + # End attributes assignment + } + + # Remove temporary list of input variables + inp <- NULL + inpQfqm <- NULL + invisible(gc()) + +# End loop +} + +``` + + +## 6. Begin data analysis. + +The first step is to get the half-hourly indices used to extract +data from the file-backed objects into internal memory as a list +of data.frames. Then, the lag time correction is applied to the gas +analyzer (IRGA) data, based on the sonic anemometer vertical velocity, +using the eddy4R.base::def.lag() function. After the lag correction +has been applied, the half-hourly derived data sub-products for relative +humidity and dewpoint temperature are calculated. + +Then, the input data that are provided as NEON Level 0 prime data products (high frequency raw data that has been time regularized and units converted) are +subsetted, and naming syntax is changed to match +NEON Level 1 data product output conventions. +eddy4R.base::wrap.dp01.agr.prd() is used to calculate the 1-minute averaged +data and quality metrics. Finally, we calculate 30-minute data using +eddy4R.base::wrap.dp01() and determine the quality metrics and final quality +flag using eddy4R.base::wrap.dp01.qfqm.ecte(). + +```{r process} + +# Kick off with a time stamp when processing starts +print(paste0(format(Sys.time(), "%F %T"), ": dataset ", date, + " derived quantities (vignette) begin")) + +# Create empty list for working parameters and variables +wrk <- list() + +# Create empty list for quality flag/quality metric data +qfqm <- list() + +# Set begin and end time for each 30-minute averaging interval, +# for each instrument system +invisible(lapply(names(data), function(x) { + if(x == "amrs") { + wrk$idx[[x]] <<- eddy4R.base::def.idx.agr(time = data$amrs$time, + PrdAgr = 1800, + FreqLoca = 40) + } else { + wrk$idx[[x]] <<- eddy4R.base::def.idx.agr(time = data$time$UTC, + PrdAgr = 1800, + FreqLoca = 20) + }})) + +# If Deve flag, meaning Development, is set to TRUE, only run a +# small number of iterations for testing purposes. Otherwise +# iterate over all variables and time periods. This vignette +# sets Deve=TRUE. +if (Para$Flow$Deve == TRUE) { + iter <- 10 + } else { + iter <- max(sapply(names(wrk$idx), + function(x) length(wrk$idx[[x]]$idxBgn))) + } + +# Another time stamp: Loop start +print(paste0(format(Sys.time(), "%F %T"), ": dataset ", + date, " DP01 calculation begin")) +numAgr <- 0 + +for(idxAgr in 1:iter) { + + numAgr <- numAgr + 1 + + # Create an identifier for the loop iterations + lvlAgr <- paste0("numAgr", ifelse(numAgr < 10, + paste0("0", numAgr), + numAgr)) + + # Create empty list for data + wrk$data <- list() + + # Loop over sensor systems to grab the data indices for the current aggregation period (i.e. 30 minute period of data). + for(idxSens in names(data)) { + wrk$data[[idxSens]] <- data[[idxSens]][wrk$idx[[idxSens]]$idxBgn[idxAgr]: + wrk$idx[[idxSens]]$idxEnd[idxAgr],] + wrk$qfqm[[idxSens]] <- qfqmFlag[[idxSens]][wrk$idx[[idxSens]]$idxBgn[idxAgr]: + wrk$idx[[idxSens]]$idxEnd[idxAgr],] + + # Assign units for each variable, from metadata + for(idxVar in base::names(wrk$data[[idxSens]])) { + + base::attr(x = wrk$data[[idxSens]][[idxVar]], which = "unit") <- + base::attr(x = data[[idxSens]][[idxVar]], which = "unit") + + }; rm(idxVar) + + }; rm(idxSens) + + # Lag time correction + # Select variables to be lagged + var <- c("rtioMoleDryCo2", "rtioMoleDryH2o", "rtioMassH2o", "presH2o") + + # Loop over lag correction variables + tmpRun <- 0 + for(idxVar in var) { + + tmpRun <- tmpRun + 1 + + # Is lag pre-determined or calculated? + # If lag is calculated: + if((base::length(base::grep(pattern = "CO2", + x = idxVar, + ignore.case = TRUE)) > 0 && + is.na(Para$Sci$dp01$co2Turb$RtioMoleDryCo2$`Lag$TimeDiff`)) | + (base::length(base::grep(pattern = "H2O", + x = idxVar, ignore.case = TRUE)) > 0 && + is.na(Para$Sci$dp01$h2oTurb$RtioMoleDryH2o$`Lag$TimeDiff`))) { + + # Calculate lag + lag <- def.lag(refe = wrk$data$soni$veloZaxs, + meas = wrk$data$irgaTurb[[idxVar]], + lagMax = 2 * FreqSamp$irgaTurb, + lagCnst = TRUE, + # Only negative lags permitted + lagNgtvPstv = c("n", "p", "np")[1], + lagAll = TRUE, + freq = FreqSamp$irgaTurb, + hpf = TRUE) + + } else { + + # If lag is pre-determined: + lag <- list() + lag$lag <- ifelse(base::length(base::grep(pattern = "CO2", + x = idxVar, + ignore.case = TRUE)) > 0, + Para$Sci$dp01$co2Turb$RtioMoleDryCo2$`Lag$TimeDiff`, + Para$Sci$dp01$h2oTurb$RtioMoleDryH2o$`Lag$TimeDiff`) + lag$corrCros <- NaN + + } + + # Shift data according to lag time + tmpAttr <- attributes(wrk$data$irgaTurb[[idxVar]])$unit + if(!is.na(lag$lag)) { + wrk$data$irgaTurb[[idxVar]] <- + DataCombine:::shift(VarVect = wrk$data$irgaTurb[[idxVar]], + shiftBy = - lag$lag, reminder = FALSE) + } + attributes(wrk$data$irgaTurb[[idxVar]])$unit <- tmpAttr; rm(tmpAttr) + + # Store lag times + if(tmpRun == 1) { + tmpLag <- lag$lag / FreqSamp$irgaTurb + tmpCorrCros <- lag$corrCros + } else { + tmpLag <- c(tmpLag, lag$lag / FreqSamp$irgaTurb) + tmpCorrCros <- c(tmpCorrCros, lag$corrCros) + } + + # End of lag correction loop + } + + # Remove temporary variables + names(tmpLag) <- var + tmpLag <- data.frame(t(tmpLag)) + names(tmpCorrCros) <- var + tmpCorrCros <- data.frame(t(tmpCorrCros)) + rm(tmpRun, lag, idxVar, var) + + # Derived variables + # Fast air temperature + wrk$data$soni$T_air_SONIC <- unlist(wrk$data$soni$tempSoni / + (1 + 0.51 * wrk$data$irgaTurb$rtioMassH2o)) + base::attr(x = wrk$data$soni$T_air_SONIC, which = "unit") <- "K" + + # Ambient water vapor saturation pressure + if(!is.na(mean(wrk$data$soni$T_air_SONIC, na.rm=TRUE))) { + wrk$data$irgaTurb$presH2oSatAtm <- + unlist(def.pres.h2o.sat.temp.mag(temp=wrk$data$soni$T_air_SONIC)) + } else { + wrk$data$irgaTurb$presH2oSatAtm <- + rep(NaN, length(wrk$data$soni$T_air_SONIC)) + } + base::attr(x = wrk$data$irgaTurb$presH2oSatAtm, which = "unit") <- "Pa" + + # Ambient relative humidity, including adjustment of partial + # pressure from cell to ambient via Dalton's law + wrk$data$irgaTurb$rhAtm <- + def.rh.pres.h2o.pres.sat.h2o(presH2o = wrk$data$irgaTurb$presH2o, + presH2oSat = wrk$data$irgaTurb$presH2oSatAtm) * + mean(wrk$data$irgaTurb$presAtm, na.rm=TRUE) / + mean(wrk$data$irgaTurb$presSum, na.rm=TRUE) + + # Ambient dew point + wrk$data$irgaTurb$tempDew <- + def.temp.dew.pres.h2o.temp.mag(presH2o = wrk$data$irgaTurb$presH2o, + temp = wrk$data$soni$T_air_SONIC) + + # Assemble data for Level 1 data product generation + + # Create empty temporary lists + # For data + wrk$tmp$data <- list() + + # For quality flags and quality metrics + wrk$tmp$qfqm <- list() + + # Assemble data + # For sonic anemometer + wrk$tmp$data$soni <- data.frame(stringsAsFactors = FALSE, + "veloXaxsErth" = wrk$data$soni$veloXaxs, + "veloYaxsErth" = wrk$data$soni$veloYaxs, + "veloZaxsErth" = wrk$data$soni$veloZaxs, + "veloXaxsYaxsErth" = wrk$data$soni$veloXaxsYaxsErth, + "angZaxsErth" = wrk$data$soni$angZaxsErth, + "tempSoni" = wrk$data$soni$tempSoni, + "tempAir" = wrk$data$soni$T_air_SONIC) + + # For AMRS + wrk$tmp$data$amrs <- data.frame(stringsAsFactors = FALSE, + "angNedXaxs" = wrk$data$amrs$angXaxs, + "angNedYaxs" = wrk$data$amrs$angYaxs, + "angNedZaxs" = wrk$data$amrs$angZaxs) + + # For CO2 + wrk$tmp$data$co2Turb <- data.frame(stringsAsFactors = FALSE, + "rtioMoleDryCo2" = wrk$data$irgaTurb$rtioMoleDryCo2, + "densMoleCo2" = wrk$data$irgaTurb$densMoleCo2, + "presAtm" = wrk$data$irgaTurb$presAtm, + "presSum" = wrk$data$irgaTurb$presSum, + "frt00Samp" = wrk$data$mfcSampTurb$frt00, + "tempAve" = wrk$data$irgaTurb$tempMean) + + # for H2O + wrk$tmp$data$h2oTurb <- data.frame(stringsAsFactors = FALSE, + "rtioMoleDryH2o" = wrk$data$irgaTurb$rtioMoleDryH2o, + "densMoleH2o" = wrk$data$irgaTurb$densMoleH2o, + "tempDew" = wrk$data$irgaTurb$tempDew, + "presAtm" = wrk$data$irgaTurb$presAtm, + "presSum" = wrk$data$irgaTurb$presSum, + "frt00Samp" = wrk$data$mfcSampTurb$frt00, + "tempAve" = wrk$data$irgaTurb$tempMean) + + # Calculate data products + # Calculate 1 and 2 minute data products + wrk$dp01AgrSub[[lvlAgr]] <- eddy4R.base::wrap.dp01.agr.prd(inpList = wrk) + + # 30-minute data products + wrk$dp01[[lvlAgr]] <- eddy4R.base::wrap.dp01( + data = wrk$tmp$data, + idx = c("soni", "amrs", "co2Turb", "h2oTurb") + ) + + # Standard error removed from 1- and 30- minute, it is now part of the ucrt calculation function + lapply(names(wrk$dp01AgrSub[[lvlAgr]]$data), function(idxData){ + wrk$dp01AgrSub[[lvlAgr]]$data[[idxData]]$se <<- NULL + wrk$dp01[[lvlAgr]][[idxData]]$se <<- NULL + }) + + + # Another time stamp: Starting quality processing + print(paste0(format(Sys.time(), "%F %T"), + ": Beginning the qfqm data processing for data in loop...", + idxAgr)) + + # Calculate the quality metrics and determine the final quality flag + wrk$qfqmOut[[lvlAgr]] <- eddy4R.base::wrap.dp01.qfqm.ecte( + qfqm = wrk$qfqm, + idx = c("soni", "amrs", "co2Turb", "h2oTurb"), + MethMeas = "ecte", + RptExpd = TRUE ) + + # Remove temporary files + wrk$data <- NULL + wrk$tmp <- NULL + invisible(gc()) + +# End loop +} +print(paste0(format(Sys.time(), "%F %T"), + ": dataset ", date, + " DP01 calculation complete")) + + +``` + +## 7. Aggregate data and quality metrics + +Now, we aggregate the results from section 6. The first step is to +aggregate the half-hourly sets of data and qfqm. Then, we plot the +final quality flag and its relationship to the alpha and beta quality +metrics. (alpha = fraction of data flagged by sensor and statistical +plausibility tests; beta = fraction of quality flags not available +due to missing data) + +```{r aggregation} + +# Concatenate results using def.dp01.agr.ecte() +out <- eddy4R.base::def.dp01.agr.ecte(inpList = wrk, + MethSubAgr = TRUE, + MethUcrt = FALSE) + + +# Generate qfqm table to be plotted +inpPlot <- data.frame(time = + format(as.POSIXct(out$time$co2Turb$timeBgn, + format="%Y-%m-%d %H:%M:%S"), + format="%H:%M"), + qfFinl = out$qfqm$soni$qfFinl$veloXaxsYaxsErth, + qmAlph = out$qfqm$soni$qmAlph$veloXaxsYaxsErth, + qmBeta = out$qfqm$soni$qmBeta$veloXaxsYaxsErth) + +# Plot final quality flag, alpha metric, and beta metric +library(ggplot2) + +plot = ggplot(inpPlot, aes(time)) + + geom_bar(aes(y = qfFinl, fill= "qfFinl"), stat="identity") + + geom_line(aes(y = qmAlph, group = 1, color = "qmAlph"), + size = 1, linetype = "dashed") + + geom_line(aes(y = qmBeta, group = 2, color = "qmBeta"), + size = 1, linetype = "dashed") + + ggtitle("veloXaxsYaxsErth") + + scale_colour_manual(" ", + values=c("qfFinl" = "black", + "qmAlph" = "blue", + "qmBeta" = "red")) + + scale_fill_manual("",values="black") + + theme(legend.key = element_blank(), + legend.title = element_blank(), + legend.box = "vertical", + plot.title = element_text(size=14, + face="bold.italic", + hjust = 0.5), + axis.title.x = element_text(size=14, face="bold"), + axis.title.y = element_text(size=14, face="bold")) + + ylim(-0.2,1.2) + + labs(y = "qfqm") + +print(plot) + +# Remove temporary files +wrk$dp01 <- NULL +wrk$dp01AgrSub <- NULL +wrk$qfqmOut <- NULL + +``` + +## 8. Format for output + +Lastly, we prepare the data for output and write it to the dp01 +output HDF5 file. We first create the skeleton structure of the +NEON HDF5 file using eddy4R.base::def.hdf5.crte(). We then perform +some packaging of the results to match the NEON HDF5 structure and +write the output to the NEON dp01 HDF5 file. + +```{r format} + +# Drop the quality column (qfqm) after the example; +# these data will be added to the HDF5 structure in +# a future release +lapply(names(out$qfqm), function(x){ + out$qfqm[[x]]$qm <<- NULL +}) + +# Use the def.hdf5.crte() function to generate the +# H5 file in NEON EC format +eddy4R.base::def.hdf5.crte(Date = date, + Site = Para$Flow$Loc, + LvlTowr = Para$Flow$LvlTowr, + DirOut = base::paste0(Para$Flow$DirOut, + "/", Para$Flow$Loc, + "/", Para$Flow$VersDp), + FileOutBase = Para$Flow$FileOutBase, + MethExpd = TRUE) + +# Determine the output filename of the file we just created +FileOut <- base::list.files(path = base::paste0(Para$Flow$DirOut, + "/", Para$Flow$Loc, + "/", Para$Flow$VersDp), + pattern = ".h5", full.names = TRUE) + +# Call the wrapper function wrap.hdf5.wrte.dp01() to package +# and write data to output HDF5 files, just expanded 30 minute data +eddy4R.base::wrap.hdf5.wrte.dp01(inpList = out, + FileIn = base::paste0(Para$Flow$DirInp, + "/","ECTE_dp0p_", + Para$Flow$Loc, "_", + date, ".h5"), + FileOut = FileOut, + SiteLoca = Para$Flow$Loc, + LvlTowr = Para$Flow$LvlTowr, + MethUcrt = FALSE, + MethSubAgr = FALSE) + +``` From 8bf81ebf8173c88c4017eeb4c447068c129b2444 Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 10 Feb 2020 20:06:39 +0000 Subject: [PATCH 019/168] - adding reference coordinate system metadata --- pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R index eb0b85ba..1446f2a7 100755 --- a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R +++ b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R @@ -176,6 +176,9 @@ if(MethDp04 == TRUE){ #Open connection to dp04 data level idDataDp04 <- rhdf5::H5Gopen(idFile,paste0("/", SiteLoca, "/dp04/data/",idxDp04)) + #Output the attributes + rhdf5::h5writeAttribute("North,East,Down (NED)", h5obj = idDataDp04, name = "sysCordRefe") + #Writing flux data to output HDF5 file rhdf5::h5writeDataset.data.frame(obj = rptDp04, h5loc = idDataDp04, name = "stat", DataFrameAsCompound = TRUE) From 3fdadb58b9ce55a9e9b7bbc476022c3194e9da9d Mon Sep 17 00:00:00 2001 From: NDurden Date: Fri, 14 Feb 2020 15:37:40 +0000 Subject: [PATCH 020/168] added 5 min time after the validation end to not include spike in sampling data --- pack/eddy4R.base/R/def.irga.vali.cor.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/def.irga.vali.cor.R b/pack/eddy4R.base/R/def.irga.vali.cor.R index 71408e23..830fedfd 100644 --- a/pack/eddy4R.base/R/def.irga.vali.cor.R +++ b/pack/eddy4R.base/R/def.irga.vali.cor.R @@ -47,6 +47,8 @@ # added time when the real validation begin # Natchaya P-Durden (2020-01-16) # generated NA for rtioMoleDryH2oCor +# Natchaya P-Durden (2020-01-14) +# added 5 min after the validation end ############################################################################################## def.irga.vali.cor <- function( data, @@ -115,7 +117,7 @@ def.irga.vali.cor <- function( if (length(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd[which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$gasType == "qfIrgaTurbValiGas05")]) == 0){ timeBgn <- as.POSIXlt(paste(dateBgn[idx], " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") } else { - timeBgn <- as.POSIXlt(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd[which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$gasType == "qfIrgaTurbValiGas05")]) + timeBgn <- as.POSIXlt(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd[which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$gasType == "qfIrgaTurbValiGas05")]+(60*5.0)) } #time when performing of zero gas is started From 485b16ffb849e1099eed1a843f5d49a0b8f6b324 Mon Sep 17 00:00:00 2001 From: NDurden Date: Tue, 18 Feb 2020 02:53:24 +0000 Subject: [PATCH 021/168] add situation when the gas high is NA --- pack/eddy4R.base/R/def.irga.vali.cor.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/def.irga.vali.cor.R b/pack/eddy4R.base/R/def.irga.vali.cor.R index 830fedfd..47a4911c 100644 --- a/pack/eddy4R.base/R/def.irga.vali.cor.R +++ b/pack/eddy4R.base/R/def.irga.vali.cor.R @@ -114,7 +114,8 @@ def.irga.vali.cor <- function( numDate <- numDate + 1 #time begin and time End to apply coefficient #time when performing of high gas is done - if (length(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd[which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$gasType == "qfIrgaTurbValiGas05")]) == 0){ + if (length(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd[which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$gasType == "qfIrgaTurbValiGas05")]) == 0 || + is.na(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$mean[which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$gasType == "qfIrgaTurbValiGas05")])){ timeBgn <- as.POSIXlt(paste(dateBgn[idx], " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") } else { timeBgn <- as.POSIXlt(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd[which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$gasType == "qfIrgaTurbValiGas05")]+(60*5.0)) @@ -128,6 +129,13 @@ def.irga.vali.cor <- function( timeEnd <- as.POSIXlt(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn[which(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$gasType == "qfIrgaTurbValiGas02")]-(60*3.5)) } + # #fail safe to make sure timeBgn less than timeEnd + # if (difftime(timeBgn, timeEnd) >= 0){ + # timeBgn <- as.POSIXlt(paste(dateBgn[idx], " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") + # } else { + # timeBgn <- timeBgn + # } + #output time timeOut <- as.POSIXlt(seq.POSIXt( from = as.POSIXlt(timeBgn, format="%Y-%m-%d %H:%M:%OS", tz="UTC"), From 9a708ac13f9e8245158baadc273faf49c0e2473d Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Thu, 20 Feb 2020 11:34:58 -0700 Subject: [PATCH 022/168] remove cybiDflt method from def.rglr, and add method for 'instantaneous regularization' --- pack/eddy4R.base/DESCRIPTION | 2 +- pack/eddy4R.base/R/def.rglr.R | 94 +++++------------------ pack/eddy4R.base/man/def.mtch.out.refe.Rd | 2 +- pack/eddy4R.base/man/def.rglr.Rd | 18 ++--- pack/eddy4R.qaqc/R/def.agr.file.dp00.R | 2 +- 5 files changed, 31 insertions(+), 87 deletions(-) diff --git a/pack/eddy4R.base/DESCRIPTION b/pack/eddy4R.base/DESCRIPTION index a09c94b2..387e0bdd 100644 --- a/pack/eddy4R.base/DESCRIPTION +++ b/pack/eddy4R.base/DESCRIPTION @@ -1,6 +1,6 @@ Package: eddy4R.base Title: Eddy-covariance calculation for R: Base package -Version: 0.2.20 +Version: 0.2.21 Authors@R: c( person("Stefan", "Metzger", email = "eddy4R.info@gmail.com", role = c("aut", "cre")), person("David", "Durden", email = "ddurden@battelleecology.org", role = c("aut")), person("Natchaya", "Pingintha-Durden", email = "ndurden@battelleecology.org", role = c("aut")), diff --git a/pack/eddy4R.base/R/def.rglr.R b/pack/eddy4R.base/R/def.rglr.R index 52b15ce2..861030e2 100644 --- a/pack/eddy4R.base/R/def.rglr.R +++ b/pack/eddy4R.base/R/def.rglr.R @@ -12,16 +12,14 @@ #' @param timeMeas A vector containing the observation times. Of class "POSIXlt" including timezone attribute, and of the same length as \code{dataMeas}. [-] #' @param dataMeas A named data.frame containing the observations. Columns may be of class "numeric" or "integer", and of the same length as \code{timeMeas}. Columns of classes other than "numeric" or "integer" are removed and not included in the returned \code{dataRegl}. [user-defined] #' @param unitMeas A vector containing the unit of each column in \code{dataMeas}. Of class "character". It is recommended to conform to the "unit representation" guidelines documented in the eddy4R.base package. -#' @param BgnRglr Desired begin time for the regularized dataset. Of class "POSIXlt" including timezone attribute, and \code{length(BgnRglr) = 1}. This input is not used in the "cybiDflt" method. [-] -#' @param EndRglr Desired end time for the regularized dataset. Of class "POSIXlt" including timezone attribute, and \code{length(EndRglr) = 1}. This input is not used in the "cybiDflt" method. [-] -#' @param TzRglr Desired timezone for the regularized dataset. Of class "character" and \code{length(TzRglr) = 1}, defaults to the same timezone as \code{BgnRglr}. For the "cybiDflt" method, the same time zone as timeMeas is used. [-] +#' @param BgnRglr Desired begin time for the regularized dataset. Of class "POSIXlt" including timezone attribute, and \code{length(BgnRglr) = 1}. [-] +#' @param EndRglr Desired end time for the regularized dataset. Of class "POSIXlt" including timezone attribute, and \code{length(EndRglr) = 1}. [-] +#' @param TzRglr Desired timezone for the regularized dataset. Of class "character" and \code{length(TzRglr) = 1}, defaults to the same timezone as \code{BgnRglr}. [-] #' @param FreqRglr Desired frequency of the regularized dataset. Of class "numeric" or "integer" and \code{length(FreqRglr) = 1}. [Hz] #' @param MethRglr Switch for different regularization methods. Of class "character", currently defaults to "CybiEc". [-] \cr -#' Method "cybiDflt" implements the default for metereological variable regularization performed by NEON CI. Namely, a new time series is created -#' from the first measurement time, rounded toward zero, using the expected data frequency. The first measurement falling -#' in between one time stamp and the next is assigned to the first of these, and all other measurements falling in this range are ignored.\cr #' Method "CybiEc" implements the default regularization method for eddy-covariance processing utilized CI. The procedure #' is documented in NEON.DOC.001069.\cr +#' Method "CybiEcTimeMeas" is a modification of CybiEc that replaces the regularized timestamp with the actual value of \code{timeMeas} for the observation (if any) that was selected following the binning options specified in \code{WndwRglr} and \code{idxWndw}. \cr #' Method "zoo" implements the regularization method using the zoo::na.approx function. This method can only handle up to millisecond precision (PrcsSec=3) #' @param WndwRglr Position of the window for binning in the "CybiEc" method. \code{WndwRglr} can be centered [Cntr], leading [Lead], or trailing [Trlg] (defaults to centered).\cr #' @param IdxWndw Determines which observation to allocate to a bin if multiple observations fall into a single bin when using the "CybiEc" method.. \code{IdxWndw} can be set to closest [Clst], first [IdxWndwMin], or last [IdxWndwMax] (defaults to closest).\cr @@ -32,7 +30,7 @@ #' @references #' License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007. \cr -#' NEON.DOC.001069 Preprocessing ATBD: The ATBD that describes the CybiEc and cybiDflt regularization methods. \cr +#' NEON.DOC.001069 Preprocessing ATBD: The ATBD that describes the CybiEc regularization method. \cr #' #' @keywords regularization, equidistant, preprocessing @@ -104,6 +102,9 @@ # Added error checking for empty data when using cybiDflt method # Cove Sturtevant (2018-05-23) # Changed term 'pos' to 'idx' for single indices, to 'set' for multiple indices +# Cove Sturtevant (2020-02-18) +# Removed MethRglr "cybiDflt", as it is no longer used by NEON CI (CybiEc is used) +# Added MethRglr "CybiEcTimeMeas" ############################################################################################## def.rglr <- function( @@ -114,7 +115,7 @@ def.rglr <- function( EndRglr=NULL, TzRglr = base::attributes(BgnRglr)$tzone, FreqRglr, - MethRglr= c("CybiEc", "cybiDflt", "zoo")[1], + MethRglr= c("CybiEc", "CybiEcTimeMeas", "zoo")[1], WndwRglr = c("Cntr", "Lead", "Trlg")[1], IdxWndw = c("Clst","IdxWndwMin","IdxWndwMax")[1], PrcsSec = 6 @@ -132,23 +133,13 @@ def.rglr <- function( } # Error-check - if(!(MethRglr %in% c("zoo","cybiDflt","CybiEc"))){ - stop(base::paste0('Unrecognized value for input MethRglr. Options are "zoo","cybiDflt","CybiEc" (case-sensitive)')) + if(!(MethRglr %in% c("zoo","CybiEcTimeMeas","CybiEc"))){ + stop(base::paste0('Unrecognized value for input MethRglr. Options are "zoo","CybiEc", and "CybiEcTimeMeas" (case-sensitive)')) } - # CI uses the first value as the starting point for the regularization, rounding down to the nearest second - # Note: the rounding down aspect is a change implemented week of 1 May 2016. Previously the starting point was - # the exact time (to the decimal second). - if(MethRglr == "cybiDflt"){ - BgnRglr <- base::as.POSIXlt(base::trunc.POSIXt(timeMeas[1],units="secs")) - EndRglr <- base::as.POSIXlt(utils::tail(timeMeas,1) + 1/FreqRglr) - - if(base::is.null(TzRglr)) { - TzRglr <- base::attributes(BgnRglr)$tzone - } - } + - if(MethRglr %in% c("zoo","cybiDflt","CybiEc")){ + if(MethRglr %in% c("zoo","CybiEcTimeMeas","CybiEc")){ if(!("POSIXlt" %in% base::class(timeMeas))){ stop("Input 'timeMeas' must be in POSIXlt") } @@ -214,14 +205,7 @@ def.rglr <- function( if(MethRglr == 'zoo' && PrcsSec > 3){ PrcsSec <- 3 } - - # Quit if there is no data and we are using cybiDflt method, since the cybiDflt method - # relies on the first data point to generate the time seq - if(base::length(timeMeas) == 0 && MethRglr == 'cybiDflt'){ - rpt <- base::list(TzRglr=NULL,FreqRglr=FreqRglr,MethRglr=MethRglr,timeRglr=timeMeas,dataRglr=dataMeas) - return(rpt) - } - + # POSIX time has some issues with sub-second precision, often rounding down to a lower value without an # obvious reason. As a result, use numeric representation of time and round to a specified precision. # When returning to POSIX time, ensure use of POSIXlt so that down-rounding does not occur. @@ -308,52 +292,9 @@ def.rglr <- function( # end MethRglr == zoo } - - - # Regularize time series according to default NEON cyber infrastructure (CI) L0 -> L0' procedure. - # NEON CI transforms raw L0 data into a regularized time series according to the expected data frequency. - # Namely, a new time series is created from the first measurement time, rounded toward zero, using the - # expected data frequency. The first measurement falling in between one time stamp and the next is assigned - # to the first of these, and all other measurements falling in this range are ignored. - # This code replicates this procedure in order to compare expected output to that produced by CI. - if(MethRglr == "cybiDflt") { - - # Which time bin does each measurement time fit into? - idxRglr <- base::.bincode(timeMeasNumc,timeRglrNumc,right=FALSE) # which bin? - dataMeas <- base::subset(dataMeas,!base::is.na(idxRglr),select=1:numVar) # Get rid of anomalous times/data not fitting in any bin - timeMeasNumc <- base::subset(timeMeasNumc,!base::is.na(idxRglr)) - idxRglr <- base::subset(idxRglr,!base::is.na(idxRglr)) - dupl <- base::duplicated(idxRglr) # which fall into an already occupied bin? - - # intialize regularized timeseries - if(base::is.character(dataMeas$data) || base::is.factor(dataMeas$data)){ - dataRglr <- base::matrix(data="NA",nrow=length(timeRglrNumc)-1,ncol=numVar) # initialize - } else { - dataRglr <- base::matrix(data=NA*1.5,nrow=length(timeRglrNumc)-1,ncol=numVar) # initialize - } - - # Pull the first value that falls within each bin - for(idxVar in 1:numVar){ - # place the first value falling into each bin - dataRglr[idxRglr[!dupl],idxVar] <- dataMeas[which(!dupl),idxVar] - } - dataRglr <- base::as.data.frame(dataRglr,stringsAsFactors=FALSE) # Make data frame - base::names(dataRglr) <- nameVar # Assign names same as dataMeas - - # Report output - rpt$timeRglr <- base::as.POSIXlt(timeRglr) - - rpt$timeRglr <- rpt$timeRglr[-length(rpt$timeRglr)] - rpt$dataRglr <- dataRglr - - # assign unit attributes - base::attributes(rpt$dataRglr)$unit <- unitMeas - } - - # Method "CybiEc" implements the default regularization method for eddy-covariance # processing utilized CI. The procedure is documented in NEON.DOC.001069. - if(MethRglr == "CybiEc") { + if(MethRglr %in% c("CybiEc","CybiEcTimeMeas")) { # delete rows with times that are duplicates of rows with smaller indices set01 <- !base::duplicated(timeMeasNumc) @@ -429,6 +370,11 @@ def.rglr <- function( } base::names(dataRglr) <- nameVar # Assign names same as dataMeas + # For CybiEcTimeMeas, replace the regularized timestamps with the actual timestamps of the measured values selected for each bin + if(MethRglr == 'CybiEcTimeMeas'){ + rpt$timeRglr[idxRglr[!dupl]] <- timeMeas[which(!dupl)] + } + # Report output rpt$dataRglr <- dataRglr # assign unit attributes diff --git a/pack/eddy4R.base/man/def.mtch.out.refe.Rd b/pack/eddy4R.base/man/def.mtch.out.refe.Rd index a41ea9b6..8b9d84c6 100644 --- a/pack/eddy4R.base/man/def.mtch.out.refe.Rd +++ b/pack/eddy4R.base/man/def.mtch.out.refe.Rd @@ -20,7 +20,7 @@ Currently none } \description{ Function definition. A function to compare the file output from a workflow to a reference output file -to ensure that changes during development to functions called by the workflow have not impacted the +to ensure that changes during development to functions called by the workflow have not impacted the results.\cr The function reads in the new data produced in the tmp directory and compares the first 10 lines to the reference output data. } diff --git a/pack/eddy4R.base/man/def.rglr.Rd b/pack/eddy4R.base/man/def.rglr.Rd index a564962a..6c8c6f76 100644 --- a/pack/eddy4R.base/man/def.rglr.Rd +++ b/pack/eddy4R.base/man/def.rglr.Rd @@ -7,9 +7,9 @@ def.rglr(timeMeas, dataMeas, unitMeas = base::attributes(dataMeas)$unit, BgnRglr = NULL, EndRglr = NULL, TzRglr = base::attributes(BgnRglr)$tzone, FreqRglr, - MethRglr = c("CybiEc", "cybiDflt", "zoo")[1], WndwRglr = c("Cntr", - "Lead", "Trlg")[1], IdxWndw = c("Clst", "IdxWndwMin", "IdxWndwMax")[1], - PrcsSec = 6) + MethRglr = c("CybiEc", "CybiEcTimeMeas", "zoo")[1], + WndwRglr = c("Cntr", "Lead", "Trlg")[1], IdxWndw = c("Clst", + "IdxWndwMin", "IdxWndwMax")[1], PrcsSec = 6) } \arguments{ \item{timeMeas}{A vector containing the observation times. Of class "POSIXlt" including timezone attribute, and of the same length as \code{dataMeas}. [-]} @@ -18,20 +18,18 @@ def.rglr(timeMeas, dataMeas, unitMeas = base::attributes(dataMeas)$unit, \item{unitMeas}{A vector containing the unit of each column in \code{dataMeas}. Of class "character". It is recommended to conform to the "unit representation" guidelines documented in the eddy4R.base package.} -\item{BgnRglr}{Desired begin time for the regularized dataset. Of class "POSIXlt" including timezone attribute, and \code{length(BgnRglr) = 1}. This input is not used in the "cybiDflt" method. [-]} +\item{BgnRglr}{Desired begin time for the regularized dataset. Of class "POSIXlt" including timezone attribute, and \code{length(BgnRglr) = 1}. [-]} -\item{EndRglr}{Desired end time for the regularized dataset. Of class "POSIXlt" including timezone attribute, and \code{length(EndRglr) = 1}. This input is not used in the "cybiDflt" method. [-]} +\item{EndRglr}{Desired end time for the regularized dataset. Of class "POSIXlt" including timezone attribute, and \code{length(EndRglr) = 1}. [-]} -\item{TzRglr}{Desired timezone for the regularized dataset. Of class "character" and \code{length(TzRglr) = 1}, defaults to the same timezone as \code{BgnRglr}. For the "cybiDflt" method, the same time zone as timeMeas is used. [-]} +\item{TzRglr}{Desired timezone for the regularized dataset. Of class "character" and \code{length(TzRglr) = 1}, defaults to the same timezone as \code{BgnRglr}. [-]} \item{FreqRglr}{Desired frequency of the regularized dataset. Of class "numeric" or "integer" and \code{length(FreqRglr) = 1}. [Hz]} \item{MethRglr}{Switch for different regularization methods. Of class "character", currently defaults to "CybiEc". [-] \cr -Method "cybiDflt" implements the default for metereological variable regularization performed by NEON CI. Namely, a new time series is created -from the first measurement time, rounded toward zero, using the expected data frequency. The first measurement falling -in between one time stamp and the next is assigned to the first of these, and all other measurements falling in this range are ignored.\cr Method "CybiEc" implements the default regularization method for eddy-covariance processing utilized CI. The procedure is documented in NEON.DOC.001069.\cr +Method "CybiEcTimeMeas" is a modification of CybiEc that replaces the regularized timestamp with the actual value of \code{timeMeas} for the observation (if any) that was selected following the binning options specified in \code{WndwRglr} and \code{idxWndw}. \cr Method "zoo" implements the regularization method using the zoo::na.approx function. This method can only handle up to millisecond precision (PrcsSec=3)} \item{WndwRglr}{Position of the window for binning in the "CybiEc" method. \code{WndwRglr} can be centered [Cntr], leading [Lead], or trailing [Trlg] (defaults to centered).\cr} @@ -90,7 +88,7 @@ def.rglr( } \references{ License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007. \cr -NEON.DOC.001069 Preprocessing ATBD: The ATBD that describes the CybiEc and cybiDflt regularization methods. \cr +NEON.DOC.001069 Preprocessing ATBD: The ATBD that describes the CybiEc regularization method. \cr } \seealso{ ?zoo:na.approx, ?stats::approx diff --git a/pack/eddy4R.qaqc/R/def.agr.file.dp00.R b/pack/eddy4R.qaqc/R/def.agr.file.dp00.R index 80572c16..e67388de 100644 --- a/pack/eddy4R.qaqc/R/def.agr.file.dp00.R +++ b/pack/eddy4R.qaqc/R/def.agr.file.dp00.R @@ -68,7 +68,7 @@ for(idxFile in 1:base::length(nameFile)){ data <- data[[2]] # Regularize time series. - data <- eddy4R.base::def.rglr(timeMeas=timeInp,dataMeas=as.data.frame(data),unitMeas=unitVar[idxFile],FreqRglr=Freq,MethRglr="cybiDflt") + data <- eddy4R.base::def.rglr(timeMeas=timeInp,dataMeas=as.data.frame(data),unitMeas=unitVar[idxFile],FreqRglr=Freq,MethRglr="CybiEc",WndwRglr='Trlg',IdxWndw='IdxWndwMin') timeRglr[[idxFile]] <- data$timeRglr dataRglr[[idxFile]] <- data$dataRglr[[1]] From 986386c2d21c55ad738dc804d54fd77b06ec7562 Mon Sep 17 00:00:00 2001 From: NDurden Date: Thu, 27 Feb 2020 20:53:33 +0000 Subject: [PATCH 023/168] update wrapper to do simple regression when only 2 input data available --- pack/eddy4R.base/R/wrap.irga.vali.R | 53 ++++++++++++++++++----------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index 3be00029..4f0b52c4 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -420,26 +420,39 @@ wrap.irga.vali <- function( #get the temporary valiData table without NA tmpValiData <- na.omit(valiData[[idxDate]][[idxData]]) - #report NA for regression coefficients if input validation data less than 3 values - if (nrow(tmpValiData) < 3){ - - # if (length(valiData[[idxDate]][[idxData]]$mean) < 4 | - # sum(is.na(valiData[[idxDate]][[idxData]]$mean)) > 0 | sum(is.na(valiData[[idxDate]][[idxData]]$se)) >0 | - # sum(is.na(valiData[[idxDate]][[idxData]]$rtioMoleDryCo2Refe)) > 0 | sum(is.na(valiData[[idxDate]][[idxData]]$rtioMoleDryCo2RefeSe)) > 1){ - tmpCoef[[idxDate]][[idxData]][,] <- NA - } else{ - #x are sensor readings; y are reference gas values - rtioMoleDryCo2Mlfr <- deming::deming(rtioMoleDryCo2Refe[1:nrow(tmpValiData)] ~ mean[1:nrow(tmpValiData)], data = tmpValiData, - xstd = se[1:nrow(tmpValiData)], ystd = rtioMoleDryCo2RefeSe[1:nrow(tmpValiData)]) - #write output to table - #intercept - tmpCoef[[idxDate]][[idxData]][1,1] <- rtioMoleDryCo2Mlfr$coefficients[[1]] - #slope - tmpCoef[[idxDate]][[idxData]][2,1] <- rtioMoleDryCo2Mlfr$coefficients[[2]] - #se - tmpCoef[[idxDate]][[idxData]][,2] <- sqrt(diag(rtioMoleDryCo2Mlfr$variance)) - #scale - tmpCoef[[idxDate]][[idxData]][1,3] <- rtioMoleDryCo2Mlfr$sigma + #report NA for regression coefficients if input validation data less than 2 values + if (nrow(tmpValiData) < 2){ + tmpCoef[[idxDate]][[idxData]][,] <- NA + } + + #do simple linear regression when there are only 2 input data + if (nrow(tmpValiData) == 2){ + rtioMoleDryCo2Mlfr <- stats::lm(rtioMoleDryCo2Refe ~ mean, data = tmpValiData) + #write output to table + #intercept + tmpCoef[[idxDate]][[idxData]][1,1] <- rtioMoleDryCo2Mlfr$coefficients[[1]] + #slope + tmpCoef[[idxDate]][[idxData]][2,1] <- rtioMoleDryCo2Mlfr$coefficients[[2]] + #se + tmpCoef[[idxDate]][[idxData]][,2] <- NA + #scale + tmpCoef[[idxDate]][[idxData]][1,3] <- NA + } + + #do MLFR if more than 2 input data avaliable + if (nrow(tmpValiData) > 2){ + #x are sensor readings; y are reference gas values + rtioMoleDryCo2Mlfr <- deming::deming(rtioMoleDryCo2Refe[1:nrow(tmpValiData)] ~ mean[1:nrow(tmpValiData)], data = tmpValiData, + xstd = se[1:nrow(tmpValiData)], ystd = rtioMoleDryCo2RefeSe[1:nrow(tmpValiData)]) + #write output to table + #intercept + tmpCoef[[idxDate]][[idxData]][1,1] <- rtioMoleDryCo2Mlfr$coefficients[[1]] + #slope + tmpCoef[[idxDate]][[idxData]][2,1] <- rtioMoleDryCo2Mlfr$coefficients[[2]] + #se + tmpCoef[[idxDate]][[idxData]][,2] <- sqrt(diag(rtioMoleDryCo2Mlfr$variance)) + #scale + tmpCoef[[idxDate]][[idxData]][1,3] <- rtioMoleDryCo2Mlfr$sigma } }#end of for loop of idxData #report output From 8fc05c6dde17b12e73d9ab0db654e22174c59300 Mon Sep 17 00:00:00 2001 From: NDurden Date: Fri, 28 Feb 2020 15:38:32 +0000 Subject: [PATCH 024/168] added logical statement to not apply filters (slope, offset, and scale) if they are equal to FALSE --- pack/eddy4R.base/R/def.irga.vali.cor.R | 85 +++++++++++++++++++------- 1 file changed, 63 insertions(+), 22 deletions(-) diff --git a/pack/eddy4R.base/R/def.irga.vali.cor.R b/pack/eddy4R.base/R/def.irga.vali.cor.R index 47a4911c..49a64bdd 100644 --- a/pack/eddy4R.base/R/def.irga.vali.cor.R +++ b/pack/eddy4R.base/R/def.irga.vali.cor.R @@ -10,9 +10,10 @@ #' @param DateProc A vector of class "character" containing the processing date. #' @param valiData List consisting of descriptive statistics (mean, min, max, vari, numSamp, se) of CO2 dry mole concentration during performing validation and CO2 dry mole concentration of reference gases. #' @param coef List consists of linear regression coefficients (slope and offset) for DateProc - 1, DateProc, and DateProc + 1. -#' @param valiCrit A logical stating if there are more than one validation occurred within DateProc. Defaut to FALSE. -#' @param ScalMax Maximum scale value (resulted from maximum-likelihood fitting of a functional relationship (MLFR)). Defaults to 20. -#' @param FracSlpMax Maximum fraction of slope value (resulted from maximum-likelihood fitting of a functional relationship (MLFR)). Defaults to 0.1. +#' @param valiCrit A logical stating if there are more than one validation occurred within DateProc. +#' @param ScalMax Maximum scale value. The validation correction will not apply if scale (resulted from maximum-likelihood fitting of a functional relationship (MLFR)) is greater than ScalMax or ScalMax = FALSE. Defaults to FALSE. +#' @param FracSlpMax Maximum fraction of slope value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the FracSlpMax or FracSlpMax = FALSE. Defaults to FALSE. +#' @param OfstMax Maximum offset value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the OfstMax (unit in mol mol-1) or OfstMax = FALSE. Defaults to FALSE. #' @param Freq Measurement frequency. Defaults to 20. [Hz] #' @return @@ -49,6 +50,8 @@ # generated NA for rtioMoleDryH2oCor # Natchaya P-Durden (2020-01-14) # added 5 min after the validation end +# Natchaya P-Durden (2020-02-28) +# added logical statement to not apply filters (slope, offset, and scale) if they are equal to FALSE ############################################################################################## def.irga.vali.cor <- function( data, @@ -56,8 +59,9 @@ def.irga.vali.cor <- function( coef, valiData, valiCrit = FALSE, - ScalMax = 20, - FracSlpMax = 0.1, + ScalMax = FALSE, + FracSlpMax = FALSE, + OfstMax = FALSE, Freq = 20 ){ #adding library @@ -71,27 +75,64 @@ def.irga.vali.cor <- function( Date <- c(base::as.Date(DateProc) - 1, base::as.Date(DateProc), base::as.Date(DateProc) + 1) Date <- as.character(Date) Freq <- Freq #measurement frequency (20 Hz) - #threshold - #minimum and maximum slope - minSlp <- 1 - FracSlpMax - maxSlp <- 1 + FracSlpMax - #scale - ScalMax <- ScalMax - #check if the slope and scale are meet the criteria if not replace them with NA - #default slope less than or equal to +/-10% (0.9 <= slope <=1.10) + + #create a list to keep all filters + filt <- list() + filt$ScalMax <- ScalMax + filt$FracSlpMax <- FracSlpMax + filt$OfstMax <- OfstMax + + + #check if filter will apply. for (idxDate in Date){ #idxDate <- Date[1] for (idxData in names(coef[[idxDate]])){ #idxData <- names(coef[[idxDate]])[1] - if (!is.na(coef[[idxDate]][[idxData]]$coef[2]) & !is.na(coef[[idxDate]][[idxData]]$scal[1]) & coef[[idxDate]][[idxData]]$coef[2] >= minSlp & coef[[idxDate]][[idxData]]$coef[2] <= maxSlp & coef[[idxDate]][[idxData]]$scal[1] <= ScalMax){ - coef[[idxDate]][[idxData]] <- coef[[idxDate]][[idxData]] - }else{ - coef[[idxDate]][[idxData]]$coef <- NA - coef[[idxDate]][[idxData]]$se <- NA - coef[[idxDate]][[idxData]]$scal <- NA - } - } - } + for (idxFilt in names(filt)){ + #idxFilt <- names(filt)[1] + if (filt[[idxFilt]] == FALSE){ + coef[[idxDate]][[idxData]] <- coef[[idxDate]][[idxData]] + } else{#testing the filters + if (idxFilt == "ScalMax"){ + if (!is.na(coef[[idxDate]][[idxData]]$scal[1]) & coef[[idxDate]][[idxData]]$scal[1] <= ScalMax){ + coef[[idxDate]][[idxData]] <- coef[[idxDate]][[idxData]] + } else { + coef[[idxDate]][[idxData]]$coef <- NA + coef[[idxDate]][[idxData]]$se <- NA + coef[[idxDate]][[idxData]]$scal <- NA + } + }#end ScalMax + + if (idxFilt == "FracSlpMax"){ + #calculate minimum and maximum slope + minSlp <- 1 - FracSlpMax + maxSlp <- 1 + FracSlpMax + if (!is.na(coef[[idxDate]][[idxData]]$coef[2]) & (coef[[idxDate]][[idxData]]$coef[2] >= minSlp & coef[[idxDate]][[idxData]]$coef[2] <= maxSlp)){ + coef[[idxDate]][[idxData]] <- coef[[idxDate]][[idxData]] + } else { + coef[[idxDate]][[idxData]]$coef <- NA + coef[[idxDate]][[idxData]]$se <- NA + coef[[idxDate]][[idxData]]$scal <- NA + } + }#end of FracSlpMax + + if (idxFilt == "OfstMax"){ + if (!is.na(coef[[idxDate]][[idxData]]$coef[1]) & (abs(coef[[idxDate]][[idxData]]$coef[1]) <= OfstMax)){ + coef[[idxDate]][[idxData]] <- coef[[idxDate]][[idxData]] + } + else { + coef[[idxDate]][[idxData]]$coef <- NA + coef[[idxDate]][[idxData]]$se <- NA + coef[[idxDate]][[idxData]]$scal <- NA + } + }#end OfstMax + }#end of testing filter + + }#end of idxFilt + + + }#end of idxData + }#end idxDate #organize input coefficient table if (valiCrit == TRUE){ From 1c8ef225376438e871f90b71b57fb228e026f7d5 Mon Sep 17 00:00:00 2001 From: NDurden Date: Mon, 2 Mar 2020 16:06:14 +0000 Subject: [PATCH 025/168] adding OfstMax in parameter --- pack/eddy4R.base/man/def.irga.vali.cor.Rd | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pack/eddy4R.base/man/def.irga.vali.cor.Rd b/pack/eddy4R.base/man/def.irga.vali.cor.Rd index 83a0fef7..be94dd21 100644 --- a/pack/eddy4R.base/man/def.irga.vali.cor.Rd +++ b/pack/eddy4R.base/man/def.irga.vali.cor.Rd @@ -4,8 +4,17 @@ \alias{def.irga.vali.cor} \title{definition function: Calculation of time-series of the correction IRGA sub data products.} \usage{ -def.irga.vali.cor(data, DateProc, coef, valiData, valiCrit = FALSE, - ScalMax = 20, FracSlpMax = 0.1, Freq = 20) +def.irga.vali.cor( + data, + DateProc, + coef, + valiData, + valiCrit = FALSE, + ScalMax = FALSE, + FracSlpMax = FALSE, + OfstMax = FALSE, + Freq = 20 +) } \arguments{ \item{data}{List consisting of \code{ff::ffdf} file-backed objects containing the dp0p input IRGA.} @@ -16,11 +25,13 @@ def.irga.vali.cor(data, DateProc, coef, valiData, valiCrit = FALSE, \item{valiData}{List consisting of descriptive statistics (mean, min, max, vari, numSamp, se) of CO2 dry mole concentration during performing validation and CO2 dry mole concentration of reference gases.} -\item{valiCrit}{A logical stating if there are more than one validation occurred within DateProc. Defaut to FALSE.} +\item{valiCrit}{A logical stating if there are more than one validation occurred within DateProc.} -\item{ScalMax}{Maximum scale value (resulted from maximum-likelihood fitting of a functional relationship (MLFR)). Defaults to 20.} +\item{ScalMax}{Maximum scale value. The validation correction will not apply if scale (resulted from maximum-likelihood fitting of a functional relationship (MLFR)) is greater than ScalMax or ScalMax = FALSE. Defaults to FALSE.} -\item{FracSlpMax}{Maximum fraction of slope value (resulted from maximum-likelihood fitting of a functional relationship (MLFR)). Defaults to 0.1.} +\item{FracSlpMax}{Maximum fraction of slope value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the FracSlpMax or FracSlpMax = FALSE. Defaults to FALSE.} + +\item{OfstMax}{Maximum offset value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the OfstMax (unit in mol mol-1) or OfstMax = FALSE. Defaults to FALSE.} \item{Freq}{Measurement frequency. Defaults to 20. [Hz]} } From f5c88dede2b4bfad0982c03f10d55b3f523312da Mon Sep 17 00:00:00 2001 From: NDurden Date: Mon, 2 Mar 2020 17:43:41 +0000 Subject: [PATCH 026/168] .Rd format changes due to new Roxygen version --- pack/eddy4R.base/DESCRIPTION | 2 +- pack/eddy4R.base/man/def.bin.Rd | 10 ++++++-- pack/eddy4R.base/man/def.dens.pres.pois.Rd | 8 +++++-- pack/eddy4R.base/man/def.dens.temp.pois.Rd | 8 +++++-- pack/eddy4R.base/man/def.dp01.agr.ecte.Rd | 8 +++++-- pack/eddy4R.base/man/def.hdf5.crte.Rd | 16 +++++++++---- pack/eddy4R.base/man/def.hdf5.extr.Rd | 12 +++++++--- pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd | 12 +++++++--- pack/eddy4R.base/man/def.hdf5.wrte.dp01.Rd | 11 +++++++-- pack/eddy4R.base/man/def.idx.agr.Rd | 11 +++++++-- pack/eddy4R.base/man/def.inst.depe.Rd | 8 +++++-- pack/eddy4R.base/man/def.lag.Rd | 20 ++++++++++++---- pack/eddy4R.base/man/def.met.body.Rd | 9 +++++--- pack/eddy4R.base/man/def.mtch.out.refe.Rd | 2 +- pack/eddy4R.base/man/def.para.flow.Rd | 23 +++++++++++++++---- pack/eddy4R.base/man/def.rglr.Rd | 19 ++++++++++----- .../eddy4R.base/man/def.rmsd.diff.prcs.rsq.Rd | 3 +-- pack/eddy4R.base/man/def.temp.pres.pois.Rd | 8 +++++-- pack/eddy4R.base/man/def.unit.conv.Rd | 11 ++++++--- pack/eddy4R.base/man/wrap.agr.vari.seSq.Rd | 3 +-- pack/eddy4R.base/man/wrap.dp00.rglr.ecse.Rd | 11 +++++++-- pack/eddy4R.base/man/wrap.dp01.qfqm.ecte.Rd | 9 ++++++-- pack/eddy4R.base/man/wrap.hdf5.read.Rd | 18 +++++++++++---- pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd | 12 ++++++++-- .../man/wrap.hdf5.wrte.dp01.api.Rd | 12 +++++++--- pack/eddy4R.base/man/wrap.para.thsh.Rd | 6 +++-- pack/eddy4R.base/man/wrap.unit.conv.out.ec.Rd | 7 ++++-- pack/eddy4R.qaqc/DESCRIPTION | 2 +- pack/eddy4R.qaqc/man/def.agr.file.dp00.Rd | 11 +++++++-- pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd | 12 ++++++---- pack/eddy4R.qaqc/man/def.dspk.br86.Rd | 9 ++++++-- pack/eddy4R.qaqc/man/def.dspk.wndw.Rd | 14 +++++++---- pack/eddy4R.qaqc/man/def.plau.Rd | 19 +++++++++------ pack/eddy4R.qaqc/man/def.plot.dp01.qfqm.Rd | 10 ++++---- pack/eddy4R.qaqc/man/def.qf.ecte.Rd | 9 ++++++-- pack/eddy4R.qaqc/man/def.qf.rmv.data.Rd | 10 ++++++-- pack/eddy4R.qaqc/man/wrap.dp01.qfqm.Rd | 17 ++++++++------ pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd | 23 ++++++++++++++----- pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd | 14 +++++++---- pack/eddy4R.qaqc/man/wrap.qf.rmv.data.Rd | 9 ++++++-- pack/eddy4R.stor/DESCRIPTION | 2 +- pack/eddy4R.stor/man/def.time.rate.diff.Rd | 10 ++++++-- pack/eddy4R.stor/man/wrap.dp01.ecse.Rd | 19 +++++++++++---- 43 files changed, 342 insertions(+), 127 deletions(-) diff --git a/pack/eddy4R.base/DESCRIPTION b/pack/eddy4R.base/DESCRIPTION index a09c94b2..39f6af00 100644 --- a/pack/eddy4R.base/DESCRIPTION +++ b/pack/eddy4R.base/DESCRIPTION @@ -28,4 +28,4 @@ Suggests: NEONprocIS.base License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 LazyData: true -RoxygenNote: 6.1.1 +RoxygenNote: 7.0.2 diff --git a/pack/eddy4R.base/man/def.bin.Rd b/pack/eddy4R.base/man/def.bin.Rd index ce2416db..03064f7f 100644 --- a/pack/eddy4R.base/man/def.bin.Rd +++ b/pack/eddy4R.base/man/def.bin.Rd @@ -4,8 +4,14 @@ \alias{def.bin} \title{Definition function: Binning data} \usage{ -def.bin(idep, depe, RngMinMax = NULL, NumBin, widtBin = c("lin", - "log10", "exp10", "logExp", "expLog"), meanFunc = c("mean", "median")) +def.bin( + idep, + depe, + RngMinMax = NULL, + NumBin, + widtBin = c("lin", "log10", "exp10", "logExp", "expLog"), + meanFunc = c("mean", "median") +) } \arguments{ \item{idep}{Either a vector or matrix of class numeric or integer containing the independent variable and of the same length as \code{depe}. []} diff --git a/pack/eddy4R.base/man/def.dens.pres.pois.Rd b/pack/eddy4R.base/man/def.dens.pres.pois.Rd index 9a34b4d9..f18e6743 100644 --- a/pack/eddy4R.base/man/def.dens.pres.pois.Rd +++ b/pack/eddy4R.base/man/def.dens.pres.pois.Rd @@ -4,8 +4,12 @@ \alias{def.dens.pres.pois} \title{Definition function: Poisson's equation (adiabatic change) - density as function of pressure change} \usage{ -def.dens.pres.pois(dens01, pres01, pres02, - Kppa = eddy4R.base::IntlNatu$KppaDry) +def.dens.pres.pois( + dens01, + pres01, + pres02, + Kppa = eddy4R.base::IntlNatu$KppaDry +) } \arguments{ \item{dens01}{Measured density, Amount per volume [same unit as returned density, e.g. kg/m3 or kmol/m3].} diff --git a/pack/eddy4R.base/man/def.dens.temp.pois.Rd b/pack/eddy4R.base/man/def.dens.temp.pois.Rd index f5bf0ac7..6e5cb603 100644 --- a/pack/eddy4R.base/man/def.dens.temp.pois.Rd +++ b/pack/eddy4R.base/man/def.dens.temp.pois.Rd @@ -4,8 +4,12 @@ \alias{def.dens.temp.pois} \title{Definition function: Poisson's equation (adiabatic change) - density as function of temperature change} \usage{ -def.dens.temp.pois(dens01, temp01, temp02, - Kppa = eddy4R.base::IntlNatu$KppaDry) +def.dens.temp.pois( + dens01, + temp01, + temp02, + Kppa = eddy4R.base::IntlNatu$KppaDry +) } \arguments{ \item{dens01}{Measured density, Amount per volume [same unit as returned density, e.g. kg/m3 or kmol/m3].} diff --git a/pack/eddy4R.base/man/def.dp01.agr.ecte.Rd b/pack/eddy4R.base/man/def.dp01.agr.ecte.Rd index 2bf7fe84..20aee572 100644 --- a/pack/eddy4R.base/man/def.dp01.agr.ecte.Rd +++ b/pack/eddy4R.base/man/def.dp01.agr.ecte.Rd @@ -4,8 +4,12 @@ \alias{def.dp01.agr.ecte} \title{Definition function: aggregation of ecte dp01 outputs} \usage{ -def.dp01.agr.ecte(inpList, MethSubAgr = FALSE, MethUcrt = FALSE, - RptExpd = FALSE) +def.dp01.agr.ecte( + inpList, + MethSubAgr = FALSE, + MethUcrt = FALSE, + RptExpd = FALSE +) } \arguments{ \item{inpList}{a list of dp01 computed output statistics and dp01 quality flags and quality metrics over multiple aggregations periods that need to be combined.} diff --git a/pack/eddy4R.base/man/def.hdf5.crte.Rd b/pack/eddy4R.base/man/def.hdf5.crte.Rd index 8a6dc07a..f80cb693 100644 --- a/pack/eddy4R.base/man/def.hdf5.crte.Rd +++ b/pack/eddy4R.base/man/def.hdf5.crte.Rd @@ -4,10 +4,18 @@ \alias{def.hdf5.crte} \title{Definition function: Create the ECTE HDF5 file structure} \usage{ -def.hdf5.crte(Date, Site = "SERC", LvlTowr, DirOut, FileOutBase = NULL, - MethExpd = TRUE, MethDp04 = FALSE, FileNameReadMe = NULL, - FileNameObjDesc = NULL, LvlGasRefe = c("702_000", "703_000", - "704_000", "705_000", "706_000")) +def.hdf5.crte( + Date, + Site = "SERC", + LvlTowr, + DirOut, + FileOutBase = NULL, + MethExpd = TRUE, + MethDp04 = FALSE, + FileNameReadMe = NULL, + FileNameObjDesc = NULL, + LvlGasRefe = c("702_000", "703_000", "704_000", "705_000", "706_000") +) } \arguments{ \item{Date}{is the date for the output file being generated.} diff --git a/pack/eddy4R.base/man/def.hdf5.extr.Rd b/pack/eddy4R.base/man/def.hdf5.extr.Rd index f1373953..586f41bd 100644 --- a/pack/eddy4R.base/man/def.hdf5.extr.Rd +++ b/pack/eddy4R.base/man/def.hdf5.extr.Rd @@ -4,9 +4,15 @@ \alias{def.hdf5.extr} \title{Definition function: Extract data and attributes from HDF5 input file to another HDF5 output file} \usage{ -def.hdf5.extr(FileInp = NULL, rpt = NULL, FileOut = NULL, - MethExtrData = TRUE, MethExtrAttr = TRUE, dp01 = NULL, - MethDp0p = FALSE) +def.hdf5.extr( + FileInp = NULL, + rpt = NULL, + FileOut = NULL, + MethExtrData = TRUE, + MethExtrAttr = TRUE, + dp01 = NULL, + MethDp0p = FALSE +) } \arguments{ \item{FileInp}{is the input HDF5 file (turb or stor) the data and metadata are being read from. It is ignored if \code{rpt} is specified.} diff --git a/pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd b/pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd index 4b38aae4..6b9c590f 100644 --- a/pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd +++ b/pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd @@ -4,9 +4,15 @@ \alias{def.hdf5.read.qfqm} \title{Wrapper function: Reading quality flags from NEON HDF5 files} \usage{ -def.hdf5.read.qfqm(DirInpLoca, SiteLoca, DateLoca, VarLoca, - LvlTowr = c("000_040", "000_050", "000_060")[3], FreqLoca, - MethMeas = c("ecte", "ecse")[1]) +def.hdf5.read.qfqm( + DirInpLoca, + SiteLoca, + DateLoca, + VarLoca, + LvlTowr = c("000_040", "000_050", "000_060")[3], + FreqLoca, + MethMeas = c("ecte", "ecse")[1] +) } \arguments{ \item{DirInpLoca}{Character: Input directory.} diff --git a/pack/eddy4R.base/man/def.hdf5.wrte.dp01.Rd b/pack/eddy4R.base/man/def.hdf5.wrte.dp01.Rd index 6b8c3904..13e648f6 100644 --- a/pack/eddy4R.base/man/def.hdf5.wrte.dp01.Rd +++ b/pack/eddy4R.base/man/def.hdf5.wrte.dp01.Rd @@ -4,8 +4,15 @@ \alias{def.hdf5.wrte.dp01} \title{Definition function: Write NEON Level 1 data, qfqm, and uncertainty to output HDF5} \usage{ -def.hdf5.wrte.dp01(inpList, FileOut, SiteLoca, LvlTowr, Dp01, - MethUcrt = TRUE, MethSubAgr = TRUE) +def.hdf5.wrte.dp01( + inpList, + FileOut, + SiteLoca, + LvlTowr, + Dp01, + MethUcrt = TRUE, + MethSubAgr = TRUE +) } \arguments{ \item{inpList}{A list of including dp01 data, quality flags and quality metrics, and uncertainty calculations to package and write to an output HDF5 file.} diff --git a/pack/eddy4R.base/man/def.idx.agr.Rd b/pack/eddy4R.base/man/def.idx.agr.Rd index da6387ce..268ac536 100644 --- a/pack/eddy4R.base/man/def.idx.agr.Rd +++ b/pack/eddy4R.base/man/def.idx.agr.Rd @@ -4,8 +4,15 @@ \alias{def.idx.agr} \title{Definition function: indices for aggregation periods} \usage{ -def.idx.agr(time, PrdAgr, FreqLoca, MethIdx = c("rglr", "specBgn", - "specEnd")[1], crdH2oVali = FALSE, data = NULL, CritTime = 0) +def.idx.agr( + time, + PrdAgr, + FreqLoca, + MethIdx = c("rglr", "specBgn", "specEnd")[1], + crdH2oVali = FALSE, + data = NULL, + CritTime = 0 +) } \arguments{ \item{time}{a vector of timestamps} diff --git a/pack/eddy4R.base/man/def.inst.depe.Rd b/pack/eddy4R.base/man/def.inst.depe.Rd index b04b4a38..d57d4a95 100644 --- a/pack/eddy4R.base/man/def.inst.depe.Rd +++ b/pack/eddy4R.base/man/def.inst.depe.Rd @@ -4,8 +4,12 @@ \alias{def.inst.depe} \title{Definition function: Install dependent packages} \usage{ -def.inst.depe(DirPack = ".", Depe = TRUE, - Repo = base::getOption("repos")[1], Lib = .libPaths()[1]) +def.inst.depe( + DirPack = ".", + Depe = TRUE, + Repo = base::getOption("repos")[1], + Lib = .libPaths()[1] +) } \arguments{ \item{DirPack}{Path to the package \code{DESCRIPTION} file, defaults to the current working directory. Character vector with single entry [-].} diff --git a/pack/eddy4R.base/man/def.lag.Rd b/pack/eddy4R.base/man/def.lag.Rd index c3a72fff..8e95a2b4 100644 --- a/pack/eddy4R.base/man/def.lag.Rd +++ b/pack/eddy4R.base/man/def.lag.Rd @@ -4,10 +4,22 @@ \alias{def.lag} \title{Definition function: Lag two datasets, so as to maximise their cross-correlation} \usage{ -def.lag(refe, meas, freq, dataRefe = refe, dataMeas = meas, - measVar = NULL, lagMax = 2 * freq, lagCnst = TRUE, - lagNgtvPstv = c("n", "p", "np")[3], lagAll = TRUE, hpf = TRUE, - fracMin = 0.1, plot = FALSE, DirPlot = NULL) +def.lag( + refe, + meas, + freq, + dataRefe = refe, + dataMeas = meas, + measVar = NULL, + lagMax = 2 * freq, + lagCnst = TRUE, + lagNgtvPstv = c("n", "p", "np")[3], + lagAll = TRUE, + hpf = TRUE, + fracMin = 0.1, + plot = FALSE, + DirPlot = NULL +) } \arguments{ \item{refe}{A vector with variable in reference time frame. Of class numeric. [-]} diff --git a/pack/eddy4R.base/man/def.met.body.Rd b/pack/eddy4R.base/man/def.met.body.Rd index bbf815da..a5eba925 100644 --- a/pack/eddy4R.base/man/def.met.body.Rd +++ b/pack/eddy4R.base/man/def.met.body.Rd @@ -4,9 +4,12 @@ \alias{def.met.body} \title{Definition function: Coordinate transformation from CSAT3 body coordinate system to meteorological coordinate system} \usage{ -def.met.body(AngZaxsSoniInst, - AngZaxsSoniOfst = eddy4R.base::def.unit.conv(data = 90, unitFrom = - "deg", unitTo = "rad"), veloBody) +def.met.body( + AngZaxsSoniInst, + AngZaxsSoniOfst = eddy4R.base::def.unit.conv(data = 90, unitFrom = "deg", unitTo = + "rad"), + veloBody +) } \arguments{ \item{AngZaxsSoniInst}{Parameter of class numeric. Azimuth (angle around z axis) direction against true north in which sonic anemometer installation (transducer array) is pointing [rad]} diff --git a/pack/eddy4R.base/man/def.mtch.out.refe.Rd b/pack/eddy4R.base/man/def.mtch.out.refe.Rd index a41ea9b6..8b9d84c6 100644 --- a/pack/eddy4R.base/man/def.mtch.out.refe.Rd +++ b/pack/eddy4R.base/man/def.mtch.out.refe.Rd @@ -20,7 +20,7 @@ Currently none } \description{ Function definition. A function to compare the file output from a workflow to a reference output file -to ensure that changes during development to functions called by the workflow have not impacted the +to ensure that changes during development to functions called by the workflow have not impacted the results.\cr The function reads in the new data produced in the tmp directory and compares the first 10 lines to the reference output data. } diff --git a/pack/eddy4R.base/man/def.para.flow.Rd b/pack/eddy4R.base/man/def.para.flow.Rd index f6f18e36..62247c28 100644 --- a/pack/eddy4R.base/man/def.para.flow.Rd +++ b/pack/eddy4R.base/man/def.para.flow.Rd @@ -4,11 +4,24 @@ \alias{def.para.flow} \title{Definition function: Determine the workflow variables} \usage{ -def.para.flow(Deve = TRUE, DirFilePara = NULL, DirInp = NA, - DirMnt = NA, DirOut = NA, DirTmp = NA, DirWrk = NA, - DateOut = NULL, FileOutBase = NULL, Read = "hdf5", - VersDp = c("001", "004")[1], VersEddy = "latest", - MethParaFlow = c("DfltInp", "EnvVar")[1], UrlInpRefe, UrlOutRefe, ...) +def.para.flow( + Deve = TRUE, + DirFilePara = NULL, + DirInp = NA, + DirMnt = NA, + DirOut = NA, + DirTmp = NA, + DirWrk = NA, + DateOut = NULL, + FileOutBase = NULL, + Read = "hdf5", + VersDp = c("001", "004")[1], + VersEddy = "latest", + MethParaFlow = c("DfltInp", "EnvVar")[1], + UrlInpRefe, + UrlOutRefe, + ... +) } \arguments{ \item{Deve}{is logical that determines if only a subset of the data should be read in to reduce testing time during development (\code{Deve = TRUE}) or all the input data should be read in (\code{Deve = FALSE})} diff --git a/pack/eddy4R.base/man/def.rglr.Rd b/pack/eddy4R.base/man/def.rglr.Rd index a564962a..8a843c6b 100644 --- a/pack/eddy4R.base/man/def.rglr.Rd +++ b/pack/eddy4R.base/man/def.rglr.Rd @@ -4,12 +4,19 @@ \alias{def.rglr} \title{Definition function: Regularizing irregular data to strictly regular / equidistant data} \usage{ -def.rglr(timeMeas, dataMeas, unitMeas = base::attributes(dataMeas)$unit, - BgnRglr = NULL, EndRglr = NULL, - TzRglr = base::attributes(BgnRglr)$tzone, FreqRglr, - MethRglr = c("CybiEc", "cybiDflt", "zoo")[1], WndwRglr = c("Cntr", - "Lead", "Trlg")[1], IdxWndw = c("Clst", "IdxWndwMin", "IdxWndwMax")[1], - PrcsSec = 6) +def.rglr( + timeMeas, + dataMeas, + unitMeas = base::attributes(dataMeas)$unit, + BgnRglr = NULL, + EndRglr = NULL, + TzRglr = base::attributes(BgnRglr)$tzone, + FreqRglr, + MethRglr = c("CybiEc", "cybiDflt", "zoo")[1], + WndwRglr = c("Cntr", "Lead", "Trlg")[1], + IdxWndw = c("Clst", "IdxWndwMin", "IdxWndwMax")[1], + PrcsSec = 6 +) } \arguments{ \item{timeMeas}{A vector containing the observation times. Of class "POSIXlt" including timezone attribute, and of the same length as \code{dataMeas}. [-]} diff --git a/pack/eddy4R.base/man/def.rmsd.diff.prcs.rsq.Rd b/pack/eddy4R.base/man/def.rmsd.diff.prcs.rsq.Rd index 18d99605..22f8d0ff 100644 --- a/pack/eddy4R.base/man/def.rmsd.diff.prcs.rsq.Rd +++ b/pack/eddy4R.base/man/def.rmsd.diff.prcs.rsq.Rd @@ -4,8 +4,7 @@ \alias{def.rmsd.diff.prcs.rsq} \title{Definition function: RMSD, bias, precision and coefficient of determination - incl. deadband} \usage{ -def.rmsd.diff.prcs.rsq(refe, test, Perc = FALSE, Deba = NULL, - DebaRltv = FALSE) +def.rmsd.diff.prcs.rsq(refe, test, Perc = FALSE, Deba = NULL, DebaRltv = FALSE) } \arguments{ \item{refe}{Variable of class numeric. Reference data.Same unit as test data.} diff --git a/pack/eddy4R.base/man/def.temp.pres.pois.Rd b/pack/eddy4R.base/man/def.temp.pres.pois.Rd index bc32d2c0..f73ecf7b 100644 --- a/pack/eddy4R.base/man/def.temp.pres.pois.Rd +++ b/pack/eddy4R.base/man/def.temp.pres.pois.Rd @@ -4,8 +4,12 @@ \alias{def.temp.pres.pois} \title{Definition function: Poisson's equation (adiabatic change) - temperature as function of pressure change} \usage{ -def.temp.pres.pois(temp01, pres01, pres02, - Kppa = eddy4R.base::IntlNatu$KppaDry) +def.temp.pres.pois( + temp01, + pres01, + pres02, + Kppa = eddy4R.base::IntlNatu$KppaDry +) } \arguments{ \item{temp01}{Measured air temperature [K]} diff --git a/pack/eddy4R.base/man/def.unit.conv.Rd b/pack/eddy4R.base/man/def.unit.conv.Rd index 707441a3..7f9337bb 100644 --- a/pack/eddy4R.base/man/def.unit.conv.Rd +++ b/pack/eddy4R.base/man/def.unit.conv.Rd @@ -4,9 +4,14 @@ \alias{def.unit.conv} \title{Definition function: Unit conversion} \usage{ -def.unit.conv(data, unitFrom = "arb", unitTo = "arb", - coefPoly = base::lapply(base::as.data.frame(data), function(x) c(0, - 1)), vrbs = FALSE, MethGc = TRUE) +def.unit.conv( + data, + unitFrom = "arb", + unitTo = "arb", + coefPoly = base::lapply(base::as.data.frame(data), function(x) c(0, 1)), + vrbs = FALSE, + MethGc = TRUE +) } \arguments{ \item{data}{Required. A named data frame of type numeric, containing the data to be converted. diff --git a/pack/eddy4R.base/man/wrap.agr.vari.seSq.Rd b/pack/eddy4R.base/man/wrap.agr.vari.seSq.Rd index 220d1b5b..c6646a77 100644 --- a/pack/eddy4R.base/man/wrap.agr.vari.seSq.Rd +++ b/pack/eddy4R.base/man/wrap.agr.vari.seSq.Rd @@ -4,8 +4,7 @@ \alias{wrap.agr.vari.seSq} \title{Wrapper function: Calculate aggregated variance and squared standard error from a small to large temporal scale.} \usage{ -wrap.agr.vari.seSq(data = data.frame(timeDoyDecm, mean, vari), zone, - MethAgr) +wrap.agr.vari.seSq(data = data.frame(timeDoyDecm, mean, vari), zone, MethAgr) } \arguments{ \item{data}{Dataframe of type numeric containing column vectors \code{timeDoyDecm}, \code{mean}, and \code{vari} of equal length.} diff --git a/pack/eddy4R.base/man/wrap.dp00.rglr.ecse.Rd b/pack/eddy4R.base/man/wrap.dp00.rglr.ecse.Rd index 39d1b393..920fe459 100644 --- a/pack/eddy4R.base/man/wrap.dp00.rglr.ecse.Rd +++ b/pack/eddy4R.base/man/wrap.dp00.rglr.ecse.Rd @@ -4,8 +4,15 @@ \alias{wrap.dp00.rglr.ecse} \title{Wrapper function: Time regularization for ECSE dp00} \usage{ -wrap.dp00.rglr.ecse(DirInp, Date, Site = "CPER", Dom = "D10", Freq, - IdDp00, horVer) +wrap.dp00.rglr.ecse( + DirInp, + Date, + Site = "CPER", + Dom = "D10", + Freq, + IdDp00, + horVer +) } \arguments{ \item{DirInp}{Character: Input directory. [-]} diff --git a/pack/eddy4R.base/man/wrap.dp01.qfqm.ecte.Rd b/pack/eddy4R.base/man/wrap.dp01.qfqm.ecte.Rd index 92fdc3cc..593701a3 100644 --- a/pack/eddy4R.base/man/wrap.dp01.qfqm.ecte.Rd +++ b/pack/eddy4R.base/man/wrap.dp01.qfqm.ecte.Rd @@ -4,8 +4,13 @@ \alias{wrap.dp01.qfqm.ecte} \title{Wrapper function: Create NEON Level 1 data product quality flags and quality metrics across list elements} \usage{ -wrap.dp01.qfqm.ecte(qfqm, idx = NULL, TypeMeas = "samp", - MethMeas = c("ecte", "ecse")[1], RptExpd = FALSE) +wrap.dp01.qfqm.ecte( + qfqm, + idx = NULL, + TypeMeas = "samp", + MethMeas = c("ecte", "ecse")[1], + RptExpd = FALSE +) } \arguments{ \item{qfqm}{A data.frame or list containing the L0p input data quality flags (sensor and plausibility flags) at native resolution. Of type numeric or integer. [-]} diff --git a/pack/eddy4R.base/man/wrap.hdf5.read.Rd b/pack/eddy4R.base/man/wrap.hdf5.read.Rd index c35023ad..25685617 100644 --- a/pack/eddy4R.base/man/wrap.hdf5.read.Rd +++ b/pack/eddy4R.base/man/wrap.hdf5.read.Rd @@ -4,10 +4,20 @@ \alias{wrap.hdf5.read} \title{Wrapper function: Reading NEON HDF5 files} \usage{ -wrap.hdf5.read(DirInpLoca, SiteLoca, DateLoca, VarLoca, - LvlTowr = c("000_040", "000_050", "000_060")[3], FreqLoca, - Rglr = FALSE, Diag = FALSE, Rng = FALSE, RngLoca = NULL, - DespLoca, MethMeas = c("ecte", "ecse")[1]) +wrap.hdf5.read( + DirInpLoca, + SiteLoca, + DateLoca, + VarLoca, + LvlTowr = c("000_040", "000_050", "000_060")[3], + FreqLoca, + Rglr = FALSE, + Diag = FALSE, + Rng = FALSE, + RngLoca = NULL, + DespLoca, + MethMeas = c("ecte", "ecse")[1] +) } \arguments{ \item{DirInpLoca}{Character: Input directory.} diff --git a/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd b/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd index 8cabaa42..e5790fcc 100644 --- a/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd +++ b/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd @@ -4,8 +4,16 @@ \alias{wrap.hdf5.wrte.dp01} \title{Wrapper function: Write NEON Level 1 data, qfqm, and uncertainty to output HDF5} \usage{ -wrap.hdf5.wrte.dp01(inpList, FileInp, FileOut, SiteLoca, LvlTowr, - MethUcrt = TRUE, MethDp04 = FALSE, MethSubAgr = TRUE) +wrap.hdf5.wrte.dp01( + inpList, + FileInp, + FileOut, + SiteLoca, + LvlTowr, + MethUcrt = TRUE, + MethDp04 = FALSE, + MethSubAgr = TRUE +) } \arguments{ \item{inpList}{A list of including dp01 data, quality flags and quality metrics, and uncertainty calculations to package and write to an output HDF5 file} diff --git a/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.api.Rd b/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.api.Rd index ef15d565..eb021715 100644 --- a/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.api.Rd +++ b/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.api.Rd @@ -4,9 +4,15 @@ \alias{wrap.hdf5.wrte.dp01.api} \title{Wrapper function: Gather/Write reingested NEON Level 1 data, qfqm, and uncertainty to output HDF5} \usage{ -wrap.hdf5.wrte.dp01.api(date, FileOut, SiteLoca, DpName = c("tempAirLvl", - "tempAirTop", "fluxHeatSoil", "radiNet", "tempSoil", "h2oSoilVol", - "presBaro"), LvlTowr, TimeAgr = c(1, 30)) +wrap.hdf5.wrte.dp01.api( + date, + FileOut, + SiteLoca, + DpName = c("tempAirLvl", "tempAirTop", "fluxHeatSoil", "radiNet", "tempSoil", + "h2oSoilVol", "presBaro"), + LvlTowr, + TimeAgr = c(1, 30) +) } \arguments{ \item{date}{Character: The date for the data to be gathered in ISO format ("YYYYmmdd").} diff --git a/pack/eddy4R.base/man/wrap.para.thsh.Rd b/pack/eddy4R.base/man/wrap.para.thsh.Rd index c9919d52..27aac338 100644 --- a/pack/eddy4R.base/man/wrap.para.thsh.Rd +++ b/pack/eddy4R.base/man/wrap.para.thsh.Rd @@ -4,10 +4,12 @@ \alias{wrap.para.thsh} \title{Wrapper Function to read threshold table from CI-Parameter-Repo} \usage{ -wrap.para.thsh(DpName = c("IrgaTurb", "MfcSampTurb", "Soni", "Amrs"), +wrap.para.thsh( + DpName = c("IrgaTurb", "MfcSampTurb", "Soni", "Amrs"), DirInp = "~/eddy/data/Thresholds_EC/CI-Parameter-Repo/ParaSci/Ecte/Dp0p", DirOut = "~/eddy/data/Thresholds_EC/threshold_ecte", - FileWrte = FALSE) + FileWrte = FALSE +) } \arguments{ \item{DpName}{Character: Name of data product. [-]} diff --git a/pack/eddy4R.base/man/wrap.unit.conv.out.ec.Rd b/pack/eddy4R.base/man/wrap.unit.conv.out.ec.Rd index 8783842f..92603fb5 100644 --- a/pack/eddy4R.base/man/wrap.unit.conv.out.ec.Rd +++ b/pack/eddy4R.base/man/wrap.unit.conv.out.ec.Rd @@ -4,8 +4,11 @@ \alias{wrap.unit.conv.out.ec} \title{Wrapper function: Output unit conversion for ECTE} \usage{ -wrap.unit.conv.out.ec(inpList, MethMeas = c("ecte", "ecse")[1], - MethType = c("Data", "Ucrt", "Qfqm", "Vali")[1]) +wrap.unit.conv.out.ec( + inpList, + MethMeas = c("ecte", "ecse")[1], + MethType = c("Data", "Ucrt", "Qfqm", "Vali")[1] +) } \arguments{ \item{inpList}{Required. A named list of data frames of type numeric, containing the data to be converted.} diff --git a/pack/eddy4R.qaqc/DESCRIPTION b/pack/eddy4R.qaqc/DESCRIPTION index 76d2dbf1..1e456c8e 100644 --- a/pack/eddy4R.qaqc/DESCRIPTION +++ b/pack/eddy4R.qaqc/DESCRIPTION @@ -22,4 +22,4 @@ Suggests: NEONprocIS.base License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 LazyData: true -RoxygenNote: 6.1.1 +RoxygenNote: 7.0.2 diff --git a/pack/eddy4R.qaqc/man/def.agr.file.dp00.Rd b/pack/eddy4R.qaqc/man/def.agr.file.dp00.Rd index 644a7dbe..ce7b6fb1 100644 --- a/pack/eddy4R.qaqc/man/def.agr.file.dp00.Rd +++ b/pack/eddy4R.qaqc/man/def.agr.file.dp00.Rd @@ -4,8 +4,15 @@ \alias{def.agr.file.dp00} \title{Definition function: Combine individual L0 data streams from file} \usage{ -def.agr.file.dp00(dirFile = ".", nameFile, nameVar, unitVar, Freq, - FmtTime = "\%d-\%b-\%Y \%I.\%M.\%OS \%p", Tz = "GMT") +def.agr.file.dp00( + dirFile = ".", + nameFile, + nameVar, + unitVar, + Freq, + FmtTime = "\%d-\%b-\%Y \%I.\%M.\%OS \%p", + Tz = "GMT" +) } \arguments{ \item{dirFile}{Optional. A character string indicating the directory in which the files to combine are stored. Default is the current working directory.} diff --git a/pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd b/pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd index 4c6a5b4a..84421aad 100644 --- a/pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd +++ b/pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd @@ -4,10 +4,14 @@ \alias{def.dp01.grp.qf} \title{Definition function: Grouping the quality flags for each of NEON ECTE and ECSE L1 data product} \usage{ -def.dp01.grp.qf(qfInp = list(), MethMeas = c("ecte", "ecse")[1], - TypeMeas = c("samp", "vali")[1], dp01 = c("envHut", "co2Turb", - "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "isoH2o", "soni", "amrs", - "tempAirLvl", "tempAirTop")[1], idGas = NULL) +def.dp01.grp.qf( + qfInp = list(), + MethMeas = c("ecte", "ecse")[1], + TypeMeas = c("samp", "vali")[1], + dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "isoH2o", + "soni", "amrs", "tempAirLvl", "tempAirTop")[1], + idGas = NULL +) } \arguments{ \item{qfInp}{A list of data frame containing the input quality flag data that related to L1 data products are being grouped. Of class integer". [-]} diff --git a/pack/eddy4R.qaqc/man/def.dspk.br86.Rd b/pack/eddy4R.qaqc/man/def.dspk.br86.Rd index 1f9a8e83..07df4dea 100644 --- a/pack/eddy4R.qaqc/man/def.dspk.br86.Rd +++ b/pack/eddy4R.qaqc/man/def.dspk.br86.Rd @@ -4,8 +4,13 @@ \alias{def.dspk.br86} \title{Definition function: Median filter de-spiking} \usage{ -def.dspk.br86(dataInp, WndwFilt = 9, NumBin = 2, ThshReso = 10, - FracRealMin = 0.025) +def.dspk.br86( + dataInp, + WndwFilt = 9, + NumBin = 2, + ThshReso = 10, + FracRealMin = 0.025 +) } \arguments{ \item{dataInp}{Required. A univariate vector of integers or numerics of Input data} diff --git a/pack/eddy4R.qaqc/man/def.dspk.wndw.Rd b/pack/eddy4R.qaqc/man/def.dspk.wndw.Rd index aed2e582..40f3f3db 100644 --- a/pack/eddy4R.qaqc/man/def.dspk.wndw.Rd +++ b/pack/eddy4R.qaqc/man/def.dspk.wndw.Rd @@ -4,11 +4,15 @@ \alias{def.dspk.wndw} \title{Definition function: Determine spike locations using window-based statistics} \usage{ -def.dspk.wndw(data, Trt = list(AlgClas = c("mean", "median")[2], - NumPtsWndw = c(11, 101)[2], NumPtsSlid = 1, ThshStd = c(3.5, 20)[2], - NaFracMax = 0.1, Infl = 0, IterMax = Inf, NumPtsGrp = c(4, 10)[2], NaTrt - = c("approx", "omit")[2]), Cntl = list(NaOmit = c(TRUE, FALSE)[2], Prnt - = c(TRUE, FALSE)[1], Plot = c(TRUE, FALSE)[1]), Vrbs = FALSE) +def.dspk.wndw( + data, + Trt = list(AlgClas = c("mean", "median")[2], NumPtsWndw = c(11, 101)[2], NumPtsSlid = + 1, ThshStd = c(3.5, 20)[2], NaFracMax = 0.1, Infl = 0, IterMax = Inf, NumPtsGrp = c(4, + 10)[2], NaTrt = c("approx", "omit")[2]), + Cntl = list(NaOmit = c(TRUE, FALSE)[2], Prnt = c(TRUE, FALSE)[1], Plot = c(TRUE, + FALSE)[1]), + Vrbs = FALSE +) } \arguments{ \item{data}{Required input. A data frame or matrix containing the data to be evaluated.} diff --git a/pack/eddy4R.qaqc/man/def.plau.Rd b/pack/eddy4R.qaqc/man/def.plau.Rd index 130b1681..abff8e02 100644 --- a/pack/eddy4R.qaqc/man/def.plau.Rd +++ b/pack/eddy4R.qaqc/man/def.plau.Rd @@ -4,14 +4,19 @@ \alias{def.plau} \title{Definition function: Plausibility tests (Range, Step, Persistence, Null, Gap)} \usage{ -def.plau(data, time = as.POSIXlt(seq.POSIXt(from = Sys.time(), by = - "sec", length.out = length(data[, 1]))), RngMin = apply(data, 2, min, - na.rm = TRUE), RngMax = apply(data, 2, max, na.rm = TRUE), +def.plau( + data, + time = as.POSIXlt(seq.POSIXt(from = Sys.time(), by = "sec", length.out = length(data[, + 1]))), + RngMin = apply(data, 2, min, na.rm = TRUE), + RngMax = apply(data, 2, max, na.rm = TRUE), DiffStepMax = apply(abs(apply(data, 2, diff)), 2, max, na.rm = TRUE), - DiffPersMin = rep.int(0, length(data)), WndwPers = 60 * - median(abs(diff(time)), na.rm = TRUE) * rep.int(1, length(data)), - TestNull = rep(FALSE, length(data)), NumGap = rep(length(data[, 1]) + - 1, length(data)), Vrbs = FALSE) + DiffPersMin = rep.int(0, length(data)), + WndwPers = 60 * median(abs(diff(time)), na.rm = TRUE) * rep.int(1, length(data)), + TestNull = rep(FALSE, length(data)), + NumGap = rep(length(data[, 1]) + 1, length(data)), + Vrbs = FALSE +) } \arguments{ \item{data}{Required input. A data frame containing the data to be evaluated (do not include the time stamp vector here).} diff --git a/pack/eddy4R.qaqc/man/def.plot.dp01.qfqm.Rd b/pack/eddy4R.qaqc/man/def.plot.dp01.qfqm.Rd index 10c2fdc9..4f1c66c3 100644 --- a/pack/eddy4R.qaqc/man/def.plot.dp01.qfqm.Rd +++ b/pack/eddy4R.qaqc/man/def.plot.dp01.qfqm.Rd @@ -4,10 +4,12 @@ \alias{def.plot.dp01.qfqm} \title{Definition function: Plot quality flags and quality metrics (basic L1 data products)} \usage{ -def.plot.dp01.qfqm(dataDp01, WndwTime = c(min(dataDp01$timeAgrBgn), - max(dataDp01$timeAgrBgn)), NameQmPlot = sub("Pass", "", - names(dataDp01$dataAgr[[1]][grep("Pass", - names(dataDp01$dataAgr[[1]]))]))) +def.plot.dp01.qfqm( + dataDp01, + WndwTime = c(min(dataDp01$timeAgrBgn), max(dataDp01$timeAgrBgn)), + NameQmPlot = sub("Pass", "", names(dataDp01$dataAgr[[1]][grep("Pass", + names(dataDp01$dataAgr[[1]]))])) +) } \arguments{ \item{dataDp01}{Required input. A list output from wrap.dp01.qfqm.R of: \cr diff --git a/pack/eddy4R.qaqc/man/def.qf.ecte.Rd b/pack/eddy4R.qaqc/man/def.qf.ecte.Rd index d34344c1..fa6f014e 100644 --- a/pack/eddy4R.qaqc/man/def.qf.ecte.Rd +++ b/pack/eddy4R.qaqc/man/def.qf.ecte.Rd @@ -4,8 +4,13 @@ \alias{def.qf.ecte} \title{Definition function: Create fake flags for ECTE sensors} \usage{ -def.qf.ecte(TimeBgn, TimeEnd, Freq = 20, Sens = c("soni", "irga", - "irgaMfcSamp", "soniAmrs")[1], PcntQf = 0.05) +def.qf.ecte( + TimeBgn, + TimeEnd, + Freq = 20, + Sens = c("soni", "irga", "irgaMfcSamp", "soniAmrs")[1], + PcntQf = 0.05 +) } \arguments{ \item{TimeBgn}{is the beginning time of the period to generate flags.} diff --git a/pack/eddy4R.qaqc/man/def.qf.rmv.data.Rd b/pack/eddy4R.qaqc/man/def.qf.rmv.data.Rd index 685a4157..8b79b2d5 100644 --- a/pack/eddy4R.qaqc/man/def.qf.rmv.data.Rd +++ b/pack/eddy4R.qaqc/man/def.qf.rmv.data.Rd @@ -4,8 +4,14 @@ \alias{def.qf.rmv.data} \title{Definition function: to remove high frequency data points that have failed quality flags} \usage{ -def.qf.rmv.data(inpData, inpQf, Sens = NULL, qfRmv = NULL, - Vrbs = FALSE, TypeData = c("integer", "real")[1]) +def.qf.rmv.data( + inpData, + inpQf, + Sens = NULL, + qfRmv = NULL, + Vrbs = FALSE, + TypeData = c("integer", "real")[1] +) } \arguments{ \item{inpData}{Input data.frame for data to be removed from based on quality flags} diff --git a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.Rd b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.Rd index 1c4c872d..fdefb660 100644 --- a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.Rd +++ b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.Rd @@ -4,14 +4,17 @@ \alias{wrap.dp01.qfqm} \title{Wrapper function: Generate basic L1 data product, including descriptive statics, quality metrics, and final quality flag} \usage{ -wrap.dp01.qfqm(data, time = base::as.POSIXlt(base::seq.POSIXt(from = - base::Sys.time(), by = "sec", length.out = base::length(data[, 1]))), +wrap.dp01.qfqm( + data, + time = base::as.POSIXlt(base::seq.POSIXt(from = base::Sys.time(), by = "sec", + length.out = base::length(data[, 1]))), setQf = base::vector("list", base::length(data)), - qf = base::vector("list", base::length(data)), WndwAgr = 1800 * - stats::median(base::abs(base::diff(time)), na.rm = TRUE), - TimeBgn = NULL, TimeEnd = NULL, - NameQfExcl = base::as.list(base::character(length = - base::length(data)))) + qf = base::vector("list", base::length(data)), + WndwAgr = 1800 * stats::median(base::abs(base::diff(time)), na.rm = TRUE), + TimeBgn = NULL, + TimeEnd = NULL, + NameQfExcl = base::as.list(base::character(length = base::length(data))) +) } \arguments{ \item{data}{Required input. A data frame containing the L0' (calibrated raw) data evaluated (do not include the time stamp vector here).} diff --git a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd index 079a2a65..1c352351 100644 --- a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd +++ b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd @@ -4,12 +4,23 @@ \alias{wrap.dp01.qfqm.ecse} \title{Wrapper function: Preprocessing and calculating quality metrics, alpha and beta quality metrics, and final quality flag for the NEON eddy-covariance stroage exchange L1 data products} \usage{ -wrap.dp01.qfqm.ecse(dp01 = c("co2Stor", "h2oStor", "tempAirLvl", - "tempAirTop", "isoCo2", "isoH2o")[1], RptExpd = FALSE, lvl, - lvlMfcSampStor = NULL, lvlMfcValiStor = NULL, lvlEnvHut = NULL, - lvlValv = NULL, lvlValvAux = NULL, lvlCrdH2oValvVali = NULL, - data = list(), qfInp = list(), TypeMeas = c("samp", "vali")[1], - PrdMeas, PrdAgr, idxTime = list()) +wrap.dp01.qfqm.ecse( + dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], + RptExpd = FALSE, + lvl, + lvlMfcSampStor = NULL, + lvlMfcValiStor = NULL, + lvlEnvHut = NULL, + lvlValv = NULL, + lvlValvAux = NULL, + lvlCrdH2oValvVali = NULL, + data = list(), + qfInp = list(), + TypeMeas = c("samp", "vali")[1], + PrdMeas, + PrdAgr, + idxTime = list() +) } \arguments{ \item{dp01}{A vector of class "character" containing the name of NEON ECSE dp01 which descriptive statistics are being calculated, \cr diff --git a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd index c1ebf009..a6149daa 100644 --- a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd +++ b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd @@ -4,11 +4,15 @@ \alias{wrap.dp01.qfqm.eddy} \title{Wrapper function: Calculate quality metrics, alpha and beta quality metrics, and final quality flag for the NEON eddy-covariance turbulent and stroage exchange L1 data products} \usage{ -wrap.dp01.qfqm.eddy(qfInp = list(), MethMeas = c("ecte", "ecse")[1], - TypeMeas = c("samp", "vali")[1], RptExpd = FALSE, - dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", - "isoCo2", "isoH2o", "soni", "soniAmrs", "tempAirLvl", "tempAirTop")[1], - idGas = NULL) +wrap.dp01.qfqm.eddy( + qfInp = list(), + MethMeas = c("ecte", "ecse")[1], + TypeMeas = c("samp", "vali")[1], + RptExpd = FALSE, + dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "isoH2o", + "soni", "soniAmrs", "tempAirLvl", "tempAirTop")[1], + idGas = NULL +) } \arguments{ \item{qfInp}{A list of data frame containing the input quality flag data that related to L1 data products are being grouped. Of class integer". [-]} diff --git a/pack/eddy4R.qaqc/man/wrap.qf.rmv.data.Rd b/pack/eddy4R.qaqc/man/wrap.qf.rmv.data.Rd index d370e020..28bfaf5c 100644 --- a/pack/eddy4R.qaqc/man/wrap.qf.rmv.data.Rd +++ b/pack/eddy4R.qaqc/man/wrap.qf.rmv.data.Rd @@ -4,8 +4,13 @@ \alias{wrap.qf.rmv.data} \title{Wrapper function: to remove high frequency data points that have failed quality flags} \usage{ -wrap.qf.rmv.data(inpList, Sens = NULL, qfRmv = NULL, Vrbs = FALSE, - MethMeas = c("ecte", "ecse")[1]) +wrap.qf.rmv.data( + inpList, + Sens = NULL, + qfRmv = NULL, + Vrbs = FALSE, + MethMeas = c("ecte", "ecse")[1] +) } \arguments{ \item{inpList}{List consisting of \code{ff::ffdf} file-backed objects, in the format provided by function \code{eddy4R.base::wrap.hdf5.read()}. Of types numeric and integer.} diff --git a/pack/eddy4R.stor/DESCRIPTION b/pack/eddy4R.stor/DESCRIPTION index 73fbc2a9..a66453e6 100644 --- a/pack/eddy4R.stor/DESCRIPTION +++ b/pack/eddy4R.stor/DESCRIPTION @@ -15,4 +15,4 @@ Suggests: License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 Encoding: UTF-8 LazyData: true -RoxygenNote: 6.1.1 +RoxygenNote: 7.0.2 diff --git a/pack/eddy4R.stor/man/def.time.rate.diff.Rd b/pack/eddy4R.stor/man/def.time.rate.diff.Rd index f643b8cd..62d74816 100644 --- a/pack/eddy4R.stor/man/def.time.rate.diff.Rd +++ b/pack/eddy4R.stor/man/def.time.rate.diff.Rd @@ -4,8 +4,14 @@ \alias{def.time.rate.diff} \title{Definition function: calculate time rate of change for ecse dp02 data and qfqm} \usage{ -def.time.rate.diff(dataInp, numDate, PrdWndwAgr, PrdIncrAgr, Date, - qfqmFlag = FALSE) +def.time.rate.diff( + dataInp, + numDate, + PrdWndwAgr, + PrdIncrAgr, + Date, + qfqmFlag = FALSE +) } \arguments{ \item{\code{dataInp}}{Input data.} diff --git a/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd b/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd index 52059d2d..930a92f9 100644 --- a/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd +++ b/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd @@ -4,11 +4,20 @@ \alias{wrap.dp01.ecse} \title{Wrapper function: Preprocessing and computing NEON eddy-covariance stroage exchange L1 data product descriptive statistics} \usage{ -wrap.dp01.ecse(dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", - "isoCo2", "isoH2o")[1], lvl, lvlMfcSampStor = NULL, lvlEnvHut = NULL, - lvlValv = NULL, lvlCrdH2oValvVali = NULL, data = list(), - qfInp = list(), TypeMeas = c("samp", "vali")[1], PrdMeas, PrdAgr, - idxTime = list()) +wrap.dp01.ecse( + dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], + lvl, + lvlMfcSampStor = NULL, + lvlEnvHut = NULL, + lvlValv = NULL, + lvlCrdH2oValvVali = NULL, + data = list(), + qfInp = list(), + TypeMeas = c("samp", "vali")[1], + PrdMeas, + PrdAgr, + idxTime = list() +) } \arguments{ \item{dp01}{A vector of class "character" containing the name of NEON ECSE dp01 which descriptive statistics are being calculated, \cr From d83df3c13f400dadcd9d48fdc9dbe6351826814f Mon Sep 17 00:00:00 2001 From: NDurden Date: Mon, 2 Mar 2020 17:44:17 +0000 Subject: [PATCH 027/168] eiv.r function --- pack/eddy4R.base/R/eiv.r | 257 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 pack/eddy4R.base/R/eiv.r diff --git a/pack/eddy4R.base/R/eiv.r b/pack/eddy4R.base/R/eiv.r new file mode 100644 index 00000000..2ab034ac --- /dev/null +++ b/pack/eddy4R.base/R/eiv.r @@ -0,0 +1,257 @@ +#http://www.mail-archive.com/r-help@r-project.org/msg85070.html: +#This is also called "Deming regression" and perhaps many other things. +#It is a lively topic in the validation of competing assay methods in the +#laboratory. I have a function 'deming.R' that does a generalized form +#of this, based on the (very nice) article below, the code is attached. +#(The attachments will be stripped by R-help, but the original requestor +#will get them.) If someone thinks this to be of general enough interest +#to package up on CRAN I'm happy donate the code to them -- I won't have +#the time for some while. +# Terry T. +#BD Ripley and M Thompson, Regression techniques for the detection +#of analytical bias, Analyst 112:377-383, 1987. + + +# Generalized Deming regression, based on Ripley, Analyst, 1987:377-383. +# +eiv <- function( + x, + y, + xstd, + ystd, + jackknife=T, + dfbeta=F, + scale=T, + intercept=F +){ + Call <- match.call() + n <- length(x) + p2 <- ifelse(intercept == F, 1, 2) #degrees of freedum in model + if (length(y) !=n) stop("x and y must be the same length") + if (length(xstd) != length(ystd)) + stop("xstd and ystd must be the same length") + + # Do missing value processing + nafun <- get(options()$na.action) + if (length(xstd)==n) { + tdata <- nafun(data.frame(x=x, y=y, xstd=xstd, ystd=ystd)) + x <- tdata$x + y <- tdata$y + xstd <- tdata$xstd + ystd <- tdata$ystd + } else { + tdata <- nafun(data.frame(x=x, y=y)) + x <- tdata$x + y <- tdata$y + if (length(xstd) !=2) stop("Wrong length for std specification") + xstd <- xstd[1] + xstd[2]*x + ystd <- ystd[1] + ystd[2] * y + } + + if (any(xstd <=0) || any(ystd <=0)) stop("Std must be positive") + + #optimality criteria for fit through zero + minfun0 <- function(beta, x, y, xv, yv) { + w <- 1/(yv + beta^2*xv) + alphahat <- 0 #constrain to zero + sum(w*(y-(alphahat + beta*x))^2) + } + + #optimality criteria for free regression + minfun <- function(beta, x, y, xv, yv) { + w <- 1/(yv + beta^2*xv) + alphahat <- sum(w * (y - beta*x))/ sum(w) + sum(w*(y-(alphahat + beta*x))^2) + } + + #function for slope calculation + afun <-function(beta, x, y, xv, yv) { + w <- 1/(yv + beta^2*xv) + sum(w * (y - beta*x))/ sum(w) + } + + #actual fit + fit <- optimize(minfun, c(.1, 10), x=x, y=y, xv=xstd^2, yv=ystd^2) + coef <- c(intercept=afun(fit$minimum, x, y, xstd^2, ystd^2), slope=fit$minimum) + + #switch between free and constrained regression + if(intercept == F) { + fit0 <- optimize(minfun0, coef[2]*c(.5, 1.5), x=x, y=y, xv=xstd^2, yv=ystd^2) + coef <- c(intercept=0, slope=fit0$minimum) + } + + #calculate scale + #weights (in units Y^2) + w <- 1 / (ystd^2 + (coef[2] * xstd)^2) + + #imputed "true" value of x + u <- w * (ystd^2 * x + xstd^2 * coef[2] * (y-coef[1])) + + #fitted values (imputed "true" value of y) + fit <- coef[1] + coef[2] * u + + + #non-scaled residuals + # print(sqrt(mean((x-u)^2 + (y-fit)^2))) + + + if (is.logical(scale) & scale) { + + #scaled residuals in x, y and combined (only makes sense if X and Y carry the same units!) + err1 <- (x - u) / xstd + err2 <- (y - fit) / ystd + #sigma <- sum(err1^2 + err2^2) / (n-p2) + + #weighted sum of squares / R-square + #http://tolstoy.newcastle.edu.au/R/help/06/08/33441.html + #in lm: values in weights being inversely proportional to the variances + #in weighted regression, u and fit beeing the best guess of the 'true' X and Y value + + #in residuals + SSEx <- sum(err1^2) + SSEy <- sum(err2^2) + SSE <- SSEx + SSEy + + + ##------------------------------ + ##INSERTION + + #percentage error + #unweighted + whr <- + 1:length(x) + # which(abs(x) > .20 & abs(y) > .20) + err1n <- ((x - u) / u)[whr] + err2n <- ((y - fit) / fit)[whr] + SSExn <- sum(err1n^2) + SSEyn <- sum(err2n^2) + SSEn <- SSExn + SSEyn + + # SSEn <- sum(rowMeans(cbind(err1n^2, err2n^2))) + RSEn <- sqrt(SSEn / (2*n-p2)) * 100 + # RSEn <- sqrt(median(c(err1n^2, err2n^2))) * 100 + mema <- eddy4R.base::def.med.mad(test=c(x[whr], y[whr]), refe=c(u[whr], fit[whr]), Perc=T) + MADn <- sqrt(mema[1]^2 + mema[2]^2) + rm(err1n, err2n, mema, SSExn, SSEyn, SSEn) + + #weighted + err1n <- (x - u) / u / xstd + err2n <- (y - fit) / fit / ystd + SSExn <- sum(err1n^2) + SSEyn <- sum(err2n^2) + SSEn <- SSExn + SSEyn + RSEnw <- sqrt(SSEn / (sum(w) * (n-p2)/n)) * 100 + rm(err1n, err2n, SSExn, SSEyn, SSEn) + + ##------------------------------ + + + #in variables + if(intercept == T) { + m <- sum(w * u / sum(w)) #weighted average (must use same weights as in regression fct.) + SSFx <- sum(((u - m) / xstd)^2) + m <- sum(w * fit / sum(w)) #weighted average + SSFy <- sum(((fit - m) / ystd)^2) + } else { + SSFx <- sum((u / xstd)^2) + SSFy <- sum((fit / ystd)^2) + } + SSF <- SSFx + SSFy + + #R-square + RSQ <- SSF / (SSF + SSE) + + #F-statistic + #degrees of freedom between models + DFnum <- 1 + #degrees of freedom of sample size + DFden <- n - p2 + #numerator + num <- SSF / DFnum + #denominator + den <- SSE / DFden + #value of F-statistic + fsta <- num / den + #false-rejection probability + pval <- pf(fsta, DFnum, DFden, lower.tail=FALSE) + #prepare output + FSTA <- c(fsta, DFnum, DFden, pval) + names(FSTA) <- c("value", "numdf", "dendf", "p-value") + + #scaled residuals after Ripley (the same): + r <- (y - (coef[1] + coef[2]*x)) * sqrt(w) + SSE <- sum(r^2) + sigma <- SSE / (n-p2) + + #residual standard error + RSE <- sqrt(SSE / (sum(w) * (n-p2)/n)) + + } else sigma <- scale^2 + + ##Z-test for significance: 5 % significance rejects values outside [-1.96, 1.96] + ##what does that do, how does it work, how to interpret? + + #weighted mean of x + x_tilde <- sum(w*x) / sum(w) + + #test for a=0 + test2 <- coef[1] * sqrt(sum(w*x^2) / sum(w*(x-u)^2) / sigma) + #test2 <- coef[1] / sqrt(sum(w*x^2) / sum(w) * sum(w * (x - x_tilde))) #following Ripley + + #test for beta=1 + test1 <- (coef[2] - 1) * sqrt(sum(w * (x-u)^2) / sigma) + #test1 <- (coef[2] - 1) * sqrt(sum(w * (x - x_tilde))) #following Ripley + + rlist <- list(coefficients=coef, test1=test1, test0=test2, scale=sigma, + err1=err1, err2=err2, u=u, r=r, MADn=MADn, SSE=SSE, RSE=RSE, RSEn=RSEn, RSEnw=RSEnw, RSQ=RSQ, FSTA=FSTA, weights=w, fitted.values=fit) + + if (jackknife) { + delta <- matrix(0., nrow=n, ncol=2) + if(intercept == F) { + for (i in 1:n) { + fit <- optimize(minfun0, c(.5, 1.5)*coef[2], + x=x[-i], y=y[-i], xv=xstd[-i]^2, yv=ystd[-i]^2) + delta[i,] <- coef - c(0, fit$minimum) + } + } else { + for (i in 1:n) { + fit <- optimize(minfun, c(.5, 1.5)*coef[2], + x=x[-i], y=y[-i], xv=xstd[-i]^2, yv=ystd[-i]^2) + ahat <- afun(fit$minimum, x[-i], y[-i], xstd[-i]^2, ystd[-i]^2) + delta[i,] <- coef - c(ahat, fit$minimum) + } + } + rlist$variance <- t(delta) %*% delta + if (dfbeta) rlist$dfbeta <- delta + } + rlist$call <- Call + class(rlist) <- 'eiv' + rlist +} + + +print.eiv <- function(x=rlist, ...) { + cat("\nCall:\n", deparse(x$call), "\n\n", sep = "") + if (is.null(x$variance)) { + table <- matrix(0., nrow=2, ncol=3) + table[,1] <- x$coefficients + table[,2] <- c(x$test0, x$test1) + table[,3] <- pnorm(-2*abs(table[,2])) + dimnames(table) <- list(c("Intercept", "Slope"), + c("Coef", "z", "p")) + } + else { + table <- matrix(0., nrow=2, ncol=4) + table[,1] <- x$coefficients + table[,2] <- sqrt(diag(x$variance)) + table[,3] <- c(x$test0, x$test1) + table[,4] <- pnorm(-2*abs(table[,3])) + dimnames(table) <- list(c("Intercept", "Slope"), + c("Coef", "se(coef)", "z", "p")) + } + print(table, ...) + cat("\n Normalized median residual standard error [%]: ", format(x$MADn, ...), "\n") + cat("\n Weighted adjusted R-squared: ", format(x$RSQ, ...), "\n") + cat("\n p-value: ", format(x$FSTA[4], ...), "\n") + invisible(x) +} \ No newline at end of file From 61df9ad90e3464444261d5ab2ea366c6d9a18488 Mon Sep 17 00:00:00 2001 From: NDurden Date: Mon, 2 Mar 2020 17:50:21 +0000 Subject: [PATCH 028/168] delete the sensitivity test (they are saved in valiSensTest branch) --- pack/eddy4R.base/R/eiv.r | 257 --------------------------------------- 1 file changed, 257 deletions(-) delete mode 100644 pack/eddy4R.base/R/eiv.r diff --git a/pack/eddy4R.base/R/eiv.r b/pack/eddy4R.base/R/eiv.r deleted file mode 100644 index 2ab034ac..00000000 --- a/pack/eddy4R.base/R/eiv.r +++ /dev/null @@ -1,257 +0,0 @@ -#http://www.mail-archive.com/r-help@r-project.org/msg85070.html: -#This is also called "Deming regression" and perhaps many other things. -#It is a lively topic in the validation of competing assay methods in the -#laboratory. I have a function 'deming.R' that does a generalized form -#of this, based on the (very nice) article below, the code is attached. -#(The attachments will be stripped by R-help, but the original requestor -#will get them.) If someone thinks this to be of general enough interest -#to package up on CRAN I'm happy donate the code to them -- I won't have -#the time for some while. -# Terry T. -#BD Ripley and M Thompson, Regression techniques for the detection -#of analytical bias, Analyst 112:377-383, 1987. - - -# Generalized Deming regression, based on Ripley, Analyst, 1987:377-383. -# -eiv <- function( - x, - y, - xstd, - ystd, - jackknife=T, - dfbeta=F, - scale=T, - intercept=F -){ - Call <- match.call() - n <- length(x) - p2 <- ifelse(intercept == F, 1, 2) #degrees of freedum in model - if (length(y) !=n) stop("x and y must be the same length") - if (length(xstd) != length(ystd)) - stop("xstd and ystd must be the same length") - - # Do missing value processing - nafun <- get(options()$na.action) - if (length(xstd)==n) { - tdata <- nafun(data.frame(x=x, y=y, xstd=xstd, ystd=ystd)) - x <- tdata$x - y <- tdata$y - xstd <- tdata$xstd - ystd <- tdata$ystd - } else { - tdata <- nafun(data.frame(x=x, y=y)) - x <- tdata$x - y <- tdata$y - if (length(xstd) !=2) stop("Wrong length for std specification") - xstd <- xstd[1] + xstd[2]*x - ystd <- ystd[1] + ystd[2] * y - } - - if (any(xstd <=0) || any(ystd <=0)) stop("Std must be positive") - - #optimality criteria for fit through zero - minfun0 <- function(beta, x, y, xv, yv) { - w <- 1/(yv + beta^2*xv) - alphahat <- 0 #constrain to zero - sum(w*(y-(alphahat + beta*x))^2) - } - - #optimality criteria for free regression - minfun <- function(beta, x, y, xv, yv) { - w <- 1/(yv + beta^2*xv) - alphahat <- sum(w * (y - beta*x))/ sum(w) - sum(w*(y-(alphahat + beta*x))^2) - } - - #function for slope calculation - afun <-function(beta, x, y, xv, yv) { - w <- 1/(yv + beta^2*xv) - sum(w * (y - beta*x))/ sum(w) - } - - #actual fit - fit <- optimize(minfun, c(.1, 10), x=x, y=y, xv=xstd^2, yv=ystd^2) - coef <- c(intercept=afun(fit$minimum, x, y, xstd^2, ystd^2), slope=fit$minimum) - - #switch between free and constrained regression - if(intercept == F) { - fit0 <- optimize(minfun0, coef[2]*c(.5, 1.5), x=x, y=y, xv=xstd^2, yv=ystd^2) - coef <- c(intercept=0, slope=fit0$minimum) - } - - #calculate scale - #weights (in units Y^2) - w <- 1 / (ystd^2 + (coef[2] * xstd)^2) - - #imputed "true" value of x - u <- w * (ystd^2 * x + xstd^2 * coef[2] * (y-coef[1])) - - #fitted values (imputed "true" value of y) - fit <- coef[1] + coef[2] * u - - - #non-scaled residuals - # print(sqrt(mean((x-u)^2 + (y-fit)^2))) - - - if (is.logical(scale) & scale) { - - #scaled residuals in x, y and combined (only makes sense if X and Y carry the same units!) - err1 <- (x - u) / xstd - err2 <- (y - fit) / ystd - #sigma <- sum(err1^2 + err2^2) / (n-p2) - - #weighted sum of squares / R-square - #http://tolstoy.newcastle.edu.au/R/help/06/08/33441.html - #in lm: values in weights being inversely proportional to the variances - #in weighted regression, u and fit beeing the best guess of the 'true' X and Y value - - #in residuals - SSEx <- sum(err1^2) - SSEy <- sum(err2^2) - SSE <- SSEx + SSEy - - - ##------------------------------ - ##INSERTION - - #percentage error - #unweighted - whr <- - 1:length(x) - # which(abs(x) > .20 & abs(y) > .20) - err1n <- ((x - u) / u)[whr] - err2n <- ((y - fit) / fit)[whr] - SSExn <- sum(err1n^2) - SSEyn <- sum(err2n^2) - SSEn <- SSExn + SSEyn - - # SSEn <- sum(rowMeans(cbind(err1n^2, err2n^2))) - RSEn <- sqrt(SSEn / (2*n-p2)) * 100 - # RSEn <- sqrt(median(c(err1n^2, err2n^2))) * 100 - mema <- eddy4R.base::def.med.mad(test=c(x[whr], y[whr]), refe=c(u[whr], fit[whr]), Perc=T) - MADn <- sqrt(mema[1]^2 + mema[2]^2) - rm(err1n, err2n, mema, SSExn, SSEyn, SSEn) - - #weighted - err1n <- (x - u) / u / xstd - err2n <- (y - fit) / fit / ystd - SSExn <- sum(err1n^2) - SSEyn <- sum(err2n^2) - SSEn <- SSExn + SSEyn - RSEnw <- sqrt(SSEn / (sum(w) * (n-p2)/n)) * 100 - rm(err1n, err2n, SSExn, SSEyn, SSEn) - - ##------------------------------ - - - #in variables - if(intercept == T) { - m <- sum(w * u / sum(w)) #weighted average (must use same weights as in regression fct.) - SSFx <- sum(((u - m) / xstd)^2) - m <- sum(w * fit / sum(w)) #weighted average - SSFy <- sum(((fit - m) / ystd)^2) - } else { - SSFx <- sum((u / xstd)^2) - SSFy <- sum((fit / ystd)^2) - } - SSF <- SSFx + SSFy - - #R-square - RSQ <- SSF / (SSF + SSE) - - #F-statistic - #degrees of freedom between models - DFnum <- 1 - #degrees of freedom of sample size - DFden <- n - p2 - #numerator - num <- SSF / DFnum - #denominator - den <- SSE / DFden - #value of F-statistic - fsta <- num / den - #false-rejection probability - pval <- pf(fsta, DFnum, DFden, lower.tail=FALSE) - #prepare output - FSTA <- c(fsta, DFnum, DFden, pval) - names(FSTA) <- c("value", "numdf", "dendf", "p-value") - - #scaled residuals after Ripley (the same): - r <- (y - (coef[1] + coef[2]*x)) * sqrt(w) - SSE <- sum(r^2) - sigma <- SSE / (n-p2) - - #residual standard error - RSE <- sqrt(SSE / (sum(w) * (n-p2)/n)) - - } else sigma <- scale^2 - - ##Z-test for significance: 5 % significance rejects values outside [-1.96, 1.96] - ##what does that do, how does it work, how to interpret? - - #weighted mean of x - x_tilde <- sum(w*x) / sum(w) - - #test for a=0 - test2 <- coef[1] * sqrt(sum(w*x^2) / sum(w*(x-u)^2) / sigma) - #test2 <- coef[1] / sqrt(sum(w*x^2) / sum(w) * sum(w * (x - x_tilde))) #following Ripley - - #test for beta=1 - test1 <- (coef[2] - 1) * sqrt(sum(w * (x-u)^2) / sigma) - #test1 <- (coef[2] - 1) * sqrt(sum(w * (x - x_tilde))) #following Ripley - - rlist <- list(coefficients=coef, test1=test1, test0=test2, scale=sigma, - err1=err1, err2=err2, u=u, r=r, MADn=MADn, SSE=SSE, RSE=RSE, RSEn=RSEn, RSEnw=RSEnw, RSQ=RSQ, FSTA=FSTA, weights=w, fitted.values=fit) - - if (jackknife) { - delta <- matrix(0., nrow=n, ncol=2) - if(intercept == F) { - for (i in 1:n) { - fit <- optimize(minfun0, c(.5, 1.5)*coef[2], - x=x[-i], y=y[-i], xv=xstd[-i]^2, yv=ystd[-i]^2) - delta[i,] <- coef - c(0, fit$minimum) - } - } else { - for (i in 1:n) { - fit <- optimize(minfun, c(.5, 1.5)*coef[2], - x=x[-i], y=y[-i], xv=xstd[-i]^2, yv=ystd[-i]^2) - ahat <- afun(fit$minimum, x[-i], y[-i], xstd[-i]^2, ystd[-i]^2) - delta[i,] <- coef - c(ahat, fit$minimum) - } - } - rlist$variance <- t(delta) %*% delta - if (dfbeta) rlist$dfbeta <- delta - } - rlist$call <- Call - class(rlist) <- 'eiv' - rlist -} - - -print.eiv <- function(x=rlist, ...) { - cat("\nCall:\n", deparse(x$call), "\n\n", sep = "") - if (is.null(x$variance)) { - table <- matrix(0., nrow=2, ncol=3) - table[,1] <- x$coefficients - table[,2] <- c(x$test0, x$test1) - table[,3] <- pnorm(-2*abs(table[,2])) - dimnames(table) <- list(c("Intercept", "Slope"), - c("Coef", "z", "p")) - } - else { - table <- matrix(0., nrow=2, ncol=4) - table[,1] <- x$coefficients - table[,2] <- sqrt(diag(x$variance)) - table[,3] <- c(x$test0, x$test1) - table[,4] <- pnorm(-2*abs(table[,3])) - dimnames(table) <- list(c("Intercept", "Slope"), - c("Coef", "se(coef)", "z", "p")) - } - print(table, ...) - cat("\n Normalized median residual standard error [%]: ", format(x$MADn, ...), "\n") - cat("\n Weighted adjusted R-squared: ", format(x$RSQ, ...), "\n") - cat("\n p-value: ", format(x$FSTA[4], ...), "\n") - invisible(x) -} \ No newline at end of file From e447d66a71fef9950d359c1d361440527f91014c Mon Sep 17 00:00:00 2001 From: NDurden Date: Thu, 5 Mar 2020 14:47:08 +0000 Subject: [PATCH 029/168] Set all thresholds to screen linear coefficients to FALSE. --- pack/eddy4R.base/R/wrap.irga.vali.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index 4f0b52c4..0f573865 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -75,6 +75,8 @@ # reporting the rtioMoleDryH2oVali table # Natchaya P-Durden (2020-01-31) # adjust workflow to run MLFR even missing one gas cylinder +# Natchaya P-Durden (2020-03-05) +# Set all thresholds to screen linear coefficients to FALSE. ############################################################################################## wrap.irga.vali <- function( @@ -498,7 +500,7 @@ wrap.irga.vali <- function( #applying the calculated coefficients to measured data #Calculate time-series (20Hz) of slope and zero offset - rpt[[DateProc]]$rtioMoleDryCo2Cor <- eddy4R.base::def.irga.vali.cor(data = data, DateProc = DateProc, coef = tmpCoef, valiData = valiData, valiCrit = valiCrit, ScalMax = 20, FracSlpMax = 0.1, Freq = 20) + rpt[[DateProc]]$rtioMoleDryCo2Cor <- eddy4R.base::def.irga.vali.cor(data = data, DateProc = DateProc, coef = tmpCoef, valiData = valiData, valiCrit = valiCrit, ScalMax = FALSE, FracSlpMax = FALSE, OfstMax = FALSE, Freq = 20) #return results return(rpt) From 093facd97e564374b2d6f68a1c24207717d92c27 Mon Sep 17 00:00:00 2001 From: NDurden Date: Thu, 5 Mar 2020 14:53:41 +0000 Subject: [PATCH 030/168] add filters to screen coefficients to function parameters --- pack/eddy4R.base/R/wrap.irga.vali.R | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index 0f573865..58cab501 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -10,6 +10,10 @@ #' @param qfqmFlag List consisting of \code{ff::ffdf} file-backed objects containing the IRGA quality flags. #' @param gasRefe List containing the values of the reference gases. [mol mol-1] #' @param DateProc A vector of class "character" containing the processing date. +#' @param ScalMax Maximum scale value. The validation correction will not apply if scale (resulted from maximum-likelihood fitting of a functional relationship (MLFR)) is greater than ScalMax or ScalMax = FALSE. Defaults to FALSE. +#' @param FracSlpMax Maximum fraction of slope value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the FracSlpMax or FracSlpMax = FALSE. Defaults to FALSE. +#' @param OfstMax Maximum offset value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the OfstMax (unit in mol mol-1) or OfstMax = FALSE. Defaults to FALSE. + #' @return #' The returned object consists of:\cr @@ -83,7 +87,10 @@ wrap.irga.vali <- function( data, qfqmFlag, gasRefe, - DateProc + DateProc, + ScalMax = FALSE, + FracSlpMax = FALSE, + OfstMax = FALSE, ) { #adding library @@ -500,7 +507,7 @@ wrap.irga.vali <- function( #applying the calculated coefficients to measured data #Calculate time-series (20Hz) of slope and zero offset - rpt[[DateProc]]$rtioMoleDryCo2Cor <- eddy4R.base::def.irga.vali.cor(data = data, DateProc = DateProc, coef = tmpCoef, valiData = valiData, valiCrit = valiCrit, ScalMax = FALSE, FracSlpMax = FALSE, OfstMax = FALSE, Freq = 20) + rpt[[DateProc]]$rtioMoleDryCo2Cor <- eddy4R.base::def.irga.vali.cor(data = data, DateProc = DateProc, coef = tmpCoef, valiData = valiData, valiCrit = valiCrit, ScalMax = ScalMax, FracSlpMax = FracSlpMax, OfstMax = OfstMax, Freq = 20) #return results return(rpt) From 5800a2a8d8c84f1fd0e78a4c2ed984f45a76a85c Mon Sep 17 00:00:00 2001 From: NDurden Date: Thu, 5 Mar 2020 14:55:31 +0000 Subject: [PATCH 031/168] deleted comma --- pack/eddy4R.base/R/wrap.irga.vali.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index 58cab501..9afd63aa 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -90,7 +90,7 @@ wrap.irga.vali <- function( DateProc, ScalMax = FALSE, FracSlpMax = FALSE, - OfstMax = FALSE, + OfstMax = FALSE ) { #adding library From 830fe45d01923a0a55ecde34b53cdd90f4be501e Mon Sep 17 00:00:00 2001 From: NDurden Date: Thu, 5 Mar 2020 16:06:34 +0000 Subject: [PATCH 032/168] .Rd file for wrap.irga.vali --- pack/eddy4R.base/man/wrap.irga.vali.Rd | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.base/man/wrap.irga.vali.Rd b/pack/eddy4R.base/man/wrap.irga.vali.Rd index 030cf8ea..d53301fb 100644 --- a/pack/eddy4R.base/man/wrap.irga.vali.Rd +++ b/pack/eddy4R.base/man/wrap.irga.vali.Rd @@ -4,7 +4,15 @@ \alias{wrap.irga.vali} \title{Wrapper function: Validation processing for IRGA} \usage{ -wrap.irga.vali(data, qfqmFlag, gasRefe, DateProc) +wrap.irga.vali( + data, + qfqmFlag, + gasRefe, + DateProc, + ScalMax = FALSE, + FracSlpMax = FALSE, + OfstMax = FALSE +) } \arguments{ \item{data}{List consisting of \code{ff::ffdf} file-backed objects containing the dp0p input IRGA.} @@ -14,6 +22,12 @@ wrap.irga.vali(data, qfqmFlag, gasRefe, DateProc) \item{gasRefe}{List containing the values of the reference gases. [mol mol-1]} \item{DateProc}{A vector of class "character" containing the processing date.} + +\item{ScalMax}{Maximum scale value. The validation correction will not apply if scale (resulted from maximum-likelihood fitting of a functional relationship (MLFR)) is greater than ScalMax or ScalMax = FALSE. Defaults to FALSE.} + +\item{FracSlpMax}{Maximum fraction of slope value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the FracSlpMax or FracSlpMax = FALSE. Defaults to FALSE.} + +\item{OfstMax}{Maximum offset value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the OfstMax (unit in mol mol-1) or OfstMax = FALSE. Defaults to FALSE.} } \value{ The returned object consists of:\cr From 467617b8a98e0a4ee100f058248bc35e9c155419 Mon Sep 17 00:00:00 2001 From: ddurden Date: Sun, 8 Mar 2020 07:28:00 +0000 Subject: [PATCH 033/168] - updating function for qfqm read in to handle data and deal with attributes --- pack/eddy4R.base/R/def.hdf5.read.qfqm.R | 52 ++++++++++++++++++++----- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.read.qfqm.R b/pack/eddy4R.base/R/def.hdf5.read.qfqm.R index 93d3ec88..e4f9bdaf 100644 --- a/pack/eddy4R.base/R/def.hdf5.read.qfqm.R +++ b/pack/eddy4R.base/R/def.hdf5.read.qfqm.R @@ -51,32 +51,64 @@ def.hdf5.read.qfqm <- function( VarLoca, LvlTowr = c("000_040", "000_050", "000_060")[3], FreqLoca, + DataType = c(data,qfqm)[1], MethMeas = c("ecte", "ecse")[1] ){ #Read in the flags from the HDF5 file if (MethMeas == "ecte") { -qfqm <- rhdf5::h5read(file = base::paste0(DirInpLoca, "/ECTE_dp0p_", SiteLoca, "_", DateLoca, ".h5"), - name = base::paste0("/", SiteLoca, "/dp0p/qfqm/", VarLoca, "/",LvlTowr), read.attributes = TRUE) +rpt <- rhdf5::h5read(file = base::paste0(DirInpLoca, "/ECTE_dp0p_", SiteLoca, "_", DateLoca, ".h5"), + name = base::paste0("/", SiteLoca, "/dp0p/",DataType,"/", VarLoca, "/",LvlTowr), read.attributes = TRUE, drop = TRUE) #drop converts to vector } if (MethMeas == "ecse") { -qfqm <- rhdf5::h5read(file = base::paste0(DirInpLoca, "/ECSE_dp0p_", SiteLoca, "_", DateLoca, ".h5"), - name = base::paste0("/", SiteLoca, "/dp0p/qfqm/", VarLoca, "/",LvlTowr), read.attributes = TRUE) +rpt <- rhdf5::h5read(file = base::paste0(DirInpLoca, "/ECSE_dp0p_", SiteLoca, "_", DateLoca, ".h5"), + name = base::paste0("/", SiteLoca, "/dp0p/",DataType,"/", VarLoca, "/",LvlTowr), read.attributes = TRUE, drop = TRUE) #drop converts to vector } +# print message to screen +msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " hdf5 read-in complete") +tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) + #Convert each flag to a vector from a 1D array -for(idx in base::names(qfqm)) qfqm[[idx]] <- base::as.vector(qfqm[[idx]]); base::rm(idx) +#for(idx in base::names(rpt)) rpt[[idx]] <- base::as.vector(rpt[[idx]]); base::rm(idx) + +#Cache attributes before coverting to data.frame +attr <- attributes(rpt) + +# convert list to data.frame +rpt <- base::as.data.frame(rpt, stringsAsFactors = FALSE) + +# convert type of variable time +if("time" %in% colnames(rpt)){ +rpt$time <- base::as.POSIXct(rpt$time, format="%Y-%m-%dT%H:%M:%OSZ", tz="UTC") + 0.0001 +} + +# perform unit conversion +rpt <- base::suppressWarnings(eddy4R.base::def.unit.conv(data = rpt, + unitFrom = attributes(rpt)$Unit, + unitTo = "intl")) + +# sd assign attribute to gasRefe +if (VarLoca == "gasRefe"){ + names(attr(rpt,"Sd")) <- attr(rpt,"Name") + names(attr(rpt,"Sd")) <- attr(rpt,"Name") + base::names(rpt$Sd) <- rpt$Name + base::names(attr$DfSd) <- attr$Name + base::attributes(data)$sd <- attr$Sd[base::names(data)] + base::attributes(data)$DfSd <- attr$DfSd[base::names(data)] +} #Apply units to each flag -lapply(seq_len(length(qfqm)), function(x){ +lapply(seq_len(length(rpt)), function(x){ tryCatch({rlog$debug(x)}, error=function(cond){print(x)}) - attributes(qfqm[[x]])$Unit <<- attributes(qfqm)$Unit[[x]] + attributes(rpt[[x]])$unit <<- attributes(rpt)$Unit[[x]] + attributes(rpt[[x]])$`Dspk$Br86$MaxReso` <<- attributes(rpt)$`Dspk$Br86$MaxReso`[[x]] + attributes(rpt[[x]])$`Dspk$Br86$NumBin` <<- attributes(rpt)$`Dspk$Br86$NumBin`[[x]] + attributes(rpt[[x]])$`Dspk$Br86$NumWndw` <<- attributes(rpt)$`Dspk$Br86$NumWndw`[[x]] }) -# convert list to data.frame -qfqm <- base::as.data.frame(qfqm, stringsAsFactors = FALSE) -return(qfqm) +return(rpt) } From bbe663058144f382331ca172bfc9025097018683 Mon Sep 17 00:00:00 2001 From: ddurden Date: Sun, 8 Mar 2020 08:15:03 +0000 Subject: [PATCH 034/168] - fixing attribute loss issues --- pack/eddy4R.base/R/def.hdf5.read.qfqm.R | 26 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.read.qfqm.R b/pack/eddy4R.base/R/def.hdf5.read.qfqm.R index e4f9bdaf..724d9ba6 100644 --- a/pack/eddy4R.base/R/def.hdf5.read.qfqm.R +++ b/pack/eddy4R.base/R/def.hdf5.read.qfqm.R @@ -58,12 +58,12 @@ def.hdf5.read.qfqm <- function( #Read in the flags from the HDF5 file if (MethMeas == "ecte") { rpt <- rhdf5::h5read(file = base::paste0(DirInpLoca, "/ECTE_dp0p_", SiteLoca, "_", DateLoca, ".h5"), - name = base::paste0("/", SiteLoca, "/dp0p/",DataType,"/", VarLoca, "/",LvlTowr), read.attributes = TRUE, drop = TRUE) #drop converts to vector + name = base::paste0("/", SiteLoca, "/dp0p/",DataType,"/", VarLoca, "/",LvlTowr), read.attributes = TRUE) } if (MethMeas == "ecse") { rpt <- rhdf5::h5read(file = base::paste0(DirInpLoca, "/ECSE_dp0p_", SiteLoca, "_", DateLoca, ".h5"), - name = base::paste0("/", SiteLoca, "/dp0p/",DataType,"/", VarLoca, "/",LvlTowr), read.attributes = TRUE, drop = TRUE) #drop converts to vector + name = base::paste0("/", SiteLoca, "/dp0p/",DataType,"/", VarLoca, "/",LvlTowr), read.attributes = TRUE) } # print message to screen @@ -71,14 +71,19 @@ msg <- paste0("dataset ", DateLoca, ": ", VarLoca, " hdf5 read-in complete") tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) #Convert each flag to a vector from a 1D array -#for(idx in base::names(rpt)) rpt[[idx]] <- base::as.vector(rpt[[idx]]); base::rm(idx) +for(idx in base::names(rpt)) rpt[[idx]] <- base::as.vector(rpt[[idx]]); base::rm(idx) #Cache attributes before coverting to data.frame attr <- attributes(rpt) +#Convert each flag to a vector from a 1D array +for(idx in base::names(attr)) attr[[idx]] <- base::as.vector(attr[[idx]]); base::rm(idx) # convert list to data.frame rpt <- base::as.data.frame(rpt, stringsAsFactors = FALSE) +#Reapply attributes to reported data.frame +attributes(rpt) <- attr + # convert type of variable time if("time" %in% colnames(rpt)){ rpt$time <- base::as.POSIXct(rpt$time, format="%Y-%m-%dT%H:%M:%OSZ", tz="UTC") + 0.0001 @@ -89,20 +94,23 @@ rpt <- base::suppressWarnings(eddy4R.base::def.unit.conv(data = rpt, unitFrom = attributes(rpt)$Unit, unitTo = "intl")) + +#Reapply attributes to reported data.frame +attributes(rpt) <- attr[grep("Unit", names(attr), value = TRUE, invert = TRUE)] + + # sd assign attribute to gasRefe if (VarLoca == "gasRefe"){ names(attr(rpt,"Sd")) <- attr(rpt,"Name") - names(attr(rpt,"Sd")) <- attr(rpt,"Name") - base::names(rpt$Sd) <- rpt$Name - base::names(attr$DfSd) <- attr$Name - base::attributes(data)$sd <- attr$Sd[base::names(data)] - base::attributes(data)$DfSd <- attr$DfSd[base::names(data)] + names(attr(rpt,"DfSd")) <- attr(rpt,"Name") + #base::attributes(rpt)$sd <- attr$Sd[base::names(rpt)] + #base::attributes(rpt)$DfSd <- attr$DfSd[base::names(rpt)] } #Apply units to each flag lapply(seq_len(length(rpt)), function(x){ tryCatch({rlog$debug(x)}, error=function(cond){print(x)}) - attributes(rpt[[x]])$unit <<- attributes(rpt)$Unit[[x]] + attributes(rpt[[x]])$unit <<- attributes(rpt)$unit[[x]] attributes(rpt[[x]])$`Dspk$Br86$MaxReso` <<- attributes(rpt)$`Dspk$Br86$MaxReso`[[x]] attributes(rpt[[x]])$`Dspk$Br86$NumBin` <<- attributes(rpt)$`Dspk$Br86$NumBin`[[x]] attributes(rpt[[x]])$`Dspk$Br86$NumWndw` <<- attributes(rpt)$`Dspk$Br86$NumWndw`[[x]] From 143cd7a02dd9d5518d56ef0207c9de5d1fd2c2ac Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 9 Mar 2020 21:22:35 +0000 Subject: [PATCH 035/168] - adding internal unit conversion and attribute reassignment --- pack/eddy4R.base/R/def.hdf5.read.qfqm.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.read.qfqm.R b/pack/eddy4R.base/R/def.hdf5.read.qfqm.R index 724d9ba6..0cd55b80 100644 --- a/pack/eddy4R.base/R/def.hdf5.read.qfqm.R +++ b/pack/eddy4R.base/R/def.hdf5.read.qfqm.R @@ -82,7 +82,7 @@ for(idx in base::names(attr)) attr[[idx]] <- base::as.vector(attr[[idx]]); base: rpt <- base::as.data.frame(rpt, stringsAsFactors = FALSE) #Reapply attributes to reported data.frame -attributes(rpt) <- attr +attributes(rpt)$unit <- attr$Unit # convert type of variable time if("time" %in% colnames(rpt)){ @@ -91,12 +91,14 @@ rpt$time <- base::as.POSIXct(rpt$time, format="%Y-%m-%dT%H:%M:%OSZ", tz="UTC") + # perform unit conversion rpt <- base::suppressWarnings(eddy4R.base::def.unit.conv(data = rpt, - unitFrom = attributes(rpt)$Unit, + unitFrom = attributes(rpt)$unit, unitTo = "intl")) #Reapply attributes to reported data.frame -attributes(rpt) <- attr[grep("Unit", names(attr), value = TRUE, invert = TRUE)] +lapply(grep("Unit", names(attr), value = TRUE, invert = TRUE), function(x){ + attributes(rpt)[x] <<- attr[x] + }) # sd assign attribute to gasRefe From 767138a27b9a1e3672c1d94924ea8102c3c4cda0 Mon Sep 17 00:00:00 2001 From: ddurden Date: Wed, 11 Mar 2020 05:42:35 +0000 Subject: [PATCH 036/168] - documentation update from repackaging --- pack/eddy4R.base/DESCRIPTION | 2 +- pack/eddy4R.base/man/def.bin.Rd | 10 ++++++-- pack/eddy4R.base/man/def.dens.pres.pois.Rd | 8 +++++-- pack/eddy4R.base/man/def.dens.temp.pois.Rd | 8 +++++-- pack/eddy4R.base/man/def.dp01.agr.ecte.Rd | 8 +++++-- pack/eddy4R.base/man/def.hdf5.crte.Rd | 16 +++++++++---- pack/eddy4R.base/man/def.hdf5.extr.Rd | 12 +++++++--- pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd | 12 +++++++--- pack/eddy4R.base/man/def.hdf5.wrte.dp01.Rd | 11 +++++++-- pack/eddy4R.base/man/def.idx.agr.Rd | 11 +++++++-- pack/eddy4R.base/man/def.inst.depe.Rd | 8 +++++-- pack/eddy4R.base/man/def.irga.vali.cor.Rd | 12 ++++++++-- pack/eddy4R.base/man/def.lag.Rd | 20 ++++++++++++---- pack/eddy4R.base/man/def.met.body.Rd | 9 +++++--- pack/eddy4R.base/man/def.mtch.out.refe.Rd | 2 +- pack/eddy4R.base/man/def.para.flow.Rd | 23 +++++++++++++++---- pack/eddy4R.base/man/def.rglr.Rd | 19 ++++++++++----- .../eddy4R.base/man/def.rmsd.diff.prcs.rsq.Rd | 3 +-- pack/eddy4R.base/man/def.temp.pres.pois.Rd | 8 +++++-- pack/eddy4R.base/man/def.unit.conv.Rd | 11 ++++++--- pack/eddy4R.base/man/wrap.agr.vari.seSq.Rd | 3 +-- pack/eddy4R.base/man/wrap.dp00.rglr.ecse.Rd | 11 +++++++-- pack/eddy4R.base/man/wrap.dp01.qfqm.ecte.Rd | 9 ++++++-- pack/eddy4R.base/man/wrap.hdf5.read.Rd | 18 +++++++++++---- pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd | 12 ++++++++-- .../man/wrap.hdf5.wrte.dp01.api.Rd | 12 +++++++--- pack/eddy4R.base/man/wrap.para.thsh.Rd | 6 +++-- pack/eddy4R.base/man/wrap.unit.conv.out.ec.Rd | 7 ++++-- pack/eddy4R.qaqc/DESCRIPTION | 2 +- pack/eddy4R.qaqc/man/def.agr.file.dp00.Rd | 11 +++++++-- pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd | 12 ++++++---- pack/eddy4R.qaqc/man/def.dspk.br86.Rd | 9 ++++++-- pack/eddy4R.qaqc/man/def.dspk.wndw.Rd | 14 +++++++---- pack/eddy4R.qaqc/man/def.plau.Rd | 19 +++++++++------ pack/eddy4R.qaqc/man/def.plot.dp01.qfqm.Rd | 10 ++++---- pack/eddy4R.qaqc/man/def.qf.ecte.Rd | 9 ++++++-- pack/eddy4R.qaqc/man/def.qf.rmv.data.Rd | 10 ++++++-- pack/eddy4R.qaqc/man/wrap.dp01.qfqm.Rd | 17 ++++++++------ pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd | 23 ++++++++++++++----- pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd | 14 +++++++---- pack/eddy4R.qaqc/man/wrap.qf.rmv.data.Rd | 9 ++++++-- pack/eddy4R.stor/DESCRIPTION | 2 +- pack/eddy4R.stor/man/def.time.rate.diff.Rd | 10 ++++++-- pack/eddy4R.stor/man/wrap.dp01.ecse.Rd | 19 +++++++++++---- 44 files changed, 352 insertions(+), 129 deletions(-) diff --git a/pack/eddy4R.base/DESCRIPTION b/pack/eddy4R.base/DESCRIPTION index a09c94b2..39f6af00 100644 --- a/pack/eddy4R.base/DESCRIPTION +++ b/pack/eddy4R.base/DESCRIPTION @@ -28,4 +28,4 @@ Suggests: NEONprocIS.base License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 LazyData: true -RoxygenNote: 6.1.1 +RoxygenNote: 7.0.2 diff --git a/pack/eddy4R.base/man/def.bin.Rd b/pack/eddy4R.base/man/def.bin.Rd index ce2416db..03064f7f 100644 --- a/pack/eddy4R.base/man/def.bin.Rd +++ b/pack/eddy4R.base/man/def.bin.Rd @@ -4,8 +4,14 @@ \alias{def.bin} \title{Definition function: Binning data} \usage{ -def.bin(idep, depe, RngMinMax = NULL, NumBin, widtBin = c("lin", - "log10", "exp10", "logExp", "expLog"), meanFunc = c("mean", "median")) +def.bin( + idep, + depe, + RngMinMax = NULL, + NumBin, + widtBin = c("lin", "log10", "exp10", "logExp", "expLog"), + meanFunc = c("mean", "median") +) } \arguments{ \item{idep}{Either a vector or matrix of class numeric or integer containing the independent variable and of the same length as \code{depe}. []} diff --git a/pack/eddy4R.base/man/def.dens.pres.pois.Rd b/pack/eddy4R.base/man/def.dens.pres.pois.Rd index 9a34b4d9..f18e6743 100644 --- a/pack/eddy4R.base/man/def.dens.pres.pois.Rd +++ b/pack/eddy4R.base/man/def.dens.pres.pois.Rd @@ -4,8 +4,12 @@ \alias{def.dens.pres.pois} \title{Definition function: Poisson's equation (adiabatic change) - density as function of pressure change} \usage{ -def.dens.pres.pois(dens01, pres01, pres02, - Kppa = eddy4R.base::IntlNatu$KppaDry) +def.dens.pres.pois( + dens01, + pres01, + pres02, + Kppa = eddy4R.base::IntlNatu$KppaDry +) } \arguments{ \item{dens01}{Measured density, Amount per volume [same unit as returned density, e.g. kg/m3 or kmol/m3].} diff --git a/pack/eddy4R.base/man/def.dens.temp.pois.Rd b/pack/eddy4R.base/man/def.dens.temp.pois.Rd index f5bf0ac7..6e5cb603 100644 --- a/pack/eddy4R.base/man/def.dens.temp.pois.Rd +++ b/pack/eddy4R.base/man/def.dens.temp.pois.Rd @@ -4,8 +4,12 @@ \alias{def.dens.temp.pois} \title{Definition function: Poisson's equation (adiabatic change) - density as function of temperature change} \usage{ -def.dens.temp.pois(dens01, temp01, temp02, - Kppa = eddy4R.base::IntlNatu$KppaDry) +def.dens.temp.pois( + dens01, + temp01, + temp02, + Kppa = eddy4R.base::IntlNatu$KppaDry +) } \arguments{ \item{dens01}{Measured density, Amount per volume [same unit as returned density, e.g. kg/m3 or kmol/m3].} diff --git a/pack/eddy4R.base/man/def.dp01.agr.ecte.Rd b/pack/eddy4R.base/man/def.dp01.agr.ecte.Rd index 2bf7fe84..20aee572 100644 --- a/pack/eddy4R.base/man/def.dp01.agr.ecte.Rd +++ b/pack/eddy4R.base/man/def.dp01.agr.ecte.Rd @@ -4,8 +4,12 @@ \alias{def.dp01.agr.ecte} \title{Definition function: aggregation of ecte dp01 outputs} \usage{ -def.dp01.agr.ecte(inpList, MethSubAgr = FALSE, MethUcrt = FALSE, - RptExpd = FALSE) +def.dp01.agr.ecte( + inpList, + MethSubAgr = FALSE, + MethUcrt = FALSE, + RptExpd = FALSE +) } \arguments{ \item{inpList}{a list of dp01 computed output statistics and dp01 quality flags and quality metrics over multiple aggregations periods that need to be combined.} diff --git a/pack/eddy4R.base/man/def.hdf5.crte.Rd b/pack/eddy4R.base/man/def.hdf5.crte.Rd index 8a6dc07a..f80cb693 100644 --- a/pack/eddy4R.base/man/def.hdf5.crte.Rd +++ b/pack/eddy4R.base/man/def.hdf5.crte.Rd @@ -4,10 +4,18 @@ \alias{def.hdf5.crte} \title{Definition function: Create the ECTE HDF5 file structure} \usage{ -def.hdf5.crte(Date, Site = "SERC", LvlTowr, DirOut, FileOutBase = NULL, - MethExpd = TRUE, MethDp04 = FALSE, FileNameReadMe = NULL, - FileNameObjDesc = NULL, LvlGasRefe = c("702_000", "703_000", - "704_000", "705_000", "706_000")) +def.hdf5.crte( + Date, + Site = "SERC", + LvlTowr, + DirOut, + FileOutBase = NULL, + MethExpd = TRUE, + MethDp04 = FALSE, + FileNameReadMe = NULL, + FileNameObjDesc = NULL, + LvlGasRefe = c("702_000", "703_000", "704_000", "705_000", "706_000") +) } \arguments{ \item{Date}{is the date for the output file being generated.} diff --git a/pack/eddy4R.base/man/def.hdf5.extr.Rd b/pack/eddy4R.base/man/def.hdf5.extr.Rd index f1373953..586f41bd 100644 --- a/pack/eddy4R.base/man/def.hdf5.extr.Rd +++ b/pack/eddy4R.base/man/def.hdf5.extr.Rd @@ -4,9 +4,15 @@ \alias{def.hdf5.extr} \title{Definition function: Extract data and attributes from HDF5 input file to another HDF5 output file} \usage{ -def.hdf5.extr(FileInp = NULL, rpt = NULL, FileOut = NULL, - MethExtrData = TRUE, MethExtrAttr = TRUE, dp01 = NULL, - MethDp0p = FALSE) +def.hdf5.extr( + FileInp = NULL, + rpt = NULL, + FileOut = NULL, + MethExtrData = TRUE, + MethExtrAttr = TRUE, + dp01 = NULL, + MethDp0p = FALSE +) } \arguments{ \item{FileInp}{is the input HDF5 file (turb or stor) the data and metadata are being read from. It is ignored if \code{rpt} is specified.} diff --git a/pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd b/pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd index 4b38aae4..6b9c590f 100644 --- a/pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd +++ b/pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd @@ -4,9 +4,15 @@ \alias{def.hdf5.read.qfqm} \title{Wrapper function: Reading quality flags from NEON HDF5 files} \usage{ -def.hdf5.read.qfqm(DirInpLoca, SiteLoca, DateLoca, VarLoca, - LvlTowr = c("000_040", "000_050", "000_060")[3], FreqLoca, - MethMeas = c("ecte", "ecse")[1]) +def.hdf5.read.qfqm( + DirInpLoca, + SiteLoca, + DateLoca, + VarLoca, + LvlTowr = c("000_040", "000_050", "000_060")[3], + FreqLoca, + MethMeas = c("ecte", "ecse")[1] +) } \arguments{ \item{DirInpLoca}{Character: Input directory.} diff --git a/pack/eddy4R.base/man/def.hdf5.wrte.dp01.Rd b/pack/eddy4R.base/man/def.hdf5.wrte.dp01.Rd index 6b8c3904..13e648f6 100644 --- a/pack/eddy4R.base/man/def.hdf5.wrte.dp01.Rd +++ b/pack/eddy4R.base/man/def.hdf5.wrte.dp01.Rd @@ -4,8 +4,15 @@ \alias{def.hdf5.wrte.dp01} \title{Definition function: Write NEON Level 1 data, qfqm, and uncertainty to output HDF5} \usage{ -def.hdf5.wrte.dp01(inpList, FileOut, SiteLoca, LvlTowr, Dp01, - MethUcrt = TRUE, MethSubAgr = TRUE) +def.hdf5.wrte.dp01( + inpList, + FileOut, + SiteLoca, + LvlTowr, + Dp01, + MethUcrt = TRUE, + MethSubAgr = TRUE +) } \arguments{ \item{inpList}{A list of including dp01 data, quality flags and quality metrics, and uncertainty calculations to package and write to an output HDF5 file.} diff --git a/pack/eddy4R.base/man/def.idx.agr.Rd b/pack/eddy4R.base/man/def.idx.agr.Rd index da6387ce..268ac536 100644 --- a/pack/eddy4R.base/man/def.idx.agr.Rd +++ b/pack/eddy4R.base/man/def.idx.agr.Rd @@ -4,8 +4,15 @@ \alias{def.idx.agr} \title{Definition function: indices for aggregation periods} \usage{ -def.idx.agr(time, PrdAgr, FreqLoca, MethIdx = c("rglr", "specBgn", - "specEnd")[1], crdH2oVali = FALSE, data = NULL, CritTime = 0) +def.idx.agr( + time, + PrdAgr, + FreqLoca, + MethIdx = c("rglr", "specBgn", "specEnd")[1], + crdH2oVali = FALSE, + data = NULL, + CritTime = 0 +) } \arguments{ \item{time}{a vector of timestamps} diff --git a/pack/eddy4R.base/man/def.inst.depe.Rd b/pack/eddy4R.base/man/def.inst.depe.Rd index b04b4a38..d57d4a95 100644 --- a/pack/eddy4R.base/man/def.inst.depe.Rd +++ b/pack/eddy4R.base/man/def.inst.depe.Rd @@ -4,8 +4,12 @@ \alias{def.inst.depe} \title{Definition function: Install dependent packages} \usage{ -def.inst.depe(DirPack = ".", Depe = TRUE, - Repo = base::getOption("repos")[1], Lib = .libPaths()[1]) +def.inst.depe( + DirPack = ".", + Depe = TRUE, + Repo = base::getOption("repos")[1], + Lib = .libPaths()[1] +) } \arguments{ \item{DirPack}{Path to the package \code{DESCRIPTION} file, defaults to the current working directory. Character vector with single entry [-].} diff --git a/pack/eddy4R.base/man/def.irga.vali.cor.Rd b/pack/eddy4R.base/man/def.irga.vali.cor.Rd index 83a0fef7..9a3dbea3 100644 --- a/pack/eddy4R.base/man/def.irga.vali.cor.Rd +++ b/pack/eddy4R.base/man/def.irga.vali.cor.Rd @@ -4,8 +4,16 @@ \alias{def.irga.vali.cor} \title{definition function: Calculation of time-series of the correction IRGA sub data products.} \usage{ -def.irga.vali.cor(data, DateProc, coef, valiData, valiCrit = FALSE, - ScalMax = 20, FracSlpMax = 0.1, Freq = 20) +def.irga.vali.cor( + data, + DateProc, + coef, + valiData, + valiCrit = FALSE, + ScalMax = 20, + FracSlpMax = 0.1, + Freq = 20 +) } \arguments{ \item{data}{List consisting of \code{ff::ffdf} file-backed objects containing the dp0p input IRGA.} diff --git a/pack/eddy4R.base/man/def.lag.Rd b/pack/eddy4R.base/man/def.lag.Rd index c3a72fff..8e95a2b4 100644 --- a/pack/eddy4R.base/man/def.lag.Rd +++ b/pack/eddy4R.base/man/def.lag.Rd @@ -4,10 +4,22 @@ \alias{def.lag} \title{Definition function: Lag two datasets, so as to maximise their cross-correlation} \usage{ -def.lag(refe, meas, freq, dataRefe = refe, dataMeas = meas, - measVar = NULL, lagMax = 2 * freq, lagCnst = TRUE, - lagNgtvPstv = c("n", "p", "np")[3], lagAll = TRUE, hpf = TRUE, - fracMin = 0.1, plot = FALSE, DirPlot = NULL) +def.lag( + refe, + meas, + freq, + dataRefe = refe, + dataMeas = meas, + measVar = NULL, + lagMax = 2 * freq, + lagCnst = TRUE, + lagNgtvPstv = c("n", "p", "np")[3], + lagAll = TRUE, + hpf = TRUE, + fracMin = 0.1, + plot = FALSE, + DirPlot = NULL +) } \arguments{ \item{refe}{A vector with variable in reference time frame. Of class numeric. [-]} diff --git a/pack/eddy4R.base/man/def.met.body.Rd b/pack/eddy4R.base/man/def.met.body.Rd index bbf815da..a5eba925 100644 --- a/pack/eddy4R.base/man/def.met.body.Rd +++ b/pack/eddy4R.base/man/def.met.body.Rd @@ -4,9 +4,12 @@ \alias{def.met.body} \title{Definition function: Coordinate transformation from CSAT3 body coordinate system to meteorological coordinate system} \usage{ -def.met.body(AngZaxsSoniInst, - AngZaxsSoniOfst = eddy4R.base::def.unit.conv(data = 90, unitFrom = - "deg", unitTo = "rad"), veloBody) +def.met.body( + AngZaxsSoniInst, + AngZaxsSoniOfst = eddy4R.base::def.unit.conv(data = 90, unitFrom = "deg", unitTo = + "rad"), + veloBody +) } \arguments{ \item{AngZaxsSoniInst}{Parameter of class numeric. Azimuth (angle around z axis) direction against true north in which sonic anemometer installation (transducer array) is pointing [rad]} diff --git a/pack/eddy4R.base/man/def.mtch.out.refe.Rd b/pack/eddy4R.base/man/def.mtch.out.refe.Rd index a41ea9b6..8b9d84c6 100644 --- a/pack/eddy4R.base/man/def.mtch.out.refe.Rd +++ b/pack/eddy4R.base/man/def.mtch.out.refe.Rd @@ -20,7 +20,7 @@ Currently none } \description{ Function definition. A function to compare the file output from a workflow to a reference output file -to ensure that changes during development to functions called by the workflow have not impacted the +to ensure that changes during development to functions called by the workflow have not impacted the results.\cr The function reads in the new data produced in the tmp directory and compares the first 10 lines to the reference output data. } diff --git a/pack/eddy4R.base/man/def.para.flow.Rd b/pack/eddy4R.base/man/def.para.flow.Rd index f6f18e36..62247c28 100644 --- a/pack/eddy4R.base/man/def.para.flow.Rd +++ b/pack/eddy4R.base/man/def.para.flow.Rd @@ -4,11 +4,24 @@ \alias{def.para.flow} \title{Definition function: Determine the workflow variables} \usage{ -def.para.flow(Deve = TRUE, DirFilePara = NULL, DirInp = NA, - DirMnt = NA, DirOut = NA, DirTmp = NA, DirWrk = NA, - DateOut = NULL, FileOutBase = NULL, Read = "hdf5", - VersDp = c("001", "004")[1], VersEddy = "latest", - MethParaFlow = c("DfltInp", "EnvVar")[1], UrlInpRefe, UrlOutRefe, ...) +def.para.flow( + Deve = TRUE, + DirFilePara = NULL, + DirInp = NA, + DirMnt = NA, + DirOut = NA, + DirTmp = NA, + DirWrk = NA, + DateOut = NULL, + FileOutBase = NULL, + Read = "hdf5", + VersDp = c("001", "004")[1], + VersEddy = "latest", + MethParaFlow = c("DfltInp", "EnvVar")[1], + UrlInpRefe, + UrlOutRefe, + ... +) } \arguments{ \item{Deve}{is logical that determines if only a subset of the data should be read in to reduce testing time during development (\code{Deve = TRUE}) or all the input data should be read in (\code{Deve = FALSE})} diff --git a/pack/eddy4R.base/man/def.rglr.Rd b/pack/eddy4R.base/man/def.rglr.Rd index a564962a..8a843c6b 100644 --- a/pack/eddy4R.base/man/def.rglr.Rd +++ b/pack/eddy4R.base/man/def.rglr.Rd @@ -4,12 +4,19 @@ \alias{def.rglr} \title{Definition function: Regularizing irregular data to strictly regular / equidistant data} \usage{ -def.rglr(timeMeas, dataMeas, unitMeas = base::attributes(dataMeas)$unit, - BgnRglr = NULL, EndRglr = NULL, - TzRglr = base::attributes(BgnRglr)$tzone, FreqRglr, - MethRglr = c("CybiEc", "cybiDflt", "zoo")[1], WndwRglr = c("Cntr", - "Lead", "Trlg")[1], IdxWndw = c("Clst", "IdxWndwMin", "IdxWndwMax")[1], - PrcsSec = 6) +def.rglr( + timeMeas, + dataMeas, + unitMeas = base::attributes(dataMeas)$unit, + BgnRglr = NULL, + EndRglr = NULL, + TzRglr = base::attributes(BgnRglr)$tzone, + FreqRglr, + MethRglr = c("CybiEc", "cybiDflt", "zoo")[1], + WndwRglr = c("Cntr", "Lead", "Trlg")[1], + IdxWndw = c("Clst", "IdxWndwMin", "IdxWndwMax")[1], + PrcsSec = 6 +) } \arguments{ \item{timeMeas}{A vector containing the observation times. Of class "POSIXlt" including timezone attribute, and of the same length as \code{dataMeas}. [-]} diff --git a/pack/eddy4R.base/man/def.rmsd.diff.prcs.rsq.Rd b/pack/eddy4R.base/man/def.rmsd.diff.prcs.rsq.Rd index 18d99605..22f8d0ff 100644 --- a/pack/eddy4R.base/man/def.rmsd.diff.prcs.rsq.Rd +++ b/pack/eddy4R.base/man/def.rmsd.diff.prcs.rsq.Rd @@ -4,8 +4,7 @@ \alias{def.rmsd.diff.prcs.rsq} \title{Definition function: RMSD, bias, precision and coefficient of determination - incl. deadband} \usage{ -def.rmsd.diff.prcs.rsq(refe, test, Perc = FALSE, Deba = NULL, - DebaRltv = FALSE) +def.rmsd.diff.prcs.rsq(refe, test, Perc = FALSE, Deba = NULL, DebaRltv = FALSE) } \arguments{ \item{refe}{Variable of class numeric. Reference data.Same unit as test data.} diff --git a/pack/eddy4R.base/man/def.temp.pres.pois.Rd b/pack/eddy4R.base/man/def.temp.pres.pois.Rd index bc32d2c0..f73ecf7b 100644 --- a/pack/eddy4R.base/man/def.temp.pres.pois.Rd +++ b/pack/eddy4R.base/man/def.temp.pres.pois.Rd @@ -4,8 +4,12 @@ \alias{def.temp.pres.pois} \title{Definition function: Poisson's equation (adiabatic change) - temperature as function of pressure change} \usage{ -def.temp.pres.pois(temp01, pres01, pres02, - Kppa = eddy4R.base::IntlNatu$KppaDry) +def.temp.pres.pois( + temp01, + pres01, + pres02, + Kppa = eddy4R.base::IntlNatu$KppaDry +) } \arguments{ \item{temp01}{Measured air temperature [K]} diff --git a/pack/eddy4R.base/man/def.unit.conv.Rd b/pack/eddy4R.base/man/def.unit.conv.Rd index 707441a3..7f9337bb 100644 --- a/pack/eddy4R.base/man/def.unit.conv.Rd +++ b/pack/eddy4R.base/man/def.unit.conv.Rd @@ -4,9 +4,14 @@ \alias{def.unit.conv} \title{Definition function: Unit conversion} \usage{ -def.unit.conv(data, unitFrom = "arb", unitTo = "arb", - coefPoly = base::lapply(base::as.data.frame(data), function(x) c(0, - 1)), vrbs = FALSE, MethGc = TRUE) +def.unit.conv( + data, + unitFrom = "arb", + unitTo = "arb", + coefPoly = base::lapply(base::as.data.frame(data), function(x) c(0, 1)), + vrbs = FALSE, + MethGc = TRUE +) } \arguments{ \item{data}{Required. A named data frame of type numeric, containing the data to be converted. diff --git a/pack/eddy4R.base/man/wrap.agr.vari.seSq.Rd b/pack/eddy4R.base/man/wrap.agr.vari.seSq.Rd index 220d1b5b..c6646a77 100644 --- a/pack/eddy4R.base/man/wrap.agr.vari.seSq.Rd +++ b/pack/eddy4R.base/man/wrap.agr.vari.seSq.Rd @@ -4,8 +4,7 @@ \alias{wrap.agr.vari.seSq} \title{Wrapper function: Calculate aggregated variance and squared standard error from a small to large temporal scale.} \usage{ -wrap.agr.vari.seSq(data = data.frame(timeDoyDecm, mean, vari), zone, - MethAgr) +wrap.agr.vari.seSq(data = data.frame(timeDoyDecm, mean, vari), zone, MethAgr) } \arguments{ \item{data}{Dataframe of type numeric containing column vectors \code{timeDoyDecm}, \code{mean}, and \code{vari} of equal length.} diff --git a/pack/eddy4R.base/man/wrap.dp00.rglr.ecse.Rd b/pack/eddy4R.base/man/wrap.dp00.rglr.ecse.Rd index 39d1b393..920fe459 100644 --- a/pack/eddy4R.base/man/wrap.dp00.rglr.ecse.Rd +++ b/pack/eddy4R.base/man/wrap.dp00.rglr.ecse.Rd @@ -4,8 +4,15 @@ \alias{wrap.dp00.rglr.ecse} \title{Wrapper function: Time regularization for ECSE dp00} \usage{ -wrap.dp00.rglr.ecse(DirInp, Date, Site = "CPER", Dom = "D10", Freq, - IdDp00, horVer) +wrap.dp00.rglr.ecse( + DirInp, + Date, + Site = "CPER", + Dom = "D10", + Freq, + IdDp00, + horVer +) } \arguments{ \item{DirInp}{Character: Input directory. [-]} diff --git a/pack/eddy4R.base/man/wrap.dp01.qfqm.ecte.Rd b/pack/eddy4R.base/man/wrap.dp01.qfqm.ecte.Rd index 92fdc3cc..593701a3 100644 --- a/pack/eddy4R.base/man/wrap.dp01.qfqm.ecte.Rd +++ b/pack/eddy4R.base/man/wrap.dp01.qfqm.ecte.Rd @@ -4,8 +4,13 @@ \alias{wrap.dp01.qfqm.ecte} \title{Wrapper function: Create NEON Level 1 data product quality flags and quality metrics across list elements} \usage{ -wrap.dp01.qfqm.ecte(qfqm, idx = NULL, TypeMeas = "samp", - MethMeas = c("ecte", "ecse")[1], RptExpd = FALSE) +wrap.dp01.qfqm.ecte( + qfqm, + idx = NULL, + TypeMeas = "samp", + MethMeas = c("ecte", "ecse")[1], + RptExpd = FALSE +) } \arguments{ \item{qfqm}{A data.frame or list containing the L0p input data quality flags (sensor and plausibility flags) at native resolution. Of type numeric or integer. [-]} diff --git a/pack/eddy4R.base/man/wrap.hdf5.read.Rd b/pack/eddy4R.base/man/wrap.hdf5.read.Rd index c35023ad..25685617 100644 --- a/pack/eddy4R.base/man/wrap.hdf5.read.Rd +++ b/pack/eddy4R.base/man/wrap.hdf5.read.Rd @@ -4,10 +4,20 @@ \alias{wrap.hdf5.read} \title{Wrapper function: Reading NEON HDF5 files} \usage{ -wrap.hdf5.read(DirInpLoca, SiteLoca, DateLoca, VarLoca, - LvlTowr = c("000_040", "000_050", "000_060")[3], FreqLoca, - Rglr = FALSE, Diag = FALSE, Rng = FALSE, RngLoca = NULL, - DespLoca, MethMeas = c("ecte", "ecse")[1]) +wrap.hdf5.read( + DirInpLoca, + SiteLoca, + DateLoca, + VarLoca, + LvlTowr = c("000_040", "000_050", "000_060")[3], + FreqLoca, + Rglr = FALSE, + Diag = FALSE, + Rng = FALSE, + RngLoca = NULL, + DespLoca, + MethMeas = c("ecte", "ecse")[1] +) } \arguments{ \item{DirInpLoca}{Character: Input directory.} diff --git a/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd b/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd index 8cabaa42..e5790fcc 100644 --- a/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd +++ b/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd @@ -4,8 +4,16 @@ \alias{wrap.hdf5.wrte.dp01} \title{Wrapper function: Write NEON Level 1 data, qfqm, and uncertainty to output HDF5} \usage{ -wrap.hdf5.wrte.dp01(inpList, FileInp, FileOut, SiteLoca, LvlTowr, - MethUcrt = TRUE, MethDp04 = FALSE, MethSubAgr = TRUE) +wrap.hdf5.wrte.dp01( + inpList, + FileInp, + FileOut, + SiteLoca, + LvlTowr, + MethUcrt = TRUE, + MethDp04 = FALSE, + MethSubAgr = TRUE +) } \arguments{ \item{inpList}{A list of including dp01 data, quality flags and quality metrics, and uncertainty calculations to package and write to an output HDF5 file} diff --git a/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.api.Rd b/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.api.Rd index ef15d565..eb021715 100644 --- a/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.api.Rd +++ b/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.api.Rd @@ -4,9 +4,15 @@ \alias{wrap.hdf5.wrte.dp01.api} \title{Wrapper function: Gather/Write reingested NEON Level 1 data, qfqm, and uncertainty to output HDF5} \usage{ -wrap.hdf5.wrte.dp01.api(date, FileOut, SiteLoca, DpName = c("tempAirLvl", - "tempAirTop", "fluxHeatSoil", "radiNet", "tempSoil", "h2oSoilVol", - "presBaro"), LvlTowr, TimeAgr = c(1, 30)) +wrap.hdf5.wrte.dp01.api( + date, + FileOut, + SiteLoca, + DpName = c("tempAirLvl", "tempAirTop", "fluxHeatSoil", "radiNet", "tempSoil", + "h2oSoilVol", "presBaro"), + LvlTowr, + TimeAgr = c(1, 30) +) } \arguments{ \item{date}{Character: The date for the data to be gathered in ISO format ("YYYYmmdd").} diff --git a/pack/eddy4R.base/man/wrap.para.thsh.Rd b/pack/eddy4R.base/man/wrap.para.thsh.Rd index c9919d52..27aac338 100644 --- a/pack/eddy4R.base/man/wrap.para.thsh.Rd +++ b/pack/eddy4R.base/man/wrap.para.thsh.Rd @@ -4,10 +4,12 @@ \alias{wrap.para.thsh} \title{Wrapper Function to read threshold table from CI-Parameter-Repo} \usage{ -wrap.para.thsh(DpName = c("IrgaTurb", "MfcSampTurb", "Soni", "Amrs"), +wrap.para.thsh( + DpName = c("IrgaTurb", "MfcSampTurb", "Soni", "Amrs"), DirInp = "~/eddy/data/Thresholds_EC/CI-Parameter-Repo/ParaSci/Ecte/Dp0p", DirOut = "~/eddy/data/Thresholds_EC/threshold_ecte", - FileWrte = FALSE) + FileWrte = FALSE +) } \arguments{ \item{DpName}{Character: Name of data product. [-]} diff --git a/pack/eddy4R.base/man/wrap.unit.conv.out.ec.Rd b/pack/eddy4R.base/man/wrap.unit.conv.out.ec.Rd index 8783842f..92603fb5 100644 --- a/pack/eddy4R.base/man/wrap.unit.conv.out.ec.Rd +++ b/pack/eddy4R.base/man/wrap.unit.conv.out.ec.Rd @@ -4,8 +4,11 @@ \alias{wrap.unit.conv.out.ec} \title{Wrapper function: Output unit conversion for ECTE} \usage{ -wrap.unit.conv.out.ec(inpList, MethMeas = c("ecte", "ecse")[1], - MethType = c("Data", "Ucrt", "Qfqm", "Vali")[1]) +wrap.unit.conv.out.ec( + inpList, + MethMeas = c("ecte", "ecse")[1], + MethType = c("Data", "Ucrt", "Qfqm", "Vali")[1] +) } \arguments{ \item{inpList}{Required. A named list of data frames of type numeric, containing the data to be converted.} diff --git a/pack/eddy4R.qaqc/DESCRIPTION b/pack/eddy4R.qaqc/DESCRIPTION index 76d2dbf1..1e456c8e 100644 --- a/pack/eddy4R.qaqc/DESCRIPTION +++ b/pack/eddy4R.qaqc/DESCRIPTION @@ -22,4 +22,4 @@ Suggests: NEONprocIS.base License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 LazyData: true -RoxygenNote: 6.1.1 +RoxygenNote: 7.0.2 diff --git a/pack/eddy4R.qaqc/man/def.agr.file.dp00.Rd b/pack/eddy4R.qaqc/man/def.agr.file.dp00.Rd index 644a7dbe..ce7b6fb1 100644 --- a/pack/eddy4R.qaqc/man/def.agr.file.dp00.Rd +++ b/pack/eddy4R.qaqc/man/def.agr.file.dp00.Rd @@ -4,8 +4,15 @@ \alias{def.agr.file.dp00} \title{Definition function: Combine individual L0 data streams from file} \usage{ -def.agr.file.dp00(dirFile = ".", nameFile, nameVar, unitVar, Freq, - FmtTime = "\%d-\%b-\%Y \%I.\%M.\%OS \%p", Tz = "GMT") +def.agr.file.dp00( + dirFile = ".", + nameFile, + nameVar, + unitVar, + Freq, + FmtTime = "\%d-\%b-\%Y \%I.\%M.\%OS \%p", + Tz = "GMT" +) } \arguments{ \item{dirFile}{Optional. A character string indicating the directory in which the files to combine are stored. Default is the current working directory.} diff --git a/pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd b/pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd index 4c6a5b4a..84421aad 100644 --- a/pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd +++ b/pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd @@ -4,10 +4,14 @@ \alias{def.dp01.grp.qf} \title{Definition function: Grouping the quality flags for each of NEON ECTE and ECSE L1 data product} \usage{ -def.dp01.grp.qf(qfInp = list(), MethMeas = c("ecte", "ecse")[1], - TypeMeas = c("samp", "vali")[1], dp01 = c("envHut", "co2Turb", - "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "isoH2o", "soni", "amrs", - "tempAirLvl", "tempAirTop")[1], idGas = NULL) +def.dp01.grp.qf( + qfInp = list(), + MethMeas = c("ecte", "ecse")[1], + TypeMeas = c("samp", "vali")[1], + dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "isoH2o", + "soni", "amrs", "tempAirLvl", "tempAirTop")[1], + idGas = NULL +) } \arguments{ \item{qfInp}{A list of data frame containing the input quality flag data that related to L1 data products are being grouped. Of class integer". [-]} diff --git a/pack/eddy4R.qaqc/man/def.dspk.br86.Rd b/pack/eddy4R.qaqc/man/def.dspk.br86.Rd index 1f9a8e83..07df4dea 100644 --- a/pack/eddy4R.qaqc/man/def.dspk.br86.Rd +++ b/pack/eddy4R.qaqc/man/def.dspk.br86.Rd @@ -4,8 +4,13 @@ \alias{def.dspk.br86} \title{Definition function: Median filter de-spiking} \usage{ -def.dspk.br86(dataInp, WndwFilt = 9, NumBin = 2, ThshReso = 10, - FracRealMin = 0.025) +def.dspk.br86( + dataInp, + WndwFilt = 9, + NumBin = 2, + ThshReso = 10, + FracRealMin = 0.025 +) } \arguments{ \item{dataInp}{Required. A univariate vector of integers or numerics of Input data} diff --git a/pack/eddy4R.qaqc/man/def.dspk.wndw.Rd b/pack/eddy4R.qaqc/man/def.dspk.wndw.Rd index aed2e582..40f3f3db 100644 --- a/pack/eddy4R.qaqc/man/def.dspk.wndw.Rd +++ b/pack/eddy4R.qaqc/man/def.dspk.wndw.Rd @@ -4,11 +4,15 @@ \alias{def.dspk.wndw} \title{Definition function: Determine spike locations using window-based statistics} \usage{ -def.dspk.wndw(data, Trt = list(AlgClas = c("mean", "median")[2], - NumPtsWndw = c(11, 101)[2], NumPtsSlid = 1, ThshStd = c(3.5, 20)[2], - NaFracMax = 0.1, Infl = 0, IterMax = Inf, NumPtsGrp = c(4, 10)[2], NaTrt - = c("approx", "omit")[2]), Cntl = list(NaOmit = c(TRUE, FALSE)[2], Prnt - = c(TRUE, FALSE)[1], Plot = c(TRUE, FALSE)[1]), Vrbs = FALSE) +def.dspk.wndw( + data, + Trt = list(AlgClas = c("mean", "median")[2], NumPtsWndw = c(11, 101)[2], NumPtsSlid = + 1, ThshStd = c(3.5, 20)[2], NaFracMax = 0.1, Infl = 0, IterMax = Inf, NumPtsGrp = c(4, + 10)[2], NaTrt = c("approx", "omit")[2]), + Cntl = list(NaOmit = c(TRUE, FALSE)[2], Prnt = c(TRUE, FALSE)[1], Plot = c(TRUE, + FALSE)[1]), + Vrbs = FALSE +) } \arguments{ \item{data}{Required input. A data frame or matrix containing the data to be evaluated.} diff --git a/pack/eddy4R.qaqc/man/def.plau.Rd b/pack/eddy4R.qaqc/man/def.plau.Rd index 130b1681..abff8e02 100644 --- a/pack/eddy4R.qaqc/man/def.plau.Rd +++ b/pack/eddy4R.qaqc/man/def.plau.Rd @@ -4,14 +4,19 @@ \alias{def.plau} \title{Definition function: Plausibility tests (Range, Step, Persistence, Null, Gap)} \usage{ -def.plau(data, time = as.POSIXlt(seq.POSIXt(from = Sys.time(), by = - "sec", length.out = length(data[, 1]))), RngMin = apply(data, 2, min, - na.rm = TRUE), RngMax = apply(data, 2, max, na.rm = TRUE), +def.plau( + data, + time = as.POSIXlt(seq.POSIXt(from = Sys.time(), by = "sec", length.out = length(data[, + 1]))), + RngMin = apply(data, 2, min, na.rm = TRUE), + RngMax = apply(data, 2, max, na.rm = TRUE), DiffStepMax = apply(abs(apply(data, 2, diff)), 2, max, na.rm = TRUE), - DiffPersMin = rep.int(0, length(data)), WndwPers = 60 * - median(abs(diff(time)), na.rm = TRUE) * rep.int(1, length(data)), - TestNull = rep(FALSE, length(data)), NumGap = rep(length(data[, 1]) + - 1, length(data)), Vrbs = FALSE) + DiffPersMin = rep.int(0, length(data)), + WndwPers = 60 * median(abs(diff(time)), na.rm = TRUE) * rep.int(1, length(data)), + TestNull = rep(FALSE, length(data)), + NumGap = rep(length(data[, 1]) + 1, length(data)), + Vrbs = FALSE +) } \arguments{ \item{data}{Required input. A data frame containing the data to be evaluated (do not include the time stamp vector here).} diff --git a/pack/eddy4R.qaqc/man/def.plot.dp01.qfqm.Rd b/pack/eddy4R.qaqc/man/def.plot.dp01.qfqm.Rd index 10c2fdc9..4f1c66c3 100644 --- a/pack/eddy4R.qaqc/man/def.plot.dp01.qfqm.Rd +++ b/pack/eddy4R.qaqc/man/def.plot.dp01.qfqm.Rd @@ -4,10 +4,12 @@ \alias{def.plot.dp01.qfqm} \title{Definition function: Plot quality flags and quality metrics (basic L1 data products)} \usage{ -def.plot.dp01.qfqm(dataDp01, WndwTime = c(min(dataDp01$timeAgrBgn), - max(dataDp01$timeAgrBgn)), NameQmPlot = sub("Pass", "", - names(dataDp01$dataAgr[[1]][grep("Pass", - names(dataDp01$dataAgr[[1]]))]))) +def.plot.dp01.qfqm( + dataDp01, + WndwTime = c(min(dataDp01$timeAgrBgn), max(dataDp01$timeAgrBgn)), + NameQmPlot = sub("Pass", "", names(dataDp01$dataAgr[[1]][grep("Pass", + names(dataDp01$dataAgr[[1]]))])) +) } \arguments{ \item{dataDp01}{Required input. A list output from wrap.dp01.qfqm.R of: \cr diff --git a/pack/eddy4R.qaqc/man/def.qf.ecte.Rd b/pack/eddy4R.qaqc/man/def.qf.ecte.Rd index d34344c1..fa6f014e 100644 --- a/pack/eddy4R.qaqc/man/def.qf.ecte.Rd +++ b/pack/eddy4R.qaqc/man/def.qf.ecte.Rd @@ -4,8 +4,13 @@ \alias{def.qf.ecte} \title{Definition function: Create fake flags for ECTE sensors} \usage{ -def.qf.ecte(TimeBgn, TimeEnd, Freq = 20, Sens = c("soni", "irga", - "irgaMfcSamp", "soniAmrs")[1], PcntQf = 0.05) +def.qf.ecte( + TimeBgn, + TimeEnd, + Freq = 20, + Sens = c("soni", "irga", "irgaMfcSamp", "soniAmrs")[1], + PcntQf = 0.05 +) } \arguments{ \item{TimeBgn}{is the beginning time of the period to generate flags.} diff --git a/pack/eddy4R.qaqc/man/def.qf.rmv.data.Rd b/pack/eddy4R.qaqc/man/def.qf.rmv.data.Rd index 685a4157..8b79b2d5 100644 --- a/pack/eddy4R.qaqc/man/def.qf.rmv.data.Rd +++ b/pack/eddy4R.qaqc/man/def.qf.rmv.data.Rd @@ -4,8 +4,14 @@ \alias{def.qf.rmv.data} \title{Definition function: to remove high frequency data points that have failed quality flags} \usage{ -def.qf.rmv.data(inpData, inpQf, Sens = NULL, qfRmv = NULL, - Vrbs = FALSE, TypeData = c("integer", "real")[1]) +def.qf.rmv.data( + inpData, + inpQf, + Sens = NULL, + qfRmv = NULL, + Vrbs = FALSE, + TypeData = c("integer", "real")[1] +) } \arguments{ \item{inpData}{Input data.frame for data to be removed from based on quality flags} diff --git a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.Rd b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.Rd index 1c4c872d..fdefb660 100644 --- a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.Rd +++ b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.Rd @@ -4,14 +4,17 @@ \alias{wrap.dp01.qfqm} \title{Wrapper function: Generate basic L1 data product, including descriptive statics, quality metrics, and final quality flag} \usage{ -wrap.dp01.qfqm(data, time = base::as.POSIXlt(base::seq.POSIXt(from = - base::Sys.time(), by = "sec", length.out = base::length(data[, 1]))), +wrap.dp01.qfqm( + data, + time = base::as.POSIXlt(base::seq.POSIXt(from = base::Sys.time(), by = "sec", + length.out = base::length(data[, 1]))), setQf = base::vector("list", base::length(data)), - qf = base::vector("list", base::length(data)), WndwAgr = 1800 * - stats::median(base::abs(base::diff(time)), na.rm = TRUE), - TimeBgn = NULL, TimeEnd = NULL, - NameQfExcl = base::as.list(base::character(length = - base::length(data)))) + qf = base::vector("list", base::length(data)), + WndwAgr = 1800 * stats::median(base::abs(base::diff(time)), na.rm = TRUE), + TimeBgn = NULL, + TimeEnd = NULL, + NameQfExcl = base::as.list(base::character(length = base::length(data))) +) } \arguments{ \item{data}{Required input. A data frame containing the L0' (calibrated raw) data evaluated (do not include the time stamp vector here).} diff --git a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd index 079a2a65..1c352351 100644 --- a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd +++ b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd @@ -4,12 +4,23 @@ \alias{wrap.dp01.qfqm.ecse} \title{Wrapper function: Preprocessing and calculating quality metrics, alpha and beta quality metrics, and final quality flag for the NEON eddy-covariance stroage exchange L1 data products} \usage{ -wrap.dp01.qfqm.ecse(dp01 = c("co2Stor", "h2oStor", "tempAirLvl", - "tempAirTop", "isoCo2", "isoH2o")[1], RptExpd = FALSE, lvl, - lvlMfcSampStor = NULL, lvlMfcValiStor = NULL, lvlEnvHut = NULL, - lvlValv = NULL, lvlValvAux = NULL, lvlCrdH2oValvVali = NULL, - data = list(), qfInp = list(), TypeMeas = c("samp", "vali")[1], - PrdMeas, PrdAgr, idxTime = list()) +wrap.dp01.qfqm.ecse( + dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], + RptExpd = FALSE, + lvl, + lvlMfcSampStor = NULL, + lvlMfcValiStor = NULL, + lvlEnvHut = NULL, + lvlValv = NULL, + lvlValvAux = NULL, + lvlCrdH2oValvVali = NULL, + data = list(), + qfInp = list(), + TypeMeas = c("samp", "vali")[1], + PrdMeas, + PrdAgr, + idxTime = list() +) } \arguments{ \item{dp01}{A vector of class "character" containing the name of NEON ECSE dp01 which descriptive statistics are being calculated, \cr diff --git a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd index c1ebf009..a6149daa 100644 --- a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd +++ b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd @@ -4,11 +4,15 @@ \alias{wrap.dp01.qfqm.eddy} \title{Wrapper function: Calculate quality metrics, alpha and beta quality metrics, and final quality flag for the NEON eddy-covariance turbulent and stroage exchange L1 data products} \usage{ -wrap.dp01.qfqm.eddy(qfInp = list(), MethMeas = c("ecte", "ecse")[1], - TypeMeas = c("samp", "vali")[1], RptExpd = FALSE, - dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", - "isoCo2", "isoH2o", "soni", "soniAmrs", "tempAirLvl", "tempAirTop")[1], - idGas = NULL) +wrap.dp01.qfqm.eddy( + qfInp = list(), + MethMeas = c("ecte", "ecse")[1], + TypeMeas = c("samp", "vali")[1], + RptExpd = FALSE, + dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "isoH2o", + "soni", "soniAmrs", "tempAirLvl", "tempAirTop")[1], + idGas = NULL +) } \arguments{ \item{qfInp}{A list of data frame containing the input quality flag data that related to L1 data products are being grouped. Of class integer". [-]} diff --git a/pack/eddy4R.qaqc/man/wrap.qf.rmv.data.Rd b/pack/eddy4R.qaqc/man/wrap.qf.rmv.data.Rd index d370e020..28bfaf5c 100644 --- a/pack/eddy4R.qaqc/man/wrap.qf.rmv.data.Rd +++ b/pack/eddy4R.qaqc/man/wrap.qf.rmv.data.Rd @@ -4,8 +4,13 @@ \alias{wrap.qf.rmv.data} \title{Wrapper function: to remove high frequency data points that have failed quality flags} \usage{ -wrap.qf.rmv.data(inpList, Sens = NULL, qfRmv = NULL, Vrbs = FALSE, - MethMeas = c("ecte", "ecse")[1]) +wrap.qf.rmv.data( + inpList, + Sens = NULL, + qfRmv = NULL, + Vrbs = FALSE, + MethMeas = c("ecte", "ecse")[1] +) } \arguments{ \item{inpList}{List consisting of \code{ff::ffdf} file-backed objects, in the format provided by function \code{eddy4R.base::wrap.hdf5.read()}. Of types numeric and integer.} diff --git a/pack/eddy4R.stor/DESCRIPTION b/pack/eddy4R.stor/DESCRIPTION index 73fbc2a9..a66453e6 100644 --- a/pack/eddy4R.stor/DESCRIPTION +++ b/pack/eddy4R.stor/DESCRIPTION @@ -15,4 +15,4 @@ Suggests: License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 Encoding: UTF-8 LazyData: true -RoxygenNote: 6.1.1 +RoxygenNote: 7.0.2 diff --git a/pack/eddy4R.stor/man/def.time.rate.diff.Rd b/pack/eddy4R.stor/man/def.time.rate.diff.Rd index f643b8cd..62d74816 100644 --- a/pack/eddy4R.stor/man/def.time.rate.diff.Rd +++ b/pack/eddy4R.stor/man/def.time.rate.diff.Rd @@ -4,8 +4,14 @@ \alias{def.time.rate.diff} \title{Definition function: calculate time rate of change for ecse dp02 data and qfqm} \usage{ -def.time.rate.diff(dataInp, numDate, PrdWndwAgr, PrdIncrAgr, Date, - qfqmFlag = FALSE) +def.time.rate.diff( + dataInp, + numDate, + PrdWndwAgr, + PrdIncrAgr, + Date, + qfqmFlag = FALSE +) } \arguments{ \item{\code{dataInp}}{Input data.} diff --git a/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd b/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd index 52059d2d..930a92f9 100644 --- a/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd +++ b/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd @@ -4,11 +4,20 @@ \alias{wrap.dp01.ecse} \title{Wrapper function: Preprocessing and computing NEON eddy-covariance stroage exchange L1 data product descriptive statistics} \usage{ -wrap.dp01.ecse(dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", - "isoCo2", "isoH2o")[1], lvl, lvlMfcSampStor = NULL, lvlEnvHut = NULL, - lvlValv = NULL, lvlCrdH2oValvVali = NULL, data = list(), - qfInp = list(), TypeMeas = c("samp", "vali")[1], PrdMeas, PrdAgr, - idxTime = list()) +wrap.dp01.ecse( + dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], + lvl, + lvlMfcSampStor = NULL, + lvlEnvHut = NULL, + lvlValv = NULL, + lvlCrdH2oValvVali = NULL, + data = list(), + qfInp = list(), + TypeMeas = c("samp", "vali")[1], + PrdMeas, + PrdAgr, + idxTime = list() +) } \arguments{ \item{dp01}{A vector of class "character" containing the name of NEON ECSE dp01 which descriptive statistics are being calculated, \cr From 373e0128347da76ce9d4c90d6efd7b6a6c1b1422 Mon Sep 17 00:00:00 2001 From: NDurden Date: Wed, 11 Mar 2020 14:56:08 +0000 Subject: [PATCH 037/168] removed qfCal and qfHeat --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 191 +++++++++++++++------------ 1 file changed, 104 insertions(+), 87 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index b09798c5..4d8f92b3 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -84,6 +84,8 @@ # adding the presStor, presValiRegInStor and and presValiRegOutStor quality flags to ECSE # Natchaya P-Durden (2019-05-28) # adding qfHeat to ECSE +# Natchaya P-Durden (2020-03-11) +# removed qfCal and qfHeat from ECSE ############################################################################################## def.dp01.grp.qf <- function( @@ -866,43 +868,43 @@ if (MethMeas == "ecse") { #grouping the flags setQf$asrpCo2 <- data.frame("qfRngAsrpCo2" = qfInp$irgaStor$qfRngAsrpCo2, "qfStepAsrpCo2" = qfInp$irgaStor$qfStepAsrpCo2, - "qfPersAsrpCo2" = qfInp$irgaStor$qfPersAsrpCo2, - "qfCalAsrpCo2" = qfInp$irgaStor$qfCalAsrpCo2) + "qfPersAsrpCo2" = qfInp$irgaStor$qfPersAsrpCo2) + #"qfCalAsrpCo2" = qfInp$irgaStor$qfCalAsrpCo2) setQf$asrpH2o <- data.frame("qfRngAsrpH2o" = qfInp$irgaStor$qfRngAsrpH2o, "qfStepAsrpH2o" = qfInp$irgaStor$qfStepAsrpH2o, - "qfPersAsrpH2o" = qfInp$irgaStor$qfPersAsrpH2o, - "qfCalAsrpH2o" = qfInp$irgaStor$qfCalAsrpH2o) + "qfPersAsrpH2o" = qfInp$irgaStor$qfPersAsrpH2o) + #"qfCalAsrpH2o" = qfInp$irgaStor$qfCalAsrpH2o) setQf$rtioMoleDryCo2 <- data.frame("qfRngRtioMoleDryCo2" = qfInp$irgaStor$qfRngRtioMoleDryCo2, "qfStepRtioMoleDryCo2" = qfInp$irgaStor$qfStepRtioMoleDryCo2, - "qfPersRtioMoleDryCo2" = qfInp$irgaStor$qfPersRtioMoleDryCo2, - "qfCalRtioMoleDryCo2" = qfInp$irgaStor$qfCalRtioMoleDryCo2) + "qfPersRtioMoleDryCo2" = qfInp$irgaStor$qfPersRtioMoleDryCo2) + #"qfCalRtioMoleDryCo2" = qfInp$irgaStor$qfCalRtioMoleDryCo2) setQf$rtioMoleDryH2o <- data.frame("qfRngRtioMoleDryH2o" = qfInp$irgaStor$qfRngRtioMoleDryH2o, "qfStepRtioMoleDryH2o" = qfInp$irgaStor$qfStepRtioMoleDryH2o, - "qfPersRtioMoleDryH2o" = qfInp$irgaStor$qfPersRtioMoleDryH2o, - "qfCalRtioMoleDryH2o" = qfInp$irgaStor$qfCalRtioMoleDryH2o) + "qfPersRtioMoleDryH2o" = qfInp$irgaStor$qfPersRtioMoleDryH2o) + #"qfCalRtioMoleDryH2o" = qfInp$irgaStor$qfCalRtioMoleDryH2o) setQf$rtioMoleWetCo2 <- data.frame("qfRngRtioMoleWetCo2" = qfInp$irgaStor$qfRngRtioMoleWetCo2, "qfStepRtioMoleWetCo2" = qfInp$irgaStor$qfStepRtioMoleWetCo2, - "qfPersRtioMoleWetCo2" = qfInp$irgaStor$qfPersRtioMoleWetCo2, - "qfCalRtioMoleWetCo2" = qfInp$irgaStor$qfCalRtioMoleWetCo2) + "qfPersRtioMoleWetCo2" = qfInp$irgaStor$qfPersRtioMoleWetCo2) + #"qfCalRtioMoleWetCo2" = qfInp$irgaStor$qfCalRtioMoleWetCo2) setQf$rtioMoleWetH2o <- data.frame("qfRngRtioMoleWetH2o" = qfInp$irgaStor$qfRngRtioMoleWetH2o, "qfStepRtioMoleWetH2o" = qfInp$irgaStor$qfStepRtioMoleWetH2o, - "qfPersRtioMoleWetH2o" = qfInp$irgaStor$qfPersRtioMoleWetH2o, - "qfCalRtioMoleWetH2o" = qfInp$irgaStor$qfCalRtioMoleWetH2o) + "qfPersRtioMoleWetH2o" = qfInp$irgaStor$qfPersRtioMoleWetH2o) + #"qfCalRtioMoleWetH2o" = qfInp$irgaStor$qfCalRtioMoleWetH2o) setQf$presIrga <- data.frame("qfRngPres" = qfInp$irgaStor$qfRngPres, "qfStepPres" = qfInp$irgaStor$qfStepPres, - "qfPersPres" = qfInp$irgaStor$qfPersPres, - "qfCalPres" = qfInp$irgaStor$qfCalPres) + "qfPersPres" = qfInp$irgaStor$qfPersPres) + #"qfCalPres" = qfInp$irgaStor$qfCalPres) setQf$tempIrga <- data.frame ("qfRngTemp" = qfInp$irgaStor$qfRngTemp, "qfStepTemp" = qfInp$irgaStor$qfStepTemp, - "qfPersTemp" = qfInp$irgaStor$qfPersTemp, - "qfCalTemp" = qfInp$irgaStor$qfCalTemp) + "qfPersTemp" = qfInp$irgaStor$qfPersTemp) + #"qfCalTemp" = qfInp$irgaStor$qfCalTemp) #change column names names(setQf$asrpCo2) <- paste0(colnames(setQf$asrpCo2), "IrgaStor") @@ -1053,7 +1055,7 @@ if (MethMeas == "ecse") { setQf$rtioMoleWetH2o, setQf$presIrga, setQf$tempIrga, setQf$envHut, setQf$valvAux, - setQf$heatInlt, + #setQf$heatInlt, setQf$frt00MfcSampStor, setQf$frtMfcSampStor, setQf$presAtmMfcSampStor, setQf$tempMfcSampStor, setQf$sensMfcSampStor, @@ -1066,7 +1068,7 @@ if (MethMeas == "ecse") { setQf$asrpH2o, setQf$rtioMoleWetH2o, setQf$presIrga, setQf$tempIrga, setQf$envHut, setQf$valvAux, - setQf$heatInlt, + #setQf$heatInlt, setQf$frt00MfcSampStor, setQf$frtMfcSampStor, setQf$presAtmMfcSampStor, setQf$tempMfcSampStor, setQf$sensMfcSampStor, @@ -1119,7 +1121,7 @@ if (MethMeas == "ecse") { setQf$rtioMoleWetH2o, setQf$presIrga, setQf$tempIrga, setQf$envHut, setQf$valvAux, - setQf$heatInlt, + #setQf$heatInlt, setQf$frt00MfcSampStor, setQf$frtMfcSampStor, setQf$presAtmMfcSampStor, setQf$tempMfcSampStor, setQf$sensMfcSampStor, @@ -1131,7 +1133,7 @@ if (MethMeas == "ecse") { rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$asrpH2o, setQf$presIrga, setQf$tempIrga, setQf$envHut, setQf$valvAux, - setQf$heatInlt, + #setQf$heatInlt, setQf$frt00MfcSampStor, setQf$frtMfcSampStor, setQf$presAtmMfcSampStor, setQf$tempMfcSampStor, setQf$sensMfcSampStor, @@ -1230,63 +1232,63 @@ if (MethMeas == "ecse") { #setQf for crdCo2 setQf$rtioMoleDryCo2 <- data.frame("qfRngRtioMoleDryCo2" = qfInp$crdCo2$qfRngRtioMoleDryCo2, "qfStepRtioMoleDryCo2" = qfInp$crdCo2$qfStepRtioMoleDryCo2, - "qfPersRtioMoleDryCo2" = qfInp$crdCo2$qfPersRtioMoleDryCo2, - "qfCalRtioMoleDryCo2" = qfInp$crdCo2$qfCalRtioMoleDryCo2) + "qfPersRtioMoleDryCo2" = qfInp$crdCo2$qfPersRtioMoleDryCo2) + #"qfCalRtioMoleDryCo2" = qfInp$crdCo2$qfCalRtioMoleDryCo2) setQf$rtioMoleDry12CCo2 <- data.frame("qfRngRtioMoleDry12CCo2" = qfInp$crdCo2$qfRngRtioMoleDry12CCo2, "qfStepRtioMoleDry12CCo2" = qfInp$crdCo2$qfStepRtioMoleDry12CCo2, - "qfPersRtioMoleDry12CCo2" = qfInp$crdCo2$qfPersRtioMoleDry12CCo2, - "qfCalRtioMoleDry12CCo2" = qfInp$crdCo2$qfCalRtioMoleDry12CCo2) + "qfPersRtioMoleDry12CCo2" = qfInp$crdCo2$qfPersRtioMoleDry12CCo2) + #"qfCalRtioMoleDry12CCo2" = qfInp$crdCo2$qfCalRtioMoleDry12CCo2) setQf$rtioMoleDry13CCo2 <- data.frame("qfRngRtioMoleDry13CCo2" = qfInp$crdCo2$qfRngRtioMoleDry13CCo2, "qfStepRtioMoleDry13CCo2" = qfInp$crdCo2$qfStepRtioMoleDry13CCo2, - "qfPersRtioMoleDry13CCo2" = qfInp$crdCo2$qfPersRtioMoleDry13CCo2, - "qfCalRtioMoleDry13CCo2" = qfInp$crdCo2$qfCalRtioMoleDry13CCo2) + "qfPersRtioMoleDry13CCo2" = qfInp$crdCo2$qfPersRtioMoleDry13CCo2) + #"qfCalRtioMoleDry13CCo2" = qfInp$crdCo2$qfCalRtioMoleDry13CCo2) setQf$rtioMoleDryH2o <- data.frame("qfRngRtioMoleDryH2o" = qfInp$crdCo2$qfRngRtioMoleDryH2o, #"qfStepRtioMoleDryH2o" = qfInp$crdCo2$qfStepRtioMoleDryH2o, - "qfPersRtioMoleDryH2o" = qfInp$crdCo2$qfPersRtioMoleDryH2o, - "qfCalRtioMoleDryH2o" = qfInp$crdCo2$qfCalRtioMoleDryH2o) + "qfPersRtioMoleDryH2o" = qfInp$crdCo2$qfPersRtioMoleDryH2o) + #"qfCalRtioMoleDryH2o" = qfInp$crdCo2$qfCalRtioMoleDryH2o) setQf$rtioMoleWetCo2 <- data.frame("qfRngRtioMoleWetCo2" = qfInp$crdCo2$qfRngRtioMoleWetCo2, "qfStepRtioMoleWetCo2" = qfInp$crdCo2$qfStepRtioMoleWetCo2, - "qfPersRtioMoleWetCo2" = qfInp$crdCo2$qfPersRtioMoleWetCo2, - "qfCalRtioMoleWetCo2" = qfInp$crdCo2$qfCalRtioMoleWetCo2) + "qfPersRtioMoleWetCo2" = qfInp$crdCo2$qfPersRtioMoleWetCo2) + #"qfCalRtioMoleWetCo2" = qfInp$crdCo2$qfCalRtioMoleWetCo2) setQf$rtioMoleWet12CCo2 <- data.frame("qfRngRtioMoleWet12CCo2" = qfInp$crdCo2$qfRngRtioMoleWet12CCo2, "qfStepRtioMoleWet12CCo2" = qfInp$crdCo2$qfStepRtioMoleWet12CCo2, - "qfPersRtioMoleWet12CCo2" = qfInp$crdCo2$qfPersRtioMoleWet12CCo2, - "qfCalRtioMoleWet12CCo2" = qfInp$crdCo2$qfCalRtioMoleWet12CCo2) + "qfPersRtioMoleWet12CCo2" = qfInp$crdCo2$qfPersRtioMoleWet12CCo2) + #"qfCalRtioMoleWet12CCo2" = qfInp$crdCo2$qfCalRtioMoleWet12CCo2) setQf$rtioMoleWet13CCo2 <- data.frame("qfRngRtioMoleWet13CCo2" = qfInp$crdCo2$qfRngRtioMoleWet13CCo2, "qfStepRtioMoleWet13CCo2" = qfInp$crdCo2$qfStepRtioMoleWet13CCo2, - "qfPersRtioMoleWet13CCo2" = qfInp$crdCo2$qfPersRtioMoleWet13CCo2, - "qfCalRtioMoleWet13CCo2 " = qfInp$crdCo2$qfCalRtioMoleWet13CCo2) + "qfPersRtioMoleWet13CCo2" = qfInp$crdCo2$qfPersRtioMoleWet13CCo2) + #"qfCalRtioMoleWet13CCo2 " = qfInp$crdCo2$qfCalRtioMoleWet13CCo2) setQf$rtioMoleWetH2o <- data.frame("qfRngRtioMoleWetH2o" = qfInp$crdCo2$qfRngRtioMoleWetH2o, #"qfStepRtioMoleWetH2o" = qfInp$crdCo2$qfStepRtioMoleWetH2o, - "qfPersRtioMoleWetH2o" = qfInp$crdCo2$qfPersRtioMoleWetH2o, - "qfCalRtioMoleWetH2o" = qfInp$crdCo2$qfCalRtioMoleWetH2o) + "qfPersRtioMoleWetH2o" = qfInp$crdCo2$qfPersRtioMoleWetH2o) + #"qfCalRtioMoleWetH2o" = qfInp$crdCo2$qfCalRtioMoleWetH2o) setQf$dlta13CCo2 <- data.frame("qfRngDlta13CCo2" = qfInp$crdCo2$qfRngDlta13CCo2, "qfStepDlta13CCo2" = qfInp$crdCo2$qfStepDlta13CCo2, - "qfPersDlta13CCo2" = qfInp$crdCo2$qfPersDlta13CCo2, - "qfCalDlta13CCo2" = qfInp$crdCo2$qfCalDlta13CCo2) + "qfPersDlta13CCo2" = qfInp$crdCo2$qfPersDlta13CCo2) + #"qfCalDlta13CCo2" = qfInp$crdCo2$qfCalDlta13CCo2) setQf$presCrdCo2 <- data.frame("qfRngPres" = qfInp$crdCo2$qfRngPres, "qfStepPres" = qfInp$crdCo2$qfStepPres, - "qfPersPres" = qfInp$crdCo2$qfPersPres, - "qfCalPres" = qfInp$crdCo2$qfCalPres) + "qfPersPres" = qfInp$crdCo2$qfPersPres) + #"qfCalPres" = qfInp$crdCo2$qfCalPres) setQf$tempCrdCo2 <- data.frame("qfRngTemp" = qfInp$crdCo2$qfRngTemp, "qfStepTemp" = qfInp$crdCo2$qfStepTemp, - "qfPersTemp" = qfInp$crdCo2$qfPersTemp, - "qfCalTemp" = qfInp$crdCo2$qfCalTemp) + "qfPersTemp" = qfInp$crdCo2$qfPersTemp) + #"qfCalTemp" = qfInp$crdCo2$qfCalTemp) setQf$tempWbox <- data.frame("qfRngTempWbox" = qfInp$crdCo2$qfRngTempWbox, "qfStepTempWbox" = qfInp$crdCo2$qfStepTempWbox, - "qfPersTempWbox" = qfInp$crdCo2$qfPersTempWbox, - "qfCalTempWbox" = qfInp$crdCo2$qfCalTempWbox) + "qfPersTempWbox" = qfInp$crdCo2$qfPersTempWbox) + #"qfCalTempWbox" = qfInp$crdCo2$qfCalTempWbox) setQf$sensCrdCo2 <- data.frame("qfSensStus" = qfInp$crdCo2$qfSensStus) #change column names @@ -1412,7 +1414,8 @@ if (MethMeas == "ecse") { setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm,setQf$sensMfm, setQf$presInlt, setQf$pumpStor, - setQf$heatInlt, idGas = idGas + #setQf$heatInlt, + idGas = idGas ) rpt$rtioMoleWetCo2 <- na.omit(tmp$rtioMoleWetCo2[which(tmp$rtioMoleWetCo2$idGas == 105 | (is.na(tmp$rtioMoleWetCo2$idGas) & tmp$rtioMoleWetCo2$qfSensStus == -1)),]) @@ -1423,7 +1426,8 @@ if (MethMeas == "ecse") { setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, setQf$pumpStor, - setQf$heatInlt, idGas = idGas + #setQf$heatInlt, + idGas = idGas ) rpt$rtioMoleDryCo2 <- na.omit(tmp$rtioMoleDryCo2[which(tmp$rtioMoleDryCo2$idGas == 105 | (is.na(tmp$rtioMoleDryCo2$idGas) & tmp$rtioMoleDryCo2$qfSensStus == -1)),]) @@ -1434,7 +1438,8 @@ if (MethMeas == "ecse") { setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, setQf$pumpStor, - setQf$heatInlt, idGas = idGas + #setQf$heatInlt, + idGas = idGas ) rpt$rtioMoleWet12CCo2 <- na.omit(tmp$rtioMoleWet12CCo2[which(tmp$rtioMoleWet12CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet12CCo2$idGas) & tmp$rtioMoleWet12CCo2$qfSensStus == -1)),]) @@ -1445,7 +1450,8 @@ if (MethMeas == "ecse") { setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, - setQf$pumpStor, setQf$heatInlt, + setQf$pumpStor, + #setQf$heatInlt, idGas = idGas ) rpt$rtioMoleDry12CCo2 <- na.omit(tmp$rtioMoleDry12CCo2[which(tmp$rtioMoleDry12CCo2$idGas == 105 | (is.na(tmp$rtioMoleDry12CCo2$idGas) & tmp$rtioMoleDry12CCo2$qfSensStus == -1)),]) @@ -1456,7 +1462,8 @@ if (MethMeas == "ecse") { setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, setQf$pumpStor, - setQf$heatInlt, idGas = idGas + #setQf$heatInlt, + idGas = idGas ) rpt$rtioMoleWet13CCo2 <- na.omit(tmp$rtioMoleWet13CCo2[which(tmp$rtioMoleWet13CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet13CCo2$idGas) & tmp$rtioMoleWet13CCo2$qfSensStus == -1)),]) @@ -1467,7 +1474,8 @@ if (MethMeas == "ecse") { setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, - setQf$pumpStor, setQf$heatInlt, + setQf$pumpStor, + #setQf$heatInlt, idGas = idGas ) @@ -1479,7 +1487,8 @@ if (MethMeas == "ecse") { setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, setQf$pumpStor, - setQf$heatInlt, idGas = idGas + #setQf$heatInlt, + idGas = idGas ) rpt$dlta13CCo2 <- na.omit(tmp$dlta13CCo2[which(tmp$dlta13CCo2$idGas == 105 | (is.na(tmp$dlta13CCo2$idGas) & tmp$dlta13CCo2$qfSensStus == -1)),]) @@ -1490,7 +1499,8 @@ if (MethMeas == "ecse") { setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, setQf$pumpStor, - setQf$heatInlt, idGas = idGas + #setQf$heatInlt, + idGas = idGas ) rpt$rtioMoleWetH2o <- na.omit(tmp$rtioMoleWetH2o[which(tmp$rtioMoleWetH2o$idGas == 11 | (is.na(tmp$rtioMoleWetH2o$idGas) & tmp$rtioMoleWetH2o$qfSensStus == -1)),]) @@ -1501,7 +1511,8 @@ if (MethMeas == "ecse") { setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, - setQf$pumpStor, setQf$heatInlt, + setQf$pumpStor, + #setQf$heatInlt, idGas = idGas ) rpt$rtioMoleDryH2o <- na.omit(tmp$rtioMoleDryH2o[which(tmp$rtioMoleDryH2o$idGas == 11 | (is.na(tmp$rtioMoleDryH2o$idGas) & tmp$rtioMoleDryH2o$qfSensStus == -1)),]) @@ -1526,8 +1537,8 @@ if (MethMeas == "ecse") { setQf$sensCrdCo2, setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm,setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, - setQf$heatInlt + setQf$presInlt, setQf$pumpStor + #setQf$heatInlt )) rpt$rtioMoleDryCo2 <- na.omit(data.frame(setQf$rtioMoleDryCo2, setQf$dlta13CCo2, @@ -1536,8 +1547,8 @@ if (MethMeas == "ecse") { setQf$sensCrdCo2, setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, - setQf$heatInlt + setQf$presInlt, setQf$pumpStor + #setQf$heatInlt )) rpt$rtioMoleWet12CCo2 <- na.omit(data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, @@ -1545,8 +1556,8 @@ if (MethMeas == "ecse") { setQf$sensCrdCo2, setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, - setQf$heatInlt + setQf$presInlt, setQf$pumpStor + #setQf$heatInlt )) rpt$rtioMoleDry12CCo2 <- na.omit(data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet13CCo2, @@ -1555,7 +1566,8 @@ if (MethMeas == "ecse") { setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, - setQf$pumpStor, setQf$heatInlt + setQf$pumpStor + #setQf$heatInlt )) rpt$rtioMoleWet13CCo2 <- na.omit(data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, @@ -1563,8 +1575,8 @@ if (MethMeas == "ecse") { setQf$sensCrdCo2, setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, - setQf$heatInlt + setQf$presInlt, setQf$pumpStor + #setQf$heatInlt )) rpt$rtioMoleDry13CCo2 <- na.omit(data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, @@ -1573,7 +1585,8 @@ if (MethMeas == "ecse") { setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, - setQf$pumpStor, setQf$heatInlt + setQf$pumpStor + #setQf$heatInlt )) rpt$dlta13CCo2 <- na.omit(data.frame(setQf$dlta13CCo2, setQf$presCrdCo2, @@ -1581,8 +1594,8 @@ if (MethMeas == "ecse") { setQf$sensCrdCo2, setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, - setQf$heatInlt + setQf$presInlt, setQf$pumpStor + #setQf$heatInlt )) rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, @@ -1590,8 +1603,8 @@ if (MethMeas == "ecse") { setQf$sensCrdCo2, setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, - setQf$heatInlt + setQf$presInlt, setQf$pumpStor + #setQf$heatInlt )) rpt$rtioMoleDryH2o <- na.omit(data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, @@ -1600,7 +1613,8 @@ if (MethMeas == "ecse") { setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, - setQf$pumpStor, setQf$heatInlt + setQf$pumpStor + #setQf$heatInlt )) rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) @@ -1844,38 +1858,38 @@ if (MethMeas == "ecse") { #setQf for crdH2o setQf$rtioMoleDryH2o <- data.frame("qfRngRtioMoleDryH2o" = qfInp$crdH2o$qfRngRtioMoleDryH2o, "qfStepRtioMoleDryH2o" = qfInp$crdH2o$qfStepRtioMoleDryH2o, - "qfPersRtioMoleDryH2o" = qfInp$crdH2o$qfPersRtioMoleDryH2o, - "qfCalRtioMoleDryH2o" = qfInp$crdH2o$qfCalRtioMoleDryH2o) + "qfPersRtioMoleDryH2o" = qfInp$crdH2o$qfPersRtioMoleDryH2o) + #"qfCalRtioMoleDryH2o" = qfInp$crdH2o$qfCalRtioMoleDryH2o) setQf$rtioMoleWetH2o <- data.frame("qfRngRtioMoleWetH2o" = qfInp$crdH2o$qfRngRtioMoleWetH2o, "qfStepRtioMoleWetH2o" = qfInp$crdH2o$qfStepRtioMoleWetH2o, - "qfPersRtioMoleWetH2o" = qfInp$crdH2o$qfPersRtioMoleWetH2o, - "qfCalRtioMoleWetH2o" = qfInp$crdH2o$qfCalRtioMoleWetH2o) + "qfPersRtioMoleWetH2o" = qfInp$crdH2o$qfPersRtioMoleWetH2o) + #"qfCalRtioMoleWetH2o" = qfInp$crdH2o$qfCalRtioMoleWetH2o) setQf$dlta18OH2o <- data.frame("qfRngDlta18OH2o" = qfInp$crdH2o$qfRngDlta18OH2o, "qfStepDlta18OH2o" = qfInp$crdH2o$qfStepDlta18OH2o, - "qfPersDlta18OH2o" = qfInp$crdH2o$qfPersDlta18OH2o, - "qfCalDlta18OH2o" = qfInp$crdH2o$qfCalDlta18OH2o) + "qfPersDlta18OH2o" = qfInp$crdH2o$qfPersDlta18OH2o) + #"qfCalDlta18OH2o" = qfInp$crdH2o$qfCalDlta18OH2o) setQf$dlta2HH2o <- data.frame("qfRngDlta2HH2o" = qfInp$crdH2o$qfRngDlta2HH2o, "qfStepDlta2HH2o" = qfInp$crdH2o$qfStepDlta2HH2o, - "qfPersDlta2HH2o" = qfInp$crdH2o$qfPersDlta2HH2o, - "qfCalDlta2HH2o" = qfInp$crdH2o$qfCalDlta2HH2o) + "qfPersDlta2HH2o" = qfInp$crdH2o$qfPersDlta2HH2o) + #"qfCalDlta2HH2o" = qfInp$crdH2o$qfCalDlta2HH2o) setQf$presCrdH2o <- data.frame("qfRngPres" = qfInp$crdH2o$qfRngPres, "qfStepPres" = qfInp$crdH2o$qfStepPres, - "qfPersPres" = qfInp$crdH2o$qfPersPres, - "qfCalPres" = qfInp$crdH2o$qfCalPres) + "qfPersPres" = qfInp$crdH2o$qfPersPres) + #"qfCalPres" = qfInp$crdH2o$qfCalPres) setQf$tempCrdH2o <- data.frame("qfRngTemp" = qfInp$crdH2o$qfRngTemp, "qfStepTemp" = qfInp$crdH2o$qfStepTemp, - "qfPersTemp" = qfInp$crdH2o$qfPersTemp, - "qfCalTemp" = qfInp$crdH2o$qfCalTemp) + "qfPersTemp" = qfInp$crdH2o$qfPersTemp) + #"qfCalTemp" = qfInp$crdH2o$qfCalTemp) setQf$tempWbox <- data.frame("qfRngTempWbox" = qfInp$crdH2o$qfRngTempWbox, "qfStepTempWbox" = qfInp$crdH2o$qfStepTempWbox, - "qfPersTempWbox" = qfInp$crdH2o$qfPersTempWbox, - "qfCalTempWbox" = qfInp$crdH2o$qfCalTempWbox) + "qfPersTempWbox" = qfInp$crdH2o$qfPersTempWbox) + #"qfCalTempWbox" = qfInp$crdH2o$qfCalTempWbox) setQf$sensCrdH2o <- data.frame("qfSensStus" = qfInp$crdH2o$qfSensStus, "qfStusN2" = qfInp$crdH2o$qfStusN2) @@ -1976,8 +1990,8 @@ if (MethMeas == "ecse") { setQf$envHut, setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, - setQf$heatInlt + setQf$presInlt, setQf$pumpStor + #setQf$heatInlt )) rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$presCrdH2o, @@ -1986,7 +2000,8 @@ if (MethMeas == "ecse") { setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, - setQf$pumpStor, setQf$heatInlt + setQf$pumpStor + #setQf$heatInlt )) rpt$dlta18OH2o <- na.omit(data.frame(setQf$dlta18OH2o, setQf$presCrdH2o, @@ -1995,7 +2010,8 @@ if (MethMeas == "ecse") { setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, - setQf$pumpStor, setQf$heatInlt + setQf$pumpStor + #setQf$heatInlt )) rpt$dlta2HH2o <- na.omit(data.frame(setQf$dlta2HH2o, setQf$presCrdH2o, @@ -2004,7 +2020,8 @@ if (MethMeas == "ecse") { setQf$frt00Mfm, setQf$frtMfm, setQf$presAtmMfm, setQf$tempMfm, setQf$sensMfm, setQf$presInlt, - setQf$pumpStor, setQf$heatInlt + setQf$pumpStor + #setQf$heatInlt )) rpt$pres <- na.omit(data.frame(setQf$presCrdH2o, setQf$sensCrdH2o$qfSensStus)) From f666f5ba6c17475b9e2027bce93646dd1ad1a6b2 Mon Sep 17 00:00:00 2001 From: NDurden Date: Thu, 12 Mar 2020 20:17:19 +0000 Subject: [PATCH 038/168] In irgaCo2 an irgaH2o, not include the period when crdCo2 take over to measure at that level and irga have to move to measure next level --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 29 ++++++++++++++++++++++++ pack/eddy4R.stor/R/wrap.dp01.ecse.R | 12 ++++++++++ 2 files changed, 41 insertions(+) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index c0b4292f..5c1a2ca8 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -75,6 +75,9 @@ # pull in the qf from presInlt # Natchaya P-Durden (2019-05-23) # pull in the qf from pumpStor, presValiRegInStor and presValiRegOutStor +# Natchaya P-Durden (2020-03-12) +# In irgaCo2 an irgaH2o, not include the period when crdCo2 take over to measure at that level +# and irga have to move to measure next level ############################################################################################## wrap.dp01.qfqm.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], @@ -213,6 +216,13 @@ wrap.dp01.qfqm.ecse <- function( rpt[[idxAgr]]$timeEnd[[idxVar]] <- wrk$idx$timeEnd[idxAgr] } + #check if this period is the period that crdCo2 take over and irga have to move to measure other level + #and qmBeta > 0.1 + if (dp01 == "co2Stor") {qmBeta <- rpt[[idxAgr]]$qmBeta$rtioMoleDryCo2} + if (dp01 == "h2oStor") {qmBeta <- rpt[[idxAgr]]$qmBeta$rtioMoleDryH2o} + if (data$crdCo2ValvLvl$`702_000`$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & qmBeta > 0.1){ + rpt[[idxAgr]] <- NULL + } #}# end of there is at least one data }; rm(idxAgr) @@ -266,6 +276,23 @@ wrap.dp01.qfqm.ecse <- function( #if last timeEnd is NA, replce that time to the last time value in data$time wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") + #get rid of period that crdCo2 take over and irga have to move to measure other level + #and number of sample less than 10% (120-120*0.1) + tmpWrkIdx <- list() + for (idxAgr in 1:length(wrk$idx$idxEnd)){ + if (dp01 == "co2Stor") {numSamp <- sum(!is.na(wrk$data$rtioMoleDryCo2[wrk$idx$idxBgn[idxAgr]:wrk$idx$idxEnd[idxAgr]]))} + if (dp01 == "h2oStor") {numSamp <- sum(!is.na(wrk$data$rtioMoleDryH2o[wrk$idx$idxBgn[idxAgr]:wrk$idx$idxEnd[idxAgr]]))} + if (data$crdCo2ValvLvl$`702_000`$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & numSamp < 108){ + tmpWrkIdx[[idxAgr]] <- idxAgr + + } + } + + #combine idxAgr which will be removed + tmpRmv <- do.call(cbind,tmpWrkIdx) + #remove those idxAgr from wrk$idx + wrk$idx <- wrk$idx[-c(tmpRmv),] + whrSamp <- wrk$idx$idxBgn[1]:wrk$idx$idxEnd[1] if (length (wrk$idx$idxBgn) > 1 ){ for(ii in 2:length (wrk$idx$idxBgn)){ @@ -1370,6 +1397,8 @@ wrap.dp01.qfqm.ecse <- function( }#end of dp01 if statement + #remove NULL list from rpt + rpt <- rpt[!sapply(rpt, is.null)] #return results return(rpt) diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index cf88be7c..887d0bda 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -64,6 +64,9 @@ # rename function from wrap.neon.dp01.ecse() to wrap.dp01.ecse() # Natchaya P-Durden (2019-01-31) # using injNum instate of qfRngTmp to determine missing data +# Natchaya P-Durden (2020-03-12) +# In irgaCo2 an irgaH2o, not include the period when crdCo2 take over to measure at that level +# and irga have to move to measure next level ############################################################################################## wrap.dp01.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], @@ -195,6 +198,13 @@ wrap.dp01.ecse <- function( rpt[[idxAgr]]$timeEnd[[idxVar]] <- wrk$idx$timeEnd[idxAgr] } + #check if this period is the period that crdCo2 take over and irga have to move to measure other level + #and number of sample less than 10% (120-120*0.1) + if (dp01 == "co2Stor") {numSamp <- rpt[[idxAgr]]$numSamp$rtioMoleDryCo2} + if (dp01 == "h2oStor") {numSamp <- rpt[[idxAgr]]$numSamp$rtioMoleDryH2o} + if (data$crdCo2ValvLvl$`702_000`$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & numSamp < 108){ + rpt[[idxAgr]] <- NULL + } #}# end of there is at least one data }; rm(idxAgr) @@ -1313,6 +1323,8 @@ wrap.dp01.ecse <- function( }#end of dp01 if statement + #remove NULL list from rpt + rpt <- rpt[!sapply(rpt, is.null)] #return results return(rpt) From f009d71cc0ffcd2b85a1dfec55d713311ef2cb9e Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 17 Mar 2020 14:06:11 +0000 Subject: [PATCH 039/168] - update attributes for qfqm and format of DataType --- pack/eddy4R.base/R/def.hdf5.read.qfqm.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.read.qfqm.R b/pack/eddy4R.base/R/def.hdf5.read.qfqm.R index 0cd55b80..6dec9f3d 100644 --- a/pack/eddy4R.base/R/def.hdf5.read.qfqm.R +++ b/pack/eddy4R.base/R/def.hdf5.read.qfqm.R @@ -12,10 +12,11 @@ #' @param VarLoca Character: Which instrument to read data from. #' @param LvlTowr The tower level that the sensor data is being collected in NEON data product convention (HOR_VER) #' @param FreqLoca Integer: Measurement frequency. +#' @param DataType Character: Specify between data and qfqm for read in. #' @param MethMeas A vector of class "character" containing the name of measurement method (eddy-covariance turbulent exchange or storage exchange), MethMeas = c("ecte", "ecse"). Defaults to "ecte". #' @return -#' Named list \code{qfqm} containing time-series of quality flags. +#' Named list \code{rpt} containing time-series of quality flags. #' @references #' License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007. @@ -51,7 +52,7 @@ def.hdf5.read.qfqm <- function( VarLoca, LvlTowr = c("000_040", "000_050", "000_060")[3], FreqLoca, - DataType = c(data,qfqm)[1], + DataType = c("data","qfqm")[1], MethMeas = c("ecte", "ecse")[1] ){ @@ -83,6 +84,7 @@ rpt <- base::as.data.frame(rpt, stringsAsFactors = FALSE) #Reapply attributes to reported data.frame attributes(rpt)$unit <- attr$Unit +if(is.null(attr(rpt,"unit")) & DataType == "qfqm") attributes(rpt)$unit <- rep(NA, length(rpt)) # convert type of variable time if("time" %in% colnames(rpt)){ @@ -90,10 +92,11 @@ rpt$time <- base::as.POSIXct(rpt$time, format="%Y-%m-%dT%H:%M:%OSZ", tz="UTC") + } # perform unit conversion +if(DataType == "data"){ rpt <- base::suppressWarnings(eddy4R.base::def.unit.conv(data = rpt, unitFrom = attributes(rpt)$unit, unitTo = "intl")) - +} #Reapply attributes to reported data.frame lapply(grep("Unit", names(attr), value = TRUE, invert = TRUE), function(x){ @@ -104,6 +107,7 @@ lapply(grep("Unit", names(attr), value = TRUE, invert = TRUE), function(x){ # sd assign attribute to gasRefe if (VarLoca == "gasRefe"){ names(attr(rpt,"Sd")) <- attr(rpt,"Name") + names(attributes(rpt))[which(names(attributes(rpt))=="Sd")] <- "sd" #Change to lower case to keep format names(attr(rpt,"DfSd")) <- attr(rpt,"Name") #base::attributes(rpt)$sd <- attr$Sd[base::names(rpt)] #base::attributes(rpt)$DfSd <- attr$DfSd[base::names(rpt)] From 763b20ae6bf81e4364017c88e0ff8c6ac565f1d3 Mon Sep 17 00:00:00 2001 From: NDurden Date: Tue, 17 Mar 2020 19:47:47 +0000 Subject: [PATCH 040/168] remove na value before applying linear interpolation if like that maxgap will not work --- pack/eddy4R.stor/R/def.itpl.time.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pack/eddy4R.stor/R/def.itpl.time.R b/pack/eddy4R.stor/R/def.itpl.time.R index c5b09b6d..371473bc 100644 --- a/pack/eddy4R.stor/R/def.itpl.time.R +++ b/pack/eddy4R.stor/R/def.itpl.time.R @@ -32,6 +32,7 @@ # original creation # Ke Xu (2018-07-01) # apply eddy4R terms: from gap to Wndw +# remove na value before applying linear interpolation if like that maxgap will not work ############################################################################################################## #Start of function call ############################################################################################################## @@ -97,6 +98,8 @@ def.itpl.time <- function( } else { if(methItpl == "linear"){ + #remove na value if like that maxgap will not work + dataInp <- na.omit(dataInp) rpt <- zoo::na.approx(object=as.vector(dataInp$mean), x=#dataInp$timeFrac as.integer(dataInp$timeFrac * 60) , xout=as.integer(timeFracOut * 60) From da86bee05c8e026893589d16fcbbb33d9a399a94 Mon Sep 17 00:00:00 2001 From: NDurden Date: Tue, 24 Mar 2020 22:53:01 +0000 Subject: [PATCH 041/168] bug fix when the last idx is greater than last index of that day (86400) --- pack/eddy4R.stor/R/wrap.dp01.ecse.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index 887d0bda..21330c9d 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -202,7 +202,9 @@ wrap.dp01.ecse <- function( #and number of sample less than 10% (120-120*0.1) if (dp01 == "co2Stor") {numSamp <- rpt[[idxAgr]]$numSamp$rtioMoleDryCo2} if (dp01 == "h2oStor") {numSamp <- rpt[[idxAgr]]$numSamp$rtioMoleDryH2o} - if (data$crdCo2ValvLvl$`702_000`$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & numSamp < 108){ + #replace wrk$idx$idxEnd[idxAgr] > 86400 to 86400 + IdxEnd <- ifelse(wrk$idx$idxEnd[idxAgr] > 86400, 86400, wrk$idx$idxEnd[idxAgr]) + if (data$crdCo2ValvLvl$`702_000`$lvlCrdCo2[IdxEnd] == lvlIrga & numSamp < 108){ rpt[[idxAgr]] <- NULL } #}# end of there is at least one data From 462f329e4ece55080ccc0e35e31f235dfe068e0d Mon Sep 17 00:00:00 2001 From: NDurden Date: Wed, 25 Mar 2020 13:27:19 +0000 Subject: [PATCH 042/168] update code to replace last idxEnd --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 2 ++ pack/eddy4R.stor/R/wrap.dp01.ecse.R | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index 5c1a2ca8..66062e9d 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -273,6 +273,8 @@ wrap.dp01.qfqm.ecse <- function( wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$irgaStor$qfRngTemp, CritTime = 60) #delete row if last timeBgn and timeEnd is NA wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] + #replace last idxEnd > 86400 by 86400 + wrk$idx$idxEnd <- ifelse(wrk$idx$idxEnd > 86400, 86400, wrk$idx$idxEnd) #if last timeEnd is NA, replce that time to the last time value in data$time wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index 21330c9d..03f2aff8 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -152,6 +152,8 @@ wrap.dp01.ecse <- function( wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$irgaStor$qfRngTemp, CritTime = 60) #delete row if last timeBgn and timeEnd is NA wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] + #replace last idxEnd > 86400 by 86400 + wrk$idx$idxEnd <- ifelse(wrk$idx$idxEnd > 86400, 86400, wrk$idx$idxEnd) #if last timeEnd is NA, replce that time to the last time value in data$time wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") #idxAgr2 <- 0 @@ -202,9 +204,7 @@ wrap.dp01.ecse <- function( #and number of sample less than 10% (120-120*0.1) if (dp01 == "co2Stor") {numSamp <- rpt[[idxAgr]]$numSamp$rtioMoleDryCo2} if (dp01 == "h2oStor") {numSamp <- rpt[[idxAgr]]$numSamp$rtioMoleDryH2o} - #replace wrk$idx$idxEnd[idxAgr] > 86400 to 86400 - IdxEnd <- ifelse(wrk$idx$idxEnd[idxAgr] > 86400, 86400, wrk$idx$idxEnd[idxAgr]) - if (data$crdCo2ValvLvl$`702_000`$lvlCrdCo2[IdxEnd] == lvlIrga & numSamp < 108){ + if (data$crdCo2ValvLvl$`702_000`$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & numSamp < 108){ rpt[[idxAgr]] <- NULL } #}# end of there is at least one data @@ -248,6 +248,8 @@ wrap.dp01.ecse <- function( wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$irgaStor$qfRngTemp, CritTime = 60) #delete row if last timeBgn and timeEnd is NA wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] + #replace last idxEnd > 86400 by 86400 + wrk$idx$idxEnd <- ifelse(wrk$idx$idxEnd > 86400, 86400, wrk$idx$idxEnd) #if last timeEnd is NA, replce that time to the last time value in data$time wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") From 90f5d1c9b7f511dd1dd655f1ffbcbe926f50785c Mon Sep 17 00:00:00 2001 From: NDurden Date: Wed, 25 Mar 2020 22:24:12 +0000 Subject: [PATCH 043/168] added lvlCrdCo2Valv to function's parameter --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 8 ++++++-- pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd | 3 +++ pack/eddy4R.stor/R/wrap.dp01.ecse.R | 6 +++++- pack/eddy4R.stor/man/wrap.dp01.ecse.Rd | 3 +++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index 66062e9d..f29991b1 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -17,6 +17,7 @@ #' @param lvlValv Measurement level of irgaValvLvl, crdCo2ValvLvl, or crdH2oValvLvl. Defaults to NULL. Of type character. [-] #' @param lvlValvAux Location of valvAux which apply to only dp01 equal to "co2Stor" or "h2oStor". Defaults to NULL. Of type character. [-] #' @param lvlCrdH2oValvVali Measurement level of crdH2oValvVali which apply to only dp01 equal to "isoH2o". Defaults to NULL. Of type character. [-] +#' @param lvlCrdCo2Valv Horizontal and vertical location for crdCo2 valve. Defaults to NULL. Of type character. [-] #' @param data A list of data frame containing the input dp0p data that related to dp01 which qfqm are being calculated. Of class integer". [User defined] #' @param qfInp A list of data frame containing the input quality flag data that related to dp01 are being grouped. Of class integer". [-] #' @param TypeMeas A vector of class "character" containing the name of measurement type (sampling or validation), TypeMeas = c("samp", "vali"). Defaults to "samp". [-] @@ -78,6 +79,8 @@ # Natchaya P-Durden (2020-03-12) # In irgaCo2 an irgaH2o, not include the period when crdCo2 take over to measure at that level # and irga have to move to measure next level +# Natchaya P-Durden (2020-03-25) +# added lvlCrdCo2Valv to the function's parameter ############################################################################################## wrap.dp01.qfqm.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], @@ -89,6 +92,7 @@ wrap.dp01.qfqm.ecse <- function( lvlValv = NULL, lvlValvAux = NULL, lvlCrdH2oValvVali = NULL, + lvlCrdCo2Valv = NULL, data = list(), qfInp = list(), TypeMeas = c("samp", "vali")[1], @@ -220,7 +224,7 @@ wrap.dp01.qfqm.ecse <- function( #and qmBeta > 0.1 if (dp01 == "co2Stor") {qmBeta <- rpt[[idxAgr]]$qmBeta$rtioMoleDryCo2} if (dp01 == "h2oStor") {qmBeta <- rpt[[idxAgr]]$qmBeta$rtioMoleDryH2o} - if (data$crdCo2ValvLvl$`702_000`$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & qmBeta > 0.1){ + if (data$crdCo2ValvLvl[[lvlCrdCo2Valv]]$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & qmBeta > 0.1){ rpt[[idxAgr]] <- NULL } #}# end of there is at least one data @@ -284,7 +288,7 @@ wrap.dp01.qfqm.ecse <- function( for (idxAgr in 1:length(wrk$idx$idxEnd)){ if (dp01 == "co2Stor") {numSamp <- sum(!is.na(wrk$data$rtioMoleDryCo2[wrk$idx$idxBgn[idxAgr]:wrk$idx$idxEnd[idxAgr]]))} if (dp01 == "h2oStor") {numSamp <- sum(!is.na(wrk$data$rtioMoleDryH2o[wrk$idx$idxBgn[idxAgr]:wrk$idx$idxEnd[idxAgr]]))} - if (data$crdCo2ValvLvl$`702_000`$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & numSamp < 108){ + if (data$crdCo2ValvLvl[[lvlCrdCo2Valv]]$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & numSamp < 108){ tmpWrkIdx[[idxAgr]] <- idxAgr } diff --git a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd index 1c352351..eedc6015 100644 --- a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd +++ b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd @@ -14,6 +14,7 @@ wrap.dp01.qfqm.ecse( lvlValv = NULL, lvlValvAux = NULL, lvlCrdH2oValvVali = NULL, + lvlCrdCo2Valv = NULL, data = list(), qfInp = list(), TypeMeas = c("samp", "vali")[1], @@ -42,6 +43,8 @@ c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o"). Default \item{lvlCrdH2oValvVali}{Measurement level of crdH2oValvVali which apply to only dp01 equal to "isoH2o". Defaults to NULL. Of type character. [-]} +\item{lvlCrdCo2Valv}{Horizontal and vertical location for crdCo2 valve. Defaults to NULL. Of type character. [-]} + \item{data}{A list of data frame containing the input dp0p data that related to dp01 which qfqm are being calculated. Of class integer". [User defined]} \item{qfInp}{A list of data frame containing the input quality flag data that related to dp01 are being grouped. Of class integer". [-]} diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index 03f2aff8..404b08ea 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -14,6 +14,7 @@ #' @param lvlEnvHut Measurement level of envHut. Defaults to NULL. Of type character. [-] #' @param lvlValv Measurement level of irgaValvLvl, crdCo2ValvLvl, or crdH2oValvLvl. Defaults to NULL. Of type character. [-] #' @param lvlCrdH2oValvVali Measurement level of crdH2oValvVali which apply to only dp01 equal to "isoH2o". Defaults to NULL. Of type character. [-] +#' @param lvlCrdCo2Valv Horizontal and vertical location for crdCo2 valve. Defaults to NULL. Of type character. [-] #' @param data A list of data frame containing the input dp0p data that related to dp01 which descriptive statistics are being calculated. Of class integer". [User defined] #' @param qfInp A list of data frame containing the input quality flag data that related to dp01 are being grouped. Of class integer". [-] #' @param TypeMeas A vector of class "character" containing the name of measurement type (sampling or validation), TypeMeas = c("samp", "vali"). Defaults to "samp". [-] @@ -67,6 +68,8 @@ # Natchaya P-Durden (2020-03-12) # In irgaCo2 an irgaH2o, not include the period when crdCo2 take over to measure at that level # and irga have to move to measure next level +# Natchaya P-Durden (2020-03-25) +# added lvlCrdCo2Valv to the function's parameter ############################################################################################## wrap.dp01.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], @@ -75,6 +78,7 @@ wrap.dp01.ecse <- function( lvlEnvHut = NULL, lvlValv = NULL, lvlCrdH2oValvVali = NULL, + lvlCrdCo2Valv = NULL, data = list(), qfInp = list(), TypeMeas = c("samp", "vali")[1], @@ -204,7 +208,7 @@ wrap.dp01.ecse <- function( #and number of sample less than 10% (120-120*0.1) if (dp01 == "co2Stor") {numSamp <- rpt[[idxAgr]]$numSamp$rtioMoleDryCo2} if (dp01 == "h2oStor") {numSamp <- rpt[[idxAgr]]$numSamp$rtioMoleDryH2o} - if (data$crdCo2ValvLvl$`702_000`$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & numSamp < 108){ + if (data$crdCo2ValvLvl[[lvlCrdCo2Valv]]$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & numSamp < 108){ rpt[[idxAgr]] <- NULL } #}# end of there is at least one data diff --git a/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd b/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd index 930a92f9..c15f4b59 100644 --- a/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd +++ b/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd @@ -11,6 +11,7 @@ wrap.dp01.ecse( lvlEnvHut = NULL, lvlValv = NULL, lvlCrdH2oValvVali = NULL, + lvlCrdCo2Valv = NULL, data = list(), qfInp = list(), TypeMeas = c("samp", "vali")[1], @@ -33,6 +34,8 @@ c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o"). Default \item{lvlCrdH2oValvVali}{Measurement level of crdH2oValvVali which apply to only dp01 equal to "isoH2o". Defaults to NULL. Of type character. [-]} +\item{lvlCrdCo2Valv}{Horizontal and vertical location for crdCo2 valve. Defaults to NULL. Of type character. [-]} + \item{data}{A list of data frame containing the input dp0p data that related to dp01 which descriptive statistics are being calculated. Of class integer". [User defined]} \item{qfInp}{A list of data frame containing the input quality flag data that related to dp01 are being grouped. Of class integer". [-]} From 5a8a8439897b63fc556858e116bc2edb1c8565c2 Mon Sep 17 00:00:00 2001 From: NDurden Date: Wed, 1 Apr 2020 19:35:46 +0000 Subject: [PATCH 044/168] added failsafe for not to break the zoo::na.approx function when timeFrac are duplicate --- pack/eddy4R.stor/R/def.itpl.time.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.stor/R/def.itpl.time.R b/pack/eddy4R.stor/R/def.itpl.time.R index c5b09b6d..8d7b6919 100644 --- a/pack/eddy4R.stor/R/def.itpl.time.R +++ b/pack/eddy4R.stor/R/def.itpl.time.R @@ -32,6 +32,8 @@ # original creation # Ke Xu (2018-07-01) # apply eddy4R terms: from gap to Wndw +# Natchaya P-Durden (2020-04-01) +# added failsafe for not to break the zoo::na.approx function when timeFrac are duplicate ############################################################################################################## #Start of function call ############################################################################################################## @@ -95,10 +97,14 @@ def.itpl.time <- function( #interpolate actual data } else { + #Failsafe for not to break the zoo::na.approx function + #if only two data are available and as.integer(dataInp$timeFrac * 60) are the same value, add 1 to timeFrac of the 2nd value + tmpTimeFrac <- as.integer(dataInp$timeFrac * 60) + if (setLgth == 2 & tmpTimeFrac[1]==tmpTimeFrac[2]) tmpTimeFrac[2] <- tmpTimeFrac[2]+1 if(methItpl == "linear"){ rpt <- zoo::na.approx(object=as.vector(dataInp$mean), x=#dataInp$timeFrac - as.integer(dataInp$timeFrac * 60) + tmpTimeFrac , xout=as.integer(timeFracOut * 60) , method = "linear", maxgap=(WndwMax/60), na.rm=FALSE, rule=1, f=0) From 8daa6e0723b525ac590c4536c9f5ed910b0571d7 Mon Sep 17 00:00:00 2001 From: NDurden Date: Tue, 14 Apr 2020 18:03:23 +0000 Subject: [PATCH 045/168] Determine the begin and end time for each validation period: update the code to be more generic that can work even we do not have a full set of gas tanks --- pack/eddy4R.base/R/def.irga.vali.cor.R | 25 ++++++++++++++++--------- pack/eddy4R.base/R/wrap.irga.vali.R | 4 ++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pack/eddy4R.base/R/def.irga.vali.cor.R b/pack/eddy4R.base/R/def.irga.vali.cor.R index 49a64bdd..2386da57 100644 --- a/pack/eddy4R.base/R/def.irga.vali.cor.R +++ b/pack/eddy4R.base/R/def.irga.vali.cor.R @@ -153,21 +153,27 @@ def.irga.vali.cor <- function( numDate <- 0 for (idx in 1:length(dateBgn)){ numDate <- numDate + 1 + tmpTimeBgn <- as.POSIXlt(paste(dateBgn[idx], " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") + tmpTimeEnd <- as.POSIXlt(paste(dateEnd[idx], " ", "", sep="00:00:00.000"), format="%Y-%m-%d %H:%M:%OS", tz="UTC") #time begin and time End to apply coefficient - #time when performing of high gas is done - if (length(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd[which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$gasType == "qfIrgaTurbValiGas05")]) == 0 || - is.na(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$mean[which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$gasType == "qfIrgaTurbValiGas05")])){ + #time when performing of last gas is done + if (all(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd == tmpTimeBgn) & + all(is.na(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$mean))){ timeBgn <- as.POSIXlt(paste(dateBgn[idx], " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") } else { - timeBgn <- as.POSIXlt(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd[which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$gasType == "qfIrgaTurbValiGas05")]+(60*5.0)) + #identify which row that timeEnd not = "23:59:59.950" + tmpEndRow <- which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd != tmpTimeBgn & !is.na(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$mean)) + timeBgn <- as.POSIXlt(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd[tmpEndRow[length(tmpEndRow)]]+(60*5.0)) } - #time when performing of zero gas is started - if (length(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn[which(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$gasType == "qfIrgaTurbValiGas02")]) == 0 || - is.na(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$mean[which(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$gasType == "qfIrgaTurbValiGas02")])){ + #time when performing of first gas is started + if (all(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn == tmpTimeEnd) & + all(is.na(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$mean))){ timeEnd <- as.POSIXlt(paste(dateEnd[idx], " ", "", sep="00:00:00.000"), format="%Y-%m-%d %H:%M:%OS", tz="UTC") } else { - timeEnd <- as.POSIXlt(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn[which(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$gasType == "qfIrgaTurbValiGas02")]-(60*3.5)) + #identify which row that timeEnd not = "00:00:00.000" + tmpBgnRow <- which(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn != tmpTimeEnd & !is.na(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$mean)) + timeEnd <- as.POSIXlt(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn[tmpBgnRow[1]]-(60*3.5)) } # #fail safe to make sure timeBgn less than timeEnd @@ -244,7 +250,8 @@ def.irga.vali.cor <- function( } #append dataframe #outTmp00 <- do.call(rbind,outSub) - +#change row.name in allSubData + row.names(allSubData) <- make.names(1:length(allSubData$time), unique = TRUE) #return data only the processing date #report time options(digits.secs=3) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index 9afd63aa..18a12836 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -132,8 +132,8 @@ wrap.irga.vali <- function( #check if there are data and qfqmFlag if(length(locDate) == 0){ #create the empty dataframe - subData <- data.frame(matrix(ncol = length(data$irgaTurb), nrow = length(data$irgaTurb[[1]]))) - subQfqmFlag <- data.frame(matrix(ncol = length(qfqmFlag$irgaTurb), nrow = length(qfqmFlag$irgaTurb[[1]]))) + subData <- data.frame(matrix(ncol = length(data$irgaTurb), nrow = 24*60*60*Freq))#20Hz data over 1 day + subQfqmFlag <- data.frame(matrix(ncol = length(qfqmFlag$irgaTurb), nrow = 24*60*60*Freq)) colnames(subData) <- names(data$irgaTurb) colnames(subQfqmFlag) <- names(qfqmFlag$irgaTurb) #add time From ce80e30c7f0d755996fbee076c20a605c71ed9e8 Mon Sep 17 00:00:00 2001 From: NDurden Date: Tue, 14 Apr 2020 18:55:20 +0000 Subject: [PATCH 046/168] add comments --- pack/eddy4R.base/R/def.irga.vali.cor.R | 3 +++ pack/eddy4R.qaqc/man/def.plau.Rd | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.base/R/def.irga.vali.cor.R b/pack/eddy4R.base/R/def.irga.vali.cor.R index 2386da57..063e2ec3 100644 --- a/pack/eddy4R.base/R/def.irga.vali.cor.R +++ b/pack/eddy4R.base/R/def.irga.vali.cor.R @@ -52,6 +52,9 @@ # added 5 min after the validation end # Natchaya P-Durden (2020-02-28) # added logical statement to not apply filters (slope, offset, and scale) if they are equal to FALSE +# Natchaya P-Durden (2020-04-14) +# update the way to determine time begin and end to be able to +# work when the validation do not have a full set of gas tanks ############################################################################################## def.irga.vali.cor <- function( data, diff --git a/pack/eddy4R.qaqc/man/def.plau.Rd b/pack/eddy4R.qaqc/man/def.plau.Rd index abff8e02..3f1e4ffd 100644 --- a/pack/eddy4R.qaqc/man/def.plau.Rd +++ b/pack/eddy4R.qaqc/man/def.plau.Rd @@ -6,8 +6,8 @@ \usage{ def.plau( data, - time = as.POSIXlt(seq.POSIXt(from = Sys.time(), by = "sec", length.out = length(data[, - 1]))), + time = as.POSIXlt(seq.POSIXt(from = Sys.time(), by = "sec", length.out = + length(data[, 1]))), RngMin = apply(data, 2, min, na.rm = TRUE), RngMax = apply(data, 2, max, na.rm = TRUE), DiffStepMax = apply(abs(apply(data, 2, diff)), 2, max, na.rm = TRUE), From 2379578cc56f3e5fda3163d3acfa36aa21e58a47 Mon Sep 17 00:00:00 2001 From: NDurden Date: Wed, 15 Apr 2020 15:13:05 +0000 Subject: [PATCH 047/168] adding logical to handle the period that falling into the last day and first day of year --- pack/eddy4R.base/R/def.irga.vali.cor.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pack/eddy4R.base/R/def.irga.vali.cor.R b/pack/eddy4R.base/R/def.irga.vali.cor.R index 063e2ec3..41a1dad1 100644 --- a/pack/eddy4R.base/R/def.irga.vali.cor.R +++ b/pack/eddy4R.base/R/def.irga.vali.cor.R @@ -55,6 +55,8 @@ # Natchaya P-Durden (2020-04-14) # update the way to determine time begin and end to be able to # work when the validation do not have a full set of gas tanks +# Natchaya P-Durden (2020-04-15) +# adding logical to handle the period that falling into the last day and first day of year ############################################################################################## def.irga.vali.cor <- function( data, @@ -195,6 +197,12 @@ def.irga.vali.cor <- function( #fractional timeFracOut <- timeOut$hour + timeOut$min / 60 + timeOut$sec / 3600 + #adding logical to handle the period that falling into the last day and first day of year + if (format(as.Date(timeBgn, format="%d/%m/%Y"),"%Y") != format(as.Date(timeEnd, format="%d/%m/%Y"),"%Y")){ + #replace those fist day (equal to 0 to max(timeOut$yday)+1) + timeOut$yday[timeOut$yday != max(timeOut$yday)] <- max(timeOut$yday)+1 + } + #calculate doy timeDoy <- timeOut$yday + 1 + timeFracOut / 24 From e872fe7f0fc3ccc12de36c2ec65990d9d14f0db2 Mon Sep 17 00:00:00 2001 From: NDurden Date: Sat, 18 Apr 2020 02:39:28 +0000 Subject: [PATCH 048/168] fix bug in dp02 temporal interpolation --- pack/eddy4R.stor/R/def.itpl.time.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.stor/R/def.itpl.time.R b/pack/eddy4R.stor/R/def.itpl.time.R index 4c895462..a6ec157c 100644 --- a/pack/eddy4R.stor/R/def.itpl.time.R +++ b/pack/eddy4R.stor/R/def.itpl.time.R @@ -103,12 +103,13 @@ def.itpl.time <- function( #if only two data are available and as.integer(dataInp$timeFrac * 60) are the same value, add 1 to timeFrac of the 2nd value tmpTimeFrac <- as.integer(dataInp$timeFrac * 60) if (setLgth == 2 & tmpTimeFrac[1]==tmpTimeFrac[2]) tmpTimeFrac[2] <- tmpTimeFrac[2]+1 - if(methItpl == "linear"){ #remove na value if like that maxgap will not work dataInp <- na.omit(dataInp) + #make sure use the right inpTime before interpolating + if (setLgth == 2){inpTime <- tmpTimeFrac}else{inpTime <- as.integer(dataInp$timeFrac * 60)} rpt <- zoo::na.approx(object=as.vector(dataInp$mean), x=#dataInp$timeFrac - tmpTimeFrac + inpTime , xout=as.integer(timeFracOut * 60) , method = "linear", maxgap=(WndwMax/60), na.rm=FALSE, rule=1, f=0) From d55347a653d449e461fed46cbb46326abd5019e0 Mon Sep 17 00:00:00 2001 From: NDurden Date: Sat, 18 Apr 2020 03:26:43 +0000 Subject: [PATCH 049/168] bug fix on removing null dataframe --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index f29991b1..ceccfc13 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -297,7 +297,8 @@ wrap.dp01.qfqm.ecse <- function( #combine idxAgr which will be removed tmpRmv <- do.call(cbind,tmpWrkIdx) #remove those idxAgr from wrk$idx - wrk$idx <- wrk$idx[-c(tmpRmv),] + if(!is.null(tmpRmv)) wrk$idx <- wrk$idx[-c(tmpRmv),] + whrSamp <- wrk$idx$idxBgn[1]:wrk$idx$idxEnd[1] if (length (wrk$idx$idxBgn) > 1 ){ From 4aed7ba801beee7f7eeae7d2c363abf4142d5528 Mon Sep 17 00:00:00 2001 From: NDurden Date: Fri, 24 Apr 2020 19:11:56 +0000 Subject: [PATCH 050/168] added failsafe replace NaN in numSamp with zero --- pack/eddy4R.stor/R/def.itpl.time.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.stor/R/def.itpl.time.R b/pack/eddy4R.stor/R/def.itpl.time.R index a6ec157c..b0aab0eb 100644 --- a/pack/eddy4R.stor/R/def.itpl.time.R +++ b/pack/eddy4R.stor/R/def.itpl.time.R @@ -36,6 +36,8 @@ # remove na value before applying linear interpolation if like that maxgap will not work # Natchaya P-Durden (2020-04-01) # added failsafe for not to break the zoo::na.approx function when timeFrac are duplicate +# Natchaya P-Durden (2020-04-24) +# added failsafe replace NaN in numSamp with zero ############################################################################################################## #Start of function call ############################################################################################################## @@ -70,6 +72,9 @@ def.itpl.time <- function( #convert to POSIXct, so the full date and time can be stored in as accessed as a single vector timeInp <- as.POSIXlt(dataInp$timeBgn, format="%Y-%m-%dT%H:%M:%OSZ", tz="UTC") + #failsafe replace NaN in numSamp with zero + dataInp$numSamp[is.na(dataInp$numSamp)] <- 0 + #if(idxDp == "co2Stor" | idxDp == "h2oStor"){ #timeBgn + numSamp/2/* 1/1Hz timeInp <- as.POSIXlt(timeInp + dataInp$numSamp/2*1/1, format="%Y-%m-%d %H:%M:%OS", tz="UTC") @@ -111,7 +116,7 @@ def.itpl.time <- function( rpt <- zoo::na.approx(object=as.vector(dataInp$mean), x=#dataInp$timeFrac inpTime , xout=as.integer(timeFracOut * 60) - , method = "linear", maxgap=(WndwMax/60), na.rm=FALSE, rule=1, f=0) + , method = "linear", maxgap=(WndwMax/60), na.rm=FALSE, rule=1, f=0,ties = mean) } From 55c7f04d4e4c59a745c0f66ab2675df69e0117b1 Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 1 May 2020 20:43:58 +0000 Subject: [PATCH 051/168] - adding switch to return percent fail and bug fix for NA --- pack/eddy4R.qaqc/R/wrap.qfqm.rpt.R | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pack/eddy4R.qaqc/R/wrap.qfqm.rpt.R b/pack/eddy4R.qaqc/R/wrap.qfqm.rpt.R index 5e205410..0b336bf2 100644 --- a/pack/eddy4R.qaqc/R/wrap.qfqm.rpt.R +++ b/pack/eddy4R.qaqc/R/wrap.qfqm.rpt.R @@ -11,6 +11,7 @@ #' @param Dp A vector of data products to check the quality report for. Defaults to NULL which will test all dp's found in HDF5 file. Of type character. [-] #' @param Vrbs A logical parameter that determines if all failed quality times should be reported (defaults to FALSE). +#' @param MethQm A character string that determines which quality metric to pull ("Pass", "Fail", "Na"). #' @return A list for all dp's provided including either summary or verbose quality report: \cr #' \code{qm} quality metrics (percent) passed sub-data products if Vrbs = TRUE. [percent] \cr @@ -33,20 +34,24 @@ # changelog and author contributions / copyrights # David Durden (2019-04-30) +# Original creation +# David Durden (2020-03-18) +# Adding argument to grab quality metric desired for submetrics ############################################################################################## # start function wrap.qfqm.rpt() wrap.qfqm.rpt <- function( - File, + FileName, Dp = NULL, - Vrbs = FALSE + Vrbs = FALSE, + MethQm = c("Pass", "Fail","Na")[1] ) { #Check if dp's are provided for quality report, otherwise check all dp's in qfqm portion of HDF5 file if(is.null(Dp)){ # List of objects in the HDF5 file - listObj <- rhdf5::h5ls(file = fileName, datasetinfo = FALSE) + listObj <- rhdf5::h5ls(file = FileName, datasetinfo = FALSE) #Vector of data product names in the qfqm tabs in the HDF5 file Dp <- listObj[grep(pattern = "/qfqm$", x = listObj$group),"name"] } # End of if statement is.null(dp) if statement @@ -55,7 +60,7 @@ if(is.null(Dp)){ qfqmVarBase <- c("timeBgn","timeEnd","qfFinl","qfSciRevw","qmAlph","qmBeta") #Extract all the groups, data, and attributes from the HDF5 file -listHdf5 <- eddy4R.base::def.hdf5.extr(FileInp = fileName) +listHdf5 <- eddy4R.base::def.hdf5.extr(FileInp = FileName) #Initialize lists qfqm <- list() @@ -74,7 +79,7 @@ for (idxDp in Dp) { rpt <- list() #Check if any final quality flags (qfFinl) are tripped - if(sum(x$qfFinl) > 0) { + if(sum(x$qfFinl, na.rm = TRUE) > 0) { #Subset rows where the final quality flag is failed rpt <- x[x$qfFinl == 1,] @@ -83,7 +88,7 @@ for (idxDp in Dp) { qfqmVarBaseSub <- dplyr::intersect(qfqmVarBase, base::names(rpt)) #Determine all qf expanded variables - qfqmVarExp <- base::grep(pattern = "Pass", x = dplyr::setdiff(base::names(rpt),qfqmVarBaseSub), value = TRUE) + qfqmVarExp <- base::grep(pattern = MethQm, x = dplyr::setdiff(base::names(rpt),qfqmVarBaseSub), value = TRUE) #Rearrange the data with the base variables at the front of the data.frame rpt <- rpt[,c(qfqmVarBaseSub,qfqmVarExp)] ############################################################################################################# @@ -100,7 +105,8 @@ for (idxDp in Dp) { qmMean <- as.data.frame(t(colMeans(rpt[,grep(pattern = "qm", names(rpt))], na.rm = TRUE))) #Convert units to percent - if(length(qmMean) > 0) qmMean <- eddy4R.base::def.unit.conv(qmMean, unitFrom = "-", unitTo = "%", MethGc = FALSE) + #if(length(qmMean) > 0) qmMean <- eddy4R.base::def.unit.conv(qmMean, unitFrom = "-", unitTo = "%", MethGc = FALSE) + if(length(qmMean) > 0) qmMean <- qmMean * 100 #Check if qmAlph and qmBeta are present to order the quality metrics if("qmAlph" %in% names(qmMean) & "qmBeta" %in% names(qmMean)){ From 17f7b1d84d45df86c405278cdc55fc1a07a2ad0f Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 4 May 2020 04:14:59 +0000 Subject: [PATCH 052/168] - Adding planar fit coefficient output --- pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R index 517042b7..67ec65c3 100755 --- a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R +++ b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R @@ -15,6 +15,7 @@ #' @param MethUcrt Logical: Determines if uncertainty information is available for output. #' @param MethDp04 logical indicating if ECTE dp04 HDF5 data should be included. #' @param MethSubAgr Logical: Determines if 1-minute data is available for output. +#' @param Meta A list of parameters and metadata for updating output HDF5 metadata #' #' @return An HDF5 file with dp01 data, qfqm, and uncertainty written @@ -68,6 +69,8 @@ # adding rtioMoleDryH2o during validation # Natchaya P-Durden (2020-01-22) # adding timeBgn and timeEnd attributes +# David Durden (2020-05-01) +# adding Pfit coefficient output metadata ############################################################################################## @@ -81,7 +84,8 @@ wrap.hdf5.wrte.dp01 <- function( LvlTowr, MethUcrt = TRUE, MethDp04 = FALSE, - MethSubAgr = TRUE + MethSubAgr = TRUE, + Meta ){ #Determine if the output file should be expanded or basic by creating a logical determined from the filename @@ -298,7 +302,8 @@ if(MethDp04 == TRUE){ rhdf5::h5writeAttribute(attributes(rptDp04Qfqm)$unit, h5obj = idQfqmDp04Df, name = "unit") } } - rhdf5::h5closeAll() + #Close HDF5 connections + rhdf5::h5closeAll() } ###################################################################### @@ -306,4 +311,17 @@ if(MethDp04 == TRUE){ ###################################################################### eddy4R.base::def.hdf5.copy.para(FileInp = FileInp, FileOut = FileOut) +#Create HDF5 connection to the output file +idFile <- rhdf5::H5Fopen(FileOut) +#Open connection to dp04 data level +idSite <- rhdf5::H5Gopen(idFile, paste0("/", SiteLoca)) + +#Write updated Pfit coefficients to output file +#Output the attributes +rhdf5::h5writeAttribute(round(Meta$Sci$`Pf$AngEnuXaxs`, digits = 6), h5obj = idSite, name = "Pf$AngEnuXaxs") +rhdf5::h5writeAttribute(round(Meta$Sci$`Pf$AngEnuYaxs`, digits = 6), h5obj = idSite, name = "Pf$AngEnuYaxs") +rhdf5::h5writeAttribute(round(Meta$Sci$`Pf$Ofst`, digits = 6), h5obj = idSite, name = "Pf$Ofst") + +#Close HDF5 connections +rhdf5::h5closeAll() } From 8fd4509369f9588cc6aa81faf4e9cf31ce440a9c Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 4 May 2020 04:18:35 +0000 Subject: [PATCH 053/168] - repackaging to update documentation --- pack/eddy4R.base/DESCRIPTION | 2 +- pack/eddy4R.base/man/IntlConv.Rd | 6 ++++-- pack/eddy4R.base/man/IntlNatu.Rd | 6 ++++-- pack/eddy4R.base/man/IntlUnit.Rd | 6 ++++-- pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd | 5 ++++- pack/eddy4R.qaqc/DESCRIPTION | 2 +- pack/eddy4R.qaqc/man/def.dspk.wndw.Rd | 4 ++-- pack/eddy4R.stor/DESCRIPTION | 2 +- 8 files changed, 21 insertions(+), 12 deletions(-) diff --git a/pack/eddy4R.base/DESCRIPTION b/pack/eddy4R.base/DESCRIPTION index 39f6af00..51d87f9d 100644 --- a/pack/eddy4R.base/DESCRIPTION +++ b/pack/eddy4R.base/DESCRIPTION @@ -28,4 +28,4 @@ Suggests: NEONprocIS.base License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 LazyData: true -RoxygenNote: 7.0.2 +RoxygenNote: 7.1.0 diff --git a/pack/eddy4R.base/man/IntlConv.Rd b/pack/eddy4R.base/man/IntlConv.Rd index 4cf28d0f..c1c7525e 100644 --- a/pack/eddy4R.base/man/IntlConv.Rd +++ b/pack/eddy4R.base/man/IntlConv.Rd @@ -4,7 +4,8 @@ \name{IntlConv} \alias{IntlConv} \title{Internal data: Parameter set: Conversion Factors} -\format{A named list of numerical polynomial conversion coefficients. Names are constructed from +\format{ +A named list of numerical polynomial conversion coefficients. Names are constructed from the quantities to be converted. The quantity to be converted from is named first, followed by the quantity to be converted to.\cr \cr @@ -167,7 +168,8 @@ quantity to be converted to.\cr \describe{ \item{NewtPndf}{force conversion, Newton to pound-force = c(0,0.224809) [lbf N-1]} \item{PndfNewt}{force conversion, pound-force to Newton = c(0,4.44822) [N lbf-1]} -}} +} +} \source{ Conversion factors are defined within flow.save.intl.cnst.R, available in the data-raw/ folder of the source version of the package diff --git a/pack/eddy4R.base/man/IntlNatu.Rd b/pack/eddy4R.base/man/IntlNatu.Rd index c6aff837..3bb7f0f7 100644 --- a/pack/eddy4R.base/man/IntlNatu.Rd +++ b/pack/eddy4R.base/man/IntlNatu.Rd @@ -4,7 +4,8 @@ \name{IntlNatu} \alias{IntlNatu} \title{Internal data: Parameter set: Natural constants} -\format{A list of named constants: +\format{ +A list of named constants: \describe{ \item{Grav}{acceleration of gravity = 9.81 [m s-2]} \item{PrdErth}{rotation period of the Earth (one sidereal day) = 86164.1 [s]} @@ -30,7 +31,8 @@ \item{RsH2o}{specific gas constant for water vapour = 461.96 [J kg-1 K-1]} \item{GmmaH2o}{CpH2o / CvH2o = 1.333776 [-]} \item{KppaH2o}{water vapour Kappa exponent for ideal gas law (Poisson), RsH2o / CpH2o = 0.2502 [-]} -}} +} +} \source{ Natural constants are defined within flow.save.intl.cnst.R, available in the data-raw/ folder of the source version of the package diff --git a/pack/eddy4R.base/man/IntlUnit.Rd b/pack/eddy4R.base/man/IntlUnit.Rd index f05ed10a..5468f046 100644 --- a/pack/eddy4R.base/man/IntlUnit.Rd +++ b/pack/eddy4R.base/man/IntlUnit.Rd @@ -4,7 +4,8 @@ \name{IntlUnit} \alias{IntlUnit} \title{Internal data: Parameter set: Unit representations} -\format{A nested list of named unit categories: +\format{ +A nested list of named unit categories: \describe{ \item{Base}{ \describe{ @@ -127,7 +128,8 @@ \code{Forc = "N"}\cr \code{Freq = "Hz"}\cr } -}} +} +} \source{ Units are defined within flow.save.intl.cnst.R, available in the data-raw/ folder of the source version of the package diff --git a/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd b/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd index e5790fcc..1511ba50 100644 --- a/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd +++ b/pack/eddy4R.base/man/wrap.hdf5.wrte.dp01.Rd @@ -12,7 +12,8 @@ wrap.hdf5.wrte.dp01( LvlTowr, MethUcrt = TRUE, MethDp04 = FALSE, - MethSubAgr = TRUE + MethSubAgr = TRUE, + Meta ) } \arguments{ @@ -31,6 +32,8 @@ wrap.hdf5.wrte.dp01( \item{MethDp04}{logical indicating if ECTE dp04 HDF5 data should be included.} \item{MethSubAgr}{Logical: Determines if 1-minute data is available for output.} + +\item{Meta}{A list of parameters and metadata for updating output HDF5 metadata} } \value{ An HDF5 file with dp01 data, qfqm, and uncertainty written diff --git a/pack/eddy4R.qaqc/DESCRIPTION b/pack/eddy4R.qaqc/DESCRIPTION index 1e456c8e..70f5f97e 100644 --- a/pack/eddy4R.qaqc/DESCRIPTION +++ b/pack/eddy4R.qaqc/DESCRIPTION @@ -22,4 +22,4 @@ Suggests: NEONprocIS.base License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 LazyData: true -RoxygenNote: 7.0.2 +RoxygenNote: 7.1.0 diff --git a/pack/eddy4R.qaqc/man/def.dspk.wndw.Rd b/pack/eddy4R.qaqc/man/def.dspk.wndw.Rd index 40f3f3db..f360abe7 100644 --- a/pack/eddy4R.qaqc/man/def.dspk.wndw.Rd +++ b/pack/eddy4R.qaqc/man/def.dspk.wndw.Rd @@ -7,8 +7,8 @@ def.dspk.wndw( data, Trt = list(AlgClas = c("mean", "median")[2], NumPtsWndw = c(11, 101)[2], NumPtsSlid = - 1, ThshStd = c(3.5, 20)[2], NaFracMax = 0.1, Infl = 0, IterMax = Inf, NumPtsGrp = c(4, - 10)[2], NaTrt = c("approx", "omit")[2]), + 1, ThshStd = c(3.5, 20)[2], NaFracMax = 0.1, Infl = 0, IterMax = Inf, NumPtsGrp = + c(4, 10)[2], NaTrt = c("approx", "omit")[2]), Cntl = list(NaOmit = c(TRUE, FALSE)[2], Prnt = c(TRUE, FALSE)[1], Plot = c(TRUE, FALSE)[1]), Vrbs = FALSE diff --git a/pack/eddy4R.stor/DESCRIPTION b/pack/eddy4R.stor/DESCRIPTION index a66453e6..5a0a8320 100644 --- a/pack/eddy4R.stor/DESCRIPTION +++ b/pack/eddy4R.stor/DESCRIPTION @@ -15,4 +15,4 @@ Suggests: License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 Encoding: UTF-8 LazyData: true -RoxygenNote: 7.0.2 +RoxygenNote: 7.1.0 From 78ca068ae268b989d31ee9f6d82e172c20191295 Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 18 May 2020 03:43:23 +0000 Subject: [PATCH 054/168] - failsafe for rare valve issue when removing crd kickoff causing no data for whole day --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 45 ++++++++++++++++++++++-- pack/eddy4R.stor/R/wrap.dp01.ecse.R | 29 +++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index ceccfc13..cdfe022e 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -227,6 +227,44 @@ wrap.dp01.qfqm.ecse <- function( if (data$crdCo2ValvLvl[[lvlCrdCo2Valv]]$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & qmBeta > 0.1){ rpt[[idxAgr]] <- NULL } + + + #Check if after removing data for valve kickooff if no data remains + if(length(wrk$idx$idxBgn) == 1 && length(rpt) == 0){ + rpt[[1]] <- list() + #idxStat <- NameQf[1] + rpt[[1]]$qmAlph <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(wrk$data))) + rpt[[1]]$qmBeta <- as.data.frame(matrix(1, nrow = 1, ncol = ncol(wrk$data))) + rpt[[1]]$qfFinl <- as.data.frame(matrix(1, nrow = 1, ncol = ncol(wrk$data))) + rpt[[1]]$qfSciRevw <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(wrk$data))) + #change data type + rpt[[1]]$qfFinl[,1:ncol(wrk$data)] <- sapply(rpt[[1]]$qfFinl[,1:ncol(wrk$data)], as.integer) + rpt[[1]]$qfSciRevw[,1:ncol(wrk$data)] <- sapply(rpt[[1]]$qfSciRevw[,1:ncol(wrk$data)], as.integer) + + for(idxQf in NameQf){ + #assign name to each column + names(rpt[[1]][[idxQf]]) <- names(wrk$data) + #not report lvlIrga + rpt[[1]][[idxQf]] <- rpt[[1]][[idxQf]][which(!(names(rpt[[1]][[idxQf]]) %in% c("lvlIrga")))] + }; rm(idxQf) + + #add both time begin and time end to rpt + rpt[[1]]$timeBgn <- list() + rpt[[1]]$timeEnd <- list() + + #output time for dp01 + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("lvlIrga")))]){ + rpt[[1]]$timeBgn[[idxVar]] <- data$time[1] + rpt[[1]]$timeEnd[[idxVar]] <- data$time[length(data$time)] + #unit + attributes(rpt[[1]]$qmAlph[[idxVar]])$unit <- "-" + attributes(rpt[[1]]$qmBeta[[idxVar]])$unit <- "-" + attributes(rpt[[1]]$qfFinl[[idxVar]])$unit <- "NA" + attributes(rpt[[1]]$qfSciRevw[[idxVar]])$unit <- "NA" + + }; rm(idxVar) + + }#end of failsafe to check if no measurement data at all in the whole day after valve kickoff removal #}# end of there is at least one data }; rm(idxAgr) @@ -299,7 +337,9 @@ wrap.dp01.qfqm.ecse <- function( #remove those idxAgr from wrk$idx if(!is.null(tmpRmv)) wrk$idx <- wrk$idx[-c(tmpRmv),] - + #If statement to check if all values were removed + if(nrow(wrk$idx) > 0){ + whrSamp <- wrk$idx$idxBgn[1]:wrk$idx$idxEnd[1] if (length (wrk$idx$idxBgn) > 1 ){ for(ii in 2:length (wrk$idx$idxBgn)){ @@ -313,7 +353,8 @@ wrap.dp01.qfqm.ecse <- function( wrk$qfqm[[idxSens]][wrk$data$lvlIrga != lvlIrga, 1:length(wrk$qfqm[[idxSens]])] <- -1 #replace all qf that not belong to that measurement level by NaN wrk$qfqm[[idxSens]][-whrSamp, 1:length(wrk$qfqm[[idxSens]])] <- NaN - } + } + }#End if statement after qfRmv } diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index 404b08ea..0a3d1f16 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -211,6 +211,35 @@ wrap.dp01.ecse <- function( if (data$crdCo2ValvLvl[[lvlCrdCo2Valv]]$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & numSamp < 108){ rpt[[idxAgr]] <- NULL } + + #Check if after removing data for valve kickooff if no data remains + if(length(wrk$idx$idxBgn) == 1 && length(rpt) == 0){ + rpt[[1]] <- list() + + for(idxStat in NameStat){ + #idxStat <- NameStat[1] + rpt[[1]][[idxStat]] <- as.data.frame(matrix(NaN, nrow = 1, ncol = ncol(wrk$data))) + #assign name to each column + names(rpt[[1]][[idxStat]]) <- names(wrk$data) + #not report lvlIrga + rpt[[1]][[idxStat]] <- rpt[[1]][[idxStat]][which(!(names(rpt[[1]][[idxStat]]) %in% c("lvlIrga")))] + + }; rm(idxStat) + #add both time begin and time end to rpt + rpt[[1]]$timeBgn <- list() + rpt[[1]]$timeEnd <- list() + + #output time for dp01 + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("lvlIrga")))]){ + rpt[[1]]$timeBgn[[idxVar]] <- data$time[1] + rpt[[1]]$timeEnd[[idxVar]] <- data$time[length(data$time)] + #unit + attributes(rpt[[1]]$mean[[idxVar]])$unit <- attributes(wrk$data[[idxVar]])$unit + + }; rm(idxVar) + + }#end failsafe of if no measurement data at all in the whole day once valve issue removed + #}# end of there is at least one data }; rm(idxAgr) From 521b610fa4f6f0ffb7497ea6ae1908d0f2993f43 Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 18 May 2020 03:47:36 +0000 Subject: [PATCH 055/168] - documenting updates for failsafe --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 2 ++ pack/eddy4R.stor/R/wrap.dp01.ecse.R | 2 ++ 2 files changed, 4 insertions(+) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index cdfe022e..0eb4ed1a 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -81,6 +81,8 @@ # and irga have to move to measure next level # Natchaya P-Durden (2020-03-25) # added lvlCrdCo2Valv to the function's parameter +# David Durden (2020-05-15) +# failsafe for crd kickoff removal causing no data for entire day ############################################################################################## wrap.dp01.qfqm.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index 0a3d1f16..ee8cb62a 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -70,6 +70,8 @@ # and irga have to move to measure next level # Natchaya P-Durden (2020-03-25) # added lvlCrdCo2Valv to the function's parameter +# David Durden (2020-05-15) +# failsafe for crd kickoff removal causing no data for entire day ############################################################################################## wrap.dp01.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], From aa3f29b964135a6f284e43ab17786aeb30f60fec Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 22 May 2020 03:59:33 +0000 Subject: [PATCH 056/168] - bug fix for qmBeta causing differing number of values between data and qfqm --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index 0eb4ed1a..e157ffb1 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -83,6 +83,8 @@ # added lvlCrdCo2Valv to the function's parameter # David Durden (2020-05-15) # failsafe for crd kickoff removal causing no data for entire day +# David Durden (2020-05-21) +# bug fix for qmBeta causing differing number of values between data and qfqm ############################################################################################## wrap.dp01.qfqm.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], @@ -226,7 +228,7 @@ wrap.dp01.qfqm.ecse <- function( #and qmBeta > 0.1 if (dp01 == "co2Stor") {qmBeta <- rpt[[idxAgr]]$qmBeta$rtioMoleDryCo2} if (dp01 == "h2oStor") {qmBeta <- rpt[[idxAgr]]$qmBeta$rtioMoleDryH2o} - if (data$crdCo2ValvLvl[[lvlCrdCo2Valv]]$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & qmBeta > 0.1){ + if (data$crdCo2ValvLvl[[lvlCrdCo2Valv]]$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & numSamp < 108){ rpt[[idxAgr]] <- NULL } From 89fdb37896186ceda90a30c6cd21f11071b1c659 Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 22 May 2020 04:35:41 +0000 Subject: [PATCH 057/168] - updating to add numSamp for evaluation --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index e157ffb1..35687c77 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -224,10 +224,10 @@ wrap.dp01.qfqm.ecse <- function( rpt[[idxAgr]]$timeEnd[[idxVar]] <- wrk$idx$timeEnd[idxAgr] } - #check if this period is the period that crdCo2 take over and irga have to move to measure other level - #and qmBeta > 0.1 - if (dp01 == "co2Stor") {qmBeta <- rpt[[idxAgr]]$qmBeta$rtioMoleDryCo2} - if (dp01 == "h2oStor") {qmBeta <- rpt[[idxAgr]]$qmBeta$rtioMoleDryH2o} + #get rid of period that crdCo2 take over and irga have to move to measure other level + #and number of sample less than 10% (120-120*0.1) + if (dp01 == "co2Stor") {numSamp <- sum(!is.na(wrk$data$rtioMoleDryCo2[wrk$idx$idxBgn[idxAgr]:wrk$idx$idxEnd[idxAgr]]))} + if (dp01 == "h2oStor") {numSamp <- sum(!is.na(wrk$data$rtioMoleDryH2o[wrk$idx$idxBgn[idxAgr]:wrk$idx$idxEnd[idxAgr]]))} if (data$crdCo2ValvLvl[[lvlCrdCo2Valv]]$lvlCrdCo2[wrk$idx$idxEnd[idxAgr]] == lvlIrga & numSamp < 108){ rpt[[idxAgr]] <- NULL } From c78173d79109d645896d96fe2efc86543db723ed Mon Sep 17 00:00:00 2001 From: ddurden Date: Wed, 27 May 2020 15:05:40 +0000 Subject: [PATCH 058/168] - Failsafe for when the valve is switched, but no validation occurs --- pack/eddy4R.base/R/def.irga.vali.cor.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pack/eddy4R.base/R/def.irga.vali.cor.R b/pack/eddy4R.base/R/def.irga.vali.cor.R index 41a1dad1..efaf4266 100644 --- a/pack/eddy4R.base/R/def.irga.vali.cor.R +++ b/pack/eddy4R.base/R/def.irga.vali.cor.R @@ -57,6 +57,8 @@ # work when the validation do not have a full set of gas tanks # Natchaya P-Durden (2020-04-15) # adding logical to handle the period that falling into the last day and first day of year +# David Durden (2020-05-26) +# Failsafe for when the valve is switched, but no validation occurs ############################################################################################## def.irga.vali.cor <- function( data, @@ -163,21 +165,21 @@ def.irga.vali.cor <- function( #time begin and time End to apply coefficient #time when performing of last gas is done if (all(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd == tmpTimeBgn) & - all(is.na(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$mean))){ + all(is.na(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$numSamp))){ timeBgn <- as.POSIXlt(paste(dateBgn[idx], " ", "23:59:59.950", sep=""), format="%Y-%m-%d %H:%M:%OS", tz="UTC") } else { #identify which row that timeEnd not = "23:59:59.950" - tmpEndRow <- which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd != tmpTimeBgn & !is.na(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$mean)) + tmpEndRow <- which(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd != tmpTimeBgn & !is.na(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$numSamp)) timeBgn <- as.POSIXlt(valiData[[dateBgn[idx]]][[coefBgn[idx]]]$timeEnd[tmpEndRow[length(tmpEndRow)]]+(60*5.0)) } #time when performing of first gas is started if (all(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn == tmpTimeEnd) & - all(is.na(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$mean))){ + all(is.na(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$numSamp))){ timeEnd <- as.POSIXlt(paste(dateEnd[idx], " ", "", sep="00:00:00.000"), format="%Y-%m-%d %H:%M:%OS", tz="UTC") } else { #identify which row that timeEnd not = "00:00:00.000" - tmpBgnRow <- which(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn != tmpTimeEnd & !is.na(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$mean)) + tmpBgnRow <- which(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn != tmpTimeEnd & !is.na(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$numSamp)) timeEnd <- as.POSIXlt(valiData[[dateEnd[idx]]][[coefEnd[idx]]]$timeBgn[tmpBgnRow[1]]-(60*3.5)) } From ea5ef1a394ef22589e6b32a384e858dabef3e4de Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 22 Jun 2020 03:39:22 +0000 Subject: [PATCH 059/168] - removing external sensor flags for storage sensors --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 580 +++++++++++++++------------ 1 file changed, 326 insertions(+), 254 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 4d8f92b3..2058047a 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -1053,54 +1053,60 @@ if (MethMeas == "ecse") { rpt$rtioMoleDryCo2 <- na.omit(data.frame(setQf$rtioMoleDryCo2, setQf$asrpCo2, setQf$asrpH2o, setQf$rtioMoleWetCo2, setQf$rtioMoleWetH2o, setQf$presIrga, - setQf$tempIrga, setQf$envHut, - setQf$valvAux, + setQf$tempIrga, #setQf$envHut, + #etQf$valvAux, #setQf$heatInlt, - setQf$frt00MfcSampStor, setQf$frtMfcSampStor, - setQf$presAtmMfcSampStor, setQf$tempMfcSampStor, + #setQf$frt00MfcSampStor, setQf$frtMfcSampStor, + #setQf$presAtmMfcSampStor, setQf$tempMfcSampStor, setQf$sensMfcSampStor, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInl, - setQf$pumpStor, setQf$pumpIrgaStor)) + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm#, setQf$presInl, + #setQf$pumpStor, setQf$pumpIrgaStor + )) rpt$rtioMoleWetCo2 <- na.omit(data.frame(setQf$rtioMoleWetCo2, setQf$asrpCo2, setQf$asrpH2o, setQf$rtioMoleWetH2o, setQf$presIrga, setQf$tempIrga, - setQf$envHut, setQf$valvAux, + #setQf$envHut, setQf$valvAux, #setQf$heatInlt, - setQf$frt00MfcSampStor, - setQf$frtMfcSampStor, setQf$presAtmMfcSampStor, - setQf$tempMfcSampStor, setQf$sensMfcSampStor, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInl, - setQf$pumpStor, setQf$pumpIrgaStor)) + #setQf$frt00MfcSampStor, + #setQf$frtMfcSampStor, setQf$presAtmMfcSampStor, + #setQf$tempMfcSampStor, + setQf$sensMfcSampStor, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm #, setQf$presInl, + #setQf$pumpStor, setQf$pumpIrgaStor + )) }#close if statement of TypeMeas == "samp" if (TypeMeas == "vali"){ rpt$rtioMoleDryCo2 <- na.omit(data.frame(setQf$rtioMoleDryCo2, setQf$asrpCo2, setQf$asrpH2o, setQf$rtioMoleWetCo2, setQf$rtioMoleWetH2o, setQf$presIrga, - setQf$tempIrga, setQf$envHut, - setQf$valvAux, setQf$frt00MfcSampStor, - setQf$frtMfcSampStor, setQf$presAtmMfcSampStor, - setQf$tempMfcSampStor, setQf$sensMfcSampStor, - setQf$frt00MfcVali, setQf$frtMfcVali, - setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali, setQf$pumpIrgaStor, - setQf$presValiRegInStor)) + setQf$tempIrga, #setQf$envHut, + #setQf$valvAux, setQf$frt00MfcSampStor, + # setQf$frtMfcSampStor, setQf$presAtmMfcSampStor, + #setQf$tempMfcSampStor, setQf$sensMfcSampStor, + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali#, setQf$pumpIrgaStor, + # setQf$presValiRegInStor + )) rpt$rtioMoleWetCo2 <- na.omit(data.frame(setQf$rtioMoleWetCo2, setQf$asrpCo2, setQf$asrpH2o, setQf$rtioMoleWetH2o, setQf$presIrga, setQf$tempIrga, - setQf$envHut, setQf$valvAux, - setQf$frt00MfcSampStor, setQf$frtMfcSampStor, - setQf$presAtmMfcSampStor, setQf$tempMfcSampStor, - setQf$sensMfcSampStor,setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali, setQf$sensMfcVali, - setQf$pumpIrgaStor, setQf$presValiRegInStor)) + #setQf$envHut, setQf$valvAux, + #setQf$frt00MfcSampStor, setQf$frtMfcSampStor, + #setQf$presAtmMfcSampStor, setQf$tempMfcSampStor, + #setQf$sensMfcSampStor,setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$pumpIrgaStor, setQf$presValiRegInStor + )) }#close if statement of TypeMeas == "vali" rpt$pres <- na.omit(data.frame(setQf$presIrga)) @@ -1119,51 +1125,56 @@ if (MethMeas == "ecse") { if (TypeMeas == "samp"){ rpt$rtioMoleDryH2o <- na.omit(data.frame(setQf$rtioMoleDryH2o, setQf$asrpH2o, setQf$rtioMoleWetH2o, setQf$presIrga, - setQf$tempIrga, setQf$envHut, - setQf$valvAux, + setQf$tempIrga, #setQf$envHut, + #setQf$valvAux, #setQf$heatInlt, - setQf$frt00MfcSampStor, setQf$frtMfcSampStor, - setQf$presAtmMfcSampStor, setQf$tempMfcSampStor, - setQf$sensMfcSampStor, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInl, - setQf$pumpStor, setQf$pumpIrgaStor)) + #setQf$frt00MfcSampStor, setQf$frtMfcSampStor, + #setQf$presAtmMfcSampStor, setQf$tempMfcSampStor, + #setQf$sensMfcSampStor, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm#, setQf$presInl, + #setQf$pumpStor, setQf$pumpIrgaStor + )) rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$asrpH2o, setQf$presIrga, setQf$tempIrga, - setQf$envHut, setQf$valvAux, + #setQf$envHut, setQf$valvAux, #setQf$heatInlt, - setQf$frt00MfcSampStor, - setQf$frtMfcSampStor, setQf$presAtmMfcSampStor, - setQf$tempMfcSampStor, setQf$sensMfcSampStor, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInl, - setQf$pumpStor, setQf$pumpIrgaStor)) + #setQf$frt00MfcSampStor, + #setQf$frtMfcSampStor, setQf$presAtmMfcSampStor, + #setQf$tempMfcSampStor, setQf$sensMfcSampStor, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm #, setQf$presInl, + #setQf$pumpStor, setQf$pumpIrgaStor + )) }#close if statement of TypeMeas == "samp" if (TypeMeas == "vali"){ rpt$rtioMoleDryH2o <- na.omit(data.frame(setQf$rtioMoleDryH2o, setQf$asrpH2o, setQf$rtioMoleWetH2o, setQf$presIrga, - setQf$tempIrga, setQf$envHut, - setQf$valvAux, setQf$frt00MfcSampStor, - setQf$frtMfcSampStor, setQf$presAtmMfcSampStor, - setQf$tempMfcSampStor, setQf$sensMfcSampStor, - setQf$frt00MfcVali, setQf$frtMfcVali, - setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali, setQf$pumpIrgaStor, - setQf$presValiRegInStor)) + setQf$tempIrga, #setQf$envHut, + #setQf$valvAux, setQf$frt00MfcSampStor, + #setQf$frtMfcSampStor, setQf$presAtmMfcSampStor, + #setQf$tempMfcSampStor, setQf$sensMfcSampStor, + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali#, setQf$pumpIrgaStor, + #setQf$presValiRegInStor + )) rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$asrpH2o, setQf$presIrga, setQf$tempIrga, - setQf$envHut, setQf$valvAux, - setQf$frt00MfcSampStor, setQf$frtMfcSampStor, - setQf$presAtmMfcSampStor, setQf$tempMfcSampStor, - setQf$sensMfcSampStor,setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali, setQf$sensMfcVali, - setQf$pumpIrgaStor, setQf$presValiRegInStor)) + #setQf$envHut, setQf$valvAux, + #setQf$frt00MfcSampStor, setQf$frtMfcSampStor, + #setQf$presAtmMfcSampStor, setQf$tempMfcSampStor, + #setQf$sensMfcSampStor,setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$pumpIrgaStor, setQf$presValiRegInStor + )) }#close if statement of TypeMeas == "vali" rpt$pres <- na.omit(data.frame(setQf$presIrga)) @@ -1407,25 +1418,29 @@ if (MethMeas == "ecse") { #if not all idGas = NA or all qfRngTemp = NA if (length(which(!is.na(idGas))) > 0){ #grouping qulity flags that related to isoCo2 L1 sub-data product - tmp$rtioMoleWetCo2 <- data.frame(setQf$rtioMoleWetCo2, setQf$dlta13CCo2, + tmp$rtioMoleWetCo2 <- data.frame(setQf$rtioMoleWetCo2, setQf$rtioMoleWet13CCo2, #setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm,setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, #setQf$heatInlt, idGas = idGas ) rpt$rtioMoleWetCo2 <- na.omit(tmp$rtioMoleWetCo2[which(tmp$rtioMoleWetCo2$idGas == 105 | (is.na(tmp$rtioMoleWetCo2$idGas) & tmp$rtioMoleWetCo2$qfSensStus == -1)),]) - tmp$rtioMoleDryCo2 <- data.frame(setQf$rtioMoleDryCo2, setQf$dlta13CCo2, - setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, + tmp$rtioMoleDryCo2 <- data.frame(setQf$rtioMoleDryCo2, #setQf$dlta13CCo2, + setQf$rtioMoleDry12CCo2, setQf$rtioMoleDry13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, #setQf$heatInlt, idGas = idGas @@ -1434,23 +1449,26 @@ if (MethMeas == "ecse") { tmp$rtioMoleWet12CCo2 <-data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, + setQf$sensCrdCo2 + #, setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, #setQf$heatInlt, idGas = idGas ) rpt$rtioMoleWet12CCo2 <- na.omit(tmp$rtioMoleWet12CCo2[which(tmp$rtioMoleWet12CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet12CCo2$idGas) & tmp$rtioMoleWet12CCo2$qfSensStus == -1)),]) - tmp$rtioMoleDry12CCo2 <- data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet13CCo2, + tmp$rtioMoleDry12CCo2 <- data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInlt, - setQf$pumpStor, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm, + #, setQf$presInlt, + #setQf$pumpStor, #setQf$heatInlt, idGas = idGas ) @@ -1458,10 +1476,12 @@ if (MethMeas == "ecse") { tmp$rtioMoleWet13CCo2 <- data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, #setQf$heatInlt, idGas = idGas @@ -1471,22 +1491,26 @@ if (MethMeas == "ecse") { tmp$rtioMoleDry13CCo2<- data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInlt, - setQf$pumpStor, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, + #setQf$pumpStor, #setQf$heatInlt, idGas = idGas ) rpt$rtioMoleDry13CCo2 <- na.omit(tmp$rtioMoleDry13CCo2[which(tmp$rtioMoleDry13CCo2$idGas == 105 | (is.na(tmp$rtioMoleDry13CCo2$idGas) & tmp$rtioMoleDry13CCo2$qfSensStus == -1)),]) - tmp$dlta13CCo2 <- data.frame(setQf$dlta13CCo2, setQf$presCrdCo2, + tmp$dlta13CCo2 <- data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, #setQf$heatInlt, idGas = idGas @@ -1495,10 +1519,12 @@ if (MethMeas == "ecse") { tmp$rtioMoleWetH2o <- data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, #setQf$heatInlt, idGas = idGas @@ -1508,10 +1534,11 @@ if (MethMeas == "ecse") { tmp$rtioMoleDryH2o <- data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInlt, - setQf$pumpStor, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, + #setQf$pumpStor, #setQf$heatInlt, idGas = idGas ) @@ -1531,89 +1558,99 @@ if (MethMeas == "ecse") { rm(tmp) } else { #grouping qulity flags that related to isoCo2 L1 sub-data product - rpt$rtioMoleWetCo2 <- na.omit(data.frame(setQf$rtioMoleWetCo2, setQf$dlta13CCo2, - setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, + rpt$rtioMoleWetCo2 <- na.omit(data.frame(setQf$rtioMoleWetCo2, setQf$rtioMoleWet12CCo2, #setQf$dlta13CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm,setQf$sensMfm, - setQf$presInlt, setQf$pumpStor + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor #setQf$heatInlt )) - rpt$rtioMoleDryCo2 <- na.omit(data.frame(setQf$rtioMoleDryCo2, setQf$dlta13CCo2, - setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, + rpt$rtioMoleDryCo2 <- na.omit(data.frame(setQf$rtioMoleDryCo2, setQf$rtioMoleDry12CCo2, #setQf$dlta13CCo2, + setQf$rtioMoleDry13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor #setQf$heatInlt )) rpt$rtioMoleWet12CCo2 <- na.omit(data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor #setQf$heatInlt )) - rpt$rtioMoleDry12CCo2 <- na.omit(data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet13CCo2, + rpt$rtioMoleDry12CCo2 <- na.omit(data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInlt, - setQf$pumpStor + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm#, setQf$presInlt, + #setQf$pumpStor #setQf$heatInlt )) rpt$rtioMoleWet13CCo2 <- na.omit(data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor + setQf$sensCrdCo2, #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor #setQf$heatInlt )) rpt$rtioMoleDry13CCo2 <- na.omit(data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInlt, - setQf$pumpStor + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm#, setQf$presInlt, + #setQf$pumpStor #setQf$heatInlt )) - rpt$dlta13CCo2 <- na.omit(data.frame(setQf$dlta13CCo2, setQf$presCrdCo2, + rpt$dlta13CCo2 <- na.omit(data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor + setQf$sensCrdCo2#, setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor #setQf$heatInlt )) rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor + setQf$sensCrdCo2, #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor #setQf$heatInlt )) rpt$rtioMoleDryH2o <- na.omit(data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInlt, - setQf$pumpStor + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm#, setQf$presInlt, + #setQf$pumpStor #setQf$heatInlt )) @@ -1634,80 +1671,93 @@ if (MethMeas == "ecse") { #if not all idGas = NA or all qfRngTemp = NA if (length(which(!is.na(idGas))) > 0){ #grouping qulity flags that related to isoCo2 L1 sub-data product - tmp$rtioMoleWetCo2 <- data.frame(setQf$rtioMoleWetCo2, setQf$dlta13CCo2, - setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, + tmp$rtioMoleWetCo2 <- data.frame(setQf$rtioMoleWetCo2, setQf$rtioMoleWet12CCo2, #setQf$dlta13CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali,setQf$sensMfcVali, - setQf$presValiRegInStor, idGas = idGas) + setQf$sensCrdCo2,# setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) rpt$rtioMoleWetCo2 <- na.omit(tmp$rtioMoleWetCo2[which(tmp$rtioMoleWetCo2$idGas == 105 | (is.na(tmp$rtioMoleWetCo2$idGas) & tmp$rtioMoleWetCo2$qfSensStus == -1)),]) - tmp$rtioMoleDryCo2<- data.frame(setQf$rtioMoleDryCo2, setQf$dlta13CCo2, - setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, + tmp$rtioMoleDryCo2<- data.frame(setQf$rtioMoleDryCo2, setQf$rtioMoleDry12CCo2, #setQf$dlta13CCo2, + setQf$rtioMoleDry13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali, setQf$sensMfcVali, - setQf$presValiRegInStor, idGas = idGas) + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) rpt$rtioMoleDryCo2 <- na.omit(tmp$rtioMoleDryCo2[which(tmp$rtioMoleDryCo2$idGas == 105 | (is.na(tmp$rtioMoleDryCo2$idGas) & tmp$rtioMoleDryCo2$qfSensStus == -1)),]) tmp$rtioMoleWet12CCo2 <- data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali, setQf$sensMfcVali, - setQf$presValiRegInStor, idGas = idGas) + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) rpt$rtioMoleWet12CCo2 <- na.omit(tmp$rtioMoleWet12CCo2[which(tmp$rtioMoleWet12CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet12CCo2$idGas) & tmp$rtioMoleWet12CCo2$qfSensStus == -1)),]) - tmp$rtioMoleDry12CCo2 <- data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet13CCo2, + tmp$rtioMoleDry12CCo2 <- data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - setQf$frt00MfcVali, setQf$frtMfcVali, - setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali, setQf$presValiRegInStor, + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali, #setQf$presValiRegInStor, idGas = idGas) rpt$rtioMoleDry12CCo2 <- na.omit(tmp$rtioMoleDry12CCo2[which(tmp$rtioMoleDry12CCo2$idGas == 105 | (is.na(tmp$rtioMoleDry12CCo2$idGas) & tmp$rtioMoleDry12CCo2$qfSensStus == -1)),]) tmp$rtioMoleWet13CCo2 <- data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali, setQf$sensMfcVali, - setQf$presValiRegInStor, idGas = idGas) + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) rpt$rtioMoleWet13CCo2 <- na.omit(tmp$rtioMoleWet13CCo2[which(tmp$rtioMoleWet13CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet13CCo2$idGas) & tmp$rtioMoleWet13CCo2$qfSensStus == -1)),]) tmp$rtioMoleDry13CCo2 <- data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - setQf$frt00MfcVali, setQf$frtMfcVali, - setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali, setQf$presValiRegInStor, + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali, #setQf$presValiRegInStor, idGas = idGas) rpt$rtioMoleDry13CCo2 <- na.omit(tmp$rtioMoleDry13CCo2[which(tmp$rtioMoleDry13CCo2$idGas == 105 | (is.na(tmp$rtioMoleDry13CCo2$idGas) & tmp$rtioMoleDry13CCo2$qfSensStus == -1)),]) - tmp$dlta13CCo2 <- data.frame(setQf$dlta13CCo2, setQf$presCrdCo2, + tmp$dlta13CCo2 <- data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali, setQf$sensMfcVali, - setQf$presValiRegInStor, idGas = idGas) + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) rpt$dlta13CCo2 <- na.omit(tmp$dlta13CCo2[which(tmp$dlta13CCo2$idGas == 105 | (is.na(tmp$dlta13CCo2$idGas) & tmp$dlta13CCo2$qfSensStus == -1)),]) tmp$rtioMoleWetH2o <- data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali, setQf$sensMfcVali, - setQf$presValiRegInStor, idGas = idGas) + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) rpt$rtioMoleWetH2o <- na.omit(tmp$rtioMoleWetH2o[which(tmp$rtioMoleWetH2o$idGas == 11 | (is.na(tmp$rtioMoleWetH2o$idGas) & tmp$rtioMoleWetH2o$qfSensStus == -1)),]) tmp$rtioMoleDryH2o <- data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - setQf$frt00MfcVali, setQf$frtMfcVali, - setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali, setQf$presValiRegInStor, + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali, #setQf$presValiRegInStor, idGas = idGas) rpt$rtioMoleDryH2o <- na.omit(tmp$rtioMoleDryH2o[which(tmp$rtioMoleDryH2o$idGas == 11 | (is.na(tmp$rtioMoleDryH2o$idGas) & tmp$rtioMoleDryH2o$qfSensStus == -1)),]) @@ -1726,70 +1776,86 @@ if (MethMeas == "ecse") { rm(tmp) } else { #grouping qulity flags that related to isoCo2 L1 sub-data product - rpt$rtioMoleWetCo2 <- na.omit(data.frame(setQf$rtioMoleWetCo2, setQf$dlta13CCo2, - setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, + rpt$rtioMoleWetCo2 <- na.omit(data.frame(setQf$rtioMoleWetCo2, setQf$rtioMoleWet12CCo2,#setQf$dlta13CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali,setQf$sensMfcVali, - setQf$presValiRegInStor)) + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) - rpt$rtioMoleDryCo2 <- na.omit(data.frame(setQf$rtioMoleDryCo2, setQf$dlta13CCo2, - setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, + rpt$rtioMoleDryCo2 <- na.omit(data.frame(setQf$rtioMoleDryCo2, setQf$rtioMoleDry12CCo2,#setQf$dlta13CCo2, + setQf$rtioMoleDry13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali, setQf$sensMfcVali, - setQf$presValiRegInStor)) + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) rpt$rtioMoleWet12CCo2 <- na.omit(data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali, setQf$sensMfcVali, - setQf$presValiRegInStor)) + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) - rpt$rtioMoleDry12CCo2 <- na.omit(data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet13CCo2, + rpt$rtioMoleDry12CCo2 <- na.omit(data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - setQf$frt00MfcVali, setQf$frtMfcVali, - setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali, setQf$presValiRegInStor)) + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali#, setQf$presValiRegInStor + )) rpt$rtioMoleWet13CCo2 <- na.omit(data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali, setQf$sensMfcVali, - setQf$presValiRegInStor)) + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) rpt$rtioMoleDry13CCo2 <- na.omit(data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - setQf$frt00MfcVali, setQf$frtMfcVali, - setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali, setQf$presValiRegInStor)) + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali#, setQf$presValiRegInStor + )) - rpt$dlta13CCo2 <- na.omit(data.frame(setQf$dlta13CCo2, setQf$presCrdCo2, + rpt$dlta13CCo2 <- na.omit(data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali, setQf$sensMfcVali, - setQf$presValiRegInStor)) + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, setQf$frt00MfcVali, - setQf$frtMfcVali, setQf$presAtmMfcVali, - setQf$tempMfcVali, setQf$sensMfcVali, - setQf$presValiRegInStor)) + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) rpt$rtioMoleDryH2o <- na.omit(data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - setQf$frt00MfcVali, setQf$frtMfcVali, - setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali, setQf$presValiRegInStor)) + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali#, setQf$presValiRegInStor + )) rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) @@ -1987,40 +2053,41 @@ if (MethMeas == "ecse") { rpt$rtioMoleDryH2o <- na.omit(data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, setQf$presCrdH2o, setQf$tempCrdH2o, setQf$tempWbox, setQf$sensCrdH2o, - setQf$envHut, setQf$frt00Mfm, - setQf$frtMfm, setQf$presAtmMfm, - setQf$tempMfm, setQf$sensMfm, - setQf$presInlt, setQf$pumpStor + #setQf$envHut, setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor #setQf$heatInlt )) rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$presCrdH2o, setQf$tempCrdH2o, setQf$tempWbox, - setQf$sensCrdH2o, setQf$envHut, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInlt, - setQf$pumpStor + setQf$sensCrdH2o, #setQf$envHut, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm#, setQf$presInlt, + #setQf$pumpStor #setQf$heatInlt )) rpt$dlta18OH2o <- na.omit(data.frame(setQf$dlta18OH2o, setQf$presCrdH2o, setQf$tempCrdH2o, setQf$tempWbox, - setQf$sensCrdH2o, setQf$envHut, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInlt, - setQf$pumpStor + setQf$sensCrdH2o, #setQf$envHut, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm#, setQf$presInlt, + #setQf$pumpStor #setQf$heatInlt )) rpt$dlta2HH2o <- na.omit(data.frame(setQf$dlta2HH2o, setQf$presCrdH2o, setQf$tempCrdH2o, setQf$tempWbox, - setQf$sensCrdH2o, setQf$envHut, - setQf$frt00Mfm, setQf$frtMfm, - setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, setQf$presInlt, - setQf$pumpStor + setQf$sensCrdH2o, #setQf$envHut, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm#, setQf$presInlt, + #setQf$pumpStor #setQf$heatInlt )) @@ -2038,26 +2105,31 @@ if (MethMeas == "ecse") { rpt$rtioMoleDryH2o <- na.omit(data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, setQf$presCrdH2o, setQf$tempCrdH2o, setQf$tempWbox, setQf$sensCrdH2o, - setQf$envHut, setQf$valiCrdH2o, - setQf$presValiRegInStor, setQf$presValiRegOutStor)) + #setQf$envHut, + setQf$valiCrdH2o, + #setQf$presValiRegInStor, setQf$presValiRegOutStor + )) rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$presCrdH2o, setQf$tempCrdH2o, setQf$tempWbox, - setQf$sensCrdH2o, setQf$envHut, - setQf$valiCrdH2o, setQf$presValiRegInStor, - setQf$presValiRegOutStor)) + setQf$sensCrdH2o, #setQf$envHut, + setQf$valiCrdH2o, #setQf$presValiRegInStor, + #setQf$presValiRegOutStor + )) rpt$dlta18OH2o <- na.omit(data.frame(setQf$dlta18OH2o, setQf$presCrdH2o, setQf$tempCrdH2o, setQf$tempWbox, - setQf$sensCrdH2o, setQf$envHut, - setQf$valiCrdH2o, setQf$presValiRegInStor, - setQf$presValiRegOutStor)) + setQf$sensCrdH2o, #setQf$envHut, + setQf$valiCrdH2o, #setQf$presValiRegInStor, + #setQf$presValiRegOutStor + )) rpt$dlta2HH2o <- na.omit(data.frame(setQf$dlta2HH2o, setQf$presCrdH2o, setQf$tempCrdH2o, setQf$tempWbox, - setQf$sensCrdH2o, setQf$envHut, - setQf$valiCrdH2o, setQf$presValiRegInStor, - setQf$presValiRegOutStor)) + setQf$sensCrdH2o, #setQf$envHut, + setQf$valiCrdH2o, #setQf$presValiRegInStor, + #setQf$presValiRegOutStor + )) rpt$pres <- na.omit(data.frame(setQf$presCrdH2o, setQf$sensCrdH2o$qfSensStus, setQf$valiCrdH2o)) rpt$temp <- na.omit(data.frame(setQf$tempCrdH2o, setQf$sensCrdH2o$qfSensStus, setQf$valiCrdH2o)) From bbbd64ca81711f7d346a10c97e8aa8696fd15aec Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 22 Jun 2020 03:40:39 +0000 Subject: [PATCH 060/168] - documenting update --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 2058047a..5b126cc0 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -86,6 +86,8 @@ # adding qfHeat to ECSE # Natchaya P-Durden (2020-03-11) # removed qfCal and qfHeat from ECSE +# David Durden (2020-06-21) +# removing flags for external sensors from ECSE qfqm ############################################################################################## def.dp01.grp.qf <- function( From 891c42a28c760253adfca1c84b0629ea691d5a04 Mon Sep 17 00:00:00 2001 From: ddurden Date: Thu, 2 Jul 2020 18:38:31 +0000 Subject: [PATCH 061/168] - updating function to check physical locations of reingest sensors exist before pulling from API --- pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R index aeb55a15..acac1f3b 100755 --- a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R +++ b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R @@ -129,6 +129,9 @@ if(class(data) == "try-error"){ LvlMeasOut <- LocMeas #Name for HDF5 output names(LvlMeasOut) <- LvlMeas + + #Check against the measurement location + LvlMeasOut <- LvlMeasOut[LvlMeasOut %in% Noble::pull.dp.locs(site = SiteLoca, dpID = DpNum)$HOR.VER] #Create the timeBgn vector for aggregation period specified (1, 30 minutes) timeBgnOut <- seq(from = lubridate::ymd_hms(timeBgn) + lubridate::seconds(1), to = base::as.POSIXlt(timeEnd) - lubridate::minutes(TimeAgr), by = paste(TimeAgr, "mins", sep = " ")) @@ -265,10 +268,14 @@ LvlMeasOut <- LocMeas #Name for HDF5 output names(LvlMeasOut) <- LvlMeas +#Check against the measurement location +LvlMeasOut <- LvlMeasOut[LvlMeasOut %in% Noble::pull.dp.locs(site = SiteLoca, dpID = DpNum)$HOR.VER] + ##################################################################################### #Sort output data and apply eddy4R naming conventions tmp$data <- lapply(LvlMeasOut, function(x){ + #print(x) #Grab just the columns to be output tmp <- data[,grep(pattern = paste(nameVar$DataOut, collapse = "|"), x = names(data))] if(DpName %in% "presBaro"){ From b3af87ec8fb5db5f4aadc037f25744bb24a6cd8e Mon Sep 17 00:00:00 2001 From: ddurden Date: Thu, 2 Jul 2020 18:39:52 +0000 Subject: [PATCH 062/168] - documenting function update --- pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R index acac1f3b..93759bce 100755 --- a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R +++ b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R @@ -47,6 +47,8 @@ # Natchaya P-Durden (2019-09-12) # get information of existing dp01 hor and ver from dp0p hdf5 file # convert qmBeta and qmAlph to fraction +# David Durden(2020-07-02) +# updating function to check physical locations of reingest sensors exist before pulling from API ############################################################################################## def.hdf5.wrte.dp01.api <- function( From 1fea3e2eb0313ff594ea6364166118e1bef08c14 Mon Sep 17 00:00:00 2001 From: ddurden Date: Thu, 2 Jul 2020 20:00:22 +0000 Subject: [PATCH 063/168] - changing to match regular expressions --- pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R index 93759bce..fb2e7e62 100755 --- a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R +++ b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R @@ -270,8 +270,11 @@ LvlMeasOut <- LocMeas #Name for HDF5 output names(LvlMeasOut) <- LvlMeas +#Check measurement levels returned from API +LvlExis <- unique(unlist(regmatches(names(data),gregexpr(pattern = "[0-9][0-9][0-9].[)0-9][0-9][0-9]", names(data))))) + #Check against the measurement location -LvlMeasOut <- LvlMeasOut[LvlMeasOut %in% Noble::pull.dp.locs(site = SiteLoca, dpID = DpNum)$HOR.VER] +LvlMeasOut <- LvlMeasOut[LvlMeasOut %in% LvlExis] ##################################################################################### From e1c6d210bf0245029ae15dfc56fb5262e7b5592f Mon Sep 17 00:00:00 2001 From: ddurden Date: Thu, 2 Jul 2020 20:03:01 +0000 Subject: [PATCH 064/168] - removing call to Noble, not needed for all missing data --- pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R | 3 --- 1 file changed, 3 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R index fb2e7e62..abbf8e61 100755 --- a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R +++ b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R @@ -131,9 +131,6 @@ if(class(data) == "try-error"){ LvlMeasOut <- LocMeas #Name for HDF5 output names(LvlMeasOut) <- LvlMeas - - #Check against the measurement location - LvlMeasOut <- LvlMeasOut[LvlMeasOut %in% Noble::pull.dp.locs(site = SiteLoca, dpID = DpNum)$HOR.VER] #Create the timeBgn vector for aggregation period specified (1, 30 minutes) timeBgnOut <- seq(from = lubridate::ymd_hms(timeBgn) + lubridate::seconds(1), to = base::as.POSIXlt(timeEnd) - lubridate::minutes(TimeAgr), by = paste(TimeAgr, "mins", sep = " ")) From da0feb14660f50e8242e8048133b5618e231177e Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 7 Jul 2020 16:24:58 +0000 Subject: [PATCH 065/168] - fixing comment bugs --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 5b126cc0..94f3fad0 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -1451,7 +1451,7 @@ if (MethMeas == "ecse") { tmp$rtioMoleWet12CCo2 <-data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2 + setQf$sensCrdCo2, #, setQf$frt00Mfm, #setQf$frtMfm, setQf$presAtmMfm, #setQf$tempMfm, @@ -1628,7 +1628,7 @@ if (MethMeas == "ecse") { rpt$dlta13CCo2 <- na.omit(data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2#, setQf$frt00Mfm, + setQf$sensCrdCo2,# setQf$frt00Mfm, #setQf$frtMfm, setQf$presAtmMfm, #setQf$tempMfm, setQf$sensMfm#, From 6380cd2a2d32762fc5795e919bb03af5dae6a547 Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 7 Jul 2020 20:06:46 +0000 Subject: [PATCH 066/168] - fixing comment issues --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 94f3fad0..d571fa92 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -2108,28 +2108,28 @@ if (MethMeas == "ecse") { setQf$presCrdH2o, setQf$tempCrdH2o, setQf$tempWbox, setQf$sensCrdH2o, #setQf$envHut, - setQf$valiCrdH2o, + setQf$valiCrdH2o#, #setQf$presValiRegInStor, setQf$presValiRegOutStor )) rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$presCrdH2o, setQf$tempCrdH2o, setQf$tempWbox, setQf$sensCrdH2o, #setQf$envHut, - setQf$valiCrdH2o, #setQf$presValiRegInStor, + setQf$valiCrdH2o#, setQf$presValiRegInStor, #setQf$presValiRegOutStor )) rpt$dlta18OH2o <- na.omit(data.frame(setQf$dlta18OH2o, setQf$presCrdH2o, setQf$tempCrdH2o, setQf$tempWbox, setQf$sensCrdH2o, #setQf$envHut, - setQf$valiCrdH2o, #setQf$presValiRegInStor, + setQf$valiCrdH2o#, setQf$presValiRegInStor, #setQf$presValiRegOutStor )) rpt$dlta2HH2o <- na.omit(data.frame(setQf$dlta2HH2o, setQf$presCrdH2o, setQf$tempCrdH2o, setQf$tempWbox, setQf$sensCrdH2o, #setQf$envHut, - setQf$valiCrdH2o, #setQf$presValiRegInStor, + setQf$valiCrdH2o#, setQf$presValiRegInStor, #setQf$presValiRegOutStor )) From 81bfa32d0aa2fce6f2dc305490c54a2425aa0695 Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 7 Jul 2020 21:26:40 +0000 Subject: [PATCH 067/168] - updating documentation --- pack/eddy4R.base/R/def.hdf5.read.qfqm.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pack/eddy4R.base/R/def.hdf5.read.qfqm.R b/pack/eddy4R.base/R/def.hdf5.read.qfqm.R index 6dec9f3d..4a0057c6 100644 --- a/pack/eddy4R.base/R/def.hdf5.read.qfqm.R +++ b/pack/eddy4R.base/R/def.hdf5.read.qfqm.R @@ -43,6 +43,8 @@ # applied term name convention; replaced Levl by Lvl # Natchaya P-Durden (2018-05-22) # rename function from def.neon.read.hdf5.qfqm() to def.hdf5.read.qfqm() +# David Durden (2020-06-22) +# extending function to work with data and qfqm, as well as adding metadata ############################################################################################## def.hdf5.read.qfqm <- function( From 5047858083af104f978b57c20c873fb6efd02428 Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 7 Jul 2020 21:27:23 +0000 Subject: [PATCH 068/168] - updating to read both data and qfqm --- pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd b/pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd index 6b9c590f..115317f6 100644 --- a/pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd +++ b/pack/eddy4R.base/man/def.hdf5.read.qfqm.Rd @@ -11,6 +11,7 @@ def.hdf5.read.qfqm( VarLoca, LvlTowr = c("000_040", "000_050", "000_060")[3], FreqLoca, + DataType = c("data", "qfqm")[1], MethMeas = c("ecte", "ecse")[1] ) } @@ -27,10 +28,12 @@ def.hdf5.read.qfqm( \item{FreqLoca}{Integer: Measurement frequency.} +\item{DataType}{Character: Specify between data and qfqm for read in.} + \item{MethMeas}{A vector of class "character" containing the name of measurement method (eddy-covariance turbulent exchange or storage exchange), MethMeas = c("ecte", "ecse"). Defaults to "ecte".} } \value{ -Named list \code{qfqm} containing time-series of quality flags. +Named list \code{rpt} containing time-series of quality flags. } \description{ definition function. Reads an HDF5 input file in NEON standard format from \code{DirInpLoca}. From 98364f4acc68e10b62f57fb999ce5c9bb64886d1 Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 7 Jul 2020 21:27:43 +0000 Subject: [PATCH 069/168] - adding qfNull output --- pack/eddy4R.qaqc/R/def.qf.rmv.data.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pack/eddy4R.qaqc/R/def.qf.rmv.data.R b/pack/eddy4R.qaqc/R/def.qf.rmv.data.R index 45664bee..0b0f98d8 100644 --- a/pack/eddy4R.qaqc/R/def.qf.rmv.data.R +++ b/pack/eddy4R.qaqc/R/def.qf.rmv.data.R @@ -48,6 +48,8 @@ # replaced dfQf by inpQf # Natchaya P-Durden (2019-03-12) # added qfRmv into the function parameter list +# Dave Durden (2020-04-24) +# Adding qfNull to output ############################################################################################## @@ -71,6 +73,16 @@ def.qf.rmv.data <- function( #List of variables to check for flags to remove bad data rpt$listVar <- base::names(inpData[!base::names(inpData) %in% c("time", "idx")]) + #Create a NULL flag based on NaN's in original data + rpt$qfNull <- as.data.frame(sapply(rpt$listVar, function(x){ + qfTmp <- base::rep_len(0L, length.out = length(inpData[[x]])) + setNull <- which(is.na(inpData[[x]])) + qfTmp[setNull] <- 1L + return(qfTmp) + })) + #Correct the Null flag names + names(rpt$qfNull) <- paste0("qfNull",toupper(substring(names(rpt$qfNull),1,1)),substring(names(rpt$qfNull),2,nchar(names(rpt$qfNull)))) + #If a sensor (Sens) is included, check for sensor specific flags to perform filtering of data if(!base::is.null(Sens) && base::length(Sens) == 1){ From 9e771c44c96c4ac1b2464dbf601c11cbebc83923 Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 7 Jul 2020 21:30:19 +0000 Subject: [PATCH 070/168] - adding despiking and qfNull --- pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R b/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R index 899fb35e..ec78ec6b 100644 --- a/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R +++ b/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R @@ -63,17 +63,36 @@ wrap.qf.rmv.data <- function( if(MethMeas == "ecte"){ # Determine quality flags to apply to each stream, quantify flags, and remove bad data across all sensors outList <- base::lapply(Sens, function(x){ - eddy4R.qaqc::def.qf.rmv.data(inpData = inpList$data[[x]][], inpQf = inpList$qfqm[[x]], Sens = x, qfRmv = qfRmv, Vrbs = Vrbs) #Remove high frequency data that is flagged by sensor specific flags or plausibility tests flags + def.qf.rmv.data(inpData = inpList$data[[x]][], inpQf = inpList$qfqm[[x]], Sens = x, qfRmv = qfRmv, Vrbs = Vrbs) #Remove high frequency data that is flagged by sensor specific flags or plausibility tests flags }) #Apply names to the output list base::names(outList) <- Sens + + #Despiking routine + test <- base::lapply(Sens, function(x){ + #x <- "irgaTurb" #for testing + varDspk <- names(outList[[x]]$inpData)[!names(outList[[x]]$inpData) %in% c("time","idx")] + tmp <- base::lapply(varDspk, function(y){ + eddy4R.qaqc::def.dspk.br86( + # input data, univariate vector of integers or numerics + dataInp = outList[[x]][[y]], + # filter width + WndwFilt = as.numeric(ramattribs(inpList$data[[x]][[y]])$`Dspk$Br86$NumWndw`), + # initial number/step size of histogram bins + NumBin = as.numeric(ramattribs(inpList$data[[x]][[y]])$`Dspk$Br86$NumBin`), + # resolution threshold + ThshReso = as.numeric(ramattribs(inpList$data[[x]][[y]])$`Dspk$Br86$MaxReso`) + )$dataOut #Remove high frequency data that is flagged by sensor specific flags or plausibility tests flags + }) + }) #Applying the bad quality flags to the reported output data base::lapply(base::names(outList), function(x) { #Outputting the data ffdf's rpt$data[[x]] <<- ff::as.ffdf(outList[[x]]$inpData) rpt$data[[x]] <<- eddy4R.base::def.unit.var(samp = rpt$data[[x]], refe = inpList$data[[x]]) #Copy units + rpt$qfqm[[x]] <<- ff::as.ffdf(base::cbind(rpt$qfqm[[x]][], outList$irgaTurb$qfNull)) }) #If verbose is true write out all the information about the quality flags applied to the raw data From 3d845bca7f93914a2e98e20875e6260e87f78276 Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Tue, 7 Jul 2020 17:38:48 -0600 Subject: [PATCH 071/168] optimize for compute speed & update package version --- pack/eddy4R.qaqc/DESCRIPTION | 2 +- pack/eddy4R.qaqc/R/def.plau.R | 383 ++++++++++++++-------------------- 2 files changed, 153 insertions(+), 232 deletions(-) diff --git a/pack/eddy4R.qaqc/DESCRIPTION b/pack/eddy4R.qaqc/DESCRIPTION index 70f5f97e..afd4eac5 100644 --- a/pack/eddy4R.qaqc/DESCRIPTION +++ b/pack/eddy4R.qaqc/DESCRIPTION @@ -1,6 +1,6 @@ Package: eddy4R.qaqc Title: Eddy-covariance calculation for R: Quality assurance and quality control -Version: 0.2.9 +Version: 0.2.10 Authors@R: c( person("Cove", "Sturtevant", email = "eddy4R.info@gmail.com", role = c("aut", "cre")), person("Stefan", "Metzger", email = "eddy4R.info@gmail.com", role = c("aut")), person("Natchaya", "Pingintha-Durden", email = "ndurden@battelleecology.org", role = c("aut")), diff --git a/pack/eddy4R.qaqc/R/def.plau.R b/pack/eddy4R.qaqc/R/def.plau.R index 3507c57e..6291ed45 100644 --- a/pack/eddy4R.qaqc/R/def.plau.R +++ b/pack/eddy4R.qaqc/R/def.plau.R @@ -87,6 +87,9 @@ # applied eddy4R term name convention; replaced posQf by setQf # Natchaya P-Durden (2018-04-11) # applied eddy4R term name convention; replaced pos by idx or set +# Cove Sturtevant (2020-07-07) +# optimized time-based persistence test and removed point-based method, adding conversion to time-based method. +# also caught bug causing a potential lack of persistence test na flags when all values between 2 points are NA. ############################################################################################## def.plau <- function ( data, # a data frame containing the data to be evaluated (do not include the time stamp vector here). Required input. @@ -190,8 +193,10 @@ def.plau <- function ( # intialize output of failed and na vector positions setQf <- vector("list",numVar) # Initialize output for each variable names(setQf) <- nameData - setDataReal <- lapply(data,FUN=function(var){which(!is.na(var))}) - setDataNa <- lapply(setDataReal,FUN=function(var){setdiff(1:numData,var)}) + dataNa <- lapply(data,FUN=function(var){is.na(var)})# logical + dataReal <- lapply(dataNa,FUN=function(var){!var}) # logical + setDataReal <- lapply(dataReal,FUN=function(var){which(var)}) # indices + setDataNa <- lapply(dataNa,FUN=function(var){which(var)}) # indices # For verbose option, initialize output if(Vrbs) { @@ -222,19 +227,27 @@ def.plau <- function ( # Do step test for(idxVar in 1:numVar) { + + diffDataIdx <- diff(data[,idxVar]) + diffDataNaIdx <- is.na(diffDataIdx) + setNaDiffDataIdx <- which(diffDataNaIdx) + setNaDiffDataIdx <- which(!diffDataNaIdx) + + setQf[[idxVar]]$setQfStep <- list(fail=numeric(0),na=numeric(0)) # initialize - setQf[[idxVar]]$setQfStep$fail <- which((abs(diff(data[,idxVar])) > DiffStepMax[idxVar])) + setQf[[idxVar]]$setQfStep$fail <- which((abs(diffDataIdx) > DiffStepMax[idxVar])) setQf[[idxVar]]$setQfStep$fail <- unique(c(setQf[[idxVar]]$setQfStep$fail,setQf[[idxVar]]$setQfStep$fail+1)) - setQf[[idxVar]]$setQfStep$na <- which(is.na(diff(data[,idxVar])))+1 + setQf[[idxVar]]$setQfStep$na <- setNaDiffDataIdx+1 # If either of the first two values are NULL, flag NA (the first value is missed by the above code) - if(is.na(diff(data[,idxVar])[1])){setQf[[idxVar]]$setQfStep$na <- unique( - c(1,setQf[[idxVar]]$setQfStep$na))} + if(diffDataNaIdx[1]){ + setQf[[idxVar]]$setQfStep$na <- unique( + c(1,setQf[[idxVar]]$setQfStep$na)) + } # If previous point is null, but next value is present, evaluate the step test with next value - setQf[[idxVar]]$setQfStep$na <- setdiff(setQf[[idxVar]]$setQfStep$na, - which(!is.na(diff(data[,idxVar])))) + setQf[[idxVar]]$setQfStep$na <- setdiff(setQf[[idxVar]]$setQfStep$na,setNaDiffDataIdx) # For Verbose option, output actual flag values if(Vrbs) { @@ -243,260 +256,168 @@ def.plau <- function ( } } - # Do persistence test with time-based windowing approach - if(class(WndwPers) == "difftime"){ + # Do persistence test + if(class(WndwPers) %in% c("numeric","integer")){ + # Figure out what the time-based representation would be + timePers <- as.POSIXlt(seq.POSIXt(from=Sys.time(),by="sec",length.out=length(data[,1]))) + WndwPers <- as.difftime(WndwPers,units='secs') + } else { + timePers <- time + } + + for(idxVar in 1:numVar) { - for(idxVar in 1:numVar) { - - dataIdxVar <- data[[idxVar]] - DiffPersMinIdx <- DiffPersMin[idxVar] - WndwPersIdx <- WndwPers[idxVar] - - # Initialize - setQf[[idxVar]]$setQfPers <- list(fail=numeric(0),na=numeric(0)) - setQf[[idxVar]]$setQfPers$na <- which(is.na(dataIdxVar)) - - # Quit if all data are NA - if(length(setDataReal[[idxVar]]) <= 1){ - setQf[[idxVar]]$setQfPers$na <- 1:numData - if(Vrbs){qf[[idxVar]]$qfPers[setQf[[idxVar]]$setQfPers$na] <- -1} - next - } else if(DiffPersMinIdx <= 0){ - if(Vrbs){qf[[idxVar]]$qfPers[setQf[[idxVar]]$setQfPers$na] <- -1} + dataIdxVar <- data[[idxVar]] + dataNaIdx <- dataNa[[idxVar]] + dataRealIdx <- dataReal[[idxVar]] + DiffPersMinIdx <- DiffPersMin[idxVar] + WndwPersIdx <- WndwPers[idxVar] + + # Initialize + setQf[[idxVar]]$setQfPers <- list(fail=numeric(0),na=numeric(0)) + setQf[[idxVar]]$setQfPers$na <- setDataNa[[idxVar]] + + # Quit if all data are NA + if(length(setDataReal[[idxVar]]) <= 1){ + setQf[[idxVar]]$setQfPers$na <- 1:numData + if(Vrbs){qf[[idxVar]]$qfPers[setQf[[idxVar]]$setQfPers$na] <- -1} + next + } else if(DiffPersMinIdx <= 0){ + if(Vrbs){qf[[idxVar]]$qfPers[setQf[[idxVar]]$setQfPers$na] <- -1} + next + } + + # Start at the beginning, making sure we aren't on a null value + idxDataBgn <- setDataReal[[idxVar]][1] + + idxDataMin <- idxDataBgn # initialize index of running min + idxDataMax <- idxDataBgn # intialize index of running max + idxData <- 2 # intialize index position + + # Grab the data for these indices + timeIdxBgn <- timePers[idxDataBgn] + dataIdxMin <- dataIdxVar[idxDataMin] + dataIdxMax <- dataIdxVar[idxDataMax] + + while(idxData <= numData) { + + #If we hit NA, get to the next non-NA value + if(dataNaIdx[idxData]){ + idxData <- idxData +1 next + } + + # Is the value at this index the running max or min? + if(dataIdxVar[idxData] < dataIdxMin) { + idxDataMin <- idxData + dataIdxMin <- dataIdxVar[idxDataMin] + } else if(dataIdxVar[idxData] > dataIdxMax) { + idxDataMax <- idxData + dataIdxMax <- dataIdxVar[idxDataMax] } - # Start at the beginning, making sure we aren't on a null value - idxDataBgn <- setDataReal[[idxVar]][1] - - idxDataMin <- idxDataBgn # initialize index of running min - idxDataMax <- idxDataBgn # intialize index of running max - idxData <- 2 # intialize index position - - # Grab the data for these indices, improves CPU time - dataIdxMin <- dataIdxVar[idxDataMin] - dataIdxMax <- dataIdxVar[idxDataMax] - while(idxData <= numData) { - - #If we hit NA, get to the next non-NA value - if(is.na(dataIdxVar[idxData])){ - idxData <- idxData +1 - next - } + # Is diff between max and min at or larger than the persistence threshold? + if(dataIdxMax-dataIdxMin >= DiffPersMinIdx) { + + # We've hit the threshold, now check whether we are beyond the allowable time interval + if(timePers[idxData]-timeIdxBgn < WndwPersIdx) { + # Hooray! The data is not "stuck" + idxDataBgn <- min(c(idxDataMin,idxDataMax))+1 # set start of next window to the next point after the earlier of the running min and max + + # Make sure we aren't on a null value + while(dataNaIdx[idxDataBgn]){ + idxDataBgn <- idxDataBgn+1 + } - # Is the value at this index the running max or min? - if(dataIdxVar[idxData] < dataIdxMin) { - idxDataMin <- idxData + idxDataMin <- idxDataBgn # reset running minimum + idxDataMax <- idxDataBgn # reset running maximum + idxData <- idxDataBgn+1 # reset the next point to be evaluated + + # Grab the data for these indices, improves CPU time + timeIdxBgn <- timePers[idxDataBgn] dataIdxMin <- dataIdxVar[idxDataMin] - } else if(dataIdxVar[idxData] > dataIdxMax) { - idxDataMax <- idxData dataIdxMax <- dataIdxVar[idxDataMax] - } - - - # Is diff between max and min at or larger than the persistence threshold? - if(dataIdxMax-dataIdxMin >= DiffPersMinIdx) { - - # We've hit the threshold, now check whether we are beyond the allowable time interval - if(diff(time[c(idxDataBgn,idxData)]) < WndwPersIdx) { - # Hooray! The data is not "stuck" - idxDataBgn <- min(c(idxDataMin,idxDataMax))+1 # set start of next window to the next point after the lower of the running min and max - - # Make sure we aren't on a null value - while(is.na(dataIdxVar[idxDataBgn])){ - idxDataBgn <- idxDataBgn+1 - } - - idxDataMin <- idxDataBgn # reset running minimum - idxDataMax <- idxDataBgn # reset running maximum - idxData <- idxDataBgn+1 # reset the next point to be evaluated + + } else { + + # We might have a stuck sensor, but first let's check whether we blew the time threshold b/c + # all the data were NA prior to this point + if (sum(dataRealIdx[idxDataBgn:(idxData-1)]) <= 1) { - # Grab the data for these indices, improves CPU time - dataIdxMin <- dataIdxVar[idxDataMin] - dataIdxMax <- dataIdxVar[idxDataMax] + # Data were all NA between the starting index and the current point, mark the non-NA points + # as cannot evaluate if they haven't already been marked for test failure + setNaAdd <- setdiff(idxDataBgn:(idxData-1),setQf[[idxVar]]$setQfPers$fail) + setQf[[idxVar]]$setQfPers$na <- union(setQf[[idxVar]]$setQfPers$na,setNaAdd) } else { - # We might have a stuck sensor, but first let's check whether we blew the time threshold b/c - # all the data were NA prior to this point - if (sum(!is.na(idxDataBgn:(idxData-1))) <= 1) { - - # Data were all NA after starting index, mark as cannot evaluate - setQf[[idxVar]]$setQfPers$na <- union(setQf[[idxVar]]$setQfPers$na,idxDataBgn:(idxData-1)) - - } else { - - # Awe bummer, the sensor was stuck before this point. - setQf[[idxVar]]$setQfPers$fail <- unique(c(setQf[[idxVar]]$setQfPers$fail, - idxDataBgn:(idxData-1))) - - # Don't mark the NA values as fail - setQf[[idxVar]]$setQfPers$fail <- setdiff(setQf[[idxVar]]$setQfPers$fail, - setQf[[idxVar]]$setQfPers$na) - } + # Awe bummer, the sensor was stuck before this point. + setQf[[idxVar]]$setQfPers$fail <- unique(c(setQf[[idxVar]]$setQfPers$fail, + idxDataBgn:(idxData-1))) - idxDataBgn <- idxData # restart the test from here - idxData <- idxDataBgn+1 # reset the next point to be evaluated - } - - } else if ((idxData == numData) && (time[idxData]-time[idxDataBgn] >= WndwPersIdx)) { - - # We didn't hit the threshold and we've reached the end of the data. We are also beyond the allowable - # time interval for the persistence test, so let's flag the data - setQf[[idxVar]]$setQfPers$fail <- unique(c(setQf[[idxVar]]$setQfPers$fail,idxDataBgn:idxData)) - - # Don't mark the NA values as fail - setQf[[idxVar]]$setQfPers$fail <- setdiff(setQf[[idxVar]]$setQfPers$fail,setQf[[idxVar]]$setQfPers$na) + } - idxData <- idxData+1 # We're done + idxDataBgn <- idxData # restart the test from here + idxData <- idxDataBgn+1 # reset the next point to be evaluated - } else { + # Grab the data for these indices, improves CPU time + timeIdxBgn <- timePers[idxDataBgn] - # We didn't pass the minimum acceptable change on this point, move to the next - idxData <- idxData+1 - } - } - # If we reached the end of the data but the last value was NA, we need to go back and evaluate the last - # non-NA value - idxData <- numData - if (is.na(dataIdxVar[idxData])) { - # Get to last non-NA point - idxData <- tail(setDataReal[[idxVar]],n=1) - - if (time[idxData]-time[idxDataBgn] >= WndwPersIdx) { - # We didn't hit the threshold for the final non-NA points and we were beyond the allowable - # time interval for the persistence test, so let's flag the end of the data - setQf[[idxVar]]$setQfPers$fail <- unique(c(setQf[[idxVar]]$setQfPers$fail,idxDataBgn:idxData)) - - # Don't mark the NA values as fail - setQf[[idxVar]]$setQfPers$fail <- setdiff(setQf[[idxVar]]$setQfPers$fail,setQf[[idxVar]]$setQfPers$na) - - } else { - # We didn't hit the threshold for the final non-NA points, but we are not yet beyond the - # allowable time interval, so let's flag as unable to evaluate - setQf[[idxVar]]$setQfPers$na <- unique(c(setQf[[idxVar]]$setQfPers$na,idxDataBgn:idxData)) - } - } - - # For Verbose option, output actual flag values - if(Vrbs) { - qf[[idxVar]]$qfPers[setQf[[idxVar]]$setQfPers$fail] <- 1 - qf[[idxVar]]$qfPers[setQf[[idxVar]]$setQfPers$na] <- -1 - } - } - } - - - # Do persistence test with point-based windowing option - if(class(WndwPers) %in% c("numeric","integer")){ - for(idxVar in 1:numVar) { - - dataIdxVar <- data[[idxVar]] # Pull out this variable - DiffPersMinIdx <- DiffPersMin[idxVar] - - # Initialize - setQf[[idxVar]]$setQfPers <- list(fail=numeric(0),na=numeric(0)) - setQf[[idxVar]]$setQfPers$na <- which(is.na(dataIdxVar)) - tmpQfPers <- rep(0,numData) # Default the flag to OK - tmpQfPersNa <- rep(-1,numData) # Set up a variable to coincidentally mark whether the data were able to be evaluated - - # Quit if all data are NA - if(length(setDataReal[[idxVar]]) <= 1){ - setQf[[idxVar]]$setQfPers$na <- 1:numData - if(Vrbs){qf[[idxVar]]$qfPers[setQf[[idxVar]]$setQfPers$na] <- -1} - next - } else if(DiffPersMinIdx <= 0){ - if(Vrbs){qf[[idxVar]]$qfPers[setQf[[idxVar]]$setQfPers$na] <- -1} - next - } - - # Loop thru the data, checking for persistence over the window size. Here, we default the data to ok, - # and if the persistence test fails over any window encompassing a particular data point, the flag - # for the point is set to 1 - for (idxData in setDataReal[[idxVar]][1]:(numData-WndwPers[idxVar]+1)){ + } - # Initialize metrics - setData <- idxData:(idxData+WndwPers[idxVar]-1) # data range to eval - dataIdx <- dataIdxVar[setData] # data to eval - dataIdxBgn <- dataIdx[1] # 1st data point in eval range + } else if ((idxData == numData) && (timePers[idxData]-timeIdxBgn >= WndwPersIdx)) { - if(is.na(dataIdxBgn) || sum(!is.na(dataIdx)) < 2){next} + # We didn't hit the threshold and we've reached the end of the data. We are also beyond the allowable + # time interval for the persistence test, so let's flag the data + setQf[[idxVar]]$setQfPers$fail <- union(setQf[[idxVar]]$setQfPers$fail,idxDataBgn:idxData) - dataIdxEnd <- tail(dataIdx,n=1) # Last data point in eval range - diffMax <- max(dataIdx,na.rm=TRUE) - min(dataIdx,na.rm=TRUE) # max difference over the eval range + idxData <- idxData+1 # We're done - # If the last point is NA and we haven't passed the threshold, get to the next point that exceeds - # the threshold and flag everything up that point - if(is.na(dataIdxEnd) && diffMax < DiffPersMinIdx){ - - # Keep looking at data until we surpass the threshold, or reach the end of the data - setDataExt <- setData[1]:numData - setDataExt <- intersect(setDataExt,setDataReal[[idxVar]]) # filter out the NA indices - idxPass <- head(which(cummax(dataIdxVar[setDataExt])-cummin(dataIdxVar[setDataExt]) >= DiffPersMinIdx),n=1) # Find the first point at which we pass the threshold - - # If we found it, stage data up to, but not including this point, for flagging - if(length(idxPass) == 1){ - setData <- setData[1]:(setDataExt[idxPass]-1) - } - } - + } else { - # Check for passing the threshold, and flag appropriately - #if(sum(!is.na(dataIdx)) > 1 && !is.na(dataIdxBgn)){ - tmpQfPersNa[setData] <- 0 # Mark data as able to eval - - if(diffMax < DiffPersMinIdx){ - tmpQfPers[setData] <- 1 # Flag - } - #} - } # End loop through data for normal persistence testing - - # Now account for NA values - tmpQfPers[tmpQfPersNa==-1] <- -1 # Set flag to -1 for cannot eval - tmpQfPers[is.na(dataIdxVar)] <- -1 # Ensure that flag is -1 for NA points + # We didn't pass the minimum acceptable change on this point, move to the next + idxData <- idxData+1 + } + } + + # If we reached the end of the data but the last value was NA, we need to go back and evaluate the last + # non-NA value + idxData <- numData + if (dataNaIdx[idxData]) { + # Get to last non-NA point + idxData <- tail(setDataReal[[idxVar]],n=1) - # If the last point is NA, go back and see what we could not evaluate - if(is.na(dataIdxVar[numData])){ - - # Initialize - idxDataEnd <- tail(setDataReal[[idxVar]],n=1) - idxData <- idxDataEnd-1 + if (timePers[idxData]-timeIdxBgn >= WndwPersIdx) { + # We didn't hit the threshold for the final non-NA points and we were beyond the allowable + # time interval for the persistence test, so let's flag the end of the data + setQf[[idxVar]]$setQfPers$fail <- unique(c(setQf[[idxVar]]$setQfPers$fail,idxDataBgn:idxData)) - # Step backward through the data until we surpass the persistence threshold. - # All data after this point needs to be marked as cannot evaluate, unless it - # has already been flagged - while(idxData > (idxDataEnd-WndwPers[idxVar]+1) && tmpQfPers[idxDataEnd] != 1){ - setData <- idxData:idxDataEnd - dataIdx <- dataIdxVar[setData] - diffMax <- suppressWarnings(max(dataIdx,na.rm=TRUE) - min(dataIdx,na.rm=TRUE)) - if (diffMax < DiffPersMinIdx){ - tmpQfPers[setData] <- -1 - idxData <- idxData-1 - } else { - break - } - } # End while loop - } # End if statement checking last value for NA - - # Output the results in the desired format - if(Vrbs){ - qf[[idxVar]]$qfPers <- tmpQfPers } else { - setQf[[idxVar]]$setQfPers$fail <- which(tmpQfPers == 1) - setQf[[idxVar]]$setQfPers$na <- which(tmpQfPers == -1) + # We didn't hit the threshold for the final non-NA points, but we are not yet beyond the + # allowable time interval, so let's flag as unable to evaluate + setQf[[idxVar]]$setQfPers$na <- union(setQf[[idxVar]]$setQfPers$na,idxDataBgn:idxData) } - - } # End for loop around variables - } # End if statement checking for numeric WndwPers value - + } + + # Don't mark the NA values as fail + setQf[[idxVar]]$setQfPers$fail <- setdiff(setQf[[idxVar]]$setQfPers$fail,setQf[[idxVar]]$setQfPers$na) + + + # For Verbose option, output actual flag values + if(Vrbs) { + qf[[idxVar]]$qfPers[setQf[[idxVar]]$setQfPers$fail] <- 1 + qf[[idxVar]]$qfPers[setQf[[idxVar]]$setQfPers$na] <- -1 + } + } + # Do Null test for(idxVar in 1:numVar) { setQf[[idxVar]]$setQfNull <- list(fail=numeric(0),na=numeric(0)) # initialize if(TestNull[idxVar]) { - setQf[[idxVar]]$setQfNull$fail <- which(is.na(data[,idxVar])) + setQf[[idxVar]]$setQfNull$fail <- setDataNa[[idxVar]] } # For Verbose option, output actual flag values From b392330b0e4612df5354151aa4b7f4ee64f3adc7 Mon Sep 17 00:00:00 2001 From: ddurden Date: Wed, 8 Jul 2020 19:51:28 +0000 Subject: [PATCH 072/168] Adding MethDp01Api argument with default to TRUE --- pack/eddy4R.base/R/def.para.flow.R | 8 ++++++-- pack/eddy4R.base/man/def.para.flow.Rd | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.base/R/def.para.flow.R b/pack/eddy4R.base/R/def.para.flow.R index f7c10ab5..2db3daf4 100644 --- a/pack/eddy4R.base/R/def.para.flow.R +++ b/pack/eddy4R.base/R/def.para.flow.R @@ -20,10 +20,11 @@ #' @param VersDp is the data product level that will be output #' @param VersEddy is the version of the eddy4R docker that is being used to perform the processing #' @param MethParaFlow is the method used to specify workflow parameters, "EnvVar" will grab ParaFlow parameters from environmental variable and "DfltInp" will use whatever is specified in the function call. +#' @param MethDp01Api is a logical (TRUE/FALSE) determining if Dp01 reingest data for storage exchange workflow should be gathered from the API. #' @param UrlInpRefe A single-entry vector of class "character" containing the web address of the reference input data zip file to be downloaded. #' @param UrlOutRefe A single-entry vector of class "character" containing the web address of the reference output data zip file to be downloaded. -#' @return \code{ParaFlow} is a list returned that indicates the workflow control parameters, including \code{ParaFlow$DirFilePara},\code{ParaFlow$DirInp}, \code{ParaFlow$DirMnt}, \code{ParaFlow$DirOut}, \code{ParaFlow$DirTmp}, \code{ParaFlow$DirWrk}, \code{ParaFlow$DateOut}, \code{ParaFlow$FileOutBase}, \code{ParaFlow$Read}, \code{ParaFlow$VersDp}, \code{ParaFlow$VersEddy}. +#' @return \code{ParaFlow} is a list returned that indicates the workflow control parameters, including \code{ParaFlow$DirFilePara},\code{ParaFlow$DirInp}, \code{ParaFlow$DirMnt}, \code{ParaFlow$DirOut}, \code{ParaFlow$DirTmp}, \code{ParaFlow$DirWrk}, \code{ParaFlow$DateOut}, \code{ParaFlow$FileOutBase}, \code{ParaFlow$Read}, \code{ParaFlow$VersDp}, \code{ParaFlow$VersEddy}, \code{ParaFlow$MethDp01Api}. #' @references #' License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007. \cr @@ -51,6 +52,8 @@ # superseed parameter MethMeas with the ability to directly provide reference data urls as arguments UrlInpRefe and UrlOutRefe # Stefan Metzger (2017-09-29) # fixing construction of ParaFlow$DirFilePara for batch-processing (when not using gold file) +# Dave Durden (2020-07-06) +# adding MethDp01Api parameter ############################################################################################################## #Start of function call to determine workflow parameters @@ -70,12 +73,13 @@ def.para.flow <- function( VersDp = c("001","004")[1], VersEddy = "latest", MethParaFlow = c("DfltInp","EnvVar")[1], + MethDp01Api = TRUE, UrlInpRefe, UrlOutRefe, ... ){ - ParaFlow <- list(Deve = Deve, DirFilePara = DirFilePara,DirInp = DirInp,DirMnt = DirMnt,DirOut = DirOut,DirTmp = DirTmp,DirWrk = DirWrk, DateOut = DateOut, FileOutBase = FileOutBase, MethParaFlow = MethParaFlow,Read = Read,VersDp = VersDp,VersEddy = VersEddy, ...) + ParaFlow <- list(Deve = Deve, DirFilePara = DirFilePara,DirInp = DirInp,DirMnt = DirMnt,DirOut = DirOut,DirTmp = DirTmp,DirWrk = DirWrk, DateOut = DateOut, FileOutBase = FileOutBase, MethParaFlow = MethParaFlow,Read = Read,VersDp = VersDp,VersEddy = VersEddy, MethDp01Api = MethDp01Api, ...) if(MethParaFlow == "EnvVar"){ #Create a list with all the specified function arguments diff --git a/pack/eddy4R.base/man/def.para.flow.Rd b/pack/eddy4R.base/man/def.para.flow.Rd index 62247c28..d307be92 100644 --- a/pack/eddy4R.base/man/def.para.flow.Rd +++ b/pack/eddy4R.base/man/def.para.flow.Rd @@ -18,6 +18,7 @@ def.para.flow( VersDp = c("001", "004")[1], VersEddy = "latest", MethParaFlow = c("DfltInp", "EnvVar")[1], + MethDp01Api = TRUE, UrlInpRefe, UrlOutRefe, ... @@ -50,12 +51,14 @@ def.para.flow( \item{MethParaFlow}{is the method used to specify workflow parameters, "EnvVar" will grab ParaFlow parameters from environmental variable and "DfltInp" will use whatever is specified in the function call.} +\item{MethDp01Api}{is a logical (TRUE/FALSE) determining if Dp01 reingest data for storage exchange workflow should be gathered from the API.} + \item{UrlInpRefe}{A single-entry vector of class "character" containing the web address of the reference input data zip file to be downloaded.} \item{UrlOutRefe}{A single-entry vector of class "character" containing the web address of the reference output data zip file to be downloaded.} } \value{ -\code{ParaFlow} is a list returned that indicates the workflow control parameters, including \code{ParaFlow$DirFilePara},\code{ParaFlow$DirInp}, \code{ParaFlow$DirMnt}, \code{ParaFlow$DirOut}, \code{ParaFlow$DirTmp}, \code{ParaFlow$DirWrk}, \code{ParaFlow$DateOut}, \code{ParaFlow$FileOutBase}, \code{ParaFlow$Read}, \code{ParaFlow$VersDp}, \code{ParaFlow$VersEddy}. +\code{ParaFlow} is a list returned that indicates the workflow control parameters, including \code{ParaFlow$DirFilePara},\code{ParaFlow$DirInp}, \code{ParaFlow$DirMnt}, \code{ParaFlow$DirOut}, \code{ParaFlow$DirTmp}, \code{ParaFlow$DirWrk}, \code{ParaFlow$DateOut}, \code{ParaFlow$FileOutBase}, \code{ParaFlow$Read}, \code{ParaFlow$VersDp}, \code{ParaFlow$VersEddy}, \code{ParaFlow$MethDp01Api}. } \description{ Definition function. Function to determine the workflow variables by either reading them in from the environmental variables, defining them explicitly, or defining them by default values From e1ba1138471baabb2192c35697fbcd1140518b3b Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Wed, 8 Jul 2020 18:53:48 -0600 Subject: [PATCH 073/168] additional optimization for gap test. WAAY faster when there are lots of gaps. --- pack/eddy4R.qaqc/R/def.plau.R | 62 ++++++++++++----------------------- 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.plau.R b/pack/eddy4R.qaqc/R/def.plau.R index 6291ed45..047f67bc 100644 --- a/pack/eddy4R.qaqc/R/def.plau.R +++ b/pack/eddy4R.qaqc/R/def.plau.R @@ -90,6 +90,8 @@ # Cove Sturtevant (2020-07-07) # optimized time-based persistence test and removed point-based method, adding conversion to time-based method. # also caught bug causing a potential lack of persistence test na flags when all values between 2 points are NA. +# Cove Sturtevant (2020-07-08) +# optimized gap test. WAY faster when there are a lot of gaps in the dataset ############################################################################################## def.plau <- function ( data, # a data frame containing the data to be evaluated (do not include the time stamp vector here). Required input. @@ -237,13 +239,12 @@ def.plau <- function ( setQf[[idxVar]]$setQfStep <- list(fail=numeric(0),na=numeric(0)) # initialize setQf[[idxVar]]$setQfStep$fail <- which((abs(diffDataIdx) > DiffStepMax[idxVar])) - setQf[[idxVar]]$setQfStep$fail <- unique(c(setQf[[idxVar]]$setQfStep$fail,setQf[[idxVar]]$setQfStep$fail+1)) + setQf[[idxVar]]$setQfStep$fail <- union(setQf[[idxVar]]$setQfStep$fail,setQf[[idxVar]]$setQfStep$fail+1) setQf[[idxVar]]$setQfStep$na <- setNaDiffDataIdx+1 # If either of the first two values are NULL, flag NA (the first value is missed by the above code) if(diffDataNaIdx[1]){ - setQf[[idxVar]]$setQfStep$na <- unique( - c(1,setQf[[idxVar]]$setQfStep$na)) + setQf[[idxVar]]$setQfStep$na <- union(1,setQf[[idxVar]]$setQfStep$na) } # If previous point is null, but next value is present, evaluate the step test with next value @@ -353,8 +354,8 @@ def.plau <- function ( } else { # Awe bummer, the sensor was stuck before this point. - setQf[[idxVar]]$setQfPers$fail <- unique(c(setQf[[idxVar]]$setQfPers$fail, - idxDataBgn:(idxData-1))) + setQf[[idxVar]]$setQfPers$fail <- union(setQf[[idxVar]]$setQfPers$fail, + idxDataBgn:(idxData-1)) } @@ -391,7 +392,7 @@ def.plau <- function ( if (timePers[idxData]-timeIdxBgn >= WndwPersIdx) { # We didn't hit the threshold for the final non-NA points and we were beyond the allowable # time interval for the persistence test, so let's flag the end of the data - setQf[[idxVar]]$setQfPers$fail <- unique(c(setQf[[idxVar]]$setQfPers$fail,idxDataBgn:idxData)) + setQf[[idxVar]]$setQfPers$fail <- union(setQf[[idxVar]]$setQfPers$fail,idxDataBgn:idxData) } else { # We didn't hit the threshold for the final non-NA points, but we are not yet beyond the @@ -432,48 +433,27 @@ def.plau <- function ( # Do Gap test for(idxVar in 1:numVar) { + # Initialize setQf[[idxVar]]$setQfGap <- list(fail=numeric(0),na=numeric(0)) # initialize - setNull <- setDataNa[[idxVar]] # find NA values - setGap <- setNull # Start out thinking every Null is a gap, we'll whittle it down below - diffSetNull <- diff(setNull) # difference between null position + # Do a rolling count of NAs with a window the length of the gap + dataNAIdx <- dataNa[[idxVar]] + NumGapIdx <- NumGap[idxVar] + numNaWndwGap <- RcppRoll::roll_sum(x=dataNAIdx,n=NumGapIdx,by=1,align='left',na.rm=FALSE) - # Only evaluate this if we need to - if (length(setNull) >= NumGap[idxVar]) { - - # Go thru each NA value to determine if it is part of a set >= NumGap[idxVar] - for (idxNull in 1:length(setNull)) { - - # Isolate positions within the NumGap[idxVar] range that are consecutive - diffSetNullSelf <- c(diffSetNull[1:idxNull-1],1,diffSetNull[idxNull:length(diffSetNull)])# Fill in the position difference vector with a value of 1 for idxNull itself - setNullPre <- seq(from=idxNull-NumGap[idxVar],to=idxNull-1,by=1) - setNullPre <- rev(setNullPre[(setNullPre > 0) & (setNullPre <= numData)]) - numNullPre <- which(diffSetNullSelf[setNullPre]!=1)[1]-1 # number of consecutive nulls prior to this Null - if (is.na(numNullPre)) { - numNullPre <- length(setNullPre) - } - setNullPost <- seq(from=idxNull,to=idxNull+NumGap[idxVar]-1,by=1) - setNullPost <- setNullPost[(setNullPost > 0) & (setNullPost <= numData)] - numNullPost <- which(diffSetNullSelf[setNullPost]!=1)[1]-1 # number of consecutive nulls including and after this Null - if (is.na(numNullPost)) { - numNullPost <- length(setNullPost) - } - - if (numNullPre+numNullPost < NumGap[idxVar]) { - # This position is not within a gap, so remove it from out list - setGap <- setdiff(setGap,setNull[idxNull]) - } - } - - setQf[[idxVar]]$setQfGap$fail <- setGap - + # Which of the windows has all gaps? Mark the test failure + setGapBgn <- which(numNaWndwGap == 4) + qfGap <- rep(0,numData) + for(idxGapBgn in setGapBgn){ + qfGap[idxGapBgn:(idxGapBgn+NumGapIdx-1)] <- 1 } - # For Verbose option, output actual flag values + setQf[[idxVar]]$setQfGap$fail <- which(qfGap == 1) + if(Vrbs) { - qf[[idxVar]]$qfGap[setQf[[idxVar]]$setQfGap$fail] <- 1 - qf[[idxVar]]$qfGap[setQf[[idxVar]]$setQfGap$na] <- -1 + qf[[idxVar]]$qfGap <- qfGap } + } # Return results From 9f17560c8909a662d1c40e070671199788e9fd89 Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Thu, 9 Jul 2020 10:03:32 -0600 Subject: [PATCH 074/168] add package dependency --- pack/eddy4R.qaqc/DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.qaqc/DESCRIPTION b/pack/eddy4R.qaqc/DESCRIPTION index afd4eac5..5f6a1681 100644 --- a/pack/eddy4R.qaqc/DESCRIPTION +++ b/pack/eddy4R.qaqc/DESCRIPTION @@ -17,7 +17,8 @@ Imports: lattice (>= 0.20-35), plyr (>= 1.8.4), reshape2 (>= 1.4.2), - Rmisc (>= 1.5) + Rmisc (>= 1.5), + RcppRoll (>= 0.3.0) Suggests: NEONprocIS.base License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 From 13e4b5402369907c7bf09d49cca7216f4502ddc5 Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Thu, 9 Jul 2020 13:28:29 -0600 Subject: [PATCH 075/168] bug fix (oddly never noticed before) --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.R index d7b37004..e0b98218 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.R @@ -238,10 +238,10 @@ wrap.dp01.qfqm <- function ( # Find data locations in window setData <- base::which((time >= timeAgrBgn[idxAgr]) & (time < timeAgrBgn[idxAgr]+WndwAgr)) - numDataAgr <- base::length(setData) + numDataIdxAgr <- base::length(setData) # If there is no data to process move to next aggregation window - if (numDataAgr == 0) { + if (numDataIdxAgr == 0) { next } From 271e063b6205e07bfe371381d3b8585e9f95e89f Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Thu, 9 Jul 2020 13:29:46 -0600 Subject: [PATCH 076/168] bug fix --- pack/eddy4R.qaqc/R/def.plau.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.plau.R b/pack/eddy4R.qaqc/R/def.plau.R index 047f67bc..ab23c897 100644 --- a/pack/eddy4R.qaqc/R/def.plau.R +++ b/pack/eddy4R.qaqc/R/def.plau.R @@ -233,7 +233,7 @@ def.plau <- function ( diffDataIdx <- diff(data[,idxVar]) diffDataNaIdx <- is.na(diffDataIdx) setNaDiffDataIdx <- which(diffDataNaIdx) - setNaDiffDataIdx <- which(!diffDataNaIdx) + setRealDiffDataIdx <- which(!diffDataNaIdx) setQf[[idxVar]]$setQfStep <- list(fail=numeric(0),na=numeric(0)) # initialize @@ -248,7 +248,7 @@ def.plau <- function ( } # If previous point is null, but next value is present, evaluate the step test with next value - setQf[[idxVar]]$setQfStep$na <- setdiff(setQf[[idxVar]]$setQfStep$na,setNaDiffDataIdx) + setQf[[idxVar]]$setQfStep$na <- setdiff(setQf[[idxVar]]$setQfStep$na,setRealDiffDataIdx) # For Verbose option, output actual flag values if(Vrbs) { From 97e1927074fe50e3542320a42e2c71b9bf03095a Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Thu, 9 Jul 2020 13:30:05 -0600 Subject: [PATCH 077/168] adjust call to def.rglr to work with new version --- pack/eddy4R.base/man/def.rglr.Rd | 2 +- pack/eddy4R.qaqc/R/def.agr.file.dp00.R | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.base/man/def.rglr.Rd b/pack/eddy4R.base/man/def.rglr.Rd index 92547cd1..f0950876 100644 --- a/pack/eddy4R.base/man/def.rglr.Rd +++ b/pack/eddy4R.base/man/def.rglr.Rd @@ -12,7 +12,7 @@ def.rglr( EndRglr = NULL, TzRglr = base::attributes(BgnRglr)$tzone, FreqRglr, - MethRglr = c("CybiEc", "cybiDflt", "zoo")[1], + MethRglr = c("CybiEc", "CybiEcTimeMeas", "zoo")[1], WndwRglr = c("Cntr", "Lead", "Trlg")[1], IdxWndw = c("Clst", "IdxWndwMin", "IdxWndwMax")[1], PrcsSec = 6 diff --git a/pack/eddy4R.qaqc/R/def.agr.file.dp00.R b/pack/eddy4R.qaqc/R/def.agr.file.dp00.R index e67388de..6432978c 100644 --- a/pack/eddy4R.qaqc/R/def.agr.file.dp00.R +++ b/pack/eddy4R.qaqc/R/def.agr.file.dp00.R @@ -37,6 +37,8 @@ # update @param format # Natchaya P-Durden (2018-04-11) # applied eddy4R term name convention; replaced pos by idx +# Cove Sturtevant (2020-07-09) +# adjust call to def.rglr to work with new version ############################################################################################## def.agr.file.dp00 <- function ( @@ -68,7 +70,9 @@ for(idxFile in 1:base::length(nameFile)){ data <- data[[2]] # Regularize time series. - data <- eddy4R.base::def.rglr(timeMeas=timeInp,dataMeas=as.data.frame(data),unitMeas=unitVar[idxFile],FreqRglr=Freq,MethRglr="CybiEc",WndwRglr='Trlg',IdxWndw='IdxWndwMin') + BgnRglr <- base::as.POSIXlt(base::trunc.POSIXt(timeInp[1],units="secs")) # Round down to the nearest whole second + EndRglr <- base::as.POSIXlt(utils::tail(timeInp,1)) + data <- eddy4R.base::def.rglr(timeMeas=timeInp,dataMeas=as.data.frame(data),unitMeas=unitVar[idxFile],BgnRglr=BgnRglr,EndRglr=EndRglr,FreqRglr=Freq,MethRglr="CybiEc",WndwRglr='Trlg',IdxWndw='IdxWndwMin') timeRglr[[idxFile]] <- data$timeRglr dataRglr[[idxFile]] <- data$dataRglr[[1]] From 87fa4c8b348f328af523f0d581f967072cb96fc0 Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Thu, 9 Jul 2020 20:33:23 -0600 Subject: [PATCH 078/168] additional optimization of persistence test achieved by turning time variable to seconds past start time --- pack/eddy4R.qaqc/DESCRIPTION | 2 +- pack/eddy4R.qaqc/R/def.plau.R | 15 +++++++++------ pack/eddy4R.qaqc/man/def.plau.Rd | 3 +-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pack/eddy4R.qaqc/DESCRIPTION b/pack/eddy4R.qaqc/DESCRIPTION index 5f6a1681..b362c7dd 100644 --- a/pack/eddy4R.qaqc/DESCRIPTION +++ b/pack/eddy4R.qaqc/DESCRIPTION @@ -1,6 +1,6 @@ Package: eddy4R.qaqc Title: Eddy-covariance calculation for R: Quality assurance and quality control -Version: 0.2.10 +Version: 0.2.11 Authors@R: c( person("Cove", "Sturtevant", email = "eddy4R.info@gmail.com", role = c("aut", "cre")), person("Stefan", "Metzger", email = "eddy4R.info@gmail.com", role = c("aut")), person("Natchaya", "Pingintha-Durden", email = "ndurden@battelleecology.org", role = c("aut")), diff --git a/pack/eddy4R.qaqc/R/def.plau.R b/pack/eddy4R.qaqc/R/def.plau.R index ab23c897..8e4ae07c 100644 --- a/pack/eddy4R.qaqc/R/def.plau.R +++ b/pack/eddy4R.qaqc/R/def.plau.R @@ -92,10 +92,12 @@ # also caught bug causing a potential lack of persistence test na flags when all values between 2 points are NA. # Cove Sturtevant (2020-07-08) # optimized gap test. WAY faster when there are a lot of gaps in the dataset +# Cove Sturtevant (2020-07-09) +# Additional optimization of persistence test achieved by turning time variable to numeric seconds past start ############################################################################################## def.plau <- function ( data, # a data frame containing the data to be evaluated (do not include the time stamp vector here). Required input. - time = as.POSIXlt(seq.POSIXt(from=Sys.time(),by="sec",length.out=length(data[,1]))), # time vector corresponding with the rows in data, in Class "POSIXlt", which is a named list of vectors representing sec, min, hour,day,mon,year. Defaults to an evenly spaced time vector starting from execution by seconds. + time = as.POSIXlt(seq.POSIXt(from=Sys.time(),by="sec",length.out=nrow(data))), # time vector corresponding with the rows in data, in Class "POSIXlt", which is a named list of vectors representing sec, min, hour,day,mon,year. Defaults to an evenly spaced time vector starting from execution by seconds. RngMin = apply(data,2,min,na.rm=TRUE), # a numeric vector containing the minimum acceptable value for each variable in data, defaults to observed minimums RngMax = apply(data,2,max,na.rm=TRUE), # a numeric vector containing the maximum acceptable value for each variable in data, defaults to observed maximums DiffStepMax = apply(abs(apply(data,2,diff)),2,max,na.rm=TRUE), # a vector containing the maximum acceptable absolute difference between sequential data points for each variable in data @@ -117,7 +119,7 @@ def.plau <- function ( # Initial stats numVar <- length(data) # Get number of variables nameData <- names(data) # Get variable names - numData <- length(data[,1]) + numData <- nrow(data) # Check time @@ -259,11 +261,12 @@ def.plau <- function ( # Do persistence test if(class(WndwPers) %in% c("numeric","integer")){ - # Figure out what the time-based representation would be - timePers <- as.POSIXlt(seq.POSIXt(from=Sys.time(),by="sec",length.out=length(data[,1]))) - WndwPers <- as.difftime(WndwPers,units='secs') + timePers <- seq_len(numData) } else { - timePers <- time + # Convert time to seconds past start. It's faster. + timePers <- as.numeric(time) # Turn time to # seconds past start + timePers <- timePers-timePers[1] + WndwPers <- as.double(WndwPers,units='secs') } for(idxVar in 1:numVar) { diff --git a/pack/eddy4R.qaqc/man/def.plau.Rd b/pack/eddy4R.qaqc/man/def.plau.Rd index 3f1e4ffd..518c9b27 100644 --- a/pack/eddy4R.qaqc/man/def.plau.Rd +++ b/pack/eddy4R.qaqc/man/def.plau.Rd @@ -6,8 +6,7 @@ \usage{ def.plau( data, - time = as.POSIXlt(seq.POSIXt(from = Sys.time(), by = "sec", length.out = - length(data[, 1]))), + time = as.POSIXlt(seq.POSIXt(from = Sys.time(), by = "sec", length.out = nrow(data))), RngMin = apply(data, 2, min, na.rm = TRUE), RngMax = apply(data, 2, max, na.rm = TRUE), DiffStepMax = apply(abs(apply(data, 2, diff)), 2, max, na.rm = TRUE), From f4ab96b924bf2acbf5763e018caa4a705508e42d Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 10 Jul 2020 17:31:15 +0000 Subject: [PATCH 079/168] - fixing setLgth issues when NaN rows omitted --- pack/eddy4R.stor/R/def.itpl.time.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.stor/R/def.itpl.time.R b/pack/eddy4R.stor/R/def.itpl.time.R index b0aab0eb..3a0046c9 100644 --- a/pack/eddy4R.stor/R/def.itpl.time.R +++ b/pack/eddy4R.stor/R/def.itpl.time.R @@ -38,6 +38,8 @@ # added failsafe for not to break the zoo::na.approx function when timeFrac are duplicate # Natchaya P-Durden (2020-04-24) # added failsafe replace NaN in numSamp with zero +# David Durden (2020-07-10) +# added failsafe to make sure the time and data lengths are the same for cases with setLgth = 2 ############################################################################################################## #Start of function call ############################################################################################################## @@ -112,7 +114,7 @@ def.itpl.time <- function( #remove na value if like that maxgap will not work dataInp <- na.omit(dataInp) #make sure use the right inpTime before interpolating - if (setLgth == 2){inpTime <- tmpTimeFrac}else{inpTime <- as.integer(dataInp$timeFrac * 60)} + if (setLgth == 2 && length(tmpTimeFrac) == setLgth){inpTime <- tmpTimeFrac}else{inpTime <- as.integer(dataInp$timeFrac * 60)} rpt <- zoo::na.approx(object=as.vector(dataInp$mean), x=#dataInp$timeFrac inpTime , xout=as.integer(timeFracOut * 60) From 3d96f820a855fa5fe2b6427c889f78fd59eaf834 Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 13 Jul 2020 14:04:42 +0000 Subject: [PATCH 080/168] - adding AMRS qfNull and qfSpk --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 49 +++++++++++++++++++++------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 4d8f92b3..f4ae00b3 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -747,51 +747,76 @@ if (MethMeas == "ecte") { setQf$accXaxs <- data.frame("qfRngAccXaxs" = qfInp$amrs$qfRngAccXaxs, "qfStepAccXaxs" = qfInp$amrs$qfStepAccXaxs, - "qfPersAccXaxs" = qfInp$amrs$qfPersAccXaxs) + "qfPersAccXaxs" = qfInp$amrs$qfPersAccXaxs, + "qfSpkAccXaxs" = qfInp$amrs$qfSpkAccXaxs, + "qfNullAccXaxs" = qfInp$amrs$qfNullAccXaxs + ) setQf$accYaxs <- data.frame("qfRngAccYaxs" = qfInp$amrs$qfRngAccYaxs, "qfStepAccYaxs" = qfInp$amrs$qfStepAccYaxs, - "qfPersAccYaxs" = qfInp$amrs$qfPersAccYaxs) + "qfPersAccYaxs" = qfInp$amrs$qfPersAccYaxs, + "qfSpkAccYaxs" = qfInp$amrs$qfSpkAccYaxs, + "qfNullAccYaxs" = qfInp$amrs$qfNullAccYaxs) setQf$accZaxs <- data.frame("qfRngAccZaxs" = qfInp$amrs$qfRngAccZaxs, "qfStepAccZaxs" = qfInp$amrs$qfStepAccZaxs, - "qfPersAccZaxs" = qfInp$amrs$qfPersAccZaxs) + "qfPersAccZaxs" = qfInp$amrs$qfPersAccZaxs, + "qfSpkAccZaxs" = qfInp$amrs$qfSpkAccZaxs, + "qfNullAccZaxs" = qfInp$amrs$qfNullAccZaxs) setQf$accXaxsDiff <- data.frame("qfRngAccXaxsDiff" = qfInp$amrs$qfRngAccXaxsDiff, "qfStepAccXaxsDiff" = qfInp$amrs$qfStepAccXaxsDiff, - "qfPersAccXaxsDiff" = qfInp$amrs$qfPersAccXaxsDiff) + "qfPersAccXaxsDiff" = qfInp$amrs$qfPersAccXaxsDiff, + "qfSpkAccXaxsDiff" = qfInp$amrs$qfSpkAccXaxsDiff, + "qfNullAccXaxsDiff" = qfInp$amrs$qfNullAccXaxsDiff) setQf$accYaxsDiff <- data.frame("qfRngAccYaxsDiff" = qfInp$amrs$qfRngAccYaxsDiff, "qfStepAccYaxsDiff" = qfInp$amrs$qfStepAccYaxsDiff, - "qfPersAccYaxsDiff" = qfInp$amrs$qfPersAccYaxsDiff) + "qfPersAccYaxsDiff" = qfInp$amrs$qfPersAccYaxsDiff, + "qfSpkAccYaxsDiff" = qfInp$amrs$qfSpkAccYaxsDiff, + "qfNullAccYaxsDiff" = qfInp$amrs$qfNullAccYaxsDiff) setQf$accZaxsDiff <- data.frame("qfRngAccZaxsDiff" = qfInp$amrs$qfRngAccZaxsDiff, "qfStepAccZaxsDiff" = qfInp$amrs$qfStepAccZaxsDiff, - "qfPersAccZaxsDiff" = qfInp$amrs$qfPersAccZaxsDiff) + "qfPersAccZaxsDiff" = qfInp$amrs$qfPersAccZaxsDiff, + "qfSpkAccZaxsDiff" = qfInp$amrs$qfSpkAccZaxsDiff, + "qfNullAccZaxsDiff" = qfInp$amrs$qfNullAccZaxsDiff) setQf$avelXaxs <- data.frame("qfRngAvelXaxs" = qfInp$amrs$qfRngAvelXaxs, "qfStepAvelXaxs" = qfInp$amrs$qfStepAvelXaxs, - "qfPersAvelXaxs" = qfInp$amrs$qfPersAvelXaxs) + "qfPersAvelXaxs" = qfInp$amrs$qfPersAvelXaxs, + "qfSpkAvelXaxs" = qfInp$amrs$qfSpkAvelXaxs, + "qfNullAvelXaxs" = qfInp$amrs$qfNullAvelXaxs) setQf$avelYaxs <- data.frame("qfRngAvelYaxs" = qfInp$amrs$qfRngAvelYaxs, "qfStepAvelYaxs" = qfInp$amrs$qfStepAvelYaxs, - "qfPersAvelYaxs" = qfInp$amrs$qfPersAvelYaxs) + "qfPersAvelYaxs" = qfInp$amrs$qfPersAvelYaxs, + "qfSpkAvelYaxs" = qfInp$amrs$qfSpkAvelYaxs, + "qfNullAvelYaxs" = qfInp$amrs$qfNullAvelYaxs) setQf$avelZaxs <- data.frame("qfRngAvelZaxs" = qfInp$amrs$qfRngAvelZaxs, "qfStepAvelZaxs" = qfInp$amrs$qfStepAvelZaxs, - "qfPersAvelZaxs" = qfInp$amrs$qfPersAvelZaxs) + "qfPersAvelZaxs" = qfInp$amrs$qfPersAvelZaxs, + "qfSpkAvelZaxs" = qfInp$amrs$qfSpkAvelZaxs, + "qfNullAvelZaxs" = qfInp$amrs$qfNullAvelZaxs) setQf$angXaxs <- data.frame("qfRngAngXaxs" = qfInp$amrs$qfRngAngXaxs, "qfStepAngXaxs" = qfInp$amrs$qfStepAngXaxs, - "qfPersAngXaxs" = qfInp$amrs$qfPersAngXaxs) + "qfPersAngXaxs" = qfInp$amrs$qfPersAngXaxs, + "qfSpkAngXaxs" = qfInp$amrs$qfSpkAngXaxs, + "qfNullAngXaxs" = qfInp$amrs$qfNullAngXaxs) setQf$angYaxs <- data.frame("qfRngAngYaxs" = qfInp$amrs$qfRngAngYaxs, "qfStepAngYaxs" = qfInp$amrs$qfStepAngYaxs, - "qfPersAngYaxs" = qfInp$amrs$qfPersAngYaxs) + "qfPersAngYaxs" = qfInp$amrs$qfPersAngYaxs, + "qfSpkAngYaxs" = qfInp$amrs$qfSpkAngYaxs, + "qfNullAngYaxs" = qfInp$amrs$qfNullAngYaxs) setQf$angZaxs <- data.frame("qfRngAngZaxs" = qfInp$amrs$qfRngAngZaxs, "qfStepAngZaxs" = qfInp$amrs$qfStepAngZaxs, - "qfPersAngZaxs" = qfInp$amrs$qfPersAngZaxs) + "qfPersAngZaxs" = qfInp$amrs$qfPersAngZaxs, + "qfSpkAngZaxs" = qfInp$amrs$qfSpkAngZaxs, + "qfNullAngZaxs" = qfInp$amrs$qfNullAngZaxs) #grouping qulity flags that related to L1 sub-data product rpt$angNedXaxs <- data.frame(setQf$sensAmrs, setQf$angXaxs) From ca3fe2fa7277ebcea40cb4bb61d6aaf5e03e2217 Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 13 Jul 2020 14:09:36 +0000 Subject: [PATCH 081/168] - adding soni qfSpk and qfNull --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index f4ae00b3..95d92ccb 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -521,27 +521,37 @@ if (MethMeas == "ecte") { #qf for along-axis wind speed setQf$veloXaxs <- data.frame("qfRngVeloXaxs" = qfInp$soni$qfRngVeloXaxs, "qfStepVeloXaxs" = qfInp$soni$qfStepVeloXaxs, - "qfPersVeloXaxs" = qfInp$soni$qfPersVeloXaxs) + "qfPersVeloXaxs" = qfInp$soni$qfPersVeloXaxs, + "qfSpkVeloXaxs" = qfInp$soni$qfSpkVeloXaxs, + "qfNullVeloXaxs" = qfInp$soni$qfNullVeloXaxs) #"qfCalVeloXaxs" = qfInp$soni$qfCalVeloXaxs) #qf for cross-axis wind speed setQf$veloYaxs <- data.frame("qfRngVeloYaxs" = qfInp$soni$qfRngVeloYaxs, "qfStepVeloYaxs" = qfInp$soni$qfStepVeloYaxs, - "qfPersVeloYaxs" = qfInp$soni$qfPersVeloYaxs) + "qfPersVeloYaxs" = qfInp$soni$qfPersVeloYaxs, + "qfSpkVeloYaxs" = qfInp$soni$qfSpkVeloYaxs, + "qfNullVeloYaxs" = qfInp$soni$qfNullVeloYaxs) #"qfCalVeloYaxs" = qfInp$soni$qfCalVeloYaxs) #qf for vertical-axis wind speed setQf$veloZaxs <- data.frame("qfRngVeloZaxs" = qfInp$soni$qfRngVeloZaxs, "qfStepVeloZaxs" = qfInp$soni$qfStepVeloZaxs, - "qfPersVeloZaxs" = qfInp$soni$qfPersVeloZaxs) + "qfPersVeloZaxs" = qfInp$soni$qfPersVeloZaxs, + "qfSpkVeloZaxs" = qfInp$soni$qfSpkVeloZaxs, + "qfNullVeloZaxs" = qfInp$soni$qfNullVeloZaxs) #"qfCalVeloZaxs" = qfInp$soni$qfCalVeloZaxs) #qf for sonic velocity setQf$veloSoni <- data.frame("qfRngVeloSoni" = qfInp$soni$qfRngVeloSoni, "qfStepVeloSoni" = qfInp$soni$qfStepVeloSoni, - "qfPersVeloSoni" = qfInp$soni$qfPersVeloSoni) + "qfPersVeloSoni" = qfInp$soni$qfPersVeloSoni, + "qfSpkVeloSoni" = qfInp$soni$qfSpkVeloSoni, + "qfNullVeloSoni" = qfInp$soni$qfNullVeloSoni) #"qfCalVeloSoni" = qfInp$soni$qfCalVeloSoni) #qf for soic temperature setQf$tempSoni <- data.frame("qfRngTempSoni" = qfInp$soni$qfRngTempSoni, "qfStepTempSoni" = qfInp$soni$qfStepTempSoni, - "qfPersTempSoni" = qfInp$soni$qfPersTempSoni) + "qfPersTempSoni" = qfInp$soni$qfPersTempSoni, + "qfSpkTempSoni" = qfInp$soni$qfSpkTempSoni, + "qfNullTempSoni" = qfInp$soni$qfNullTempSoni) #"qfCalTempSoni" = qfInp$soni$qfCalTempSoni) #external quality flags from irgaTurb for grouping qf of tempAir From da03d9e8fa67c95d12e40e0c767427e58cbbb8ea Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 13 Jul 2020 14:33:45 +0000 Subject: [PATCH 082/168] - adding co2Turb and h2oTurb qfSpk and qfNull flags --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 136 ++++++++++++++++++++------- 1 file changed, 102 insertions(+), 34 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 95d92ccb..f9a820da 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -174,158 +174,218 @@ if (MethMeas == "ecte") { setQf$tempIn <- data.frame("qfRngTempIn" = qfInp$irgaTurb$qfRngTempIn, "qfStepTempIn" = qfInp$irgaTurb$qfStepTempIn, - "qfPersTempIn" = qfInp$irgaTurb$qfPersTempIn) + "qfPersTempIn" = qfInp$irgaTurb$qfPersTempIn, + "qfSpkTempIn" = qfInp$irgaTurb$qfSpkTempIn, + "qfNullTempIn" = qfInp$irgaTurb$qfNullTempIn) #"qfCalTempIn" = qfInp$irgaTurb$qfCalTempIn) setQf$tempOut <- data.frame("qfRngTempOut" = qfInp$irgaTurb$qfRngTempOut, "qfStepTempOut" = qfInp$irgaTurb$qfStepTempOut, - "qfPersTempOut" = qfInp$irgaTurb$qfPersTempOut) + "qfPersTempOut" = qfInp$irgaTurb$qfPersTempOut, + "qfSpkTempOut" = qfInp$irgaTurb$qfSpkTempOut, + "qfNullTempOut" = qfInp$irgaTurb$qfNullTempOut) #"qfCalTempOut" = qfInp$irgaTurb$qfCalTempOut) setQf$tempAve <- data.frame ("qfRngTempMean" = qfInp$irgaTurb$qfRngTempMean, "qfStepTempMean" = qfInp$irgaTurb$qfStepTempMean, - "qfPersTempMean" = qfInp$irgaTurb$qfPersTempMean) + "qfPersTempMean" = qfInp$irgaTurb$qfPersTempMean, + "qfSpkTempMean" = qfInp$irgaTurb$qfSpkTempMean, + "qfNullTempMean" = qfInp$irgaTurb$qfNullTempMean) #"qfCalTempMean" = qfInp$irgaTurb$qfCalTempMean) setQf$presAtmIrgaTurb <- data.frame("qfRngPresAtm" = qfInp$irgaTurb$qfRngPresAtm, "qfStepPresAtm" = qfInp$irgaTurb$qfStepPresAtm, - "qfPersPresAtm" = qfInp$irgaTurb$qfPersPresAtm) + "qfPersPresAtm" = qfInp$irgaTurb$qfPersPresAtm, + "qfSpkPresAtm" = qfInp$irgaTurb$qfSpkPresAtm, + "qfNullPresAtm" = qfInp$irgaTurb$qfNullPresAtm) #"qfCalPresAtm" = qfInp$irgaTurb$qfCalPresAtm) setQf$presDiffIrgaTurb <- data.frame("qfRngPresDiff" = qfInp$irgaTurb$qfRngPresDiff, "qfStepPresDiff" = qfInp$irgaTurb$qfStepPresDiff, - "qfPersPresDiff" = qfInp$irgaTurb$qfPersPresDiff) + "qfPersPresDiff" = qfInp$irgaTurb$qfPersPresDiff, + "qfSpkPresDiff" = qfInp$irgaTurb$qfSpkPresDiff, + "qfNullPresDiff" = qfInp$irgaTurb$qfNullPresDiff) #"qfCalPresDiff" = qfInp$irgaTurb$qfCalPresDiff) setQf$presSum <- data.frame("qfRngPresSum" = qfInp$irgaTurb$qfRngPresSum, "qfStepPresSum" = qfInp$irgaTurb$qfStepPresSum, - "qfPersPresSum" = qfInp$irgaTurb$qfPersPresSum) + "qfPersPresSum" = qfInp$irgaTurb$qfPersPresSum, + "qfSpkPresSum" = qfInp$irgaTurb$qfSpkPresSum, + "qfNullPresSum" = qfInp$irgaTurb$qfNullPresSum) #"qfCalPresSum" = qfInp$irgaTurb$qfCalPresSum) setQf$powrH2oSamp <- data.frame ("qfRngPowrH2oSamp" = qfInp$irgaTurb$qfRngPowrH2oSamp, "qfStepPowrH2oSamp" = qfInp$irgaTurb$qfStepPowrH2oSamp, - "qfPersPowrH2oSamp" = qfInp$irgaTurb$qfPersPowrH2oSamp) + "qfPersPowrH2oSamp" = qfInp$irgaTurb$qfPersPowrH2oSamp, + "qfSpkPowrH2oSamp" = qfInp$irgaTurb$qfSpkPowrH2oSamp, + "qfNullPowrH2oSamp" = qfInp$irgaTurb$qfNullPowrH2oSamp) #"qfCalPowrH2oSamp" = qfInp$irgaTurb$qfCalPowrH2oSamp) setQf$powrH2oRefe <- data.frame ("qfRngPowrH2oRefe" = qfInp$irgaTurb$qfRngPowrH2oRefe, "qfStepPowrH2oRefe" = qfInp$irgaTurb$qfStepPowrH2oRefe, - "qfPersPowrH2oRefe" = qfInp$irgaTurb$qfPersPowrH2oRefe) + "qfPersPowrH2oRefe" = qfInp$irgaTurb$qfPersPowrH2oRefe, + "qfSpkPowrH2oRefe" = qfInp$irgaTurb$qfSpkPowrH2oRefe, + "qfNullPowrH2oRefe" = qfInp$irgaTurb$qfNullPowrH2oRefe) #"qfCalPowrH2oRefe" = qfInp$irgaTurb$qfCalPowrH2oRefe) setQf$asrpH2o <- data.frame("qfRngAsrpH2o" = qfInp$irgaTurb$qfRngAsrpH2o, "qfStepAsrpH2o" = qfInp$irgaTurb$qfStepAsrpH2o, - "qfPersAsrpH2o" = qfInp$irgaTurb$qfPersAsrpH2o) + "qfPersAsrpH2o" = qfInp$irgaTurb$qfPersAsrpH2o, + "qfSpkAsrpH2o" = qfInp$irgaTurb$qfSpkAsrpH2o, + "qfNullAsrpH2o" = qfInp$irgaTurb$qfNullAsrpH2o) #"qfCalAsrpH2o" = qfInp$irgaTurb$qfCalAsrpH2o) setQf$densMoleH2o <- data.frame("qfRngDensMoleH2o" = qfInp$irgaTurb$qfRngDensMoleH2o, "qfStepDensMoleH2o" = qfInp$irgaTurb$qfStepDensMoleH2o, - "qfPersDensMoleH2o" = qfInp$irgaTurb$qfPersDensMoleH2o) + "qfPersDensMoleH2o" = qfInp$irgaTurb$qfPersDensMoleH2o, + "qfSpkDensMoleH2o" = qfInp$irgaTurb$qfSpkDensMoleH2o, + "qfNullDensMoleH2o" = qfInp$irgaTurb$qfNullDensMoleH2o) #"qfCalDensMoleH2o" = qfInp$irgaTurb$qfCalDensMoleH2o) setQf$rtioMoleDryH2o <- data.frame("qfRngRtioMoleDryH2o" = qfInp$irgaTurb$qfRngRtioMoleDryH2o, "qfStepRtioMoleDryH2o" = qfInp$irgaTurb$qfStepRtioMoleDryH2o, - "qfPersRtioMoleDryH2o" = qfInp$irgaTurb$qfPersRtioMoleDryH2o) + "qfPersRtioMoleDryH2o" = qfInp$irgaTurb$qfPersRtioMoleDryH2o, + "qfSpkRtioMoleDryH2o" = qfInp$irgaTurb$qfSpkRtioMoleDryH2o, + "qfNullRtioMoleDryH2o" = qfInp$irgaTurb$qfNullRtioMoleDryH2o) #"qfCalRtioMoleDryH2o" = qfInp$irgaTurb$qfCalRtioMoleDryH2o) setQf$powrCo2Samp <- data.frame("qfRngPowrCo2Samp" = qfInp$irgaTurb$qfRngPowrCo2Samp, "qfStepPowrCo2Samp" = qfInp$irgaTurb$qfStepPowrCo2Samp, - "qfPersPowrCo2Samp" = qfInp$irgaTurb$qfPersPowrCo2Samp) + "qfPersPowrCo2Samp" = qfInp$irgaTurb$qfPersPowrCo2Samp, + "qfSpkPowrCo2Samp" = qfInp$irgaTurb$qfSpkPowrCo2Samp, + "qfNullPowrCo2Samp" = qfInp$irgaTurb$qfNullPowrCo2Samp) #"qfCalPowrCo2Samp" = qfInp$irgaTurb$qfCalPowrCo2Samp) setQf$powrCo2Refe <- data.frame ("qfRngPowrCo2Refe" = qfInp$irgaTurb$qfRngPowrCo2Refe, "qfStepPowrCo2Refe" = qfInp$irgaTurb$qfStepPowrCo2Refe, - "qfPersPowrCo2Refe" = qfInp$irgaTurb$qfPersPowrCo2Refe) + "qfPersPowrCo2Refe" = qfInp$irgaTurb$qfPersPowrCo2Refe, + "qfSpkPowrCo2Refe" = qfInp$irgaTurb$qfSpkPowrCo2Refe, + "qfNullPowrCo2Refe" = qfInp$irgaTurb$qfNullPowrCo2Refe) #"qfCalPowrCo2Refe" = qfInp$irgaTurb$qfCalPowrCo2Refe) setQf$asrpCo2 <- data.frame("qfRngAsrpCo2" = qfInp$irgaTurb$qfRngAsrpCo2, "qfStepAsrpCo2" = qfInp$irgaTurb$qfStepAsrpCo2, - "qfPersAsrpCo2" = qfInp$irgaTurb$qfPersAsrpCo2) + "qfPersAsrpCo2" = qfInp$irgaTurb$qfPersAsrpCo2, + "qfSpkAsrpCo2" = qfInp$irgaTurb$qfSpkAsrpCo2, + "qfNullAsrpCo2" = qfInp$irgaTurb$qfNullAsrpCo2) #"qfCalAsrpCo2" = qfInp$irgaTurb$qfCalAsrpCo2) setQf$densMoleCo2 <- data.frame("qfRngDensMoleCo2" = qfInp$irgaTurb$qfRngDensMoleCo2, "qfStepDensMoleCo2" = qfInp$irgaTurb$qfStepDensMoleCo2, - "qfPersDensMoleCo2" = qfInp$irgaTurb$qfPersDensMoleCo2) + "qfPersDensMoleCo2" = qfInp$irgaTurb$qfPersDensMoleCo2, + "qfSpkDensMoleCo2" = qfInp$irgaTurb$qfSpkDensMoleCo2, + "qfNullDensMoleCo2" = qfInp$irgaTurb$qfNullDensMoleCo2) #"qfCalDensMoleCo2" = qfInp$irgaTurb$qfCalDensMoleCo2) setQf$rtioMoleDryCo2 <- data.frame("qfRngRtioMoleDryCo2" = qfInp$irgaTurb$qfRngRtioMoleDryCo2, "qfStepRtioMoleDryCo2" = qfInp$irgaTurb$qfStepRtioMoleDryCo2, - "qfPersRtioMoleDryCo2" = qfInp$irgaTurb$qfPersRtioMoleDryCo2) + "qfPersRtioMoleDryCo2" = qfInp$irgaTurb$qfPersRtioMoleDryCo2, + "qfSpkRtioMoleDryCo2" = qfInp$irgaTurb$qfSpkRtioMoleDryCo2, + "qfNullRtioMoleDryCo2" = qfInp$irgaTurb$qfNullRtioMoleDryCo2) # "qfCalRtioMoleDryCo2" = qfInp$irgaTurb$qfCalRtioMoleDryCo2) setQf$ssiCo2 <- data.frame("qfRngSsiCo2" = qfInp$irgaTurb$qfRngSsiCo2, "qfStepSsiCo2" = qfInp$irgaTurb$qfStepSsiCo2, - "qfPersSsiCo2" = qfInp$irgaTurb$qfPersSsiCo2) + "qfPersSsiCo2" = qfInp$irgaTurb$qfPersSsiCo2, + "qfSpkSsiCo2" = qfInp$irgaTurb$qfSpkSsiCo2, + "qfNullSsiCo2" = qfInp$irgaTurb$qfNullSsiCo2) #"qfCalSsiCo2" = qfInp$irgaTurb$qfCalSsiCo2) setQf$ssiH2o <- data.frame("qfRngSsiH2o" = qfInp$irgaTurb$qfRngSsiH2o, "qfStepSsiH2o" = qfInp$irgaTurb$qfStepSsiH2o, - "qfPersSsiH2o" = qfInp$irgaTurb$qfPersSsiH2o) + "qfPersSsiH2o" = qfInp$irgaTurb$qfPersSsiH2o, + "qfSpkSsiH2o" = qfInp$irgaTurb$qfSpkSsiH2o, + "qfNullSsiH2o" = qfInp$irgaTurb$qfNullSsiH2o) #"qfCalSsiH2o" = qfInp$irgaTurb$qfCalSsiH2o) #external quality flags from mfcSampTurb if ("mfcSampTurb" %in% names(qfInp)){ #mfcSampTurb - setQf$frt00MfcSampTurb <- data.frame("qfRngFrt00" = qfInp$mfcSampTurb$qfRngFrt00) + setQf$frt00MfcSampTurb <- data.frame("qfRngFrt00" = qfInp$mfcSampTurb$qfRngFrt00,"qfSpkFrt00" = qfInp$mfcSampTurb$qfSpkFrt00,"qfNullFrt00" = qfInp$mfcSampTurb$qfNullFrt00) #,"qfPersFrt00" = qfInp$mfcSampTurb$qfPersFrt00) setQf$frtMfcSampTurb <- data.frame("qfRngFrt" = qfInp$mfcSampTurb$qfRngFrt, - "qfPersFrt" = qfInp$mfcSampTurb$qfPersFrt) + "qfPersFrt" = qfInp$mfcSampTurb$qfPersFrt, + "qfSpkFrt" = qfInp$mfcSampTurb$qfSpkFrt, + "qfNullFrt" = qfInp$mfcSampTurb$qfNullFrt) setQf$presAtmMfcSampTurb <- data.frame("qfRngPresAtm" = qfInp$mfcSampTurb$qfRngPresAtm, "qfStepPresAtm" = qfInp$mfcSampTurb$qfStepPresAtm, - "qfPersPresAtm" = qfInp$mfcSampTurb$qfPersPresAtm) + "qfPersPresAtm" = qfInp$mfcSampTurb$qfPersPresAtm, + "qfSpkPresAtm" = qfInp$mfcSampTurb$qfSpkPresAtm, + "qfNullPresAtm" = qfInp$mfcSampTurb$qfNullPresAtm) setQf$tempMfcSampTurb <- data.frame("qfRngTemp" = qfInp$mfcSampTurb$qfRngTemp, "qfStepTemp" = qfInp$mfcSampTurb$qfStepTemp, - "qfPersTemp" = qfInp$mfcSampTurb$qfPersTemp) + "qfPersTemp" = qfInp$mfcSampTurb$qfPersTemp, + "qfSpkTemp" = qfInp$mfcSampTurb$qfSpkTemp, + "qfNullTemp" = qfInp$mfcSampTurb$qfNullTemp) } else { #assign qf for mfcSampTurb to -1 when qf mfcSampTurb is missing - setQf$frt00MfcSampTurb <- data.frame("qfRngFrt00" = -1) + setQf$frt00MfcSampTurb <- data.frame("qfRngFrt00" = -1,"qfSpkFrt00" = -1,"qfNullFrt00" = -1) #,"qfPersFrt00" = -1) setQf$frtMfcSampTurb <- data.frame("qfRngFrt" = -1, - "qfPersFrt" = -1) + "qfPersFrt" = -1, + "qfSpkFrt" = -1, + "qfNullFrt" = -1) setQf$presAtmMfcSampTurb <- data.frame("qfRngPresAtm" = -1, "qfStepPresAtm" = -1, - "qfPersPresAtm" = -1) + "qfPersPresAtm" = -1, + "qfSpkPresAtm" = -1, + "qfNullPresAtm" = -1) setQf$tempMfcSampTurb <- data.frame("qfRngTemp" = -1, "qfStepTemp" = -1, - "qfPersTemp" = -1) + "qfPersTemp" = -1, + "qfSpkTemp" = -1, + "qfNullTemp" = -1) } #external quality flags from mfcValiTurb if ("mfcValiTurb" %in% names(qfInp)){ #mfcValiTurb - setQf$frt00MfcValiTurb <- data.frame("qfRngFrt00" = qfInp$mfcValiTurb$qfRngFrt00) + setQf$frt00MfcValiTurb <- data.frame("qfRngFrt00" = qfInp$mfcValiTurb$qfRngFrt00, "qfSpkFrt00" = qfInp$mfcValiTurb$qfSpkFrt00, "qfNullFrt00" = qfInp$mfcValiTurb$qfNullFrt00) # "qfPersFrt00" = qfInp$mfcValiTurb$qfPersFrt00) setQf$frtMfcValiTurb <- data.frame("qfRngFrt" = qfInp$mfcValiTurb$qfRngFrt, - "qfPersFrt" = qfInp$mfcValiTurb$qfPersFrt) + "qfPersFrt" = qfInp$mfcValiTurb$qfPersFrt, + "qfSpkFrt" = qfInp$mfcValiTurb$qfSpkFrt, + "qfNullFrt" = qfInp$mfcValiTurb$qfNullFrt) setQf$presAtmMfcValiTurb <- data.frame("qfRngPresAtm" = qfInp$mfcValiTurb$qfRngPresAtm, "qfStepPresAtm" = qfInp$mfcValiTurb$qfStepPresAtm, - "qfPersPresAtm" = qfInp$mfcValiTurb$qfPersPresAtm) + "qfPersPresAtm" = qfInp$mfcValiTurb$qfPersPresAtm, + "qfSpkPresAtm" = qfInp$mfcValiTurb$qfSpkPresAtm, + "qfNullPresAtm" = qfInp$mfcValiTurb$qfNullPresAtm) setQf$tempMfcValiTurb <- data.frame("qfRngTemp" = qfInp$mfcValiTurb$qfRngTemp, "qfStepTemp" = qfInp$mfcValiTurb$qfStepTemp, - "qfPersTemp" = qfInp$mfcValiTurb$qfPersTemp) + "qfPersTemp" = qfInp$mfcValiTurb$qfPersTemp, + "qfSpkTemp" = qfInp$mfcValiTurb$qfSpkTemp, + "qfNullTemp" = qfInp$mfcValiTurb$qfNullTemp) } else { #assign qf for mfcValiTurb to -1 when qf mfcValiTurb is missing - setQf$frt00MfcValiTurb <- data.frame("qfRngFrt00" = -1) + setQf$frt00MfcValiTurb <- data.frame("qfRngFrt00" = -1, "qfSpkFrt00" = -1, "qfNullFrt00" = -1) #"qfPersFrt00" = -1) setQf$frtMfcValiTurb <- data.frame("qfRngFrt" = -1, - "qfPersFrt" = -1) + "qfPersFrt" = -1, + "qfSpkFrt" = -1, + "qfNullFrt" = -1) setQf$presAtmMfcValiTurb <- data.frame("qfRngPresAtm" = -1, "qfStepPresAtm" = -1, - "qfPersPresAtm" = -1) + "qfPersPresAtm" = -1, + "qfSpkPresAtm" = -1, + "qfNullPresAtm" = -1) setQf$tempMfcValiTurb <- data.frame("qfRngTemp" = -1, "qfStepTemp" = -1, - "qfPersTemp" = -1) + "qfPersTemp" = -1, + "qfSpkTemp" = -1, + "qfNullTemp" = -1) } #quality flags from soni for grouping qf of tempDew @@ -334,10 +394,14 @@ if (MethMeas == "ecte") { "qfPersVeloSoni" = qfInp$soni$qfPersVeloSoni, "qfRngVeloSoni" = qfInp$soni$qfRngVeloSoni, "qfStepVeloSoni" = qfInp$soni$qfStepVeloSoni, + "qfNullVeloSoni" = qfInp$soni$qfNullVeloSoni, + "qfSpkVeloSoni" = qfInp$soni$qfSpkVeloSoni, #"qfCalTempSoni" = qfInp$soni$qfCalTempSoni, "qfPersTempSoni" = qfInp$soni$qfPersTempSoni, "qfRngTempSoni" = qfInp$soni$qfRngTempSoni, "qfStepTempSoni" = qfInp$soni$qfStepTempSoni, + "qfNullTempSoni" = qfInp$soni$qfNullTempSoni, + "qfSpkTempSoni" = qfInp$soni$qfSpkTempSoni, "qfSoniUnrs" = qfInp$soni$qfSoniUnrs, "qfSoniData" = qfInp$soni$qfSoniData, "qfSoniTrig" = qfInp$soni$qfSoniTrig, @@ -353,10 +417,14 @@ if (MethMeas == "ecte") { "qfPersVeloSoni" = -1, "qfRngVeloSoni" = -1, "qfStepVeloSoni" = -1, + "qfNullVeloSoni" = -1, + "qfSpkVeloSoni" = -1, #"qfCalTempSoni" = -1, "qfPersTempSoni" = -1, "qfRngTempSoni" = -1, "qfStepTempSoni" = -1, + "qfNullTempSoni" = -1, + "qfSpkTempSoni" = -1, "qfSoniUnrs" = -1, "qfSoniData" = -1, "qfSoniTrig" = -1, From c5b204e17d350a0c4fbd112b38692a5707ac8738 Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 13 Jul 2020 14:35:20 +0000 Subject: [PATCH 083/168] - fixing despiking flag output --- pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R | 32 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R b/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R index ec78ec6b..2592bd0d 100644 --- a/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R +++ b/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R @@ -63,36 +63,46 @@ wrap.qf.rmv.data <- function( if(MethMeas == "ecte"){ # Determine quality flags to apply to each stream, quantify flags, and remove bad data across all sensors outList <- base::lapply(Sens, function(x){ - def.qf.rmv.data(inpData = inpList$data[[x]][], inpQf = inpList$qfqm[[x]], Sens = x, qfRmv = qfRmv, Vrbs = Vrbs) #Remove high frequency data that is flagged by sensor specific flags or plausibility tests flags + eddy4R.qaqc::def.qf.rmv.data(inpData = inpList$data[[x]][], inpQf = inpList$qfqm[[x]], Sens = x, qfRmv = qfRmv, Vrbs = Vrbs) #Remove high frequency data that is flagged by sensor specific flags or plausibility tests flags }) #Apply names to the output list base::names(outList) <- Sens #Despiking routine - test <- base::lapply(Sens, function(x){ - #x <- "irgaTurb" #for testing - varDspk <- names(outList[[x]]$inpData)[!names(outList[[x]]$inpData) %in% c("time","idx")] - tmp <- base::lapply(varDspk, function(y){ - eddy4R.qaqc::def.dspk.br86( +base::lapply(Sens, function(x){ + #x <- Sens[2] #for testing + print(x) + varDspk <- names(outList[[x]]$inpData)[!names(outList[[x]]$inpData) %in% c("time","idx","frtSet00")] + base::lapply(varDspk, function(y){ + print(y) + #y <- "asrpCo2" + tmp <- eddy4R.qaqc::def.dspk.br86( # input data, univariate vector of integers or numerics - dataInp = outList[[x]][[y]], + dataInp = outList[[x]]$inpData[[y]][], # filter width WndwFilt = as.numeric(ramattribs(inpList$data[[x]][[y]])$`Dspk$Br86$NumWndw`), # initial number/step size of histogram bins NumBin = as.numeric(ramattribs(inpList$data[[x]][[y]])$`Dspk$Br86$NumBin`), # resolution threshold ThshReso = as.numeric(ramattribs(inpList$data[[x]][[y]])$`Dspk$Br86$MaxReso`) - )$dataOut #Remove high frequency data that is flagged by sensor specific flags or plausibility tests flags - }) - }) + ) #Remove high frequency data that is flagged by sensor specific flags or plausibility tests flags + outList[[x]]$inpData[[y]] <<- tmp$dataOut + + #Create flag name + nameQf <- base::paste0("qfSpk",base::toupper(base::substring(y,1,1)),base::substring(y,2,base::nchar(y))) + #Output despiking flag + outList[[x]]$qfSpk[[nameQf]] <<- tmp$qfSpk + + }) #End lapply for variables + })#End lapply around sensors #Applying the bad quality flags to the reported output data base::lapply(base::names(outList), function(x) { #Outputting the data ffdf's rpt$data[[x]] <<- ff::as.ffdf(outList[[x]]$inpData) rpt$data[[x]] <<- eddy4R.base::def.unit.var(samp = rpt$data[[x]], refe = inpList$data[[x]]) #Copy units - rpt$qfqm[[x]] <<- ff::as.ffdf(base::cbind(rpt$qfqm[[x]][], outList$irgaTurb$qfNull)) + rpt$qfqm[[x]] <<- ff::as.ffdf(base::cbind(rpt$qfqm[[x]][], outList[[x]]$qfNull, as.data.frame(outList[[x]]$qfSpk))) }) #If verbose is true write out all the information about the quality flags applied to the raw data From 4dca1bfee24282b65035537ba3d16a29757a3d70 Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 14 Jul 2020 16:34:52 +0000 Subject: [PATCH 084/168] - Added qfNull and qfSpk for all variables, removed qfNull from ancillary data streams --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index f9a820da..cb2734f2 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -86,6 +86,8 @@ # adding qfHeat to ECSE # Natchaya P-Durden (2020-03-11) # removed qfCal and qfHeat from ECSE +# David Durden (2020-07-14) +# Added qfNull and qfSpk for all variables, removed qfNull from ancillary data streams ############################################################################################## def.dp01.grp.qf <- function( @@ -2263,6 +2265,20 @@ if (MethMeas == "ecse") { }#close if statement of dp01 == tempAirLvl }# closed if statement of MethMeas == "ecse" +#Create name vector +nameVar <- names(rpt) + +#calculate qmAlpha, qmBeta, qfFinl +rpt <- lapply(names(rpt), function(x){ + nameQfNull <- grep("null", names(rpt[[x]]), ignore.case=TRUE, value = TRUE) + nameQfNullRmv <- grep(x, nameQfNull, ignore.case=TRUE, value = TRUE, invert = TRUE) + outQf <- rpt[[x]][,!names(inp[[x]]) %in% nameQfNullRmv] + #Return output + return(outQf) + })#End lapply around removing other variables qfNull flags +#Reattribute variable names +names(rpt) <- nameVar + #return values return(rpt) From 0f67c246146b482d91dfcd5066a42f0eb0d86b3f Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 14 Jul 2020 16:58:19 +0000 Subject: [PATCH 085/168] - removing testing print statements --- pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R b/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R index 2592bd0d..5a1333f8 100644 --- a/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R +++ b/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R @@ -72,10 +72,10 @@ wrap.qf.rmv.data <- function( #Despiking routine base::lapply(Sens, function(x){ #x <- Sens[2] #for testing - print(x) + #print(x) varDspk <- names(outList[[x]]$inpData)[!names(outList[[x]]$inpData) %in% c("time","idx","frtSet00")] base::lapply(varDspk, function(y){ - print(y) + #print(y) #y <- "asrpCo2" tmp <- eddy4R.qaqc::def.dspk.br86( # input data, univariate vector of integers or numerics From 843700a430047f2a62be48a96b4f16704c98e2a8 Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 14 Jul 2020 16:59:46 +0000 Subject: [PATCH 086/168] - adding documentation --- pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R b/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R index 5a1333f8..1971f245 100644 --- a/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R +++ b/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R @@ -41,6 +41,8 @@ # replaced dfQf by inpQf # Natchaya P-Durden (2019-03-12) # added Sens and qfRmv into the function parameter list +# David Durden (2020-07-14) +# added despiking routine and output qfSpk and qfNull ############################################################################################## From 18250eb94dcbdc979cd18dba024f5ec58a2569d2 Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 14 Jul 2020 19:22:12 +0000 Subject: [PATCH 087/168] - bug fix --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index cb2734f2..d6c092da 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -2272,7 +2272,7 @@ nameVar <- names(rpt) rpt <- lapply(names(rpt), function(x){ nameQfNull <- grep("null", names(rpt[[x]]), ignore.case=TRUE, value = TRUE) nameQfNullRmv <- grep(x, nameQfNull, ignore.case=TRUE, value = TRUE, invert = TRUE) - outQf <- rpt[[x]][,!names(inp[[x]]) %in% nameQfNullRmv] + outQf <- rpt[[x]][,!names(rpt[[x]]) %in% nameQfNullRmv] #Return output return(outQf) })#End lapply around removing other variables qfNull flags From 8baa04f182c82ee153777ba4ab7f585a4ca6756a Mon Sep 17 00:00:00 2001 From: ddurden Date: Thu, 16 Jul 2020 05:41:25 +0000 Subject: [PATCH 088/168] - adding information for failed gold file match --- pack/eddy4R.base/R/def.mtch.out.refe.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/def.mtch.out.refe.R b/pack/eddy4R.base/R/def.mtch.out.refe.R index 5f5fd4fd..f62b7a00 100644 --- a/pack/eddy4R.base/R/def.mtch.out.refe.R +++ b/pack/eddy4R.base/R/def.mtch.out.refe.R @@ -39,6 +39,8 @@ # rename to def.mtch.out.refe() # Natchaya P-Durden (2018-04-03) # update @param format +# David Durden (2020-07-16) +# add some information when it falls ############################################################################################## def.mtch.out.refe <- function( @@ -55,7 +57,7 @@ def.mtch.out.refe <- function( #Compare the first numLine lines of the data between the output and reference if(!isTRUE(base::all.equal(dataOut[1:NumLine,],dataRefe[1:NumLine,]))){ - base::stop("Bummer! The current output DOES NOT MATCH the reference output :(") + base::stop(cat("Summary output: \n dataOut & dataRefe \n", str(dataOut[1:NumLine,]),"\n\n", str(dataRefe[1:NumLine,]),"Bummer! The current output DOES NOT MATCH the reference output :( ==> diferences are: \n", base::all.equal(dataOut[1:NumLine,],dataRefe[1:NumLine,]), "\n\n" )) } else { tryCatch({rlog$debug("Yay! The current output MATCHES the reference output :)")}, error=function(cond){ From 7382a202c3727b300ae80de1556b996841860b1a Mon Sep 17 00:00:00 2001 From: ddurden Date: Thu, 23 Jul 2020 20:00:57 +0000 Subject: [PATCH 089/168] - failsafe for valve issues --- pack/eddy4R.stor/R/wrap.dp01.ecse.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index ee8cb62a..1c94a1c0 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -164,7 +164,7 @@ wrap.dp01.ecse <- function( wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") #idxAgr2 <- 0 for (idxAgr in 1:length(wrk$idx$idxBgn)){ - #idxAgr <- 4 + #idxAgr <- 3 #only use the middle 2 min after the first 1 min wrk$inpMask$data <- list() @@ -214,8 +214,11 @@ wrap.dp01.ecse <- function( rpt[[idxAgr]] <- NULL } + #Remove any empty lists in case valve issues + if(length(wrk$idx$idxBgn) == idxAgr) rpt <- Filter(Negate(is.null), rpt) + #Check if after removing data for valve kickooff if no data remains - if(length(wrk$idx$idxBgn) == 1 && length(rpt) == 0){ + if(length(wrk$idx$idxBgn) == idxAgr && length(rpt) == 0){ rpt[[1]] <- list() for(idxStat in NameStat){ From 5c516bd4e68005d0ed46243a7a040d1130726839 Mon Sep 17 00:00:00 2001 From: ddurden Date: Thu, 23 Jul 2020 20:05:33 +0000 Subject: [PATCH 090/168] - removing null values in list --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index 35687c77..5e6ae278 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -232,9 +232,11 @@ wrap.dp01.qfqm.ecse <- function( rpt[[idxAgr]] <- NULL } + #Remove any empty lists in case valve issues + if(length(wrk$idx$idxBgn) == idxAgr) rpt <- Filter(Negate(is.null), rpt) #Check if after removing data for valve kickooff if no data remains - if(length(wrk$idx$idxBgn) == 1 && length(rpt) == 0){ + if(length(wrk$idx$idxBgn) == idxAgr && length(rpt) == 0){ rpt[[1]] <- list() #idxStat <- NameQf[1] rpt[[1]]$qmAlph <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(wrk$data))) From a009fac7e299dee2ef144fc13bdc4a9328c313cb Mon Sep 17 00:00:00 2001 From: ddurden Date: Thu, 23 Jul 2020 20:11:29 +0000 Subject: [PATCH 091/168] - updating function documentation --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 2 ++ pack/eddy4R.stor/R/wrap.dp01.ecse.R | 2 ++ 2 files changed, 4 insertions(+) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index 5e6ae278..718bae96 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -85,6 +85,8 @@ # failsafe for crd kickoff removal causing no data for entire day # David Durden (2020-05-21) # bug fix for qmBeta causing differing number of values between data and qfqm +# David Durden (2020-07-23) +# bug fix for valve issues where looks like consistently Stor data thrown off by Crd ############################################################################################## wrap.dp01.qfqm.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index 1c94a1c0..c8dd567e 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -72,6 +72,8 @@ # added lvlCrdCo2Valv to the function's parameter # David Durden (2020-05-15) # failsafe for crd kickoff removal causing no data for entire day +# David Durden (2020-07-23) +# bug fix for valve issues where looks like consistently Stor data thrown off by Crd ############################################################################################## wrap.dp01.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], From 28aa026f2926a4f66871e56e9374e239613d4dcc Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 24 Jul 2020 13:56:29 +0000 Subject: [PATCH 092/168] - Failsafe if multiple lines exist, but removed due to NaN --- pack/eddy4R.stor/R/def.itpl.time.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.stor/R/def.itpl.time.R b/pack/eddy4R.stor/R/def.itpl.time.R index 3a0046c9..cd1d7e62 100644 --- a/pack/eddy4R.stor/R/def.itpl.time.R +++ b/pack/eddy4R.stor/R/def.itpl.time.R @@ -40,6 +40,8 @@ # added failsafe replace NaN in numSamp with zero # David Durden (2020-07-10) # added failsafe to make sure the time and data lengths are the same for cases with setLgth = 2 +# David Durden(2020-07-24) +# Failsafe if multiple lines exist, but removed due to NaN ############################################################################################################## #Start of function call ############################################################################################################## @@ -114,7 +116,12 @@ def.itpl.time <- function( #remove na value if like that maxgap will not work dataInp <- na.omit(dataInp) #make sure use the right inpTime before interpolating - if (setLgth == 2 && length(tmpTimeFrac) == setLgth){inpTime <- tmpTimeFrac}else{inpTime <- as.integer(dataInp$timeFrac * 60)} + if (setLgth == 2 && length(tmpTimeFrac) == setLgth){ + inpTime <- tmpTimeFrac + }else{ + inpTime <- as.integer(dataInp$timeFrac * 60) + if (setLgth == 2 & inpTime[1]==inpTime[2]) inpTime[2] <- inpTime[2]+1 #Failsafe if multiple lines exist, but removed due to NaN + } #End if for setLgth == 2 and length of tmpTime == to setLgth rpt <- zoo::na.approx(object=as.vector(dataInp$mean), x=#dataInp$timeFrac inpTime , xout=as.integer(timeFracOut * 60) From 682bed8b3cecd6cc93369e2fa26e24e9bc76e62c Mon Sep 17 00:00:00 2001 From: ddurden Date: Sat, 9 Jan 2021 18:17:37 +0000 Subject: [PATCH 093/168] Added failsafe for number of samples in mean less than 2 --- pack/eddy4R.stor/R/def.itpl.time.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.stor/R/def.itpl.time.R b/pack/eddy4R.stor/R/def.itpl.time.R index cd1d7e62..bd8c5108 100644 --- a/pack/eddy4R.stor/R/def.itpl.time.R +++ b/pack/eddy4R.stor/R/def.itpl.time.R @@ -42,6 +42,8 @@ # added failsafe to make sure the time and data lengths are the same for cases with setLgth = 2 # David Durden(2020-07-24) # Failsafe if multiple lines exist, but removed due to NaN +# David Durden(2020-12-24) +# Added numSamp > 1 since na.omit below would remove later since variance can not be calculated ############################################################################################################## #Start of function call ############################################################################################################## @@ -98,7 +100,7 @@ def.itpl.time <- function( #data: determine which datapoints to assess - setLgth <- length(which(!is.na(dataInp$mean))) + setLgth <- length(which(!is.na(dataInp$mean) & dataInp$numSamp > 1)) #Added numSamp > 1 since na.omit below would remove later since variance can not be calculated #less than 2 values (minimum required by approx() function) From de3e0b3a3664ad4c9eb3dfc48e9c197efd7147c7 Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Thu, 4 Feb 2021 10:07:28 -0700 Subject: [PATCH 094/168] add option to retain non-numeric columns in regularization. Also add option to output start and end times of the regularization windows --- pack/eddy4R.base/R/def.rglr.R | 54 ++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/pack/eddy4R.base/R/def.rglr.R b/pack/eddy4R.base/R/def.rglr.R index 861030e2..3ff15577 100644 --- a/pack/eddy4R.base/R/def.rglr.R +++ b/pack/eddy4R.base/R/def.rglr.R @@ -9,8 +9,8 @@ #' @description Function defintion. #' Takes a (potentially) irregularly spaced timeseries \code{timeMeas} of data \code{dataMeas} and returns a strictuly regularly spaced timeseries \code{timeRglr} of data \code{dataRglr}. \strong{ATTENTION}: \code{MethRglr = "zoo"} uses the zoo:na.approx() function, which does not currently abide by its \code{maxgap} argument version 1.7-13. In result, where gaps exist currently the last known value is repeated instead of NAs being inserted. An Email with a request for bugfixing has been sent to \email{Achim.Zeileis@R-project.org} (2016-05-08). -#' @param timeMeas A vector containing the observation times. Of class "POSIXlt" including timezone attribute, and of the same length as \code{dataMeas}. [-] -#' @param dataMeas A named data.frame containing the observations. Columns may be of class "numeric" or "integer", and of the same length as \code{timeMeas}. Columns of classes other than "numeric" or "integer" are removed and not included in the returned \code{dataRegl}. [user-defined] +#' @param timeMeas A vector containing the observation times. Of class "POSIXlt" including timezone attribute, and of the same row length as \code{dataMeas}. [-] +#' @param dataMeas A named data.frame containing the observations, with row length matching that of \code{timeMeas}. Not that if the zoo method is chosen in \code{MethRglr} or input \code{DropNotNumc} is TRUE, any columns with class other than "numeric" or "integer" are removed and not included in the returned \code{dataRegl}. [user-defined] #' @param unitMeas A vector containing the unit of each column in \code{dataMeas}. Of class "character". It is recommended to conform to the "unit representation" guidelines documented in the eddy4R.base package. #' @param BgnRglr Desired begin time for the regularized dataset. Of class "POSIXlt" including timezone attribute, and \code{length(BgnRglr) = 1}. [-] #' @param EndRglr Desired end time for the regularized dataset. Of class "POSIXlt" including timezone attribute, and \code{length(EndRglr) = 1}. [-] @@ -23,10 +23,13 @@ #' Method "zoo" implements the regularization method using the zoo::na.approx function. This method can only handle up to millisecond precision (PrcsSec=3) #' @param WndwRglr Position of the window for binning in the "CybiEc" method. \code{WndwRglr} can be centered [Cntr], leading [Lead], or trailing [Trlg] (defaults to centered).\cr #' @param IdxWndw Determines which observation to allocate to a bin if multiple observations fall into a single bin when using the "CybiEc" method.. \code{IdxWndw} can be set to closest [Clst], first [IdxWndwMin], or last [IdxWndwMax] (defaults to closest).\cr +#' @param DropNotNumc Logical. TRUE (default) for removing any non-numeric data columns prior to regularization (this is done automatically for zoo method). FALSE to attempt to regularize all data columns. +#' @param RptTimeWndw Logical. TRUE for including the start and end time of each bin with the output, in list element timeWndw. Defaults to FALSE. Not available as TRUE for zoo method. #' @param PrcsSec A single numeric (integer) value indicating the operational precision of the seconds field of time vectors. Defaults to 6 (microsecond-precision). Values higher than 6 cannot be guaranteed to produce desired results. -#' @return Returns a list with elements \code{TzRglr}, \code{FreqRglr}, \code{MethRglr}, \code{timeRglr}, and \code{dataRglr}. +#' @return Returns a list with elements \code{TzRglr}, \code{FreqRglr}, \code{MethRglr}, \code{timeRglr}, and \code{dataRglr}. +#' An additional list element \code{timeWndw} will be included if input \code{RptTimeWndw=TRUE} #' @references #' License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007. \cr @@ -105,6 +108,9 @@ # Cove Sturtevant (2020-02-18) # Removed MethRglr "cybiDflt", as it is no longer used by NEON CI (CybiEc is used) # Added MethRglr "CybiEcTimeMeas" +# Cove Sturtevant (2021-02-02) +# Added option to retain non-numeric columns for everything but zoo method +# Added option to output the time bins (start and end times) in a new list element in the output ############################################################################################## def.rglr <- function( @@ -118,6 +124,8 @@ def.rglr <- function( MethRglr= c("CybiEc", "CybiEcTimeMeas", "zoo")[1], WndwRglr = c("Cntr", "Lead", "Trlg")[1], IdxWndw = c("Clst","IdxWndwMin","IdxWndwMax")[1], + DropNotNumc = TRUE, + RptTimeWndw = FALSE, PrcsSec = 6 ){ @@ -137,6 +145,15 @@ def.rglr <- function( stop(base::paste0('Unrecognized value for input MethRglr. Options are "zoo","CybiEc", and "CybiEcTimeMeas" (case-sensitive)')) } + # Error-check + if(MethRglr == "zoo" && DropNotNumc == FALSE){ + warning('Input parameter DropNotNumc is always set to TRUE for MethRglr=zoo. User selected input has been overwritten.') + } + + # Error-check + if(MethRglr == "zoo" && RptTimeWndw == TRUE){ + warning('Input parameter RptTimeWndw = TRUE is not currently an option for MethRglr=zoo. User selected input has been overwritten.') + } if(MethRglr %in% c("zoo","CybiEcTimeMeas","CybiEc")){ @@ -230,6 +247,7 @@ def.rglr <- function( rpt$FreqRglr <- FreqRglr rpt$MethRglr <- MethRglr rpt$timeRglr <- timeRglr + numRglr <- length(timeRglr) # default: using the zoo::na.approx() function # takes 3 s for 1,728,000 observations, i.e. one day of one 20 Hz variable @@ -263,7 +281,7 @@ def.rglr <- function( # if less than 2 values (minimum required by na.approx() function) if(whr03 < 2) { - rpt$dataRglr[,idx] <- base::rep(NaN, base::length(rpt$timeRglr)) + rpt$dataRglr[,idx] <- base::rep(NaN, numRglr) #else interpolate dataMeas } else { @@ -305,12 +323,14 @@ def.rglr <- function( # reduce dataMeas to variables that are of type double or integer (not character!) - set02 <- base::sapply(1:base::ncol(dataMeas), function(x) base::typeof(dataMeas[[x]])) - set02 <- which((set02 %in% c("double", "integer"))) - dataMeas <- base::subset(dataMeas, select = set02) - unitMeas <- unitMeas[set02] - base::rm(set02) - + if(DropNotNumc == TRUE){ + set02 <- base::sapply(1:base::ncol(dataMeas), function(x) base::typeof(dataMeas[[x]])) + set02 <- which((set02 %in% c("double", "integer"))) + dataMeas <- base::subset(dataMeas, select = set02) + unitMeas <- unitMeas[set02] + base::rm(set02) + } + # Number of variables in dataframe numVar <- base::ncol(dataMeas) # Variable names @@ -363,8 +383,12 @@ def.rglr <- function( }}else{dupl <- rep(FALSE, length(idxRglr))} #If no duplicates exist, all equal FALSE # Pull the value that chosen by IdxWndw within each bin - dataRglr <- base::data.frame(base::matrix(data=NA*1.5,nrow=length(timeRglrNumc),ncol=numVar)) # initialize, mulitply by 1.5 to give numeric + typeData <- lapply(dataMeas,base::class) # Get the class of each variable so we can make sure the output gets the same + dataRglr <- base::data.frame(base::matrix(data=NA*1.5,nrow=numRglr,ncol=numVar)) # initialize, multiply by 1.5 to give numeric for(idxVar in 1:numVar){ + # Give the column its original class + base::class(dataRglr[[idxVar]]) <- typeData[[idxVar]] + # place the value falling into each bin dataRglr[idxRglr[!dupl],idxVar] <- dataMeas[which(!dupl),idxVar] } @@ -375,6 +399,14 @@ def.rglr <- function( rpt$timeRglr[idxRglr[!dupl]] <- timeMeas[which(!dupl)] } + if(RptTimeWndw==TRUE){ + secRtioWndw <- base::round(timeWndw-base::floor(timeWndw),digits=PrcsSec) # Grab the fractional seconds + timeWndw <- base::as.POSIXlt(base::floor(timeWndw),tz=TzRglr,origin=epoc,digits=20) # Convert to POSIXlt + timeWndw$sec <- timeWndw$sec+secRtioWndw # Add back in the fractional seconds + rpt$timeWndw <- data.frame(timeWndwBgn=timeWndw[1:numRglr],timeWndwEnd=timeWndw[2:(numRglr+1)]) + } + + # Report output rpt$dataRglr <- dataRglr # assign unit attributes From 8d6d98f4cee0dfd701846d9daec4d6b2cb395110 Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Thu, 4 Feb 2021 10:17:55 -0700 Subject: [PATCH 095/168] update eddy4R.base package --- pack/eddy4R.base/DESCRIPTION | 4 ++-- pack/eddy4R.base/man/def.rglr.Rd | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pack/eddy4R.base/DESCRIPTION b/pack/eddy4R.base/DESCRIPTION index 8bcf58fa..92104368 100644 --- a/pack/eddy4R.base/DESCRIPTION +++ b/pack/eddy4R.base/DESCRIPTION @@ -1,6 +1,6 @@ Package: eddy4R.base Title: Eddy-covariance calculation for R: Base package -Version: 0.2.21 +Version: 0.2.22 Authors@R: c( person("Stefan", "Metzger", email = "eddy4R.info@gmail.com", role = c("aut", "cre")), person("David", "Durden", email = "ddurden@battelleecology.org", role = c("aut")), person("Natchaya", "Pingintha-Durden", email = "ndurden@battelleecology.org", role = c("aut")), @@ -28,4 +28,4 @@ Suggests: NEONprocIS.base License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 LazyData: true -RoxygenNote: 7.1.0 +RoxygenNote: 7.1.1 diff --git a/pack/eddy4R.base/man/def.rglr.Rd b/pack/eddy4R.base/man/def.rglr.Rd index f0950876..a4681e26 100644 --- a/pack/eddy4R.base/man/def.rglr.Rd +++ b/pack/eddy4R.base/man/def.rglr.Rd @@ -15,13 +15,15 @@ def.rglr( MethRglr = c("CybiEc", "CybiEcTimeMeas", "zoo")[1], WndwRglr = c("Cntr", "Lead", "Trlg")[1], IdxWndw = c("Clst", "IdxWndwMin", "IdxWndwMax")[1], + DropNotNumc = TRUE, + RptTimeWndw = FALSE, PrcsSec = 6 ) } \arguments{ -\item{timeMeas}{A vector containing the observation times. Of class "POSIXlt" including timezone attribute, and of the same length as \code{dataMeas}. [-]} +\item{timeMeas}{A vector containing the observation times. Of class "POSIXlt" including timezone attribute, and of the same row length as \code{dataMeas}. [-]} -\item{dataMeas}{A named data.frame containing the observations. Columns may be of class "numeric" or "integer", and of the same length as \code{timeMeas}. Columns of classes other than "numeric" or "integer" are removed and not included in the returned \code{dataRegl}. [user-defined]} +\item{dataMeas}{A named data.frame containing the observations, with row length matching that of \code{timeMeas}. Not that if the zoo method is chosen in \code{MethRglr} or input \code{DropNotNumc} is TRUE, any columns with class other than "numeric" or "integer" are removed and not included in the returned \code{dataRegl}. [user-defined]} \item{unitMeas}{A vector containing the unit of each column in \code{dataMeas}. Of class "character". It is recommended to conform to the "unit representation" guidelines documented in the eddy4R.base package.} @@ -43,10 +45,15 @@ Method "zoo" implements the regularization method using the zoo::na.approx funct \item{IdxWndw}{Determines which observation to allocate to a bin if multiple observations fall into a single bin when using the "CybiEc" method.. \code{IdxWndw} can be set to closest [Clst], first [IdxWndwMin], or last [IdxWndwMax] (defaults to closest).\cr} +\item{DropNotNumc}{Logical. TRUE (default) for removing any non-numeric data columns prior to regularization (this is done automatically for zoo method). FALSE to attempt to regularize all data columns.} + +\item{RptTimeWndw}{Logical. TRUE for including the start and end time of each bin with the output, in list element timeWndw. Defaults to FALSE. Not available as TRUE for zoo method.} + \item{PrcsSec}{A single numeric (integer) value indicating the operational precision of the seconds field of time vectors. Defaults to 6 (microsecond-precision). Values higher than 6 cannot be guaranteed to produce desired results.} } \value{ -Returns a list with elements \code{TzRglr}, \code{FreqRglr}, \code{MethRglr}, \code{timeRglr}, and \code{dataRglr}. +Returns a list with elements \code{TzRglr}, \code{FreqRglr}, \code{MethRglr}, \code{timeRglr}, and \code{dataRglr}. +An additional list element \code{timeWndw} will be included if input \code{RptTimeWndw=TRUE} } \description{ Function defintion. From bd4c5914952d612c769df9410c51716a5987f44a Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Mon, 15 Feb 2021 13:49:13 -0700 Subject: [PATCH 096/168] fix bug crashing regularization code when class of variables in input data frame was 'array'. --- pack/eddy4R.base/DESCRIPTION | 2 +- pack/eddy4R.base/R/def.rglr.R | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.base/DESCRIPTION b/pack/eddy4R.base/DESCRIPTION index 92104368..75fc2e49 100644 --- a/pack/eddy4R.base/DESCRIPTION +++ b/pack/eddy4R.base/DESCRIPTION @@ -1,6 +1,6 @@ Package: eddy4R.base Title: Eddy-covariance calculation for R: Base package -Version: 0.2.22 +Version: 0.2.23 Authors@R: c( person("Stefan", "Metzger", email = "eddy4R.info@gmail.com", role = c("aut", "cre")), person("David", "Durden", email = "ddurden@battelleecology.org", role = c("aut")), person("Natchaya", "Pingintha-Durden", email = "ndurden@battelleecology.org", role = c("aut")), diff --git a/pack/eddy4R.base/R/def.rglr.R b/pack/eddy4R.base/R/def.rglr.R index 3ff15577..8f2d6cb2 100644 --- a/pack/eddy4R.base/R/def.rglr.R +++ b/pack/eddy4R.base/R/def.rglr.R @@ -111,6 +111,10 @@ # Cove Sturtevant (2021-02-02) # Added option to retain non-numeric columns for everything but zoo method # Added option to output the time bins (start and end times) in a new list element in the output +# Cove Sturtevant (2021-02-15) +# bug fix. Sometimes class returns 'array', which was causing an error when forcing the type of +# each regularized variable to the same as that in the input data frame. +# Replaced 'class' with 'typeof' to fix. ############################################################################################## def.rglr <- function( @@ -383,7 +387,7 @@ def.rglr <- function( }}else{dupl <- rep(FALSE, length(idxRglr))} #If no duplicates exist, all equal FALSE # Pull the value that chosen by IdxWndw within each bin - typeData <- lapply(dataMeas,base::class) # Get the class of each variable so we can make sure the output gets the same + typeData <- lapply(dataMeas,base::typeof) # Get the type of each variable so we can make sure the output gets the same dataRglr <- base::data.frame(base::matrix(data=NA*1.5,nrow=numRglr,ncol=numVar)) # initialize, multiply by 1.5 to give numeric for(idxVar in 1:numVar){ # Give the column its original class From e5258bb1ecc95a95ab0376b615848e26e26eb894 Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Mon, 15 Feb 2021 14:45:03 -0700 Subject: [PATCH 097/168] use class rather than typeof where possible to enable regularization of time vectors --- pack/eddy4R.base/R/def.rglr.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.base/R/def.rglr.R b/pack/eddy4R.base/R/def.rglr.R index 8f2d6cb2..7b0c662e 100644 --- a/pack/eddy4R.base/R/def.rglr.R +++ b/pack/eddy4R.base/R/def.rglr.R @@ -387,11 +387,15 @@ def.rglr <- function( }}else{dupl <- rep(FALSE, length(idxRglr))} #If no duplicates exist, all equal FALSE # Pull the value that chosen by IdxWndw within each bin - typeData <- lapply(dataMeas,base::typeof) # Get the type of each variable so we can make sure the output gets the same + classData <- lapply(dataMeas,base::class) # Get the type of each variable so we can make sure the output gets the same + typeData <- lapply(dataMeas,base::typeof) dataRglr <- base::data.frame(base::matrix(data=NA*1.5,nrow=numRglr,ncol=numVar)) # initialize, multiply by 1.5 to give numeric for(idxVar in 1:numVar){ # Give the column its original class - base::class(dataRglr[[idxVar]]) <- typeData[[idxVar]] + base::class(dataRglr[[idxVar]]) <- tryCatch( + base::class(dataRglr[[idxVar]]) <- classData[[idxVar]], + error=function(e){base::class(dataRglr[[idxVar]]) <- typeData[[idxVar]]}) + # place the value falling into each bin dataRglr[idxRglr[!dupl],idxVar] <- dataMeas[which(!dupl),idxVar] From 83f92756e364298f43e2bb708fbab3b36712d3ed Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Thu, 8 Apr 2021 17:51:04 +0000 Subject: [PATCH 098/168] added initial changes to include ch4Conc in all dp01 lists, replicated isoCo2 processing for ch4conc using the crdCo2 input dataset --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 388 ++++++++++++++++++++++- pack/eddy4R.stor/R/wrap.dp01.ecse.R | 381 +++++++++++++++++++++- 2 files changed, 767 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index 718bae96..3ae1d454 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -87,9 +87,11 @@ # bug fix for qmBeta causing differing number of values between data and qfqm # David Durden (2020-07-23) # bug fix for valve issues where looks like consistently Stor data thrown off by Crd +# Chris Florian (2021-02-26) +# adding ch4Conc to dp01 list ############################################################################################## wrap.dp01.qfqm.ecse <- function( - dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], + dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o", "ch4Conc")[1], RptExpd = FALSE, lvl, lvlMfcSampStor = NULL, @@ -1050,6 +1052,390 @@ wrap.dp01.qfqm.ecse <- function( }#end of TypeMeas %in% "vali" if statement }##end of dp01 if statement + + #calculate dp01 for "ch4Conc" ######################################################################################## + if (dp01 %in% c("ch4Conc")){ + #during sampling period + if (TypeMeas %in% "samp"){ + #assign lvlIrga for each measurement level + if (lvl == "000_010") {lvlCrdCo2 <- "lvl01"} + if (lvl == "000_020") {lvlCrdCo2 <- "lvl02"} + if (lvl == "000_030") {lvlCrdCo2 <- "lvl03"} + if (lvl == "000_040") {lvlCrdCo2 <- "lvl04"} + if (lvl == "000_050") {lvlCrdCo2 <- "lvl05"} + if (lvl == "000_060") {lvlCrdCo2 <- "lvl06"} + if (lvl == "000_070") {lvlCrdCo2 <- "lvl07"} + if (lvl == "000_080") {lvlCrdCo2 <- "lvl08"} + #assign lvlMfm + lvlMfm <- paste0("700_", strsplit(lvl, "_")[[1]][2]) + + #input the whole day data + wrk$data <- data.frame(stringsAsFactors = FALSE, + "pres" = data$crdCo2[[lvl]]$pres, + "presEnvHut" = data$envHut[[lvlEnvHut]]$pres, + "rhEnvHut" = data$envHut[[lvlEnvHut]]$rh, + "rtioMoleDryCh4" = data$crdCo2[[lvl]]$rtioMoleDryCh4, + "rtioMoleWetCh4" = data$crdCo2[[lvl]]$rtioMoleWetCh4, + "rtioMoleWetH2oEnvHut" = data$envHut[[lvlEnvHut]]$rtioMoleWetH2o, + "temp" = data$crdCo2[[lvl]]$temp, + "tempEnvHut" = data$envHut[[lvlEnvHut]]$temp, + "lvlCrdCo2" = data$crdCo2ValvLvl[[lvlValv]]$lvlCrdCo2 + + ) + + #input the whole day qfqm + wrk$qfqm <- list() + #subset only + wrk$qfqm$crdCo2 <- qfInp$crdCo2[[lvl]] + wrk$qfqm$envHut <- qfInp$envHut[[lvlEnvHut]] + wrk$qfqm$mfm <- qfInp$mfm[[lvlMfm]] + if ("presInlt" %in% names(qfInp)) wrk$qfqm$presInlt <- qfInp$presInlt[[lvl]] + if ("pumpStor" %in% names(qfInp)) wrk$qfqm$pumpStor <- qfInp$pumpStor[[lvlMfm]] + + if (PrdMeas == PrdAgr) { + #PrdAgr <- 9 + #9 minutely sampling data + #idxLvLPrdAgr <- paste0(lvl, "_", sprintf("%02d", PrdAgr), "m") + #rpt[[dp01]][[idxLvLPrdAgr]] <- list() + + #if there is at least one measurement + if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ + #determine the index of each measurement + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + #delete row if last timeBgn and timeEnd is NA + wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] + #replace last idxEnd > 86400 by 86400 + wrk$idx$idxEnd <- ifelse(wrk$idx$idxEnd > 86400, 86400, wrk$idx$idxEnd) + #if last timeEnd is NA, replce that time to the last time value in data$time + wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") + #idxAgr2 <- 0 + for (idxAgr in 1:length(wrk$idx$idxBgn)){ + #idxAgr <- 25 + #get data for each idxAgr + wrk$inpMask$data <- list() + wrk$inpMask$data <- wrk$data[wrk$idx$idxBgn[idxAgr]:wrk$idx$idxEnd[idxAgr],] + #wrk$inpMask for qfqm + wrk$inpMask$qfqm <- list() + lapply(names(wrk$qfqm), function (x) wrk$inpMask$qfqm[[x]] <<- wrk$qfqm[[x]][wrk$idx$idxBgn[idxAgr]:wrk$idx$idxEnd[idxAgr],] ) + + for (idxSens in names(wrk$inpMask$qfqm)){ + #replace qfqm with -1 when valve switch to measure to next level before schedule time (9 min) + wrk$inpMask$qfqm[[idxSens]][wrk$inpMask$data$lvlCrdCo2 != lvlCrdCo2, 1:length(wrk$inpMask$qfqm[[idxSens]])] <- -1 + } + + #qfqm processing + rpt[[idxAgr]] <- eddy4R.qaqc::wrap.dp01.qfqm.eddy( + qfInp = wrk$inpMask$qfqm, + MethMeas = "ecse", + TypeMeas = "samp", + RptExpd = FALSE, + dp01 = dp01, + idGas = wrk$inpMask$data$idGas + ) + #grab and add both time begin and time end to rpt + rpt[[idxAgr]]$timeBgn <- list() + rpt[[idxAgr]]$timeEnd <- list() + + #output time for dp01 + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("idGas", "lvlCrdCo2")))]){ + rpt[[idxAgr]]$timeBgn[[idxVar]] <- wrk$idx$timeBgn[idxAgr] + rpt[[idxAgr]]$timeEnd[[idxVar]] <- wrk$idx$timeEnd[idxAgr] + }; rm(idxVar) + + #}# end of there is at least one data + + }; rm(idxAgr) + } else { + + rpt[[1]] <- list() + #idxStat <- NameQf[1] + rpt[[1]]$qmAlph <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(wrk$data))) + rpt[[1]]$qmBeta <- as.data.frame(matrix(1, nrow = 1, ncol = ncol(wrk$data))) + rpt[[1]]$qfFinl <- as.data.frame(matrix(1, nrow = 1, ncol = ncol(wrk$data))) + rpt[[1]]$qfSciRevw <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(wrk$data))) + #change data type + rpt[[1]]$qfFinl[,1:ncol(wrk$data)] <- sapply(rpt[[1]]$qfFinl[,1:ncol(wrk$data)], as.integer) + rpt[[1]]$qfSciRevw[,1:ncol(wrk$data)] <- sapply(rpt[[1]]$qfSciRevw[,1:ncol(wrk$data)], as.integer) + + for(idxQf in NameQf){ + #assign name to each column + names(rpt[[1]][[idxQf]]) <- names(wrk$data) + #not report lvlIrga + rpt[[1]][[idxQf]] <- rpt[[1]][[idxQf]][which(!(names(rpt[[1]][[idxQf]]) %in% c("idGas", "lvlCrdCo2")))] + }; rm(idxQf) + + #add both time begin and time end to rpt + rpt[[1]]$timeBgn <- list() + rpt[[1]]$timeEnd <- list() + + #output time for dp01 + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("idGas", "lvlCrdCo2")))]){ + rpt[[1]]$timeBgn[[idxVar]] <- data$time[1] + rpt[[1]]$timeEnd[[idxVar]] <- data$time[length(data$time)] + #unit + attributes(rpt[[1]]$qmAlph[[idxVar]])$unit <- "-" + attributes(rpt[[1]]$qmBeta[[idxVar]])$unit <- "-" + attributes(rpt[[1]]$qfFinl[[idxVar]])$unit <- "NA" + attributes(rpt[[1]]$qfSciRevw[[idxVar]])$unit <- "NA" + }; rm(idxVar) + + }#end of if no measurement data at all in the whole day + } #end of PrdAgr + + if (PrdMeas != PrdAgr) { + #PrdAgr <- 30 + #if there is at least one measurement + if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ + + #determine the index of each measurement + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + #delete row if last timeBgn and timeEnd is NA + wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] + #if last timeEnd is NA, replce that time to the last time value in data$time + wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") + whrSamp <- wrk$idx$idxBgn[1]:wrk$idx$idxEnd[1] + if (length (wrk$idx$idxBgn) > 1 ){ + for(ii in 2:length (wrk$idx$idxBgn)){ + whrSamp <- c(whrSamp, wrk$idx$idxBgn[ii]:wrk$idx$idxEnd[ii]) + } + } + wrk$data[-whrSamp, 1:16] <- NaN + + for (idxSens in names(wrk$qfqm)){ + #replace qfqm with -1 when valve switch to measure to next level before schedule time (9 min) + wrk$qfqm[[idxSens]][wrk$data$lvlCrdCo2 != lvlCrdCo2, 1:length(wrk$qfqm[[idxSens]])] <- -1 + #replace all qf that not belong to that measurement level by NaN + wrk$qfqm[[idxSens]][-whrSamp, 1:length(wrk$qfqm[[idxSens]])] <- NaN + } + } + + for(idxAgr in c(1:length(idxTime[[paste0(PrdAgr, "min")]]$Bgn))) { + #idxAgr <- 48 + #get data for each idxAgr + wrk$inpMask$data <- list() + idxLvLPrdAgr <- paste0(lvl, "_", sprintf("%02d", PrdAgr), "m") + + wrk$inpMask$data <- wrk$data[idxTime[[paste0(PrdAgr, "min")]]$Bgn[idxAgr]:idxTime[[paste0(PrdAgr, "min")]]$End[idxAgr],] + # for qfqm + wrk$inpMask$qfqm <- list() + lapply(names(wrk$qfqm), function (x) wrk$inpMask$qfqm[[x]] <<- wrk$qfqm[[x]][idxTime[[paste0(PrdAgr, "min")]]$Bgn[idxAgr]:idxTime[[paste0(PrdAgr, "min")]]$End[idxAgr],]) + + #qfqm processing + rpt[[idxAgr]] <- eddy4R.qaqc::wrap.dp01.qfqm.eddy( + qfInp = wrk$inpMask$qfqm, + MethMeas = "ecse", + TypeMeas = "samp", + RptExpd = RptExpd, + dp01 = dp01, + idGas = wrk$inpMask$data$idGas + ) + + #grab and add both time begin and time end to rpt + rpt[[idxAgr]]$timeBgn <- list() + rpt[[idxAgr]]$timeEnd <- list() + + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("idGas", "lvlCrdCo2")))]){ + rpt[[idxAgr]]$timeBgn[[idxVar]] <- data$time[idxTime[[paste0(PrdAgr, "min")]]$Bgn[idxAgr]] + rpt[[idxAgr]]$timeEnd[[idxVar]] <- data$time[idxTime[[paste0(PrdAgr, "min")]]$End[idxAgr]] + } + + }; #rm(idxAgr) + + }#end of PrdAgr == 30 + }#end of TypeMeas %in% "samp" + + #during validation period + if (TypeMeas %in% "vali"){ + #assign lvlPresValiRegInStor for each gas + if (lvl == "co2Arch") lvlPresValiRegInStor <- "710_000" + if (lvl == "co2Low") lvlPresValiRegInStor <- "712_000" + if (lvl == "co2Med") lvlPresValiRegInStor <- "713_000" + if (lvl == "co2High") lvlPresValiRegInStor <- "714_000" + #input the whole day data + wrk$data <- data.frame(stringsAsFactors = FALSE, + "dlta13CCo2" = data$crdCo2[[lvl]]$dlta13CCo2, + "dlta13CCo2Refe" = data$crdCo2[[lvl]]$dlta13CCo2Refe, + "idGas" = data$crdCo2[[lvl]]$idGas, + "pres" = data$crdCo2[[lvl]]$pres, + "presEnvHut" = data$envHut[[lvlEnvHut]]$pres, + "rhEnvHut" = data$envHut[[lvlEnvHut]]$rh, + "rtioMoleDry12CCo2" = data$crdCo2[[lvl]]$rtioMoleDry12CCo2, + "rtioMoleDry13CCo2" = data$crdCo2[[lvl]]$rtioMoleDry13CCo2, + "rtioMoleDryCo2" = data$crdCo2[[lvl]]$rtioMoleDryCo2, + "rtioMoleDryCo2Refe" = data$crdCo2[[lvl]]$rtioMoleDryCo2Refe, + "rtioMoleDryH2o" = data$crdCo2[[lvl]]$rtioMoleDryH2o, + "rtioMoleWet12CCo2" = data$crdCo2[[lvl]]$rtioMoleWet12CCo2, + "rtioMoleWet13CCo2" = data$crdCo2[[lvl]]$rtioMoleWet13CCo2, + "rtioMoleWetCo2" = data$crdCo2[[lvl]]$rtioMoleWetCo2, + "rtioMoleWetH2o" = data$crdCo2[[lvl]]$rtioMoleWetH2o, + "rtioMoleWetH2oEnvHut" = data$envHut[[lvlEnvHut]]$rtioMoleWetH2o, + "temp" = data$crdCo2[[lvl]]$temp, + "tempEnvHut" = data$envHut[[lvlEnvHut]]$temp + + ) + #input the whole day qfqm + wrk$qfqm <- list() + wrk$qfqm$crdCo2 <- qfInp$crdCo2[[lvl]] + wrk$qfqm$envHut <- qfInp$envHut[[lvlEnvHut]] + wrk$qfqm$mfcValiStor <- qfInp$mfcValiStor[[lvlMfcValiStor]] + if ("presValiRegInStor" %in% names(qfInp)) wrk$qfqm$presValiRegInStor <- qfInp$presValiRegInStor[[lvlPresValiRegInStor]] + + if (PrdMeas == PrdAgr) { + #PrdAgr <- 9 + #9 minutely sampling data + #idxLvLPrdAgr <- paste0(lvl, "_", sprintf("%02d", PrdAgr), "m") + #rpt[[dp01]][[idxLvLPrdAgr]] <- list() + + #if there is at least one measurement + if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ + #determine the end time of each measurement + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + #delete row if last timeBgn and timeEnd is NA + wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] + #if last timeEnd is NA, replce that time to the last time value in data$time + wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") + + #idxAgr2 <- 0 + for (idxAgr in 1:length(wrk$idx$idxBgn)){ + #idxAgr <- 1 + #determine input data for each idxAgr + wrk$inpMask$data <- list() + wrk$inpMask$data <- wrk$data[wrk$idx$idxBgn[idxAgr]:wrk$idx$idxEnd[idxAgr],] + #wrk$inpMask for qfqm + wrk$inpMask$qfqm <- list() + lapply(names(wrk$qfqm), function (x) wrk$inpMask$qfqm[[x]] <<- wrk$qfqm[[x]][wrk$idx$idxBgn[idxAgr]:wrk$idx$idxEnd[idxAgr],] ) + + #qfqm processing + rpt[[idxAgr]] <- eddy4R.qaqc::wrap.dp01.qfqm.eddy( + qfInp = wrk$inpMask$qfqm, + MethMeas = "ecse", + TypeMeas = "vali", + RptExpd = FALSE, + dp01 = dp01, + idGas = wrk$inpMask$data$idGas + ) + + #grab and add both time begin and time end to rpt + rpt[[idxAgr]]$timeBgn <- list() + rpt[[idxAgr]]$timeEnd <- list() + + #output time for qf dp01; do not output reference gas + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("rtioMoleDryCo2Refe", "dlta13CCo2Refe", "idGas")))]){ + rpt[[idxAgr]]$timeBgn[[idxVar]] <- wrk$idx$timeBgn[idxAgr] + rpt[[idxAgr]]$timeEnd[[idxVar]] <- wrk$idx$timeEnd[idxAgr] + }; rm(idxVar) + + }#; rm(idxAgr) + + } else { + + rpt[[1]] <- list() + + if(lvl %in% c("co2Arch")){ + rpt[[1]]$qmAlph <- as.data.frame(matrix(NaN, nrow = 1, ncol = ncol(wrk$data))) + rpt[[1]]$qmBeta <- as.data.frame(matrix(NaN, nrow = 1, ncol = ncol(wrk$data))) + rpt[[1]]$qfFinl <- as.data.frame(matrix(NaN, nrow = 1, ncol = ncol(wrk$data))) + rpt[[1]]$qfSciRevw <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(wrk$data))) + #change data type + rpt[[1]]$qfSciRevw[,1:ncol(wrk$data)] <- sapply(rpt[[1]]$qfSciRevw[,1:ncol(wrk$data)], as.integer) + }else{ + rpt[[1]]$qmAlph <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(wrk$data))) + rpt[[1]]$qmBeta <- as.data.frame(matrix(1, nrow = 1, ncol = ncol(wrk$data))) + rpt[[1]]$qfFinl <- as.data.frame(matrix(1, nrow = 1, ncol = ncol(wrk$data))) + rpt[[1]]$qfSciRevw <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(wrk$data))) + #change data type + rpt[[1]]$qfFinl[,1:ncol(wrk$data)] <- sapply(rpt[[1]]$qfFinl[,1:ncol(wrk$data)], as.integer) + rpt[[1]]$qfSciRevw[,1:ncol(wrk$data)] <- sapply(rpt[[1]]$qfSciRevw[,1:ncol(wrk$data)], as.integer) + } + + for(idxQf in NameQf){ + #assign name to each column + names(rpt[[1]][[idxQf]]) <- names(wrk$data) + #not report lvlIrga + rpt[[1]][[idxQf]] <- rpt[[1]][[idxQf]][which(!(names(rpt[[1]][[idxQf]]) %in% c("rtioMoleDryCo2Refe", "dlta13CCo2Refe", "idGas")))] + }; rm(idxQf) + + #add both time begin and time end to rpt + rpt[[1]]$timeBgn <- list() + rpt[[1]]$timeEnd <- list() + + #output time for dp01 + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("rtioMoleDryCo2Refe", "dlta13CCo2Refe", "idGas")))]){ + rpt[[1]]$timeBgn[[idxVar]] <- data$time[1] + rpt[[1]]$timeEnd[[idxVar]] <- data$time[length(data$time)] + #unit + attributes(rpt[[1]]$qmAlph[[idxVar]])$unit <- "-" + attributes(rpt[[1]]$qmBeta[[idxVar]])$unit <- "-" + attributes(rpt[[1]]$qfFinl[[idxVar]])$unit <- "NA" + attributes(rpt[[1]]$qfSciRevw[[idxVar]])$unit <- "NA" + }; rm(idxVar) + + }#end of if no measurement data at all in the whole day + + } #end of PrdAgr == 9 + + if (PrdMeas != PrdAgr) { + #PrdAgr <- 30 + #if there is at least one measurement + if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ + # #determine the end time of each measurement + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + #delete row if last timeBgn and timeEnd is NA + wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] + #if last timeEnd is NA, replce that time to the last time value in data$time + wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") + + whrSamp <- wrk$idx$idxBgn[1]:wrk$idx$idxEnd[1] + if (length (wrk$idx$idxBgn) > 1 ){ + for(ii in 2:length (wrk$idx$idxBgn)){ + whrSamp <- c(whrSamp, wrk$idx$idxBgn[ii]:wrk$idx$idxEnd[ii]) + } + } + wrk$data[-whrSamp, ] <- NaN + for (idxSens in names(wrk$qfqm)){ + #replace all qf that not belong to that measurement level by NaN + wrk$qfqm[[idxSens]][-whrSamp, 1:length(wrk$qfqm[[idxSens]])] <- NaN + } + } + + for(idxAgr in c(1:length(idxTime[[paste0(PrdAgr, "min")]]$Bgn))) { + #idxAgr <- 1 + + ## grab data at the selected mask data + # for data + wrk$inpMask$data <- list() + idxLvLPrdAgr <- paste0(lvl, "_", sprintf("%02d", PrdAgr), "m") + wrk$inpMask$data <- wrk$data[idxTime[[paste0(PrdAgr, "min")]]$Bgn[idxAgr]:idxTime[[paste0(PrdAgr, "min")]]$End[idxAgr],] + + # for qfqm + wrk$inpMask$qfqm <- list() + lapply(names(wrk$qfqm), function (x) wrk$inpMask$qfqm[[x]] <<- wrk$qfqm[[x]][idxTime[[paste0(PrdAgr, "min")]]$Bgn[idxAgr]:idxTime[[paste0(PrdAgr, "min")]]$End[idxAgr],]) + + #qfqm processing + rpt[[idxAgr]] <- eddy4R.qaqc::wrap.dp01.qfqm.eddy( + qfInp = wrk$inpMask$qfqm, + MethMeas = "ecse", + TypeMeas = "vali", + RptExpd = RptExpd, + dp01 = dp01, + idGas = wrk$inpMask$data$idGas + ) + + #grab and add both time begin and time end to rpt + rpt[[idxAgr]]$timeBgn <- list() + rpt[[idxAgr]]$timeEnd <- list() + + #output time for qf dp01; do not output reference gas + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("rtioMoleDryCo2Refe", "dlta13CCo2Refe", "idGas")))]){ + rpt[[idxAgr]]$timeBgn[[idxVar]] <- data$time[idxTime[[paste0(PrdAgr, "min")]]$Bgn[idxAgr]] + rpt[[idxAgr]]$timeEnd[[idxVar]] <- data$time[idxTime[[paste0(PrdAgr, "min")]]$End[idxAgr]] + }; rm(idxVar) + + }; #rm(idxAgr) + } #end of PrdAgr == 30 + }#end of TypeMeas %in% "vali" if statement + }##end of dp01 if statement + #calculate dp01 for "isoH2o" ######################################################################################## if (dp01 %in% c("isoH2o")){ #during sampling period diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index c8dd567e..72c213c2 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -74,9 +74,11 @@ # failsafe for crd kickoff removal causing no data for entire day # David Durden (2020-07-23) # bug fix for valve issues where looks like consistently Stor data thrown off by Crd +# Chris Florian (2021-02-24) +# adding ch4Conc L1 data processing steps ############################################################################################## wrap.dp01.ecse <- function( - dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], + dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o", "ch4Conc")[1], lvl, lvlMfcSampStor = NULL, lvlEnvHut = NULL, @@ -971,6 +973,383 @@ wrap.dp01.ecse <- function( }#end of TypeMeas %in% "vali" if statement }##end of dp01 if statement + + #calculate dp01 for "ch4Conc" ######################################################################################## + if (dp01 %in% c("ch4Conc")){ + #during sampling period + if (TypeMeas %in% "samp"){ + #assign lvlCrdCo2 for each measurement level + if (lvl == "000_010") {lvlCrdCo2 <- "lvl01"} + if (lvl == "000_020") {lvlCrdCo2 <- "lvl02"} + if (lvl == "000_030") {lvlCrdCo2 <- "lvl03"} + if (lvl == "000_040") {lvlCrdCo2 <- "lvl04"} + if (lvl == "000_050") {lvlCrdCo2 <- "lvl05"} + if (lvl == "000_060") {lvlCrdCo2 <- "lvl06"} + if (lvl == "000_070") {lvlCrdCo2 <- "lvl07"} + if (lvl == "000_080") {lvlCrdCo2 <- "lvl08"} + + #input the whole day data + wrk$data <- data.frame(stringsAsFactors = FALSE, + "pres" = data$crdCo2[[lvl]]$pres, + "presEnvHut" = data$envHut[[lvlEnvHut]]$pres, + "rhEnvHut" = data$envHut[[lvlEnvHut]]$rh, + "rtioMoleDryCh4" = data$crdCo2[[lvl]]$rtioMoleDryCh4, + "rtioMoleWetCh4" = data$crdCo2[[lvl]]$rtioMoleWetCh4, + "rtioMoleWetH2oEnvHut" = data$envHut[[lvlEnvHut]]$rtioMoleWetH2o, + "temp" = data$crdCo2[[lvl]]$temp, + "tempEnvHut" = data$envHut[[lvlEnvHut]]$temp, + "lvlCrdCo2" = data$crdCo2ValvLvl[[lvlValv]]$lvlCrdCo2 + ) + + #input the whole day qfqm + wrk$qfqm <- list() + #subset only + wrk$qfqm$crdCo2 <- qfInp$crdCo2[[lvl]] + + if (PrdMeas == PrdAgr) { + #PrdAgr <- 9 + #9 minutely sampling data + #idxLvLPrdAgr <- paste0(lvl, "_", sprintf("%02d", PrdAgr), "m") + #rpt[[dp01]][[idxLvLPrdAgr]] <- list() + + #if there is at least one measurement + if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ + #determine the index of each measurement + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + #delete row if last timeBgn and timeEnd is NA + wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] + #if last timeEnd is NA, replce that time to the last time value in data$time + wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") + #idxAgr2 <- 0 + for (idxAgr in 1:length(wrk$idx$idxBgn)){ + #idxAgr <- 25 + #get data for each idxAgr + wrk$inpMask$data <- list() + wrk$inpMask$data <- wrk$data[wrk$idx$idxBgn[idxAgr]:wrk$idx$idxEnd[idxAgr],] + + #replace data with NaN when valve switch to measure to next level before schedule time (9 min) + wrk$inpMask$data$presEnvHut <- ifelse(wrk$inpMask$data$lvlCrdCo2 == lvlCrdCo2, wrk$inpMask$data$presEnvHut, NaN) + wrk$inpMask$data$rhEnvHut <- ifelse(wrk$inpMask$data$lvlCrdCo2 == lvlCrdCo2, wrk$inpMask$data$rhEnvHut, NaN) + wrk$inpMask$data$rtioMoleWetH2oEnvHut <- ifelse(wrk$inpMask$data$lvlCrdCo2 == lvlCrdCo2, wrk$inpMask$data$rtioMoleWetH2oEnvHut, NaN) + wrk$inpMask$data$tempEnvHut <- ifelse(wrk$inpMask$data$lvlCrdCo2 == lvlCrdCo2, wrk$inpMask$data$tempEnvHut, NaN) + + #get rid of lvlCrdCo2 + wrk$inpMask$data <- wrk$inpMask$data[,-which(names(wrk$inpMask$data) == "lvlCrdCo2")] + + #dp01 processing + rpt[[idxAgr]] <- eddy4R.base::wrap.dp01( + # assign data: data.frame or list of type numeric or integer + data = wrk$inpMask$data#, + # if data is a list, which list entries should be processed into Level 1 data products? + # defaults to NULL which expects data to be a data.frame + #idx = + #names(wrk$inpMask$data[[dp01]]) #"000_010_02m" + ) + + #units: + for (idxVar in names(rpt[[1]]$mean)){ + #idxVar <- names(rpt[[1]]$mean)[1] + attributes(rpt[[1]]$mean[[idxVar]])$unit <- attributes(wrk$data[[idxVar]])$unit + } + + #grab and add both time begin and time end to rpt + rpt[[idxAgr]]$timeBgn <- list() + rpt[[idxAgr]]$timeEnd <- list() + + #output time for dp01 + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("lvlCrdCo2")))]){ + rpt[[idxAgr]]$timeBgn[[idxVar]] <- wrk$idx$timeBgn[idxAgr] + rpt[[idxAgr]]$timeEnd[[idxVar]] <- wrk$idx$timeEnd[idxAgr] + }; rm(idxVar) + + #}# end of there is at least one data + + }; rm(idxAgr) + } else { + + rpt[[1]] <- list() + + for(idxStat in NameStat){ + #idxStat <- NameStat[1] + rpt[[1]][[idxStat]] <- as.data.frame(matrix(NaN, nrow = 1, ncol = ncol(wrk$data))) + #assign name to each column + names(rpt[[1]][[idxStat]]) <- names(wrk$data) + #not report lvlCrdCo2 + rpt[[1]][[idxStat]] <- rpt[[1]][[idxStat]][which(!(names(rpt[[1]][[idxStat]]) %in% c("lvlCrdCo2")))] + + }; rm(idxStat) + #add both time begin and time end to rpt + rpt[[1]]$timeBgn <- list() + rpt[[1]]$timeEnd <- list() + + #output time for dp01 + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("lvlCrdCo2")))]){ + rpt[[1]]$timeBgn[[idxVar]] <- data$time[1] + rpt[[1]]$timeEnd[[idxVar]] <- data$time[length(data$time)] + #unit + attributes(rpt[[1]]$mean[[idxVar]])$unit <- attributes(wrk$data[[idxVar]])$unit + + }; rm(idxVar) + + }#end of if no measurement data at all in the whole day + } #end of PrdAgr + + if (PrdMeas != PrdAgr) { + #PrdAgr <- 30 + #if there is at least one measurement + if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ + + #determine the index of each measurement + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + #delete row if last timeBgn and timeEnd is NA + wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] + #if last timeEnd is NA, replce that time to the last time value in data$time + wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") + + whrSamp <- wrk$idx$idxBgn[1]:wrk$idx$idxEnd[1] + if (length (wrk$idx$idxBgn) > 1 ){ + for(ii in 2:length (wrk$idx$idxBgn)){ + whrSamp <- c(whrSamp, wrk$idx$idxBgn[ii]:wrk$idx$idxEnd[ii]) + } + } + + tmpAttr <- list() + for (idxData in c("presEnvHut", "rhEnvHut", "rtioMoleWetH2oEnvHut", "tempEnvHut")){ + #defined attributes + tmpAttr[[idxData]] <- attributes(wrk$data[[idxData]]) + #replace idxData data with NaN when irga got kick out to measure the new measurement level + wrk$data[[idxData]] <- ifelse(wrk$data$lvlCrdCo2 == lvlCrdCo2, wrk$data[[idxData]], NaN) + } + wrk$data[-whrSamp, 1:15] <- NaN + #added attributes + for (idxData in c("presEnvHut", "rhEnvHut", "rtioMoleWetH2oEnvHut", "tempEnvHut")){ + attributes(wrk$data[[idxData]]) <- tmpAttr[[idxData]] + } + } else {#if there are no data at all in wrk$data$temp + wrk$data[,1:15] <- NaN + } + + + for(idxAgr in c(1:length(idxTime[[paste0(PrdAgr, "min")]]$Bgn))) { + #idxAgr <- 48 + + + ## grab data at the selected mask data + # for data + wrk$inpMask$data <- list() + idxLvLPrdAgr <- paste0(lvl, "_", sprintf("%02d", PrdAgr), "m") + + wrk$inpMask$data <- wrk$data[idxTime[[paste0(PrdAgr, "min")]]$Bgn[idxAgr]:idxTime[[paste0(PrdAgr, "min")]]$End[idxAgr],] + #get rid of lvlCrdCo2 + wrk$inpMask$data <- wrk$inpMask$data[,-which(names(wrk$inpMask$data) == "lvlCrdCo2")] + + #call wrap.dp01.R to calculate descriptive statistics + rpt[[idxAgr]] <- eddy4R.base::wrap.dp01( + # assign data: data.frame or list of type numeric or integer + data = wrk$inpMask$data#, + # if data is a list, which list entries should be processed into Level 1 data products? + # defaults to NULL which expects data to be a data.frame + #idx = + #names(wrk$inpMask$data[[dp01]]) #"000_010_02m" + ) + + #units: + for (idxVar in names(rpt[[1]]$mean)){ + #idxVar <- names(rpt[[1]]$mean)[1] + attributes(rpt[[1]]$mean[[idxVar]])$unit <- attributes(wrk$data[[idxVar]])$unit + } + + #grab and add both time begin and time end to rpt + rpt[[idxAgr]]$timeBgn <- list() + rpt[[idxAgr]]$timeEnd <- list() + + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("lvlCrdCo2")))]){ + rpt[[idxAgr]]$timeBgn[[idxVar]] <- data$time[idxTime[[paste0(PrdAgr, "min")]]$Bgn[idxAgr]] + rpt[[idxAgr]]$timeEnd[[idxVar]] <- data$time[idxTime[[paste0(PrdAgr, "min")]]$End[idxAgr]] + } + + }; #rm(idxAgr) + + }#end of PrdAgr == 30 + + }#end of TypeMeas %in% "samp" if statement + + #during validation period + if (TypeMeas %in% "vali"){ + #input the whole day data + wrk$data <- data.frame(stringsAsFactors = FALSE, + "dlta13CCo2" = data$crdCo2[[lvl]]$dlta13CCo2, + "dlta13CCo2Refe" = data$crdCo2[[lvl]]$dlta13CCo2Refe, + "pres" = data$crdCo2[[lvl]]$pres, + "presEnvHut" = data$envHut[[lvlEnvHut]]$pres, + "rhEnvHut" = data$envHut[[lvlEnvHut]]$rh, + "rtioMoleDry12CCo2" = data$crdCo2[[lvl]]$rtioMoleDry12CCo2, + "rtioMoleDry13CCo2" = data$crdCo2[[lvl]]$rtioMoleDry13CCo2, + "rtioMoleDryCo2" = data$crdCo2[[lvl]]$rtioMoleDryCo2, + "rtioMoleDryCo2Refe" = data$crdCo2[[lvl]]$rtioMoleDryCo2Refe, + "rtioMoleDryH2o" = data$crdCo2[[lvl]]$rtioMoleDryH2o, + "rtioMoleWet12CCo2" = data$crdCo2[[lvl]]$rtioMoleWet12CCo2, + "rtioMoleWet13CCo2" = data$crdCo2[[lvl]]$rtioMoleWet13CCo2, + "rtioMoleWetCo2" = data$crdCo2[[lvl]]$rtioMoleWetCo2, + "rtioMoleWetH2o" = data$crdCo2[[lvl]]$rtioMoleWetH2o, + "rtioMoleWetH2oEnvHut" = data$envHut[[lvlEnvHut]]$rtioMoleWetH2o, + "temp" = data$crdCo2[[lvl]]$temp, + "tempEnvHut" = data$envHut[[lvlEnvHut]]$temp + ) + + #input the whole day qfqm + wrk$qfqm <- list() + wrk$qfqm$crdCo2 <- qfInp$crdCo2[[lvl]] + + if (PrdMeas == PrdAgr) { + #PrdAgr <- 9 + #9 minutely sampling data + #idxLvLPrdAgr <- paste0(lvl, "_", sprintf("%02d", PrdAgr), "m") + #rpt[[dp01]][[idxLvLPrdAgr]] <- list() + + #if there is at least one measurement + if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ + #determine the end time of each measurement + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + #delete row if last timeBgn and timeEnd is NA + wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] + #if last timeEnd is NA, replce that time to the last time value in data$time + wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") + + #idxAgr2 <- 0 + for (idxAgr in 1:length(wrk$idx$idxBgn)){ + #idxAgr <- 1 + #determine input data for each idxAgr + wrk$inpMask$data <- list() + wrk$inpMask$data <- wrk$data[wrk$idx$idxBgn[idxAgr]:wrk$idx$idxEnd[idxAgr],] + + #calculate dp01 + rpt[[idxAgr]] <- eddy4R.base::wrap.dp01( + # assign data: data.frame or list of type numeric or integer + data = wrk$inpMask$data#, + # if data is a list, which list entries should be processed into Level 1 data products? + # defaults to NULL which expects data to be a data.frame + #idx = + #names(wrk$inpMask$data[[dp01]]) #"000_010_02m" + ) + + #units: + for (idxVar in names(rpt[[1]]$mean)){ + #idxVar <- names(rpt[[1]]$mean)[1] + attributes(rpt[[1]]$mean[[idxVar]])$unit <- attributes(wrk$data[[idxVar]])$unit + } + + #grab and add both time begin and time end to rpt + rpt[[idxAgr]]$timeBgn <- list() + rpt[[idxAgr]]$timeEnd <- list() + + #output time for dp01 + for(idxVar in names(wrk$data)){ + # rpt[[idxAgr2]]$timeBgn[[idxVar]] <- data$time[(whrEnd[idxAgr] - 20 - 2*60+1)] + # rpt[[idxAgr2]]$timeEnd[[idxVar]] <- data$time[(whrEnd[idxAgr] - 20)] + rpt[[idxAgr]]$timeBgn[[idxVar]] <- wrk$idx$timeBgn[idxAgr] + rpt[[idxAgr]]$timeEnd[[idxVar]] <- wrk$idx$timeEnd[idxAgr] + }; rm(idxVar) + + }#; rm(idxAgr) + + } else { + + rpt[[1]] <- list() + + for(idxStat in NameStat){ + #idxStat <- NameStat[1] + rpt[[1]][[idxStat]] <- as.data.frame(matrix(NaN, nrow = 1, ncol = ncol(wrk$data))) + #assign name to each column + names(rpt[[1]][[idxStat]]) <- names(wrk$data) + + }; rm(idxStat) + #add both time begin and time end to rpt + rpt[[1]]$timeBgn <- list() + rpt[[1]]$timeEnd <- list() + + #output time for dp01 + for(idxVar in names(wrk$data)){ + rpt[[1]]$timeBgn[[idxVar]] <- data$time[1] + rpt[[1]]$timeEnd[[idxVar]] <- data$time[length(data$time)] + #unit + attributes(rpt[[1]]$mean[[idxVar]])$unit <- attributes(wrk$data[[idxVar]])$unit + + }; rm(idxVar) + + }#end of if no measurement data at all in the whole day + + } #end of PrdAgr == 9 + + + + if (PrdMeas != PrdAgr) { + #PrdAgr <- 30 + #if there is at least one measurement + if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ + # #determine the end time of each measurement + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + #delete row if last timeBgn and timeEnd is NA + wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] + #if last timeEnd is NA, replce that time to the last time value in data$time + wrk$idx$timeEnd <- as.POSIXct(ifelse(is.na(wrk$idx$timeEnd), data$time[length(data$time)], wrk$idx$timeEnd), origin = "1970-01-01", tz = "UTC") + + whrSamp <- wrk$idx$idxBgn[1]:wrk$idx$idxEnd[1] + if (length (wrk$idx$idxBgn) > 1 ){ + for(ii in 2:length (wrk$idx$idxBgn)){ + whrSamp <- c(whrSamp, wrk$idx$idxBgn[ii]:wrk$idx$idxEnd[ii]) + } + } + wrk$data[-whrSamp, ] <- NaN + } else {#end of if no measurement data at all in the whole day + tmpAttr <- list() + for (idxData in c("presEnvHut", "rhEnvHut", "rtioMoleWetH2oEnvHut", "tempEnvHut")){ + #defined attributes + tmpAttr[[idxData]] <- attributes(wrk$data[[idxData]]) + wrk$data[[idxData]] <- NaN + attributes(wrk$data[[idxData]]) <- tmpAttr[[idxData]] + } + } + + for(idxAgr in c(1:length(idxTime[[paste0(PrdAgr, "min")]]$Bgn))) { + #idxAgr <- 1 + + ## grab data at the selected mask data + # for data + wrk$inpMask$data <- list() + idxLvLPrdAgr <- paste0(lvl, "_", sprintf("%02d", PrdAgr), "m") + wrk$inpMask$data <- wrk$data[idxTime[[paste0(PrdAgr, "min")]]$Bgn[idxAgr]:idxTime[[paste0(PrdAgr, "min")]]$End[idxAgr],] + + #call wrap.dp01.R to calculate descriptive statistics + rpt[[idxAgr]] <- eddy4R.base::wrap.dp01( + # assign data: data.frame or list of type numeric or integer + data = wrk$inpMask$data#, + ) + + #units: + for (idxVar in names(rpt[[1]]$mean)){ + #idxVar <- names(rpt[[1]]$mean)[1] + attributes(rpt[[1]]$mean[[idxVar]])$unit <- attributes(wrk$data[[idxVar]])$unit + } + + #grab and add both time begin and time end to rpt + rpt[[idxAgr]]$timeBgn <- list() + rpt[[idxAgr]]$timeEnd <- list() + + #output time for dp01 + for(idxVar in names(wrk$data)){ + # rpt[[idxAgr2]]$timeBgn[[idxVar]] <- data$time[(whrEnd[idxAgr] - 20 - 2*60+1)] + # rpt[[idxAgr2]]$timeEnd[[idxVar]] <- data$time[(whrEnd[idxAgr] - 20)] + rpt[[idxAgr]]$timeBgn[[idxVar]] <- data$time[idxTime[[paste0(PrdAgr, "min")]]$Bgn[idxAgr]] + rpt[[idxAgr]]$timeEnd[[idxVar]] <- data$time[idxTime[[paste0(PrdAgr, "min")]]$End[idxAgr]] + }; rm(idxVar) + + }; #rm(idxAgr) + } #end of PrdAgr == 30 + }#end of TypeMeas %in% "vali" if statement + }##end of dp01 if statement + + #calculate dp01 for "isoH2o" ######################################################################################## if (dp01 %in% c("isoH2o")){ #during sampling period From 1e4899b055e818564da03b76021c0efe5e0e6a1e Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Fri, 16 Apr 2021 02:19:17 +0000 Subject: [PATCH 099/168] adding ch4Conc quality flag groupings --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 1050 +++++++++++++--------- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R | 4 +- 2 files changed, 621 insertions(+), 433 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 7404dd88..e072a046 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -10,7 +10,7 @@ #' @param MethMeas A vector of class "character" containing the name of measurement method (eddy-covariance turbulent exchange or storage exchange), MethMeas = c("ecte", "ecse"). Defaults to "ecse". [-] #' @param TypeMeas A vector of class "character" containing the name of measurement type (sampling or validation), TypeMeas = c("samp", "ecse"). Defaults to "samp". [-] #' @param dp01 A vector of class "character" containing the name of NEON ECTE and ECSE L1 data products which the flags are being grouped, \cr -#' c("envHut", "co2Turb", "h2oTurb", "isoCo2", "isoH2o", "soni", "amrs", "tempAirLvl", "tempAirTop"). Defaults to "co2Turb". [-] +#' c("envHut", "co2Turb", "h2oTurb", "isoCo2", "ch4Conc", isoH2o", "soni", "amrs", "tempAirLvl", "tempAirTop"). Defaults to "co2Turb". [-] #' @param idGas A data frame contianing gas ID for isoCo2 measurement. Need to provide when dp01 = "isoCo2". Default to NULL. [-] #' @return A list of data frame of the quality flags related to that sub-data product. \cr @@ -90,13 +90,15 @@ # removing flags for external sensors from ECSE qfqm # David Durden (2020-07-14) # Added qfNull and qfSpk for all variables, removed qfNull from ancillary data streams +# Chris Florian (2020-04-09) +# adding ch4Conc to the dp01 list and adding all ch4 qfqm variables ############################################################################################## def.dp01.grp.qf <- function( qfInp = list(), MethMeas = c("ecte", "ecse")[1], TypeMeas = c("samp", "vali")[1], - dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "isoH2o", "soni", "amrs", "tempAirLvl", "tempAirTop")[1], + dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "ch4Conc", "isoH2o", "soni", "amrs", "tempAirLvl", "tempAirTop")[1], idGas =NULL ){ #check existing input list @@ -130,6 +132,12 @@ def.dp01.grp.qf <- function( } }# close if statement of dp01 + if (dp01 %in% c("ch4Conc")) { + if (!("crdCo2" %in% names(qfInp))){ + base::stop("Missing crdCo2 quality flags") + } + }# close if statement of dp01 + if (dp01 %in% c("isoH2o")) { if (!("crdH2o" %in% names(qfInp))){ base::stop("Missing crdH2o quality flags") @@ -906,7 +914,7 @@ if (MethMeas == "ecte") { rpt$angNedZaxs <- data.frame(setQf$sensAmrs, setQf$angZaxs) }#close if statement of TypeMeas %in% c("samp", "vali") } #close if statement of dp01 == "amrs" -} #close if statement of MethMeas == "ecse" +} #close if statement of MethMeas == "ecte" # ecse ####################################################################################### if (MethMeas == "ecse") { @@ -1298,8 +1306,8 @@ if (MethMeas == "ecse") { setQf <- NULL }##close if statement of dp01 %in% c("co2Stor", "h2oStor") -#isoCo2 #################################################################################### - if (dp01 == "isoCo2") { +#isoCo2 and ch4Conc #################################################################################### + if (dp01 %in% c("isoCo2", "ch4Conc")) { #check if data are exist #external quality flags from envHut if (!("envHut" %in% names(qfInp)) || length(which(!is.na(qfInp$crdCo2$qfRngTemp))) == 0){ @@ -1347,6 +1355,7 @@ if (MethMeas == "ecse") { if (length(which(!is.na(qfInp$crdCo2$qfSensStus))) == 0){ qfInp$crdCo2$qfSensStus <- -1 } + #setQf for crdCo2 setQf$rtioMoleDryCo2 <- data.frame("qfRngRtioMoleDryCo2" = qfInp$crdCo2$qfRngRtioMoleDryCo2, "qfStepRtioMoleDryCo2" = qfInp$crdCo2$qfStepRtioMoleDryCo2, @@ -1363,6 +1372,12 @@ if (MethMeas == "ecse") { "qfPersRtioMoleDry13CCo2" = qfInp$crdCo2$qfPersRtioMoleDry13CCo2) #"qfCalRtioMoleDry13CCo2" = qfInp$crdCo2$qfCalRtioMoleDry13CCo2) + setQf$rtioMoleDryCh4 <- data.frame("qfRngRtioMoleDryCh4" = qfInp$crdCo2$qfRngRtioMoleDryCh4, + "qfStepRtioMoleDryCh4" = qfInp$crdCo2$qfStepRtioMoleDryCh4, + "qfPersRtioMoleDryCh4" = qfInp$crdCo2$qfPersRtioMoleDryCh4) + #"qfCalRtioMoleDryCh4" = qfInp$crdCo2$qfCalRtioMoleDryCh4) + + setQf$rtioMoleDryH2o <- data.frame("qfRngRtioMoleDryH2o" = qfInp$crdCo2$qfRngRtioMoleDryH2o, #"qfStepRtioMoleDryH2o" = qfInp$crdCo2$qfStepRtioMoleDryH2o, "qfPersRtioMoleDryH2o" = qfInp$crdCo2$qfPersRtioMoleDryH2o) @@ -1383,6 +1398,11 @@ if (MethMeas == "ecse") { "qfPersRtioMoleWet13CCo2" = qfInp$crdCo2$qfPersRtioMoleWet13CCo2) #"qfCalRtioMoleWet13CCo2 " = qfInp$crdCo2$qfCalRtioMoleWet13CCo2) + setQf$rtioMoleWetCh4 <- data.frame("qfRngRtioMoleWetCh4" = qfInp$crdCo2$qfRngRtioMoleWetCh4, + "qfStepRtioMoleWetCh4" = qfInp$crdCo2$qfStepRtioMoleWetCh4, + "qfPersRtioMoleWetCh4" = qfInp$crdCo2$qfPersRtioMoleWetCh4) + #"qfCalRtioMoleWetCh4" = qfInp$crdCo2$qfCalRtioMoleWetCh4) + setQf$rtioMoleWetH2o <- data.frame("qfRngRtioMoleWetH2o" = qfInp$crdCo2$qfRngRtioMoleWetH2o, #"qfStepRtioMoleWetH2o" = qfInp$crdCo2$qfStepRtioMoleWetH2o, "qfPersRtioMoleWetH2o" = qfInp$crdCo2$qfPersRtioMoleWetH2o) @@ -1413,10 +1433,12 @@ if (MethMeas == "ecse") { names(setQf$rtioMoleDryCo2) <- paste0(colnames(setQf$rtioMoleDryCo2), "CrdCo2") names(setQf$rtioMoleDry12CCo2) <- paste0(colnames(setQf$rtioMoleDry12CCo2), "CrdCo2") names(setQf$rtioMoleDry13CCo2) <- paste0(colnames(setQf$rtioMoleDry13CCo2), "CrdCo2") + names(setQf$rtioMoleDryCh4) <- paste0(colnames(setQf$rtioMoleDryCh4), "CrdCo2") names(setQf$rtioMoleDryH2o) <- paste0(colnames(setQf$rtioMoleDryH2o), "CrdCo2") names(setQf$rtioMoleWetCo2) <- paste0(colnames(setQf$rtioMoleWetCo2), "CrdCo2") names(setQf$rtioMoleWet12CCo2) <- paste0(colnames(setQf$rtioMoleWet12CCo2), "CrdCo2") names(setQf$rtioMoleWet13CCo2) <- paste0(colnames(setQf$rtioMoleWet13CCo2), "CrdCo2") + names(setQf$rtioMoleWetCh4) <- paste0(colnames(setQf$rtioMoleWetCh4), "CrdCo2") names(setQf$rtioMoleWetH2o) <- paste0(colnames(setQf$rtioMoleWetH2o), "CrdCo2") names(setQf$dlta13CCo2) <- paste0(colnames(setQf$dlta13CCo2), "CrdCo2") names(setQf$presCrdCo2) <- paste0(colnames(setQf$presCrdCo2), "CrdCo2") @@ -1518,46 +1540,35 @@ if (MethMeas == "ecse") { #change column names names(setQf$presValiRegInStor) <- paste0(colnames(setQf$presValiRegInStor), "PresValiRegInStor") - #define qf which use only sampling period - if (TypeMeas == "samp") { - #temporary list - tmp <- list() - #if not all idGas = NA or all qfRngTemp = NA - if (length(which(!is.na(idGas))) > 0){ - #grouping qulity flags that related to isoCo2 L1 sub-data product - tmp$rtioMoleWetCo2 <- data.frame(setQf$rtioMoleWetCo2, setQf$rtioMoleWet13CCo2, #setQf$dlta13CCo2, - setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, - #setQf$frt00Mfm, - #setQf$frtMfm, setQf$presAtmMfm, - #setQf$tempMfm, - setQf$sensMfm, - #setQf$presInlt, setQf$pumpStor, - #setQf$heatInlt, - idGas = idGas - ) - rpt$rtioMoleWetCo2 <- na.omit(tmp$rtioMoleWetCo2[which(tmp$rtioMoleWetCo2$idGas == 105 | (is.na(tmp$rtioMoleWetCo2$idGas) & tmp$rtioMoleWetCo2$qfSensStus == -1)),]) - - tmp$rtioMoleDryCo2 <- data.frame(setQf$rtioMoleDryCo2, #setQf$dlta13CCo2, - setQf$rtioMoleDry12CCo2, setQf$rtioMoleDry13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, - #setQf$frt00Mfm, - #setQf$frtMfm, setQf$presAtmMfm, - #setQf$tempMfm, - setQf$sensMfm, - #setQf$presInlt, setQf$pumpStor, - #setQf$heatInlt, - idGas = idGas - - ) - rpt$rtioMoleDryCo2 <- na.omit(tmp$rtioMoleDryCo2[which(tmp$rtioMoleDryCo2$idGas == 105 | (is.na(tmp$rtioMoleDryCo2$idGas) & tmp$rtioMoleDryCo2$qfSensStus == -1)),]) - - tmp$rtioMoleWet12CCo2 <-data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, + #grouping quality flags related to the isoCo2 L1 data product + + if (dp01 %in% "isoCo2") { + #define qf which use only sampling period + if (TypeMeas == "samp") { + #temporary list + tmp <- list() + #if not all idGas = NA or all qfRngTemp = NA + if (length(which(!is.na(idGas))) > 0){ + #grouping qulity flags that related to isoCo2 L1 sub-data product + tmp$rtioMoleWetCo2 <- data.frame(setQf$rtioMoleWetCo2, setQf$rtioMoleWet13CCo2, #setQf$dlta13CCo2, + setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, - #, setQf$frt00Mfm, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, + #setQf$heatInlt, + idGas = idGas + ) + rpt$rtioMoleWetCo2 <- na.omit(tmp$rtioMoleWetCo2[which(tmp$rtioMoleWetCo2$idGas == 105 | (is.na(tmp$rtioMoleWetCo2$idGas) & tmp$rtioMoleWetCo2$qfSensStus == -1)),]) + + tmp$rtioMoleDryCo2 <- data.frame(setQf$rtioMoleDryCo2, #setQf$dlta13CCo2, + setQf$rtioMoleDry12CCo2, setQf$rtioMoleDry13CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, + #setQf$frt00Mfm, #setQf$frtMfm, setQf$presAtmMfm, #setQf$tempMfm, setQf$sensMfm, @@ -1565,291 +1576,246 @@ if (MethMeas == "ecse") { #setQf$heatInlt, idGas = idGas - ) - rpt$rtioMoleWet12CCo2 <- na.omit(tmp$rtioMoleWet12CCo2[which(tmp$rtioMoleWet12CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet12CCo2$idGas) & tmp$rtioMoleWet12CCo2$qfSensStus == -1)),]) - - tmp$rtioMoleDry12CCo2 <- data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet12CCo2, + ) + rpt$rtioMoleDryCo2 <- na.omit(tmp$rtioMoleDryCo2[which(tmp$rtioMoleDryCo2$idGas == 105 | (is.na(tmp$rtioMoleDryCo2$idGas) & tmp$rtioMoleDryCo2$qfSensStus == -1)),]) + + tmp$rtioMoleWet12CCo2 <-data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, + #, setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, + #setQf$heatInlt, + idGas = idGas + + ) + rpt$rtioMoleWet12CCo2 <- na.omit(tmp$rtioMoleWet12CCo2[which(tmp$rtioMoleWet12CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet12CCo2$idGas) & tmp$rtioMoleWet12CCo2$qfSensStus == -1)),]) + + tmp$rtioMoleDry12CCo2 <- data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet12CCo2, + setQf$presCrdCo2, setQf$tempCrdCo2, + setQf$tempWbox, setQf$sensCrdCo2, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm, + #, setQf$presInlt, + #setQf$pumpStor, + #setQf$heatInlt, + idGas = idGas + ) + rpt$rtioMoleDry12CCo2 <- na.omit(tmp$rtioMoleDry12CCo2[which(tmp$rtioMoleDry12CCo2$idGas == 105 | (is.na(tmp$rtioMoleDry12CCo2$idGas) & tmp$rtioMoleDry12CCo2$qfSensStus == -1)),]) + + tmp$rtioMoleWet13CCo2 <- data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, + #setQf$heatInlt, + idGas = idGas + + ) + rpt$rtioMoleWet13CCo2 <- na.omit(tmp$rtioMoleWet13CCo2[which(tmp$rtioMoleWet13CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet13CCo2$idGas) & tmp$rtioMoleWet13CCo2$qfSensStus == -1)),]) + + tmp$rtioMoleDry13CCo2<- data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, #setQf$frt00Mfm, setQf$frtMfm, #setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, - #, setQf$presInlt, + setQf$sensMfm, + #setQf$presInlt, #setQf$pumpStor, #setQf$heatInlt, idGas = idGas - ) - rpt$rtioMoleDry12CCo2 <- na.omit(tmp$rtioMoleDry12CCo2[which(tmp$rtioMoleDry12CCo2$idGas == 105 | (is.na(tmp$rtioMoleDry12CCo2$idGas) & tmp$rtioMoleDry12CCo2$qfSensStus == -1)),]) - - tmp$rtioMoleWet13CCo2 <- data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, - #setQf$frt00Mfm, - #setQf$frtMfm, setQf$presAtmMfm, - #setQf$tempMfm, - setQf$sensMfm, - #setQf$presInlt, setQf$pumpStor, - #setQf$heatInlt, - idGas = idGas - - ) - rpt$rtioMoleWet13CCo2 <- na.omit(tmp$rtioMoleWet13CCo2[which(tmp$rtioMoleWet13CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet13CCo2$idGas) & tmp$rtioMoleWet13CCo2$qfSensStus == -1)),]) - - tmp$rtioMoleDry13CCo2<- data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, - setQf$presCrdCo2, setQf$tempCrdCo2, - setQf$tempWbox, setQf$sensCrdCo2, - #setQf$frt00Mfm, setQf$frtMfm, - #setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, - #setQf$presInlt, - #setQf$pumpStor, - #setQf$heatInlt, - idGas = idGas - - ) - rpt$rtioMoleDry13CCo2 <- na.omit(tmp$rtioMoleDry13CCo2[which(tmp$rtioMoleDry13CCo2$idGas == 105 | (is.na(tmp$rtioMoleDry13CCo2$idGas) & tmp$rtioMoleDry13CCo2$qfSensStus == -1)),]) - - tmp$dlta13CCo2 <- data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, - setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, - #setQf$frt00Mfm, - #setQf$frtMfm, setQf$presAtmMfm, - #setQf$tempMfm, - setQf$sensMfm, - #setQf$presInlt, setQf$pumpStor, - #setQf$heatInlt, - idGas = idGas - - ) - rpt$dlta13CCo2 <- na.omit(tmp$dlta13CCo2[which(tmp$dlta13CCo2$idGas == 105 | (is.na(tmp$dlta13CCo2$idGas) & tmp$dlta13CCo2$qfSensStus == -1)),]) - - tmp$rtioMoleWetH2o <- data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, - #setQf$frt00Mfm, - #setQf$frtMfm, setQf$presAtmMfm, - #setQf$tempMfm, - setQf$sensMfm, - #setQf$presInlt, setQf$pumpStor, - #setQf$heatInlt, - idGas = idGas - - ) - rpt$rtioMoleWetH2o <- na.omit(tmp$rtioMoleWetH2o[which(tmp$rtioMoleWetH2o$idGas == 11 | (is.na(tmp$rtioMoleWetH2o$idGas) & tmp$rtioMoleWetH2o$qfSensStus == -1)),]) - - tmp$rtioMoleDryH2o <- data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, - setQf$presCrdCo2, setQf$tempCrdCo2, - setQf$tempWbox, setQf$sensCrdCo2, - #setQf$frt00Mfm, setQf$frtMfm, - #setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm, - #setQf$presInlt, - #setQf$pumpStor, - #setQf$heatInlt, - idGas = idGas - ) - rpt$rtioMoleDryH2o <- na.omit(tmp$rtioMoleDryH2o[which(tmp$rtioMoleDryH2o$idGas == 11 | (is.na(tmp$rtioMoleDryH2o$idGas) & tmp$rtioMoleDryH2o$qfSensStus == -1)),]) - - rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) - rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) - rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) - rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) - rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) - rpt$rtioMoleWetH2oEnvHut <- na.omit(data.frame (setQf$rtioMoleWetH2oEnvHut)) - #remove idGas column - lapply(names(rpt), function(x){ - rpt[[x]] <<- rpt[[x]][, ! names(rpt[[x]]) %in% "idGas", drop = F] - }) - #remove tmp - rm(tmp) - } else { - #grouping qulity flags that related to isoCo2 L1 sub-data product - rpt$rtioMoleWetCo2 <- na.omit(data.frame(setQf$rtioMoleWetCo2, setQf$rtioMoleWet12CCo2, #setQf$dlta13CCo2, - setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, - #setQf$frt00Mfm, - #setQf$frtMfm, setQf$presAtmMfm, - #setQf$tempMfm, - setQf$sensMfm#, - #setQf$presInlt, setQf$pumpStor - #setQf$heatInlt - )) - - rpt$rtioMoleDryCo2 <- na.omit(data.frame(setQf$rtioMoleDryCo2, setQf$rtioMoleDry12CCo2, #setQf$dlta13CCo2, - setQf$rtioMoleDry13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, - #setQf$frt00Mfm, - #setQf$frtMfm, setQf$presAtmMfm, - #setQf$tempMfm, - setQf$sensMfm#, - #setQf$presInlt, setQf$pumpStor - #setQf$heatInlt - )) - - rpt$rtioMoleWet12CCo2 <- na.omit(data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, - #setQf$frt00Mfm, - #setQf$frtMfm, setQf$presAtmMfm, - #setQf$tempMfm, - setQf$sensMfm#, - #setQf$presInlt, setQf$pumpStor - #setQf$heatInlt - )) - - rpt$rtioMoleDry12CCo2 <- na.omit(data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet12CCo2, - setQf$presCrdCo2, setQf$tempCrdCo2, - setQf$tempWbox, setQf$sensCrdCo2, - #setQf$frt00Mfm, setQf$frtMfm, - #setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm#, setQf$presInlt, - #setQf$pumpStor - #setQf$heatInlt - )) - - rpt$rtioMoleWet13CCo2 <- na.omit(data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, #setQf$frt00Mfm, - #setQf$frtMfm, setQf$presAtmMfm, - #setQf$tempMfm, - setQf$sensMfm#, - #setQf$presInlt, setQf$pumpStor - #setQf$heatInlt - )) - - rpt$rtioMoleDry13CCo2 <- na.omit(data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, - setQf$presCrdCo2, setQf$tempCrdCo2, - setQf$tempWbox, setQf$sensCrdCo2, - #setQf$frt00Mfm, setQf$frtMfm, - #setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm#, setQf$presInlt, - #setQf$pumpStor - #setQf$heatInlt - )) - - rpt$dlta13CCo2 <- na.omit(data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, - setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2,# setQf$frt00Mfm, - #setQf$frtMfm, setQf$presAtmMfm, - #setQf$tempMfm, - setQf$sensMfm#, - #setQf$presInlt, setQf$pumpStor - #setQf$heatInlt - )) - - rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, #setQf$frt00Mfm, - #setQf$frtMfm, setQf$presAtmMfm, - #setQf$tempMfm, - setQf$sensMfm#, - #setQf$presInlt, setQf$pumpStor - #setQf$heatInlt - )) - - rpt$rtioMoleDryH2o <- na.omit(data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, - setQf$presCrdCo2, setQf$tempCrdCo2, - setQf$tempWbox, setQf$sensCrdCo2, - #setQf$frt00Mfm, setQf$frtMfm, - #setQf$presAtmMfm, setQf$tempMfm, - setQf$sensMfm#, setQf$presInlt, - #setQf$pumpStor - #setQf$heatInlt - )) - - rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) - rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) - rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) - rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) - rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) - rpt$rtioMoleWetH2oEnvHut <- na.omit(data.frame (setQf$rtioMoleWetH2oEnvHut)) - }# close else statement - - }#close if statement of TypeMeas == "samp" - - #define qf which use only validation period - if (TypeMeas == "vali") { - #temporary list - tmp <- list() - #if not all idGas = NA or all qfRngTemp = NA - if (length(which(!is.na(idGas))) > 0){ - #grouping qulity flags that related to isoCo2 L1 sub-data product - tmp$rtioMoleWetCo2 <- data.frame(setQf$rtioMoleWetCo2, setQf$rtioMoleWet12CCo2, #setQf$dlta13CCo2, - setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2,# setQf$frt00MfcVali, - #setQf$frtMfcVali, setQf$presAtmMfcVali, - #setQf$tempMfcVali, - setQf$sensMfcVali, - #setQf$presValiRegInStor, - idGas = idGas) - rpt$rtioMoleWetCo2 <- na.omit(tmp$rtioMoleWetCo2[which(tmp$rtioMoleWetCo2$idGas == 105 | (is.na(tmp$rtioMoleWetCo2$idGas) & tmp$rtioMoleWetCo2$qfSensStus == -1)),]) - - tmp$rtioMoleDryCo2<- data.frame(setQf$rtioMoleDryCo2, setQf$rtioMoleDry12CCo2, #setQf$dlta13CCo2, - setQf$rtioMoleDry13CCo2, setQf$presCrdCo2, + + ) + rpt$rtioMoleDry13CCo2 <- na.omit(tmp$rtioMoleDry13CCo2[which(tmp$rtioMoleDry13CCo2$idGas == 105 | (is.na(tmp$rtioMoleDry13CCo2$idGas) & tmp$rtioMoleDry13CCo2$qfSensStus == -1)),]) + + tmp$dlta13CCo2 <- data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, #setQf$frt00MfcVali, - #setQf$frtMfcVali, setQf$presAtmMfcVali, - #setQf$tempMfcVali, - setQf$sensMfcVali, - #setQf$presValiRegInStor, - idGas = idGas) - rpt$rtioMoleDryCo2 <- na.omit(tmp$rtioMoleDryCo2[which(tmp$rtioMoleDryCo2$idGas == 105 | (is.na(tmp$rtioMoleDryCo2$idGas) & tmp$rtioMoleDryCo2$qfSensStus == -1)),]) - - tmp$rtioMoleWet12CCo2 <- data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, #setQf$frt00MfcVali, - #setQf$frtMfcVali, setQf$presAtmMfcVali, - #setQf$tempMfcVali, - setQf$sensMfcVali, - #setQf$presValiRegInStor, - idGas = idGas) - rpt$rtioMoleWet12CCo2 <- na.omit(tmp$rtioMoleWet12CCo2[which(tmp$rtioMoleWet12CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet12CCo2$idGas) & tmp$rtioMoleWet12CCo2$qfSensStus == -1)),]) - - tmp$rtioMoleDry12CCo2 <- data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet12CCo2, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, + #setQf$heatInlt, + idGas = idGas + + ) + rpt$dlta13CCo2 <- na.omit(tmp$dlta13CCo2[which(tmp$dlta13CCo2$idGas == 105 | (is.na(tmp$dlta13CCo2$idGas) & tmp$dlta13CCo2$qfSensStus == -1)),]) + + tmp$rtioMoleWetH2o <- data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, + #setQf$heatInlt, + idGas = idGas + + ) + rpt$rtioMoleWetH2o <- na.omit(tmp$rtioMoleWetH2o[which(tmp$rtioMoleWetH2o$idGas == 11 | (is.na(tmp$rtioMoleWetH2o$idGas) & tmp$rtioMoleWetH2o$qfSensStus == -1)),]) + + tmp$rtioMoleDryH2o <- data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, setQf$presCrdCo2, setQf$tempCrdCo2, - setQf$tempWbox, setQf$sensCrdCo2, - #setQf$frt00MfcVali, setQf$frtMfcVali, - #setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali, #setQf$presValiRegInStor, - idGas = idGas) - rpt$rtioMoleDry12CCo2 <- na.omit(tmp$rtioMoleDry12CCo2[which(tmp$rtioMoleDry12CCo2$idGas == 105 | (is.na(tmp$rtioMoleDry12CCo2$idGas) & tmp$rtioMoleDry12CCo2$qfSensStus == -1)),]) + setQf$tempWbox, setQf$sensCrdCo2, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, + #setQf$pumpStor, + #setQf$heatInlt, + idGas = idGas + ) + rpt$rtioMoleDryH2o <- na.omit(tmp$rtioMoleDryH2o[which(tmp$rtioMoleDryH2o$idGas == 11 | (is.na(tmp$rtioMoleDryH2o$idGas) & tmp$rtioMoleDryH2o$qfSensStus == -1)),]) + + rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) + rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) + rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) + rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) + rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) + rpt$rtioMoleWetH2oEnvHut <- na.omit(data.frame (setQf$rtioMoleWetH2oEnvHut)) + #remove idGas column + lapply(names(rpt), function(x){ + rpt[[x]] <<- rpt[[x]][, ! names(rpt[[x]]) %in% "idGas", drop = F] + }) + #remove tmp + rm(tmp) + } else { + #grouping qulity flags that related to isoCo2 L1 sub-data product + rpt$rtioMoleWetCo2 <- na.omit(data.frame(setQf$rtioMoleWetCo2, setQf$rtioMoleWet12CCo2, #setQf$dlta13CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor + #setQf$heatInlt + )) + + rpt$rtioMoleDryCo2 <- na.omit(data.frame(setQf$rtioMoleDryCo2, setQf$rtioMoleDry12CCo2, #setQf$dlta13CCo2, + setQf$rtioMoleDry13CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor + #setQf$heatInlt + )) + + rpt$rtioMoleWet12CCo2 <- na.omit(data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor + #setQf$heatInlt + )) + + rpt$rtioMoleDry12CCo2 <- na.omit(data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet12CCo2, + setQf$presCrdCo2, setQf$tempCrdCo2, + setQf$tempWbox, setQf$sensCrdCo2, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm#, setQf$presInlt, + #setQf$pumpStor + #setQf$heatInlt + )) + + rpt$rtioMoleWet13CCo2 <- na.omit(data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor + #setQf$heatInlt + )) + + rpt$rtioMoleDry13CCo2 <- na.omit(data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, + setQf$presCrdCo2, setQf$tempCrdCo2, + setQf$tempWbox, setQf$sensCrdCo2, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm#, setQf$presInlt, + #setQf$pumpStor + #setQf$heatInlt + )) + + rpt$dlta13CCo2 <- na.omit(data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2,# setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor + #setQf$heatInlt + )) + + rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor + #setQf$heatInlt + )) + + rpt$rtioMoleDryH2o <- na.omit(data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, + setQf$presCrdCo2, setQf$tempCrdCo2, + setQf$tempWbox, setQf$sensCrdCo2, + #setQf$frt00Mfm, setQf$frtMfm, + #setQf$presAtmMfm, setQf$tempMfm, + setQf$sensMfm#, setQf$presInlt, + #setQf$pumpStor + #setQf$heatInlt + )) + + rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) + rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) + rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) + rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) + rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) + rpt$rtioMoleWetH2oEnvHut <- na.omit(data.frame (setQf$rtioMoleWetH2oEnvHut)) + }# close else statement - tmp$rtioMoleWet13CCo2 <- data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, + }#close if statement of TypeMeas == "samp" + + #define qf which use only validation period + if (TypeMeas == "vali") { + #temporary list + tmp <- list() + #if not all idGas = NA or all qfRngTemp = NA + if (length(which(!is.na(idGas))) > 0){ + #grouping qulity flags that related to isoCo2 L1 sub-data product + tmp$rtioMoleWetCo2 <- data.frame(setQf$rtioMoleWetCo2, setQf$rtioMoleWet12CCo2, #setQf$dlta13CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, #setQf$frt00MfcVali, + setQf$sensCrdCo2,# setQf$frt00MfcVali, #setQf$frtMfcVali, setQf$presAtmMfcVali, #setQf$tempMfcVali, - setQf$sensMfcVali, - #setQf$presValiRegInStor, - idGas = idGas) - rpt$rtioMoleWet13CCo2 <- na.omit(tmp$rtioMoleWet13CCo2[which(tmp$rtioMoleWet13CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet13CCo2$idGas) & tmp$rtioMoleWet13CCo2$qfSensStus == -1)),]) - - tmp$rtioMoleDry13CCo2 <- data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, - setQf$presCrdCo2, setQf$tempCrdCo2, - setQf$tempWbox, setQf$sensCrdCo2, - #setQf$frt00MfcVali, setQf$frtMfcVali, - #setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali, #setQf$presValiRegInStor, - idGas = idGas) - rpt$rtioMoleDry13CCo2 <- na.omit(tmp$rtioMoleDry13CCo2[which(tmp$rtioMoleDry13CCo2$idGas == 105 | (is.na(tmp$rtioMoleDry13CCo2$idGas) & tmp$rtioMoleDry13CCo2$qfSensStus == -1)),]) - - tmp$dlta13CCo2 <- data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, - setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, #setQf$frt00MfcVali, - #setQf$frtMfcVali, setQf$presAtmMfcVali, - #setQf$tempMfcVali, - setQf$sensMfcVali, - #setQf$presValiRegInStor, - idGas = idGas) - rpt$dlta13CCo2 <- na.omit(tmp$dlta13CCo2[which(tmp$dlta13CCo2$idGas == 105 | (is.na(tmp$dlta13CCo2$idGas) & tmp$dlta13CCo2$qfSensStus == -1)),]) - - tmp$rtioMoleWetH2o <- data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) + rpt$rtioMoleWetCo2 <- na.omit(tmp$rtioMoleWetCo2[which(tmp$rtioMoleWetCo2$idGas == 105 | (is.na(tmp$rtioMoleWetCo2$idGas) & tmp$rtioMoleWetCo2$qfSensStus == -1)),]) + + tmp$rtioMoleDryCo2<- data.frame(setQf$rtioMoleDryCo2, setQf$rtioMoleDry12CCo2, #setQf$dlta13CCo2, + setQf$rtioMoleDry13CCo2, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, #setQf$frt00MfcVali, #setQf$frtMfcVali, setQf$presAtmMfcVali, @@ -1857,126 +1823,345 @@ if (MethMeas == "ecse") { setQf$sensMfcVali, #setQf$presValiRegInStor, idGas = idGas) - rpt$rtioMoleWetH2o <- na.omit(tmp$rtioMoleWetH2o[which(tmp$rtioMoleWetH2o$idGas == 11 | (is.na(tmp$rtioMoleWetH2o$idGas) & tmp$rtioMoleWetH2o$qfSensStus == -1)),]) - - tmp$rtioMoleDryH2o <- data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, - setQf$presCrdCo2, setQf$tempCrdCo2, - setQf$tempWbox, setQf$sensCrdCo2, - #setQf$frt00MfcVali, setQf$frtMfcVali, - #setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali, #setQf$presValiRegInStor, - idGas = idGas) - rpt$rtioMoleDryH2o <- na.omit(tmp$rtioMoleDryH2o[which(tmp$rtioMoleDryH2o$idGas == 11 | (is.na(tmp$rtioMoleDryH2o$idGas) & tmp$rtioMoleDryH2o$qfSensStus == -1)),]) - - rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) - - rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) - rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) - rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) - rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) - rpt$rtioMoleWetH2oEnvHut <- na.omit(data.frame (setQf$rtioMoleWetH2oEnvHut)) - #remove idGas column - lapply(names(rpt), function(x){ - rpt[[x]] <<- rpt[[x]][, ! names(rpt[[x]]) %in% "idGas", drop = F] - }) - #remove tmp - rm(tmp) - } else { - #grouping qulity flags that related to isoCo2 L1 sub-data product - rpt$rtioMoleWetCo2 <- na.omit(data.frame(setQf$rtioMoleWetCo2, setQf$rtioMoleWet12CCo2,#setQf$dlta13CCo2, - setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, #setQf$frt00MfcVali, - #setQf$frtMfcVali, setQf$presAtmMfcVali, - #setQf$tempMfcVali, - setQf$sensMfcVali#, - #setQf$presValiRegInStor - )) - - rpt$rtioMoleDryCo2 <- na.omit(data.frame(setQf$rtioMoleDryCo2, setQf$rtioMoleDry12CCo2,#setQf$dlta13CCo2, - setQf$rtioMoleDry13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, #setQf$frt00MfcVali, - #setQf$frtMfcVali, setQf$presAtmMfcVali, - #setQf$tempMfcVali, - setQf$sensMfcVali#, - #setQf$presValiRegInStor - )) - - rpt$rtioMoleWet12CCo2 <- na.omit(data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, #setQf$frt00MfcVali, - #setQf$frtMfcVali, setQf$presAtmMfcVali, - #setQf$tempMfcVali, - setQf$sensMfcVali#, - #setQf$presValiRegInStor - )) - - rpt$rtioMoleDry12CCo2 <- na.omit(data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet12CCo2, - setQf$presCrdCo2, setQf$tempCrdCo2, - setQf$tempWbox, setQf$sensCrdCo2, - #setQf$frt00MfcVali, setQf$frtMfcVali, - #setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali#, setQf$presValiRegInStor - )) - - rpt$rtioMoleWet13CCo2 <- na.omit(data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, #setQf$frt00MfcVali, - #setQf$frtMfcVali, setQf$presAtmMfcVali, - #setQf$tempMfcVali, - setQf$sensMfcVali#, - #setQf$presValiRegInStor - )) - - rpt$rtioMoleDry13CCo2 <- na.omit(data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, - setQf$presCrdCo2, setQf$tempCrdCo2, - setQf$tempWbox, setQf$sensCrdCo2, - #setQf$frt00MfcVali, setQf$frtMfcVali, - #setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali#, setQf$presValiRegInStor - )) - - rpt$dlta13CCo2 <- na.omit(data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, - setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, #setQf$frt00MfcVali, - #setQf$frtMfcVali, setQf$presAtmMfcVali, - #setQf$tempMfcVali, - setQf$sensMfcVali#, - #setQf$presValiRegInStor - )) - - rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, - setQf$sensCrdCo2, #setQf$frt00MfcVali, - #setQf$frtMfcVali, setQf$presAtmMfcVali, - #setQf$tempMfcVali, - setQf$sensMfcVali#, - #setQf$presValiRegInStor - )) - - rpt$rtioMoleDryH2o <- na.omit(data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, - setQf$presCrdCo2, setQf$tempCrdCo2, - setQf$tempWbox, setQf$sensCrdCo2, - #setQf$frt00MfcVali, setQf$frtMfcVali, - #setQf$presAtmMfcVali, setQf$tempMfcVali, - setQf$sensMfcVali#, setQf$presValiRegInStor - )) - - rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) + rpt$rtioMoleDryCo2 <- na.omit(tmp$rtioMoleDryCo2[which(tmp$rtioMoleDryCo2$idGas == 105 | (is.na(tmp$rtioMoleDryCo2$idGas) & tmp$rtioMoleDryCo2$qfSensStus == -1)),]) + + tmp$rtioMoleWet12CCo2 <- data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) + rpt$rtioMoleWet12CCo2 <- na.omit(tmp$rtioMoleWet12CCo2[which(tmp$rtioMoleWet12CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet12CCo2$idGas) & tmp$rtioMoleWet12CCo2$qfSensStus == -1)),]) + + tmp$rtioMoleDry12CCo2 <- data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet12CCo2, + setQf$presCrdCo2, setQf$tempCrdCo2, + setQf$tempWbox, setQf$sensCrdCo2, + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali, #setQf$presValiRegInStor, + idGas = idGas) + rpt$rtioMoleDry12CCo2 <- na.omit(tmp$rtioMoleDry12CCo2[which(tmp$rtioMoleDry12CCo2$idGas == 105 | (is.na(tmp$rtioMoleDry12CCo2$idGas) & tmp$rtioMoleDry12CCo2$qfSensStus == -1)),]) + + tmp$rtioMoleWet13CCo2 <- data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) + rpt$rtioMoleWet13CCo2 <- na.omit(tmp$rtioMoleWet13CCo2[which(tmp$rtioMoleWet13CCo2$idGas == 105 | (is.na(tmp$rtioMoleWet13CCo2$idGas) & tmp$rtioMoleWet13CCo2$qfSensStus == -1)),]) + + tmp$rtioMoleDry13CCo2 <- data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, + setQf$presCrdCo2, setQf$tempCrdCo2, + setQf$tempWbox, setQf$sensCrdCo2, + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali, #setQf$presValiRegInStor, + idGas = idGas) + rpt$rtioMoleDry13CCo2 <- na.omit(tmp$rtioMoleDry13CCo2[which(tmp$rtioMoleDry13CCo2$idGas == 105 | (is.na(tmp$rtioMoleDry13CCo2$idGas) & tmp$rtioMoleDry13CCo2$qfSensStus == -1)),]) + + tmp$dlta13CCo2 <- data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) + rpt$dlta13CCo2 <- na.omit(tmp$dlta13CCo2[which(tmp$dlta13CCo2$idGas == 105 | (is.na(tmp$dlta13CCo2$idGas) & tmp$dlta13CCo2$qfSensStus == -1)),]) + + tmp$rtioMoleWetH2o <- data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) + rpt$rtioMoleWetH2o <- na.omit(tmp$rtioMoleWetH2o[which(tmp$rtioMoleWetH2o$idGas == 11 | (is.na(tmp$rtioMoleWetH2o$idGas) & tmp$rtioMoleWetH2o$qfSensStus == -1)),]) + + tmp$rtioMoleDryH2o <- data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, + setQf$presCrdCo2, setQf$tempCrdCo2, + setQf$tempWbox, setQf$sensCrdCo2, + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali, #setQf$presValiRegInStor, + idGas = idGas) + rpt$rtioMoleDryH2o <- na.omit(tmp$rtioMoleDryH2o[which(tmp$rtioMoleDryH2o$idGas == 11 | (is.na(tmp$rtioMoleDryH2o$idGas) & tmp$rtioMoleDryH2o$qfSensStus == -1)),]) + + rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) + + rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) + rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) + rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) + rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) + rpt$rtioMoleWetH2oEnvHut <- na.omit(data.frame (setQf$rtioMoleWetH2oEnvHut)) + #remove idGas column + lapply(names(rpt), function(x){ + rpt[[x]] <<- rpt[[x]][, ! names(rpt[[x]]) %in% "idGas", drop = F] + }) + #remove tmp + rm(tmp) + } else { + #grouping qulity flags that related to isoCo2 L1 sub-data product + rpt$rtioMoleWetCo2 <- na.omit(data.frame(setQf$rtioMoleWetCo2, setQf$rtioMoleWet12CCo2,#setQf$dlta13CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) + + rpt$rtioMoleDryCo2 <- na.omit(data.frame(setQf$rtioMoleDryCo2, setQf$rtioMoleDry12CCo2,#setQf$dlta13CCo2, + setQf$rtioMoleDry13CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) + + rpt$rtioMoleWet12CCo2 <- na.omit(data.frame(setQf$rtioMoleWet12CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) + + rpt$rtioMoleDry12CCo2 <- na.omit(data.frame(setQf$rtioMoleDry12CCo2, setQf$rtioMoleWet12CCo2, + setQf$presCrdCo2, setQf$tempCrdCo2, + setQf$tempWbox, setQf$sensCrdCo2, + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali#, setQf$presValiRegInStor + )) + + rpt$rtioMoleWet13CCo2 <- na.omit(data.frame(setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) + + rpt$rtioMoleDry13CCo2 <- na.omit(data.frame(setQf$rtioMoleDry13CCo2, setQf$rtioMoleWet13CCo2, + setQf$presCrdCo2, setQf$tempCrdCo2, + setQf$tempWbox, setQf$sensCrdCo2, + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali#, setQf$presValiRegInStor + )) + + rpt$dlta13CCo2 <- na.omit(data.frame(setQf$dlta13CCo2, setQf$rtioMoleWet12CCo2, + setQf$rtioMoleWet13CCo2, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) + + rpt$rtioMoleWetH2o <- na.omit(data.frame(setQf$rtioMoleWetH2o, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) + + rpt$rtioMoleDryH2o <- na.omit(data.frame(setQf$rtioMoleDryH2o, setQf$rtioMoleWetH2o, + setQf$presCrdCo2, setQf$tempCrdCo2, + setQf$tempWbox, setQf$sensCrdCo2, + #setQf$frt00MfcVali, setQf$frtMfcVali, + #setQf$presAtmMfcVali, setQf$tempMfcVali, + setQf$sensMfcVali#, setQf$presValiRegInStor + )) + + rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) + + rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) + rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) + rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) + rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) + rpt$rtioMoleWetH2oEnvHut <- na.omit(data.frame (setQf$rtioMoleWetH2oEnvHut)) + }#close else statement + }##close if statement of TypeMeas == "vali" + }#close if statment if isoCo2 is in dp01 + + #grouping quality flags related to the ch4Conc L1 data product + + if (dp01 %in% "ch4Conc") { + #define qf which use only sampling period + if (TypeMeas == "samp") { + #temporary list + tmp <- list() + #if not all idGas = NA or all qfRngTemp = NA + if (length(which(!is.na(idGas))) > 0){ + #grouping qulity flags that related to isoCo2 L1 sub-data product + tmp$rtioMoleWetCh4 <- data.frame(setQf$rtioMoleWetCh4, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, + #setQf$heatInlt, + idGas = idGas + ) + rpt$rtioMoleWetCh4 <- na.omit(tmp$rtioMoleWetCh4[which(tmp$rtioMoleWetCh4$idGas == 25 | (is.na(tmp$rtioMoleWetCh4$idGas) & tmp$rtioMoleWetCh4$qfSensStus == -1)),]) + + tmp$rtioMoleDryCh4 <- data.frame(setQf$rtioMoleDryCh4, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm, + #setQf$presInlt, setQf$pumpStor, + #setQf$heatInlt, + idGas = idGas + + ) + rpt$rtioMoleDryCh4 <- na.omit(tmp$rtioMoleDryCh4[which(tmp$rtioMoleDryCh4$idGas == 25 | (is.na(tmp$rtioMoleDryCh4$idGas) & tmp$rtioMoleDryCh4$qfSensStus == -1)),]) + + + + rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) + rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) + rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) + rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) + rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) + rpt$rtioMoleWetH2oEnvHut <- na.omit(data.frame (setQf$rtioMoleWetH2oEnvHut)) + #remove idGas column + lapply(names(rpt), function(x){ + rpt[[x]] <<- rpt[[x]][, ! names(rpt[[x]]) %in% "idGas", drop = F] + }) + #remove tmp + rm(tmp) + } else { + #grouping qulity flags that related to ch4Conc L1 sub-data product + rpt$rtioMoleWetCh4 <- na.omit(data.frame(setQf$rtioMoleWetCh4, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor + #setQf$heatInlt + )) + + rpt$rtioMoleDryCh4 <- na.omit(data.frame(setQf$rtioMoleDryCh4, setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, + #setQf$frt00Mfm, + #setQf$frtMfm, setQf$presAtmMfm, + #setQf$tempMfm, + setQf$sensMfm#, + #setQf$presInlt, setQf$pumpStor + #setQf$heatInlt + )) + + + rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) + rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) + rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) + rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) + rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) + rpt$rtioMoleWetH2oEnvHut <- na.omit(data.frame (setQf$rtioMoleWetH2oEnvHut)) + }# close else statement - rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) - rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) - rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) - rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) - rpt$rtioMoleWetH2oEnvHut <- na.omit(data.frame (setQf$rtioMoleWetH2oEnvHut)) - }#close else statement - }##close if statement of TypeMeas == "vali" + }#close if statement of TypeMeas == "samp" + + #define qf which use only validation period + if (TypeMeas == "vali") { + #temporary list + tmp <- list() + #if not all idGas = NA or all qfRngTemp = NA + if (length(which(!is.na(idGas))) > 0){ + #grouping qulity flags that related to ch4Conc L1 sub-data product + tmp$rtioMoleWetCh4 <- data.frame(setQf$rtioMoleWetCh4, + setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2,# setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) + rpt$rtioMoleWetCh4 <- na.omit(tmp$rtioMoleWetCh4[which(tmp$rtioMoleWetCh4$idGas == 25 | (is.na(tmp$rtioMoleWetCh4$idGas) & tmp$rtioMoleWetCh4$qfSensStus == -1)),]) + + tmp$rtioMoleDryCh4 <- data.frame(setQf$rtioMoleWetCh4, + setQf$presCrdCo2, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2,# setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali, + #setQf$presValiRegInStor, + idGas = idGas) + rpt$rtioMoleDryCh4 <- na.omit(tmp$rtioMoleDryCh4[which(tmp$rtioMoleDryCh4$idGas == 25 | (is.na(tmp$rtioMoleDryCh4$idGas) & tmp$rtioMoleDryCh4$qfSensStus == -1)),]) + + + rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) + rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) + rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) + rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) + rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) + rpt$rtioMoleWetH2oEnvHut <- na.omit(data.frame (setQf$rtioMoleWetH2oEnvHut)) + #remove idGas column + lapply(names(rpt), function(x){ + rpt[[x]] <<- rpt[[x]][, ! names(rpt[[x]]) %in% "idGas", drop = F] + }) + #remove tmp + rm(tmp) + } else { + #grouping qulity flags that related to isoCo2 L1 sub-data product + rpt$rtioMoleWetCh4 <- na.omit(data.frame(setQf$rtioMoleWetCh4, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) + + rpt$rtioMoleDryCh4 <- na.omit(data.frame(setQf$rtioMoleDryCh4, + setQf$tempCrdCo2, setQf$tempWbox, + setQf$sensCrdCo2, #setQf$frt00MfcVali, + #setQf$frtMfcVali, setQf$presAtmMfcVali, + #setQf$tempMfcVali, + setQf$sensMfcVali#, + #setQf$presValiRegInStor + )) + + rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) + + rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) + rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) + rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) + rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) + rpt$rtioMoleWetH2oEnvHut <- na.omit(data.frame (setQf$rtioMoleWetH2oEnvHut)) + }#close else statement + }##close if statement of TypeMeas == "vali" + }#close if statment if ch4Conc is in dp01 #remove setQf setQf <- NULL - }##close if statement of dp01 == isoCo2 - + }##close if statement of dp01 %in% c("isoCo2", "ch4Conc") + #isoH2o #################################################################################### if (dp01 == "isoH2o") { #check if data are exist @@ -2358,3 +2543,4 @@ return(rpt) #end function def.dp01.grp.qf() } + diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R index 44b3fb01..ba80fe4d 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R @@ -70,6 +70,8 @@ # rename function from wrap.neon.dp01.qfqm() to wrap.dp01.qfqm.eddy() # Natchaya P-Durden (2019-07-23) # adding one row with qf = -1 in the empty dataframe to eliminate code break in def.qf.finl() +# Chris Florian (2021-04-09) +# adding ch4Conc to the dp01 list ############################################################################################## wrap.dp01.qfqm.eddy <- function( @@ -77,7 +79,7 @@ wrap.dp01.qfqm.eddy <- function( MethMeas = c("ecte", "ecse")[1], TypeMeas = c("samp", "vali")[1], RptExpd = FALSE, - dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "isoH2o", "soni", "soniAmrs", "tempAirLvl", "tempAirTop")[1], + dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "ch4Conc", "isoH2o", "soni", "soniAmrs", "tempAirLvl", "tempAirTop")[1], idGas =NULL ) { From 0179f50f21e573be2778463b063115f7b2876272 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Wed, 2 Jun 2021 14:44:45 +0000 Subject: [PATCH 100/168] updating crdCh4 variable order to match other functions --- pack/eddy4R.stor/R/wrap.dp01.ecse.R | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index 72c213c2..68c08431 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -990,14 +990,14 @@ wrap.dp01.ecse <- function( #input the whole day data wrk$data <- data.frame(stringsAsFactors = FALSE, + "rtioMoleWetCh4" = data$crdCo2[[lvl]]$rtioMoleWetCh4, + "rtioMoleDryCh4" = data$crdCo2[[lvl]]$rtioMoleDryCh4, + "temp" = data$crdCo2[[lvl]]$temp, "pres" = data$crdCo2[[lvl]]$pres, "presEnvHut" = data$envHut[[lvlEnvHut]]$pres, "rhEnvHut" = data$envHut[[lvlEnvHut]]$rh, - "rtioMoleDryCh4" = data$crdCo2[[lvl]]$rtioMoleDryCh4, - "rtioMoleWetCh4" = data$crdCo2[[lvl]]$rtioMoleWetCh4, - "rtioMoleWetH2oEnvHut" = data$envHut[[lvlEnvHut]]$rtioMoleWetH2o, - "temp" = data$crdCo2[[lvl]]$temp, "tempEnvHut" = data$envHut[[lvlEnvHut]]$temp, + "rtioMoleWetH2oEnvHut" = data$envHut[[lvlEnvHut]]$rtioMoleWetH2o, "lvlCrdCo2" = data$crdCo2ValvLvl[[lvlValv]]$lvlCrdCo2 ) @@ -1178,23 +1178,14 @@ wrap.dp01.ecse <- function( if (TypeMeas %in% "vali"){ #input the whole day data wrk$data <- data.frame(stringsAsFactors = FALSE, - "dlta13CCo2" = data$crdCo2[[lvl]]$dlta13CCo2, - "dlta13CCo2Refe" = data$crdCo2[[lvl]]$dlta13CCo2Refe, + "rtioMoleWetCh4" = data$crdCo2[[lvl]]$rtioMoleWetCh4, + "rtioMoleDryCh4" = data$crdCo2[[lvl]]$rtioMoleDryCh4, + "temp" = data$crdCo2[[lvl]]$temp, "pres" = data$crdCo2[[lvl]]$pres, "presEnvHut" = data$envHut[[lvlEnvHut]]$pres, "rhEnvHut" = data$envHut[[lvlEnvHut]]$rh, - "rtioMoleDry12CCo2" = data$crdCo2[[lvl]]$rtioMoleDry12CCo2, - "rtioMoleDry13CCo2" = data$crdCo2[[lvl]]$rtioMoleDry13CCo2, - "rtioMoleDryCo2" = data$crdCo2[[lvl]]$rtioMoleDryCo2, - "rtioMoleDryCo2Refe" = data$crdCo2[[lvl]]$rtioMoleDryCo2Refe, - "rtioMoleDryH2o" = data$crdCo2[[lvl]]$rtioMoleDryH2o, - "rtioMoleWet12CCo2" = data$crdCo2[[lvl]]$rtioMoleWet12CCo2, - "rtioMoleWet13CCo2" = data$crdCo2[[lvl]]$rtioMoleWet13CCo2, - "rtioMoleWetCo2" = data$crdCo2[[lvl]]$rtioMoleWetCo2, - "rtioMoleWetH2o" = data$crdCo2[[lvl]]$rtioMoleWetH2o, - "rtioMoleWetH2oEnvHut" = data$envHut[[lvlEnvHut]]$rtioMoleWetH2o, - "temp" = data$crdCo2[[lvl]]$temp, - "tempEnvHut" = data$envHut[[lvlEnvHut]]$temp + "tempEnvHut" = data$envHut[[lvlEnvHut]]$temp, + "rtioMoleWetH2oEnvHut" = data$envHut[[lvlEnvHut]]$rtioMoleWetH2o ) #input the whole day qfqm From e8f6e6669c01455f066859637042d868a3a2ce8e Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Wed, 2 Jun 2021 17:12:01 +0000 Subject: [PATCH 101/168] updating qfRmv to not exclude rtioMoleWetH2o data that are below the low humidity threshold --- pack/eddy4R.stor/R/wrap.prd.day.ecse.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.stor/R/wrap.prd.day.ecse.R b/pack/eddy4R.stor/R/wrap.prd.day.ecse.R index 8bde978b..3fb56e9f 100644 --- a/pack/eddy4R.stor/R/wrap.prd.day.ecse.R +++ b/pack/eddy4R.stor/R/wrap.prd.day.ecse.R @@ -36,6 +36,8 @@ # update input parameters in wrap.qf.rmv.data function # Natchaya P-Durden (2019-05-06) # adding logic to determine qfFrt00 from mfm +# Chris Florian (2021-06-02) +# updating qfRmv to not exclude rtioMoleWetH2o data that are below the low humidity threshold ############################################################################################## wrap.prd.day.ecse <- function( @@ -57,7 +59,7 @@ wrap.prd.day.ecse <- function( } #Removing high frequency flagged data #Applying the bad quality flags to the reported output data - rpt <- eddy4R.qaqc::wrap.qf.rmv.data(inpList = inpList, Vrbs = FALSE, MethMeas = "ecse", Sens = NULL, qfRmv = c("qfCal", "qfRh", "qfTemp")) + rpt <- eddy4R.qaqc::wrap.qf.rmv.data(inpList = inpList, Vrbs = FALSE, MethMeas = "ecse", Sens = NULL, qfRmv = c("qfCal", "qfRh", "qfTemp", "qfLowRtioMoleWetH2o")) # perform de-spiking From d24c77c8bd75345c594f647fa63ec7fa344487ef Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Tue, 8 Jun 2021 14:35:00 -0600 Subject: [PATCH 102/168] Bug fixes for persistence test: - Fix bug causing looping (sometimes infinitely) over periods already flagged by persistence test - Fix bug truncating fractional seconds from time vector - adjusted indexing statements to allow input of tibble data frame, which does not automatically drop the data frame when accessing a single column using [,] - repackage eddy4R.qaqc --- pack/eddy4R.qaqc/DESCRIPTION | 4 +-- pack/eddy4R.qaqc/R/def.plau.R | 39 ++++++++++++++++----------- pack/eddy4R.qaqc/man/def.plau.Rd | 8 +++--- pack/eddy4R.qaqc/man/wrap.qfqm.rpt.Rd | 13 ++++++--- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/pack/eddy4R.qaqc/DESCRIPTION b/pack/eddy4R.qaqc/DESCRIPTION index b362c7dd..91ed8b50 100644 --- a/pack/eddy4R.qaqc/DESCRIPTION +++ b/pack/eddy4R.qaqc/DESCRIPTION @@ -1,6 +1,6 @@ Package: eddy4R.qaqc Title: Eddy-covariance calculation for R: Quality assurance and quality control -Version: 0.2.11 +Version: 0.2.12 Authors@R: c( person("Cove", "Sturtevant", email = "eddy4R.info@gmail.com", role = c("aut", "cre")), person("Stefan", "Metzger", email = "eddy4R.info@gmail.com", role = c("aut")), person("Natchaya", "Pingintha-Durden", email = "ndurden@battelleecology.org", role = c("aut")), @@ -23,4 +23,4 @@ Suggests: NEONprocIS.base License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 LazyData: true -RoxygenNote: 7.1.0 +RoxygenNote: 7.1.1 diff --git a/pack/eddy4R.qaqc/R/def.plau.R b/pack/eddy4R.qaqc/R/def.plau.R index 8e4ae07c..41e2bf0d 100644 --- a/pack/eddy4R.qaqc/R/def.plau.R +++ b/pack/eddy4R.qaqc/R/def.plau.R @@ -94,6 +94,11 @@ # optimized gap test. WAY faster when there are a lot of gaps in the dataset # Cove Sturtevant (2020-07-09) # Additional optimization of persistence test achieved by turning time variable to numeric seconds past start +# Cove Sturtevant (2021-06-08) +# Fix bug causing looping (sometimes infinitely) over periods already flagged by persistence test. +# Fix bug truncating fractional seconds from time vector +# adjusted indexing statements to allow input of tibble data frame, which does not automatically drop the data +# frame when accessing a single column using [,]. ############################################################################################## def.plau <- function ( data, # a data frame containing the data to be evaluated (do not include the time stamp vector here). Required input. @@ -101,14 +106,13 @@ def.plau <- function ( RngMin = apply(data,2,min,na.rm=TRUE), # a numeric vector containing the minimum acceptable value for each variable in data, defaults to observed minimums RngMax = apply(data,2,max,na.rm=TRUE), # a numeric vector containing the maximum acceptable value for each variable in data, defaults to observed maximums DiffStepMax = apply(abs(apply(data,2,diff)),2,max,na.rm=TRUE), # a vector containing the maximum acceptable absolute difference between sequential data points for each variable in data - DiffPersMin = rep.int(0,length(data)), # a vector containing the minimum absolute change in value for each variable in data over the interval specified in WndwPers. Defaults to a vector of zeros. - WndwPers = 60*median(abs(diff(time)),na.rm=TRUE)*rep.int(1,length(data)), # a vector of class difftime specifying the time interval for each variable in data over which to test for the minimum absolute change in value specified in DiffPersMin. Defaults to 60 x median observed time difference. Class difftime can be generated using as.difftime. - TestNull = rep(FALSE,length(data)), # apply the null test? A logical vector of [TRUE or FALSE] of length equal to number of variables in data. Defaults to FALSE (no null values are flagged) - NumGap = rep(length(data[,1])+1,length(data)), # an integer greater than 0 specifying the number of consecutive NA values that constitute a gap + DiffPersMin = rep.int(0,ncol(data)), # a vector containing the minimum absolute change in value for each variable in data over the interval specified in WndwPers. Defaults to a vector of zeros. + WndwPers = 60*median(abs(diff(time)),na.rm=TRUE)*rep.int(1,ncol(data)), # a vector of class difftime specifying the time interval for each variable in data over which to test for the minimum absolute change in value specified in DiffPersMin. Defaults to 60 x median observed time difference. Class difftime can be generated using as.difftime. + TestNull = rep(FALSE,ncol(data)), # apply the null test? A logical vector of [TRUE or FALSE] of length equal to number of variables in data. Defaults to FALSE (no null values are flagged) + NumGap = rep(nrow(data)+1,ncol(data)), # an integer greater than 0 specifying the number of consecutive NA values that constitute a gap Vrbs = FALSE # FALSE = output the vector positions of the fail and na results, TRUE = output flag values for each test ) { - - + # Error Checking ---------------------------------------------------------- # Check data @@ -117,7 +121,7 @@ def.plau <- function ( } # Initial stats - numVar <- length(data) # Get number of variables + numVar <- ncol(data) # Get number of variables nameData <- names(data) # Get variable names numData <- nrow(data) @@ -218,7 +222,7 @@ def.plau <- function ( # Do range test for(idxVar in 1:numVar) { setQf[[idxVar]]$setQfRng <- list(fail=numeric(0),na=numeric(0)) # initialize - setQf[[idxVar]]$setQfRng$fail <- which((data[,idxVar] < RngMin[idxVar]) | (data[,idxVar] > RngMax[idxVar])) + setQf[[idxVar]]$setQfRng$fail <- which((data[[idxVar]] < RngMin[idxVar]) | (data[[idxVar]] > RngMax[idxVar])) setQf[[idxVar]]$setQfRng$na <- setDataNa[[idxVar]] # For Verbose option, output actual flag values @@ -232,7 +236,7 @@ def.plau <- function ( # Do step test for(idxVar in 1:numVar) { - diffDataIdx <- diff(data[,idxVar]) + diffDataIdx <- diff(data[[idxVar]]) diffDataNaIdx <- is.na(diffDataIdx) setNaDiffDataIdx <- which(diffDataNaIdx) setRealDiffDataIdx <- which(!diffDataNaIdx) @@ -264,8 +268,7 @@ def.plau <- function ( timePers <- seq_len(numData) } else { # Convert time to seconds past start. It's faster. - timePers <- as.numeric(time) # Turn time to # seconds past start - timePers <- timePers-timePers[1] + timePers <- as.double(time-time[1], units = "secs") # Turn time to numeric seconds past start WndwPers <- as.double(WndwPers,units='secs') } @@ -328,7 +331,7 @@ def.plau <- function ( if(timePers[idxData]-timeIdxBgn < WndwPersIdx) { # Hooray! The data is not "stuck" idxDataBgn <- min(c(idxDataMin,idxDataMax))+1 # set start of next window to the next point after the earlier of the running min and max - + # Make sure we aren't on a null value while(dataNaIdx[idxDataBgn]){ idxDataBgn <- idxDataBgn+1 @@ -362,11 +365,17 @@ def.plau <- function ( } - idxDataBgn <- idxData # restart the test from here - idxData <- idxDataBgn+1 # reset the next point to be evaluated - + # Restart the test from here + idxDataBgn <- idxData + idxData <- idxDataBgn+1 + + idxDataMin <- idxDataBgn # reset running minimum + idxDataMax <- idxDataBgn # reset running maximum + # Grab the data for these indices, improves CPU time timeIdxBgn <- timePers[idxDataBgn] + dataIdxMin <- dataIdxVar[idxDataMin] + dataIdxMax <- dataIdxVar[idxDataMax] } diff --git a/pack/eddy4R.qaqc/man/def.plau.Rd b/pack/eddy4R.qaqc/man/def.plau.Rd index 518c9b27..35fded23 100644 --- a/pack/eddy4R.qaqc/man/def.plau.Rd +++ b/pack/eddy4R.qaqc/man/def.plau.Rd @@ -10,10 +10,10 @@ def.plau( RngMin = apply(data, 2, min, na.rm = TRUE), RngMax = apply(data, 2, max, na.rm = TRUE), DiffStepMax = apply(abs(apply(data, 2, diff)), 2, max, na.rm = TRUE), - DiffPersMin = rep.int(0, length(data)), - WndwPers = 60 * median(abs(diff(time)), na.rm = TRUE) * rep.int(1, length(data)), - TestNull = rep(FALSE, length(data)), - NumGap = rep(length(data[, 1]) + 1, length(data)), + DiffPersMin = rep.int(0, ncol(data)), + WndwPers = 60 * median(abs(diff(time)), na.rm = TRUE) * rep.int(1, ncol(data)), + TestNull = rep(FALSE, ncol(data)), + NumGap = rep(nrow(data) + 1, ncol(data)), Vrbs = FALSE ) } diff --git a/pack/eddy4R.qaqc/man/wrap.qfqm.rpt.Rd b/pack/eddy4R.qaqc/man/wrap.qfqm.rpt.Rd index 79b3ba6e..50238df1 100644 --- a/pack/eddy4R.qaqc/man/wrap.qfqm.rpt.Rd +++ b/pack/eddy4R.qaqc/man/wrap.qfqm.rpt.Rd @@ -4,14 +4,21 @@ \alias{wrap.qfqm.rpt} \title{Wrapper function: QFQM quality report for eddy-covariance dp04 HDF5 files} \usage{ -wrap.qfqm.rpt(File, Dp = NULL, Vrbs = FALSE) +wrap.qfqm.rpt( + FileName, + Dp = NULL, + Vrbs = FALSE, + MethQm = c("Pass", "Fail", "Na")[1] +) } \arguments{ -\item{File}{character vector for the full path to the HDF5 file to perform the quality report [-]} - \item{Dp}{A vector of data products to check the quality report for. Defaults to NULL which will test all dp's found in HDF5 file. Of type character. [-]} \item{Vrbs}{A logical parameter that determines if all failed quality times should be reported (defaults to FALSE).} + +\item{MethQm}{A character string that determines which quality metric to pull ("Pass", "Fail", "Na").} + +\item{File}{character vector for the full path to the HDF5 file to perform the quality report [-]} } \value{ A list for all dp's provided including either summary or verbose quality report: \cr From 8d74923ede6aabfa61c5a5bb26794cc944948c09 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Sat, 19 Jun 2021 00:17:02 +0000 Subject: [PATCH 103/168] bug fix to add presCrdCo2 to validation period --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index e072a046..0c1298ea 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -2024,7 +2024,7 @@ if (MethMeas == "ecse") { rpt$rtioMoleWetCh4 <- na.omit(tmp$rtioMoleWetCh4[which(tmp$rtioMoleWetCh4$idGas == 25 | (is.na(tmp$rtioMoleWetCh4$idGas) & tmp$rtioMoleWetCh4$qfSensStus == -1)),]) tmp$rtioMoleDryCh4 <- data.frame(setQf$rtioMoleDryCh4, setQf$presCrdCo2, - setQf$tempCrdCo2, setQf$tempWbox, + setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2, #setQf$frt00Mfm, #setQf$frtMfm, setQf$presAtmMfm, @@ -2129,9 +2129,10 @@ if (MethMeas == "ecse") { #remove tmp rm(tmp) } else { - #grouping qulity flags that related to isoCo2 L1 sub-data product + #grouping qulity flags that related to ch4Conc L1 sub-data product rpt$rtioMoleWetCh4 <- na.omit(data.frame(setQf$rtioMoleWetCh4, setQf$tempCrdCo2, setQf$tempWbox, + setQf$presCrdCo2, setQf$sensCrdCo2, #setQf$frt00MfcVali, #setQf$frtMfcVali, setQf$presAtmMfcVali, #setQf$tempMfcVali, @@ -2141,6 +2142,7 @@ if (MethMeas == "ecse") { rpt$rtioMoleDryCh4 <- na.omit(data.frame(setQf$rtioMoleDryCh4, setQf$tempCrdCo2, setQf$tempWbox, + setQf$presCrdCo2, setQf$sensCrdCo2, #setQf$frt00MfcVali, #setQf$frtMfcVali, setQf$presAtmMfcVali, #setQf$tempMfcVali, From 71d7fe6790e4863bfaa6d33b6e8ce478de2926f2 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Sat, 19 Jun 2021 00:17:27 +0000 Subject: [PATCH 104/168] adding braces to lapply function calls --- pack/eddy4R.base/R/def.hdf5.pack.R | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.pack.R b/pack/eddy4R.base/R/def.hdf5.pack.R index 47e31d57..f93beb4f 100644 --- a/pack/eddy4R.base/R/def.hdf5.pack.R +++ b/pack/eddy4R.base/R/def.hdf5.pack.R @@ -123,12 +123,12 @@ if(MethMeas %in% "ecse"){ if(exists('qm', where = inpList[[idxDp]][[idxLvLReso]][[1]]) == TRUE){ # Add the qm's to tmp list - tmp00[[idxDp]][[idxLvLReso]]$qm <- lapply(names(inpList[[idxDp]][[idxLvLReso]][[1]]$qm), function(idxStat) + tmp00[[idxDp]][[idxLvLReso]]$qm <- lapply(names(inpList[[idxDp]][[idxLvLReso]][[1]]$qm), function(idxStat) { # second call to lapply, targeting the observations to be combined into the result data.frames do.call(rbind, lapply(1:length(inpList[[idxDp]][[idxLvLReso]]), function(idxt) { inpList[[idxDp]][[idxLvLReso]][[idxt]]$qm[[idxStat]] } ) - )) + )}) # assign names to data.frames names(tmp00[[idxDp]][[idxLvLReso]]$qm) <- names(inpList[[idxDp]][[idxLvLReso]][[1]]$qm) } @@ -136,10 +136,11 @@ if(MethMeas %in% "ecse"){ #Remove qm from the inpList for(idx in 1:length(inpList[[idxDp]][[idxLvLReso]])) {inpList[[idxDp]][[idxLvLReso]][[idx]]$qm <- NULL} - tmp01[[idxDp]][[idxLvLReso]] <- lapply(names(inpList[[idxDp]][[idxLvLReso]][[1]]), function(idxStat) + tmp01[[idxDp]][[idxLvLReso]] <- lapply(names(inpList[[idxDp]][[idxLvLReso]][[1]]), function(idxStat) { # second call to lapply, targeting the observations to be combined into the result data.frames - do.call(rbind, lapply(1:length(inpList[[idxDp]][[idxLvLReso]]), function(idxt) inpList[[idxDp]][[idxLvLReso]][[idxt]][[idxStat]] )) - ) + do.call(rbind, lapply(1:length(inpList[[idxDp]][[idxLvLReso]]), function(idxt) { + inpList[[idxDp]][[idxLvLReso]][[idxt]][[idxStat]]})) + }) # assign names to data.frames names(tmp01[[idxDp]][[idxLvLReso]]) <- names(inpList[[idxDp]][[idxLvLReso]][[1]]) From 37a7d847a8894ae949861b1674ea25aaca4bee85 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Sat, 19 Jun 2021 00:20:34 +0000 Subject: [PATCH 105/168] adding ch4Refe to validation time period --- pack/eddy4R.stor/R/wrap.dp01.ecse.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index 68c08431..ebfd8f9f 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -76,6 +76,8 @@ # bug fix for valve issues where looks like consistently Stor data thrown off by Crd # Chris Florian (2021-02-24) # adding ch4Conc L1 data processing steps +# Chris Florian (2021-06-09) +# adding rtioMoleDryCh4Refe data to validation time period ############################################################################################## wrap.dp01.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o", "ch4Conc")[1], @@ -1180,6 +1182,7 @@ wrap.dp01.ecse <- function( wrk$data <- data.frame(stringsAsFactors = FALSE, "rtioMoleWetCh4" = data$crdCo2[[lvl]]$rtioMoleWetCh4, "rtioMoleDryCh4" = data$crdCo2[[lvl]]$rtioMoleDryCh4, + "rtioMoleDryCh4Refe" = data$crdCo2[[lvl]]$rtioMoleDryCh4Refe, "temp" = data$crdCo2[[lvl]]$temp, "pres" = data$crdCo2[[lvl]]$pres, "presEnvHut" = data$envHut[[lvlEnvHut]]$pres, From c1e8edd06e48160f7f947c22a24769c6b0de27cd Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Sat, 19 Jun 2021 00:21:05 +0000 Subject: [PATCH 106/168] adjusting data input for crdCh4 validation to remove CO2 variables --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 26 ++++++++++-------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index 3ae1d454..23be24be 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -89,6 +89,10 @@ # bug fix for valve issues where looks like consistently Stor data thrown off by Crd # Chris Florian (2021-02-26) # adding ch4Conc to dp01 list +# Chris Florian (2021-06-03) +# adjusting data input for crdCh4 validation time periods +# Chris Florian (2021-06-07) +# updating list to remove the CH4 reference values from qfqm ############################################################################################## wrap.dp01.qfqm.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o", "ch4Conc")[1], @@ -1253,21 +1257,13 @@ wrap.dp01.qfqm.ecse <- function( if (lvl == "co2High") lvlPresValiRegInStor <- "714_000" #input the whole day data wrk$data <- data.frame(stringsAsFactors = FALSE, - "dlta13CCo2" = data$crdCo2[[lvl]]$dlta13CCo2, - "dlta13CCo2Refe" = data$crdCo2[[lvl]]$dlta13CCo2Refe, "idGas" = data$crdCo2[[lvl]]$idGas, "pres" = data$crdCo2[[lvl]]$pres, "presEnvHut" = data$envHut[[lvlEnvHut]]$pres, "rhEnvHut" = data$envHut[[lvlEnvHut]]$rh, - "rtioMoleDry12CCo2" = data$crdCo2[[lvl]]$rtioMoleDry12CCo2, - "rtioMoleDry13CCo2" = data$crdCo2[[lvl]]$rtioMoleDry13CCo2, - "rtioMoleDryCo2" = data$crdCo2[[lvl]]$rtioMoleDryCo2, - "rtioMoleDryCo2Refe" = data$crdCo2[[lvl]]$rtioMoleDryCo2Refe, - "rtioMoleDryH2o" = data$crdCo2[[lvl]]$rtioMoleDryH2o, - "rtioMoleWet12CCo2" = data$crdCo2[[lvl]]$rtioMoleWet12CCo2, - "rtioMoleWet13CCo2" = data$crdCo2[[lvl]]$rtioMoleWet13CCo2, - "rtioMoleWetCo2" = data$crdCo2[[lvl]]$rtioMoleWetCo2, - "rtioMoleWetH2o" = data$crdCo2[[lvl]]$rtioMoleWetH2o, + "rtioMoleDryCh4" = data$crdCo2[[lvl]]$rtioMoleDryCo2, + "rtioMoleDryCh4Refe" = data$crdCo2[[lvl]]$rtioMoleDryCo2Refe, + "rtioMoleWetCh4" = data$crdCo2[[lvl]]$rtioMoleWetCo2, "rtioMoleWetH2oEnvHut" = data$envHut[[lvlEnvHut]]$rtioMoleWetH2o, "temp" = data$crdCo2[[lvl]]$temp, "tempEnvHut" = data$envHut[[lvlEnvHut]]$temp @@ -1320,7 +1316,7 @@ wrap.dp01.qfqm.ecse <- function( rpt[[idxAgr]]$timeEnd <- list() #output time for qf dp01; do not output reference gas - for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("rtioMoleDryCo2Refe", "dlta13CCo2Refe", "idGas")))]){ + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("rtioMoleDryCh4Refe", "idGas")))]){ rpt[[idxAgr]]$timeBgn[[idxVar]] <- wrk$idx$timeBgn[idxAgr] rpt[[idxAgr]]$timeEnd[[idxVar]] <- wrk$idx$timeEnd[idxAgr] }; rm(idxVar) @@ -1352,7 +1348,7 @@ wrap.dp01.qfqm.ecse <- function( #assign name to each column names(rpt[[1]][[idxQf]]) <- names(wrk$data) #not report lvlIrga - rpt[[1]][[idxQf]] <- rpt[[1]][[idxQf]][which(!(names(rpt[[1]][[idxQf]]) %in% c("rtioMoleDryCo2Refe", "dlta13CCo2Refe", "idGas")))] + rpt[[1]][[idxQf]] <- rpt[[1]][[idxQf]][which(!(names(rpt[[1]][[idxQf]]) %in% c("rtioMoleDryCh4Refe", "idGas")))] }; rm(idxQf) #add both time begin and time end to rpt @@ -1360,7 +1356,7 @@ wrap.dp01.qfqm.ecse <- function( rpt[[1]]$timeEnd <- list() #output time for dp01 - for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("rtioMoleDryCo2Refe", "dlta13CCo2Refe", "idGas")))]){ + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("rtioMoleDryCh4Refe", "idGas")))]){ rpt[[1]]$timeBgn[[idxVar]] <- data$time[1] rpt[[1]]$timeEnd[[idxVar]] <- data$time[length(data$time)] #unit @@ -1426,7 +1422,7 @@ wrap.dp01.qfqm.ecse <- function( rpt[[idxAgr]]$timeEnd <- list() #output time for qf dp01; do not output reference gas - for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("rtioMoleDryCo2Refe", "dlta13CCo2Refe", "idGas")))]){ + for(idxVar in names(wrk$data)[which(!(names(wrk$data) %in% c("rtioMoleDryCh4Refe", "idGas")))]){ rpt[[idxAgr]]$timeBgn[[idxVar]] <- data$time[idxTime[[paste0(PrdAgr, "min")]]$Bgn[idxAgr]] rpt[[idxAgr]]$timeEnd[[idxVar]] <- data$time[idxTime[[paste0(PrdAgr, "min")]]$End[idxAgr]] }; rm(idxVar) From dcdb00b8b85683a763c7e93e1386285a388cd722 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Tue, 22 Jun 2021 03:12:33 +0000 Subject: [PATCH 107/168] Bug fix in validation qf dataframe setup --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 0c1298ea..9ac748f1 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -2104,7 +2104,7 @@ if (MethMeas == "ecse") { idGas = idGas) rpt$rtioMoleWetCh4 <- na.omit(tmp$rtioMoleWetCh4[which(tmp$rtioMoleWetCh4$idGas == 25 | (is.na(tmp$rtioMoleWetCh4$idGas) & tmp$rtioMoleWetCh4$qfSensStus == -1)),]) - tmp$rtioMoleDryCh4 <- data.frame(setQf$rtioMoleWetCh4, + tmp$rtioMoleDryCh4 <- data.frame(setQf$rtioMoleDryCh4, setQf$presCrdCo2, setQf$tempCrdCo2, setQf$tempWbox, setQf$sensCrdCo2,# setQf$frt00MfcVali, @@ -2117,7 +2117,7 @@ if (MethMeas == "ecse") { rpt$temp <- na.omit(data.frame(setQf$tempCrdCo2, setQf$sensCrdCo2)) - rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) + rpt$pres <- na.omit(data.frame(setQf$presCrdCo2, setQf$sensCrdCo2)) rpt$presEnvHut <- na.omit(data.frame(setQf$presEnvHut)) rpt$rhEnvHut <- na.omit(data.frame (setQf$rhEnvHut)) rpt$tempEnvHut <- na.omit(data.frame (setQf$tempEnvHut)) From 38ac31ba5866dd69a0e41018458a2777a4f69933 Mon Sep 17 00:00:00 2001 From: covesturtevant Date: Tue, 29 Jun 2021 12:05:59 -0600 Subject: [PATCH 108/168] fix bug in gap test effectively hard coding the gap test threshold to 4 --- pack/eddy4R.qaqc/DESCRIPTION | 2 +- pack/eddy4R.qaqc/R/def.plau.R | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.qaqc/DESCRIPTION b/pack/eddy4R.qaqc/DESCRIPTION index 91ed8b50..642c11e1 100644 --- a/pack/eddy4R.qaqc/DESCRIPTION +++ b/pack/eddy4R.qaqc/DESCRIPTION @@ -1,6 +1,6 @@ Package: eddy4R.qaqc Title: Eddy-covariance calculation for R: Quality assurance and quality control -Version: 0.2.12 +Version: 0.2.13 Authors@R: c( person("Cove", "Sturtevant", email = "eddy4R.info@gmail.com", role = c("aut", "cre")), person("Stefan", "Metzger", email = "eddy4R.info@gmail.com", role = c("aut")), person("Natchaya", "Pingintha-Durden", email = "ndurden@battelleecology.org", role = c("aut")), diff --git a/pack/eddy4R.qaqc/R/def.plau.R b/pack/eddy4R.qaqc/R/def.plau.R index 41e2bf0d..e6e12ad4 100644 --- a/pack/eddy4R.qaqc/R/def.plau.R +++ b/pack/eddy4R.qaqc/R/def.plau.R @@ -99,6 +99,8 @@ # Fix bug truncating fractional seconds from time vector # adjusted indexing statements to allow input of tibble data frame, which does not automatically drop the data # frame when accessing a single column using [,]. +# Cove Sturtevant (2021-06-29) +# fix bug in gap test. The code effectively hard-coded the gap test threshold to 4. ############################################################################################## def.plau <- function ( data, # a data frame containing the data to be evaluated (do not include the time stamp vector here). Required input. @@ -454,7 +456,7 @@ def.plau <- function ( numNaWndwGap <- RcppRoll::roll_sum(x=dataNAIdx,n=NumGapIdx,by=1,align='left',na.rm=FALSE) # Which of the windows has all gaps? Mark the test failure - setGapBgn <- which(numNaWndwGap == 4) + setGapBgn <- which(numNaWndwGap == NumGapIdx) qfGap <- rep(0,numData) for(idxGapBgn in setGapBgn){ qfGap[idxGapBgn:(idxGapBgn+NumGapIdx-1)] <- 1 From 04ea3a4f768dec65c17e5c7976e00365486ef90c Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Wed, 30 Jun 2021 20:16:08 +0000 Subject: [PATCH 109/168] adding unit conversion for CH4 --- pack/eddy4R.base/R/wrap.unit.conv.out.ec.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R b/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R index 03e95ca5..5557b4e9 100644 --- a/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R +++ b/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R @@ -40,6 +40,8 @@ # converting time format in ecse qfqm # Natchaya P-Durden (2020-01-17) # adding unit conversion for rtioMoleDryH2o during validation +# Chris Florian (2021-06-22) +# adding CH4 unit conversion ############################################################################################ wrap.unit.conv.out.ec <- function( @@ -241,6 +243,9 @@ if(MethMeas == "ecse"){ "rtioMoleDryCo2" = "umol2Co2 mol-2", "rtioMoleWetCo2" = "umol2Co2 mol-2", "rtioMoleDryCo2Refe" = "umol2Co2 mol-2", + "rtioMoleDryCh4" = "umol2Ch4 mol-2", + "rtioMoleWetCh4" = "umol2Ch4 mol-2", + "rtioMoleDryCh4Refe" = "umol2Ch4 mol-2", "temp" = "C2", "tempEnvHut" = "C2", "rtioMoleDryH2o" = "mmol2H2o mol-2", @@ -267,6 +272,9 @@ if(MethMeas == "ecse"){ wrkAttr$rtioMoleDryCo2 <- c("mean" = "molCo2 mol-1", "min" = "molCo2 mol-1", "max" = "molCo2 mol-1", "vari" = "molCo2 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$rtioMoleWetCo2 <- c("mean" = "molCo2 mol-1", "min" = "molCo2 mol-1", "max" = "molCo2 mol-1", "vari" = "molCo2 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$rtioMoleDryCo2Refe <- c("mean" = "molCo2 mol-1", "min" = "molCo2 mol-1", "max" = "molCo2 mol-1", "vari" = "molCo2 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") + wrkAttr$rtioMoleDryCh4 <- c("mean" = "molCh4 mol-1", "min" = "molCh4 mol-1", "max" = "molCh4 mol-1", "vari" = "molCh4 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") + wrkAttr$rtioMoleWetCh4 <- c("mean" = "molCh4 mol-1", "min" = "molCh4 mol-1", "max" = "molCh4 mol-1", "vari" = "molCh4 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") + wrkAttr$rtioMoleDryCh4Refe <- c("mean" = "molCh4 mol-1", "min" = "molCh4 mol-1", "max" = "molCh4 mol-1", "vari" = "molCh4 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$temp <- c("mean" = "K", "min" = "K", "max" = "K", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA")#with means removed unit of wrk vari of temp is equal to out wrkAttr$tempEnvHut <- c("mean" = "K", "min" = "K", "max" = "K", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$rtioMoleDryH2o <- c("mean" = "molH2o mol-1", "min" = "molH2o mol-1", "max" = "molH2o mol-1", "vari" = "molH2o mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") @@ -304,6 +312,9 @@ if(MethMeas == "ecse"){ outAttr$rtioMoleDryCo2 <- c("mean" = "umolCo2 mol-1", "min" = "umolCo2 mol-1", "max" = "umolCo2 mol-1", "vari" = "umolCo2 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$rtioMoleWetCo2 <- c("mean" = "umolCo2 mol-1", "min" = "umolCo2 mol-1", "max" = "umolCo2 mol-1", "vari" = "umolCo2 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$rtioMoleDryCo2Refe <- c("mean" = "umolCo2 mol-1", "min" = "umolCo2 mol-1", "max" = "umolCo2 mol-1", "vari" = "umolCo2 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") + wrkAttr$rtioMoleDryCh4 <- c("mean" = "umolCh4 mol-1", "min" = "umolCh4 mol-1", "max" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") + wrkAttr$rtioMoleWetCh4 <- c("mean" = "umolCh4 mol-1", "min" = "umolCh4 mol-1", "max" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") + wrkAttr$rtioMoleDryCh4Refe <- c("mean" = "umolCh4 mol-1", "min" = "umolCh4 mol-1", "max" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$temp <- c("mean" = "C", "min" = "C", "max" = "C", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$tempEnvHut <- c("mean" = "C", "min" = "C", "max" = "C", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$rtioMoleDryH2o <- c("mean" = "mmolH2o mol-1", "min" = "mmolH2o mol-1", "max" = "mmolH2o mol-1", "vari" = "mmolH2o mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") @@ -526,6 +537,8 @@ if(MethMeas == "ecse"){ wrkAttr$rhEnvHut <- c("mean" = "-", "vari" = "-", "se" = "-", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$rtioMoleDryCo2 <- c("mean" = "molCo2 mol-1", "vari" = "molCo2 mol-1", "se" = "molCo2 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$rtioMoleWetCo2 <- c("mean" = "molCo2 mol-1", "vari" = "molCo2 mol-1", "se" = "molCo2 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") + wrkAttr$rtioMoleDryCh4 <- c("mean" = "molCh4 mol-1", "vari" = "molCh4 mol-1", "se" = "molCh4 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") + wrkAttr$rtioMoleWetCh4 <- c("mean" = "molCh4 mol-1", "vari" = "molCh4 mol-1", "se" = "molCh4 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$temp <- c("mean" = "C", "vari" = "C", "se" = "C", "NA", "NA")#with means removed unit of wrk mean, vari, and se of temp is equal to out wrkAttr$tempEnvHut <- c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$rtioMoleDryH2o <- c("mean" = "molH2o mol-1", "vari" = "molH2o mol-1", "se" = "molH2o mol-1", "timeBgn" = "NA", "timeEnd" = "NA") @@ -547,6 +560,8 @@ if(MethMeas == "ecse"){ outAttr$rhEnvHut <- c("mean" = "%", "vari" = "%", "se" = "%", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$rtioMoleDryCo2 <- c("mean" = "umolCo2 mol-1", "vari" = "umolCo2 mol-1", "se" = "umolCo2 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$rtioMoleWetCo2 <- c("mean" = "umolCo2 mol-1", "vari" = "umolCo2 mol-1", "se" = "umolCo2 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") + outAttr$rtioMoleDryCh4 <- c("mean" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "se" = "umolCh4 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") + outAttr$rtioMoleWetCh4 <- c("mean" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "se" = "umolCh4 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$temp <- c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$tempEnvHut <- c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$rtioMoleDryH2o <- c("mean" = "mmolH2o mol-1", "vari" = "mmolH2o mol-1", "se" = "mmolH2o mol-1", "timeBgn" = "NA", "timeEnd" = "NA") From cf9fa22806a8d37108b7767e3e18206efdc95b86 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Wed, 30 Jun 2021 21:44:00 +0000 Subject: [PATCH 110/168] updating number of columns for ch4Conc --- pack/eddy4R.stor/R/wrap.dp01.ecse.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index ebfd8f9f..a8e6e804 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -78,6 +78,8 @@ # adding ch4Conc L1 data processing steps # Chris Florian (2021-06-09) # adding rtioMoleDryCh4Refe data to validation time period +# Chris Florian +# updating the columns used to select data from 15 to 8 for ch4Conc to get rid of extra dataframes ############################################################################################## wrap.dp01.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o", "ch4Conc")[1], @@ -1122,13 +1124,13 @@ wrap.dp01.ecse <- function( #replace idxData data with NaN when irga got kick out to measure the new measurement level wrk$data[[idxData]] <- ifelse(wrk$data$lvlCrdCo2 == lvlCrdCo2, wrk$data[[idxData]], NaN) } - wrk$data[-whrSamp, 1:15] <- NaN + wrk$data[-whrSamp, 1:8] <- NaN #the range of columns represents the varibles included except the valve data #added attributes for (idxData in c("presEnvHut", "rhEnvHut", "rtioMoleWetH2oEnvHut", "tempEnvHut")){ attributes(wrk$data[[idxData]]) <- tmpAttr[[idxData]] } } else {#if there are no data at all in wrk$data$temp - wrk$data[,1:15] <- NaN + wrk$data[,1:8] <- NaN #the range of columns represents the varibles included except the valve data } From b6d9b332346976d2bedebe6fdf7ea003a7ca62df Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 13 Jul 2021 15:59:16 +0000 Subject: [PATCH 111/168] - dealing with data.frame issue updates for R 4.0 --- pack/eddy4R.base/R/def.hdf5.pack.R | 3 +- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R | 38 ++++++++++++------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.pack.R b/pack/eddy4R.base/R/def.hdf5.pack.R index 47e31d57..08647977 100644 --- a/pack/eddy4R.base/R/def.hdf5.pack.R +++ b/pack/eddy4R.base/R/def.hdf5.pack.R @@ -112,6 +112,7 @@ if(MethMeas %in% "ecse"){ if (Dp %in% c("Dp01", "Dp02")) { for(idxDp in names(inpList)) { + #idxDp <- "co2Stor" #for testing tmp00[[idxDp]] <- list() tmp01[[idxDp]] <- list() @@ -138,7 +139,7 @@ if(MethMeas %in% "ecse"){ tmp01[[idxDp]][[idxLvLReso]] <- lapply(names(inpList[[idxDp]][[idxLvLReso]][[1]]), function(idxStat) # second call to lapply, targeting the observations to be combined into the result data.frames - do.call(rbind, lapply(1:length(inpList[[idxDp]][[idxLvLReso]]), function(idxt) inpList[[idxDp]][[idxLvLReso]][[idxt]][[idxStat]] )) + base::as.data.frame(dplyr::bind_rows(lapply(1:length(inpList[[idxDp]][[idxLvLReso]]), function(idxt) inpList[[idxDp]][[idxLvLReso]][[idxt]][[idxStat]] ))) ) # assign names to data.frames diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R index 44b3fb01..e5bbeed1 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R @@ -7,12 +7,12 @@ #' @description Wrapper function. Calculate quality metrics, alpha and beta quality metrics, and final quality flag for the NEON eddy-covariance turbulent and storage exchange L1 data products. -#' @param qfInp A list of data frame containing the input quality flag data that related to L1 data products are being grouped. Of class integer". [-] -#' @param MethMeas A vector of class "character" containing the name of measurement method (eddy-covariance turbulent exchange or storage exchange), MethMeas = c("ecte", "ecse"). Defaults to "ecse". [-] +#' @param qfInp A list of data frame containing the input quality flag data that related to L1 data products are being grouped. Of class integer". [-] +#' @param MethMeas A vector of class "character" containing the name of measurement method (eddy-covariance turbulent exchange or storage exchange), MethMeas = c("ecte", "ecse"). Defaults to "ecse". [-] #' @param TypeMeas A vector of class "character" containing the name of measurement type (sampling or validation), TypeMeas = c("samp", "ecse"). Defaults to "samp". [-] #' @param RptExpd A logical parameter that determines if the full quality metric \code{qm} is output in the returned list (defaults to FALSE). #' @param dp01 A vector of class "character" containing the name of NEON ECTE and ECSE L1 data products which the flags are being grouped, \cr -#' c("envHut", "co2Turb", "h2oTurb", "isoCo2", "isoH2o", "soni", "soniAmrs", "tempAirLvl", "tempAirTop"). Defaults to "co2Turb". [-] +#' c("envHut", "co2Turb", "h2oTurb", "isoCo2", "isoH2o", "soni", "soniAmrs", "tempAirLvl", "tempAirTop"). Defaults to "co2Turb". [-] #' @param \code{idGas} A data frame contianing gas ID for isoCo2 measurement. Need to provide when dp01 = "isoCo2". Default to NULL. [-] #' @return A list of: \cr @@ -27,7 +27,7 @@ #' @keywords NEON QAQC, quality flags, quality metrics -#' @examples +#' @examples #' #generate the fake quality flags for each sensor #' TimeBgn <- "2016-04-24 02:00:00.000" #' TimeEnd <- "2016-04-24 02:29:59.950" @@ -57,7 +57,7 @@ # revised original function to wrap.neon.dp01.qfqm () # added ECSE quality flags # Dave Durden (2017-04-24) -# Changed output to dataframes, added switch +# Changed output to dataframes, added switch # for expanded output and updated the output data type. # Natchaya P-Durden (2017-08-02) # added idGas and replaced isopCo2 and isopH2o by isoCo2 and isoH2o @@ -75,7 +75,7 @@ wrap.dp01.qfqm.eddy <- function( qfInp = list(), MethMeas = c("ecte", "ecse")[1], - TypeMeas = c("samp", "vali")[1], + TypeMeas = c("samp", "vali")[1], RptExpd = FALSE, dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "isoH2o", "soni", "soniAmrs", "tempAirLvl", "tempAirTop")[1], idGas =NULL @@ -86,13 +86,13 @@ wrap.dp01.qfqm.eddy <- function( tmp <- list() #grouping qf inp <- eddy4R.qaqc::def.dp01.grp.qf(qfInp = qfInp, MethMeas = MethMeas, TypeMeas = TypeMeas, dp01=dp01, idGas = idGas) - + #adding one row with qf = -1 in the empty dataframe to eliminate code break in def.qf.finl lapply(names(inp), function(x) if (nrow(inp[[x]]) == 0) inp[[x]][1,] <<- -1) - + #calculate qmAlpha, qmBeta, qfFinl tmp <- lapply(inp, FUN = eddy4R.qaqc::def.qf.finl) - + #assign default qfSciRevw lapply(names(tmp), function(x) tmp[[x]]$qfqm$qfSciRevw <<- 0) #Only report expanded quality metrics if producing expanded file @@ -103,28 +103,28 @@ wrap.dp01.qfqm.eddy <- function( lapply(names(tmp), function(x) rpt$qm[[x]] <<- tmp[[x]]$qm) #Add units to the output of expanded quality metrics for(idxVar in names(rpt$qm)){ - lapply(names(rpt$qm[[idxVar]]), function(x) attr(rpt$qm[[idxVar]][[x]], which = "unit") <<- "-") + lapply(names(rpt$qm[[idxVar]]), function(x) attr(rpt$qm[[idxVar]][[x]], which = "unit") <<- "-") } } - + #assign return results for basic results lapply(names(tmp), function(x) rpt$qmAlph[[x]] <<- tmp[[x]]$qfqm$qmAlph) lapply(names(tmp), function(x) rpt$qmBeta[[x]] <<- tmp[[x]]$qfqm$qmBeta) lapply(names(tmp), function(x) rpt$qfFinl[[x]] <<- as.integer(tmp[[x]]$qfqm$qfFinl)) lapply(names(tmp), function(x) rpt$qfSciRevw[[x]] <<- as.integer(tmp[[x]]$qfqm$qfSciRevw)) - + # Convert output to dataframe's - rpt$qmAlph <- data.frame(t(rpt$qmAlph), row.names = NULL) - rpt$qmBeta <- data.frame(t(rpt$qmBeta), row.names = NULL) - rpt$qfFinl <- data.frame(t(rpt$qfFinl), row.names = NULL) - rpt$qfSciRevw <- data.frame(t(rpt$qfSciRevw), row.names = NULL) - + rpt$qmAlph <- base::rbind.data.frame(rpt$qmAlph) + rpt$qmBeta <- base::rbind.data.frame(rpt$qmBeta) + rpt$qfFinl <- base::rbind.data.frame(rpt$qfFinl) + rpt$qfSciRevw <- base::rbind.data.frame(rpt$qfSciRevw) + lapply(names(rpt$qmAlph), function(x) attr(rpt$qmAlph[[x]], which = "unit") <<- "-") lapply(names(rpt$qmBeta), function(x) attr(rpt$qmBeta[[x]], which = "unit") <<- "-") lapply(names(rpt$qfFinl), function(x) attr(rpt$qfFinl[[x]], which = "unit") <<- "NA") lapply(names(rpt$qfSciRevw), function(x) attr(rpt$qfSciRevw[[x]], which = "unit") <<- "NA") #return results return(rpt) - + } -# end function wrap.neon.ecte.dp01.qfqm() \ No newline at end of file +# end function wrap.neon.ecte.dp01.qfqm() From 79d372cc3a538eaee6eef95ccf263ebf6e6cb810 Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 13 Jul 2021 15:59:48 +0000 Subject: [PATCH 112/168] - repackaging updates --- pack/eddy4R.qaqc/DESCRIPTION | 2 +- pack/eddy4R.qaqc/man/wrap.qfqm.rpt.Rd | 13 ++++++++++--- pack/eddy4R.stor/DESCRIPTION | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pack/eddy4R.qaqc/DESCRIPTION b/pack/eddy4R.qaqc/DESCRIPTION index b362c7dd..4efb39a1 100644 --- a/pack/eddy4R.qaqc/DESCRIPTION +++ b/pack/eddy4R.qaqc/DESCRIPTION @@ -23,4 +23,4 @@ Suggests: NEONprocIS.base License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 LazyData: true -RoxygenNote: 7.1.0 +RoxygenNote: 7.1.1 diff --git a/pack/eddy4R.qaqc/man/wrap.qfqm.rpt.Rd b/pack/eddy4R.qaqc/man/wrap.qfqm.rpt.Rd index 79b3ba6e..50238df1 100644 --- a/pack/eddy4R.qaqc/man/wrap.qfqm.rpt.Rd +++ b/pack/eddy4R.qaqc/man/wrap.qfqm.rpt.Rd @@ -4,14 +4,21 @@ \alias{wrap.qfqm.rpt} \title{Wrapper function: QFQM quality report for eddy-covariance dp04 HDF5 files} \usage{ -wrap.qfqm.rpt(File, Dp = NULL, Vrbs = FALSE) +wrap.qfqm.rpt( + FileName, + Dp = NULL, + Vrbs = FALSE, + MethQm = c("Pass", "Fail", "Na")[1] +) } \arguments{ -\item{File}{character vector for the full path to the HDF5 file to perform the quality report [-]} - \item{Dp}{A vector of data products to check the quality report for. Defaults to NULL which will test all dp's found in HDF5 file. Of type character. [-]} \item{Vrbs}{A logical parameter that determines if all failed quality times should be reported (defaults to FALSE).} + +\item{MethQm}{A character string that determines which quality metric to pull ("Pass", "Fail", "Na").} + +\item{File}{character vector for the full path to the HDF5 file to perform the quality report [-]} } \value{ A list for all dp's provided including either summary or verbose quality report: \cr diff --git a/pack/eddy4R.stor/DESCRIPTION b/pack/eddy4R.stor/DESCRIPTION index 5a0a8320..a419d98c 100644 --- a/pack/eddy4R.stor/DESCRIPTION +++ b/pack/eddy4R.stor/DESCRIPTION @@ -15,4 +15,4 @@ Suggests: License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 Encoding: UTF-8 LazyData: true -RoxygenNote: 7.1.0 +RoxygenNote: 7.1.1 From f0b691bcf57b15845140b8e61383829984da1592 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Tue, 13 Jul 2021 18:29:44 +0000 Subject: [PATCH 113/168] bug fix for ch4Conc unit conversion --- pack/eddy4R.base/R/wrap.unit.conv.out.ec.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R b/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R index 5557b4e9..f907d4fa 100644 --- a/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R +++ b/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R @@ -312,9 +312,9 @@ if(MethMeas == "ecse"){ outAttr$rtioMoleDryCo2 <- c("mean" = "umolCo2 mol-1", "min" = "umolCo2 mol-1", "max" = "umolCo2 mol-1", "vari" = "umolCo2 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$rtioMoleWetCo2 <- c("mean" = "umolCo2 mol-1", "min" = "umolCo2 mol-1", "max" = "umolCo2 mol-1", "vari" = "umolCo2 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$rtioMoleDryCo2Refe <- c("mean" = "umolCo2 mol-1", "min" = "umolCo2 mol-1", "max" = "umolCo2 mol-1", "vari" = "umolCo2 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") - wrkAttr$rtioMoleDryCh4 <- c("mean" = "umolCh4 mol-1", "min" = "umolCh4 mol-1", "max" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") - wrkAttr$rtioMoleWetCh4 <- c("mean" = "umolCh4 mol-1", "min" = "umolCh4 mol-1", "max" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") - wrkAttr$rtioMoleDryCh4Refe <- c("mean" = "umolCh4 mol-1", "min" = "umolCh4 mol-1", "max" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") + outAttr$rtioMoleDryCh4 <- c("mean" = "umolCh4 mol-1", "min" = "umolCh4 mol-1", "max" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") + outAttr$rtioMoleWetCh4 <- c("mean" = "umolCh4 mol-1", "min" = "umolCh4 mol-1", "max" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") + outAttr$rtioMoleDryCh4Refe <- c("mean" = "umolCh4 mol-1", "min" = "umolCh4 mol-1", "max" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$temp <- c("mean" = "C", "min" = "C", "max" = "C", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$tempEnvHut <- c("mean" = "C", "min" = "C", "max" = "C", "vari" = "C", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$rtioMoleDryH2o <- c("mean" = "mmolH2o mol-1", "min" = "mmolH2o mol-1", "max" = "mmolH2o mol-1", "vari" = "mmolH2o mol-1", "numSamp" = "NA", "timeBgn" = "NA", "timeEnd" = "NA") @@ -539,6 +539,7 @@ if(MethMeas == "ecse"){ wrkAttr$rtioMoleWetCo2 <- c("mean" = "molCo2 mol-1", "vari" = "molCo2 mol-1", "se" = "molCo2 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$rtioMoleDryCh4 <- c("mean" = "molCh4 mol-1", "vari" = "molCh4 mol-1", "se" = "molCh4 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$rtioMoleWetCh4 <- c("mean" = "molCh4 mol-1", "vari" = "molCh4 mol-1", "se" = "molCh4 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") + wrkAttr$rtioMoleDryCh4Refe <- c("mean" = "molCh4 mol-1", "vari" = "molCh4 mol-1", "se" = "molCh4 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$temp <- c("mean" = "C", "vari" = "C", "se" = "C", "NA", "NA")#with means removed unit of wrk mean, vari, and se of temp is equal to out wrkAttr$tempEnvHut <- c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA") wrkAttr$rtioMoleDryH2o <- c("mean" = "molH2o mol-1", "vari" = "molH2o mol-1", "se" = "molH2o mol-1", "timeBgn" = "NA", "timeEnd" = "NA") @@ -562,6 +563,7 @@ if(MethMeas == "ecse"){ outAttr$rtioMoleWetCo2 <- c("mean" = "umolCo2 mol-1", "vari" = "umolCo2 mol-1", "se" = "umolCo2 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$rtioMoleDryCh4 <- c("mean" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "se" = "umolCh4 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$rtioMoleWetCh4 <- c("mean" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "se" = "umolCh4 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") + outAttr$rtioMoleDryCh4Refe <- c("mean" = "umolCh4 mol-1", "vari" = "umolCh4 mol-1", "se" = "umolCh4 mol-1", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$temp <- c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$tempEnvHut <- c("mean" = "C", "vari" = "C", "se" = "C", "timeBgn" = "NA", "timeEnd" = "NA") outAttr$rtioMoleDryH2o <- c("mean" = "mmolH2o mol-1", "vari" = "mmolH2o mol-1", "se" = "mmolH2o mol-1", "timeBgn" = "NA", "timeEnd" = "NA") From 713b4a1a2295b58aa1e7a31eca10d436e17f985f Mon Sep 17 00:00:00 2001 From: ddurden Date: Thu, 15 Jul 2021 14:25:31 +0000 Subject: [PATCH 114/168] - bug fix for grob widths --- pack/eddy4R.qaqc/R/def.plot.dp01.qfqm.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.qaqc/R/def.plot.dp01.qfqm.R b/pack/eddy4R.qaqc/R/def.plot.dp01.qfqm.R index df4908ce..ea9dbb6d 100644 --- a/pack/eddy4R.qaqc/R/def.plot.dp01.qfqm.R +++ b/pack/eddy4R.qaqc/R/def.plot.dp01.qfqm.R @@ -45,6 +45,8 @@ # Changed term 'Pos' to 'Set' for multiple indices # David Durden (2019-02-05) # Fixing bug with Rmisc::multiplot and POSIXlt +# David Durden (2021-07-15) +# Fixing bug with R4.0.3 update where grob widths didn't match up ############################################################################################## @@ -220,7 +222,7 @@ def.plot.dp01.qfqm <- function ( grobNa <- ggplot2::ggplotGrob(plotNa) # grab the grob for this plot for later manipulation # Adjust grobs and combine to align plots (since we want the legend only for the middle plot) - colGrobLeg <- which(!(grobFail$widths %in% grobPass$widths)) # where the legend width is located in grobFail + colGrobLeg <- which(!(as.character(grobFail$widths) %in% as.character(grobPass$widths))) # where the legend width is located in grobFail distWdthLeg <- grobFail$widths[colGrobLeg] # Get legend width grobPass <- gtable::gtable_add_cols(grobPass, distWdthLeg, colGrobLeg[1]-1) # Add an entry for the legend width matching grobFail grobNa <- gtable::gtable_add_cols(grobNa, distWdthLeg, colGrobLeg[1]-1) # Add an entry for the legend width matching grobFail From 38f16733dc79f986b4d4cb64147325830c5ddce7 Mon Sep 17 00:00:00 2001 From: ddurden Date: Thu, 15 Jul 2021 14:42:04 +0000 Subject: [PATCH 115/168] - bug fix for grob columns --- pack/eddy4R.qaqc/R/def.plot.dp01.qfqm.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack/eddy4R.qaqc/R/def.plot.dp01.qfqm.R b/pack/eddy4R.qaqc/R/def.plot.dp01.qfqm.R index ea9dbb6d..c17339d5 100644 --- a/pack/eddy4R.qaqc/R/def.plot.dp01.qfqm.R +++ b/pack/eddy4R.qaqc/R/def.plot.dp01.qfqm.R @@ -251,7 +251,7 @@ def.plot.dp01.qfqm <- function ( grobFinl <- ggplot2::ggplotGrob(plotFinl) # grab the grob for this plot for later manipulation # Adjust grobs and combine to align plots (since we want the legend only for the top plot) - colGrobLeg <- which(!(grobAlphBeta$widths %in% grobFinl$widths)) # where the legend width is located in grobFail + colGrobLeg <- which(!(as.character(grobAlphBeta$widths) %in% as.character(grobFinl$widths))) # where the legend width is located in grobFail distWdthLeg <- grobAlphBeta$widths[colGrobLeg] # Get legend width grobFinl <- gtable::gtable_add_cols(grobFinl, distWdthLeg, colGrobLeg[1]-1) # Add an entry for the legend width matching grobAlphBeta From 0faa5ee869871483dddf4ec886b70cae35e73935 Mon Sep 17 00:00:00 2001 From: ddurden Date: Thu, 15 Jul 2021 18:34:41 +0000 Subject: [PATCH 116/168] - dealing with R4.0.3 update bug, tmp$qfqm <- NULL was removing tmp$qfqmOut values, put in failsafe --- pack/eddy4R.base/R/wrap.dp01.agr.prd.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.dp01.agr.prd.R b/pack/eddy4R.base/R/wrap.dp01.agr.prd.R index 4c548edd..25ee257d 100644 --- a/pack/eddy4R.base/R/wrap.dp01.agr.prd.R +++ b/pack/eddy4R.base/R/wrap.dp01.agr.prd.R @@ -50,6 +50,8 @@ # rename function from wrap.neon.dp01.agr.prd() to wrap.dp01.agr.prd() # Natchaya P-Durden (2018-05-23) # rename function from wrap.neon.dp01.qfqm.ec() to wrap.dp01.qfqm.ecte() +# David Durden (2021-07-15) +# dealing with R4.0.3 update bug, tmp$qfqm <- NULL was removing tmp$qfqmOut values, put in failsafe ############################################################################################## @@ -133,12 +135,13 @@ for(idxAgr in 1:iter){ ) tmp$qfqmOut[[lvlAgr]] <- eddy4R.base::wrap.dp01.qfqm.ecte(qfqm = tmp$qfqm, idx = names(tmp$data), MethMeas = "ecte", RptExpd = FALSE ) - + +tmp$qfqm[names(tmp$qfqm)] <- NULL tmp$data <- NULL -tmp$qfqm <- NULL invisible(gc()) } +#Format for output rpt <- eddy4R.base::def.dp01.agr.ecte(inpList = tmp) return(rpt) From 1dce4281455f14f648e51f034d78a1298506ec3d Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Tue, 3 Aug 2021 14:37:00 +0000 Subject: [PATCH 117/168] adding logic to run methane or not depending on data products in input list --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 9ac748f1..47334449 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -1372,10 +1372,14 @@ if (MethMeas == "ecse") { "qfPersRtioMoleDry13CCo2" = qfInp$crdCo2$qfPersRtioMoleDry13CCo2) #"qfCalRtioMoleDry13CCo2" = qfInp$crdCo2$qfCalRtioMoleDry13CCo2) - setQf$rtioMoleDryCh4 <- data.frame("qfRngRtioMoleDryCh4" = qfInp$crdCo2$qfRngRtioMoleDryCh4, - "qfStepRtioMoleDryCh4" = qfInp$crdCo2$qfStepRtioMoleDryCh4, - "qfPersRtioMoleDryCh4" = qfInp$crdCo2$qfPersRtioMoleDryCh4) - #"qfCalRtioMoleDryCh4" = qfInp$crdCo2$qfCalRtioMoleDryCh4) + + if ("ch4Conc" %in% names(qfInp)){ + setQf$rtioMoleDryCh4 <- data.frame("qfRngRtioMoleDryCh4" = qfInp$crdCo2$qfRngRtioMoleDryCh4, + "qfStepRtioMoleDryCh4" = qfInp$crdCo2$qfStepRtioMoleDryCh4, + "qfPersRtioMoleDryCh4" = qfInp$crdCo2$qfPersRtioMoleDryCh4) + #"qfCalRtioMoleDryCh4" = qfInp$crdCo2$qfCalRtioMoleDryCh4) + } + setQf$rtioMoleDryH2o <- data.frame("qfRngRtioMoleDryH2o" = qfInp$crdCo2$qfRngRtioMoleDryH2o, @@ -1397,11 +1401,13 @@ if (MethMeas == "ecse") { "qfStepRtioMoleWet13CCo2" = qfInp$crdCo2$qfStepRtioMoleWet13CCo2, "qfPersRtioMoleWet13CCo2" = qfInp$crdCo2$qfPersRtioMoleWet13CCo2) #"qfCalRtioMoleWet13CCo2 " = qfInp$crdCo2$qfCalRtioMoleWet13CCo2) - + + if ("ch4Conc" %in% names(qfInp)){ setQf$rtioMoleWetCh4 <- data.frame("qfRngRtioMoleWetCh4" = qfInp$crdCo2$qfRngRtioMoleWetCh4, "qfStepRtioMoleWetCh4" = qfInp$crdCo2$qfStepRtioMoleWetCh4, "qfPersRtioMoleWetCh4" = qfInp$crdCo2$qfPersRtioMoleWetCh4) #"qfCalRtioMoleWetCh4" = qfInp$crdCo2$qfCalRtioMoleWetCh4) + } setQf$rtioMoleWetH2o <- data.frame("qfRngRtioMoleWetH2o" = qfInp$crdCo2$qfRngRtioMoleWetH2o, #"qfStepRtioMoleWetH2o" = qfInp$crdCo2$qfStepRtioMoleWetH2o, @@ -1433,12 +1439,12 @@ if (MethMeas == "ecse") { names(setQf$rtioMoleDryCo2) <- paste0(colnames(setQf$rtioMoleDryCo2), "CrdCo2") names(setQf$rtioMoleDry12CCo2) <- paste0(colnames(setQf$rtioMoleDry12CCo2), "CrdCo2") names(setQf$rtioMoleDry13CCo2) <- paste0(colnames(setQf$rtioMoleDry13CCo2), "CrdCo2") - names(setQf$rtioMoleDryCh4) <- paste0(colnames(setQf$rtioMoleDryCh4), "CrdCo2") + if ("ch4Conc" %in% names(qfInp)){names(setQf$rtioMoleDryCh4) <- paste0(colnames(setQf$rtioMoleDryCh4), "CrdCo2")} names(setQf$rtioMoleDryH2o) <- paste0(colnames(setQf$rtioMoleDryH2o), "CrdCo2") names(setQf$rtioMoleWetCo2) <- paste0(colnames(setQf$rtioMoleWetCo2), "CrdCo2") names(setQf$rtioMoleWet12CCo2) <- paste0(colnames(setQf$rtioMoleWet12CCo2), "CrdCo2") names(setQf$rtioMoleWet13CCo2) <- paste0(colnames(setQf$rtioMoleWet13CCo2), "CrdCo2") - names(setQf$rtioMoleWetCh4) <- paste0(colnames(setQf$rtioMoleWetCh4), "CrdCo2") + if ("ch4Conc" %in% names(qfInp)){names(setQf$rtioMoleWetCh4) <- paste0(colnames(setQf$rtioMoleWetCh4), "CrdCo2")} names(setQf$rtioMoleWetH2o) <- paste0(colnames(setQf$rtioMoleWetH2o), "CrdCo2") names(setQf$dlta13CCo2) <- paste0(colnames(setQf$dlta13CCo2), "CrdCo2") names(setQf$presCrdCo2) <- paste0(colnames(setQf$presCrdCo2), "CrdCo2") From be19cce8a710fa9b456eb5f126abb04a2d361df0 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Wed, 4 Aug 2021 22:34:36 +0000 Subject: [PATCH 118/168] added funtion to correct reference values and run benchmarking regression, modified wrapper and workflow to handle validation thresholding --- pack/eddy4R.base/NAMESPACE | 1 + pack/eddy4R.base/R/def.irga.vali.thsh.R | 84 ++++++++++++++++++++++ pack/eddy4R.base/R/wrap.irga.vali.R | 34 ++++++++- pack/eddy4R.base/man/def.irga.vali.thsh.Rd | 42 +++++++++++ 4 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 pack/eddy4R.base/R/def.irga.vali.thsh.R create mode 100644 pack/eddy4R.base/man/def.irga.vali.thsh.Rd diff --git a/pack/eddy4R.base/NAMESPACE b/pack/eddy4R.base/NAMESPACE index e338e271..5865c02f 100644 --- a/pack/eddy4R.base/NAMESPACE +++ b/pack/eddy4R.base/NAMESPACE @@ -30,6 +30,7 @@ export(def.idx.agr) export(def.idx.diff) export(def.inst.depe) export(def.irga.vali.cor) +export(def.irga.vali.thsh) export(def.lag) export(def.mean.med.mode) export(def.med.mad) diff --git a/pack/eddy4R.base/R/def.irga.vali.thsh.R b/pack/eddy4R.base/R/def.irga.vali.thsh.R new file mode 100644 index 00000000..9f49c807 --- /dev/null +++ b/pack/eddy4R.base/R/def.irga.vali.thsh.R @@ -0,0 +1,84 @@ +############################################################################################## +#' @title Definition function: Threshold IRGA validation data based on benchmarking regression + +#' @author +#' Chris Florian \email{eddy4R.info@gmail.com} + +#' @description Wrapper function to apply IRGA validation. + +#' @param data List of validation data as a report from eddy4R.base::wrap.irga.vali() +#' @param gasRefe List containing the values of the reference gases. [mol mol-1] +#' @param DateProc A vector of class "character" containing the processing date. +#' @param bnchSlpMax Maximum acceptable slope of the benchmarking regression +#' @param bnchSlpMin Minimum acceptable slope of the benchmarking regression + + +#' @return pass/fail criteria for a day's validation + + +#' @references +#' License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007. + +#' @keywords derived, irgaTurb, post-processing, pre-processing, validation + +#' @examples +#' Currently none. + +#' @seealso Currently none. + +#' @export + +# changelog and author contributions / copyrights +# Chris Florian (2021-08-03) +# original creation +############################################################################################## + +def.irga.vali.thsh <- function( + data, + DateProc, + bnchSlpMax, + bnchSlpMin +) { + + #get reference gas values for the processing date (in mol mol-1) + + zeroRefe <- data$rtioMoleDryCo2Vali$rtioMoleDryCo2Refe[2] + lowRefe <- data$rtioMoleDryCo2Vali$rtioMoleDryCo2Refe[3] + midRefe <- data$rtioMoleDryCo2Vali$rtioMoleDryCo2Refe[4] + highRefe <- data$rtioMoleDryCo2Vali$rtioMoleDryCo2Refe[5] + + refeVals <- c(zeroRefe, lowRefe, midRefe, highRefe) + + #get the mean measured values of the reference gas for the processing date + zeroMeas <- data$rtioMoleDryCo2Vali$mean[2] + lowMeas <- data$rtioMoleDryCo2Vali$mean[3] + midMeas <- data$rtioMoleDryCo2Vali$mean[4] + highMeas <- data$rtioMoleDryCo2Vali$mean[5] + + #correct measured LI7200 validation gas data based on calibration coefficients + + measZeroCor <- zeroMeas*data$rtioMoleDryCo2Mlf$coef[2] + data$rtioMoleDryCo2Mlf$coef[1] + measLowCor <- lowMeas*data$rtioMoleDryCo2Mlf$coef[2] + data$rtioMoleDryCo2Mlf$coef[1] + measMidCor <- midMeas*data$rtioMoleDryCo2Mlf$coef[2] + data$rtioMoleDryCo2Mlf$coef[1] + measHighCor <- highMeas*data$rtioMoleDryCo2Mlf$coef[2] + data$rtioMoleDryCo2Mlf$coef[1] + + rtioMoleDryCo2RefeCor <- c(measZeroCor, measLowCor, measMidCor, measHighCor) + + + #run benchmarking least squares regression on corrected mean values from the reference gasses vs. the reference values + #make sure this can handle NaN values + valiLmSlp <- lm(rtioMoleDryCo2RefeCor ~ refeVals)$coefficient[[2]] + + if (valiLmSlp >= bnchSlpMin & valiLmSlp <= bnchSlpMax){ + valiPass <- TRUE + } else { + valiPass <- FALSE + } + + #compile report including validation pass status and the corrected reference files to add to the vali table + rpt <- list() + rpt$valiPass <- valiPass + rpt$rtioMoleDryCo2RefeCor <- rtioMoleDryCo2RefeCor + + return(rpt) +} diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index 18a12836..fd8f9673 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -81,6 +81,8 @@ # adjust workflow to run MLFR even missing one gas cylinder # Natchaya P-Durden (2020-03-05) # Set all thresholds to screen linear coefficients to FALSE. +# Chris Florian (2021-08-03) +# add thresholding based on benchmarking regression ############################################################################################## wrap.irga.vali <- function( @@ -508,7 +510,37 @@ wrap.irga.vali <- function( #applying the calculated coefficients to measured data #Calculate time-series (20Hz) of slope and zero offset rpt[[DateProc]]$rtioMoleDryCo2Cor <- eddy4R.base::def.irga.vali.cor(data = data, DateProc = DateProc, coef = tmpCoef, valiData = valiData, valiCrit = valiCrit, ScalMax = ScalMax, FracSlpMax = FracSlpMax, OfstMax = OfstMax, Freq = 20) - + + #run the benchmarking regression to determine if the validation was good + valiPass <- eddy4R.base::def.irga.vali.thsh(data = rpt[[DateProc]], DateProc = DateProc, bnchSlpMax = 1.05, bnchSlpMin = 0.95) + + #remove corrected data if validation fails benchmarking test + if (valiPass$valiPass == FALSE){ + rpt[[DateProc]]$rtioMoleDryCo2Cor <- NaN + #raise quality flag in validation table to indicate validation status + rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfValiThsh <- c(NA, 1) + } else { + rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfValiThsh <- c(NA, 0) + } + + #add corrected reference gas values to vali table + rpt[[DateProc]]$rtioMoleDryCo2Vali$rtioMoleDryCo2RefeCor <- c(NaN, valiPass$rtioMoleDryCo2RefeCor) + + #reorder to place the corrected reference values next to the original reference values + rpt[[DateProc]]$rtioMoleDryCo2Vali <- rpt[[DateProc]]$rtioMoleDryCo2Vali[c("mean", "min", "max", "vari", "numSamp", "rtioMoleDryCo2Refe", "rtioMoleDryCo2RefeCor", "timeBgn", "timeEnd")] + + #reset attributes + + attributes(rpt[[DateProc]]$rtioMoleDryCo2Vali)$unit <- c("molCo2 mol-1Dry", #"mean" + "molCo2 mol-1Dry", #"min" + "molCo2 mol-1Dry", #"max" + "molCo2 mol-1Dry",#"vari" + "NA", #"numSamp" + "molCo2 mol-1Dry",#gasRefe + "molCo2 mol-1Dry",#gasRefeCor + "NA", #"timeBgn" + "NA")#"timeEnd" + #return results return(rpt) } diff --git a/pack/eddy4R.base/man/def.irga.vali.thsh.Rd b/pack/eddy4R.base/man/def.irga.vali.thsh.Rd new file mode 100644 index 00000000..c723fe23 --- /dev/null +++ b/pack/eddy4R.base/man/def.irga.vali.thsh.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/def.irga.vali.thsh.R +\name{def.irga.vali.thsh} +\alias{def.irga.vali.thsh} +\title{Definition function: Threshold IRGA validation data based on benchmarking regression} +\usage{ +def.irga.vali.thsh(data, DateProc, bnchSlpMax, bnchSlpMin) +} +\arguments{ +\item{data}{List of validation data as a report from eddy4R.base::wrap.irga.vali()} + +\item{DateProc}{A vector of class "character" containing the processing date.} + +\item{bnchSlpMax}{Maximum acceptable slope of the benchmarking regression} + +\item{bnchSlpMin}{Minimum acceptable slope of the benchmarking regression} + +\item{gasRefe}{List containing the values of the reference gases. [mol mol-1]} +} +\value{ +pass/fail criteria for a day's validation +} +\description{ +Wrapper function to apply IRGA validation. +} +\examples{ +Currently none. +} +\references{ +License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007. +} +\seealso{ +Currently none. +} +\author{ +Chris Florian \email{eddy4R.info@gmail.com} +} +\keyword{derived,} +\keyword{irgaTurb,} +\keyword{post-processing,} +\keyword{pre-processing,} +\keyword{validation} From cbff1312d026d3c108a288478546923a4d5ad24b Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Thu, 5 Aug 2021 22:13:17 +0000 Subject: [PATCH 119/168] adding units for rtioMoleDryCo2RefeCor --- pack/eddy4R.base/R/wrap.unit.conv.out.ec.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R b/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R index 03e95ca5..acd1f2e9 100644 --- a/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R +++ b/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R @@ -40,6 +40,8 @@ # converting time format in ecse qfqm # Natchaya P-Durden (2020-01-17) # adding unit conversion for rtioMoleDryH2o during validation +# Chris Florian (2021-08-05) +# adding units for rtioMoleDryCo2RefeCor ############################################################################################ wrap.unit.conv.out.ec <- function( @@ -134,7 +136,7 @@ if(MethType == "ucrt"){ if(MethType == "vali"){ outAttr$co2Turb <- base::list( - "rtioMoleDryCo2Vali"= c("mean" = "umolCo2 mol-1Dry", "min" = "umolCo2 mol-1Dry", "max" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "numSamp" = "NA", "rtioMoleDryCo2Refe" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA")) + "rtioMoleDryCo2Vali"= c("mean" = "umolCo2 mol-1Dry", "min" = "umolCo2 mol-1Dry", "max" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "numSamp" = "NA", "rtioMoleDryCo2Refe" = "umolCo2 mol-1Dry", "rtioMoleDryCo2RefeCor" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA")) outAttr$h2oTurb <- base::list( "rtioMoleDryH2oVali"= c("mean" = "mmolH2o mol-1Dry", "min" = "mmolH2o mol-1Dry", "max" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "numSamp" = "NA", "rtioMoleDryH2oRefe" = "mmolH2o mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA")) } @@ -209,9 +211,9 @@ for(idxDp in base::names(rpt)){ if(MethType == "vali"){ #refeName <- names(outAttr[[idxDp]][[idxVar]][6]) - nameAttr <- c("mean", "min", "max", "vari", "numSamp" , names(outAttr[[idxDp]][[idxVar]][6]), "timeBgn", "timeEnd" ) + nameAttr <- c("mean", "min", "max", "vari", "numSamp" , names(outAttr[[idxDp]][[idxVar]][6]), names(outAttr[[idxDp]][[idxVar]][7]), "timeBgn", "timeEnd" ) #wrkAttr[[idxDp]][[idxVar]] <- c("mean"= baseAttr, "min" = baseAttr, "max" = baseAttr, "vari" = baseAttr, "numSamp" = baseAttr, refeName = baseAttr, "timeBgn" = "NA", "timeEnd" = "NA") - wrkAttr[[idxDp]][[idxVar]] <- c(baseAttr, baseAttr, baseAttr, baseAttr, baseAttr, baseAttr, "NA", "NA") + wrkAttr[[idxDp]][[idxVar]] <- c(baseAttr, baseAttr, baseAttr, baseAttr, baseAttr, baseAttr, baseAttr, "NA", "NA") names(wrkAttr[[idxDp]][[idxVar]]) <- nameAttr } From 752d0574ce9077108bbb56bdaed856852bf22b8a Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Mon, 9 Aug 2021 19:46:22 +0000 Subject: [PATCH 120/168] updating h5 write code to add qfValiThsh to the vali table attributes --- pack/eddy4R.base/R/def.hdf5.wrte.dp01.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R index 8076a8f8..fa3b4f47 100755 --- a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R +++ b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R @@ -52,6 +52,8 @@ # removed rtioMoleDryH2oCor and rtioMoleDryH2oRaw data and ucrt from the basic file # Natchaya P-Durden (2020-02-23) # removed unnecessary qfqm unit attributes when writing the basic file +# Chris Florian (2021-08-09) +# adding qfValiThsh to rtioMoleDryCo2Vali attributes ############################################################################################## @@ -138,6 +140,7 @@ if(MethSubAgr == TRUE){ rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$coef, h5obj = dgid, name = "coef") rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$coefSe, h5obj = dgid, name = "coefSe") rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$scal, h5obj = dgid, name = "scal") + rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$qfValiThsh, h5obj = dgid, name = "qfValiThsh") }} } ########################################################################################## From 57d09a5c5f654f4274be6121036138cb5788688c Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Mon, 9 Aug 2021 20:43:01 +0000 Subject: [PATCH 121/168] adding logic to prevent errors if refe or mean values are missing --- pack/eddy4R.base/R/def.irga.vali.thsh.R | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pack/eddy4R.base/R/def.irga.vali.thsh.R b/pack/eddy4R.base/R/def.irga.vali.thsh.R index 9f49c807..0ea03971 100644 --- a/pack/eddy4R.base/R/def.irga.vali.thsh.R +++ b/pack/eddy4R.base/R/def.irga.vali.thsh.R @@ -31,6 +31,8 @@ # changelog and author contributions / copyrights # Chris Florian (2021-08-03) # original creation +# Chris Florian (2021-08-09) +# adding logic to prevent errors if data are missing ############################################################################################## def.irga.vali.thsh <- function( @@ -66,15 +68,25 @@ def.irga.vali.thsh <- function( #run benchmarking least squares regression on corrected mean values from the reference gasses vs. the reference values - #make sure this can handle NaN values - valiLmSlp <- lm(rtioMoleDryCo2RefeCor ~ refeVals)$coefficient[[2]] + #adding logic to avoid an error when one of the lists passed into lm() is entirely NA - if (valiLmSlp >= bnchSlpMin & valiLmSlp <= bnchSlpMax){ - valiPass <- TRUE + if(all(!is.na(refeVals)) == TRUE & all(!is.na(rtioMoleDryCo2RefeCor)) == TRUE){ + valiLmSlp <- stats::lm(rtioMoleDryCo2RefeCor ~ refeVals)$coefficient[[2]] } else { - valiPass <- FALSE + valiLmSlp <- NA } + #set valiPass flag, 0 for good validation, 1 for bad, -1 for missing values + if(!is.na(valiLmSlp)){ + if (valiLmSlp >= bnchSlpMin & valiLmSlp <= bnchSlpMax){ + valiPass <- TRUE + } else { + valiPass <- FALSE + } + } else { + valiPass <- -1 + } + #compile report including validation pass status and the corrected reference files to add to the vali table rpt <- list() rpt$valiPass <- valiPass From ba8f474561b7dec0bba19e7c27bd87536d0b632c Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Mon, 9 Aug 2021 21:22:17 +0000 Subject: [PATCH 122/168] adding -1 flag for missing validations --- pack/eddy4R.base/R/wrap.irga.vali.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index fd8f9673..66809163 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -83,6 +83,8 @@ # Set all thresholds to screen linear coefficients to FALSE. # Chris Florian (2021-08-03) # add thresholding based on benchmarking regression +# Chris Florian (2021-08-09) +# adding -1 flag for missing validations ############################################################################################## wrap.irga.vali <- function( @@ -519,8 +521,10 @@ wrap.irga.vali <- function( rpt[[DateProc]]$rtioMoleDryCo2Cor <- NaN #raise quality flag in validation table to indicate validation status rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfValiThsh <- c(NA, 1) - } else { + } else if (valiPass$valiPass == TRUE) { rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfValiThsh <- c(NA, 0) + } else { + rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfValiThsh <- c(NA, -1) } #add corrected reference gas values to vali table From a0f2c27910f7c5d6297102d80b07076f0d6f68b7 Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 17 Aug 2021 20:46:48 +0000 Subject: [PATCH 123/168] - failsafe for rhdf5 metadata attribute added in rhdf5 2.34.0 --- pack/eddy4R.base/R/def.hdf5.extr.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pack/eddy4R.base/R/def.hdf5.extr.R b/pack/eddy4R.base/R/def.hdf5.extr.R index e4e144ca..01e3b743 100755 --- a/pack/eddy4R.base/R/def.hdf5.extr.R +++ b/pack/eddy4R.base/R/def.hdf5.extr.R @@ -52,6 +52,8 @@ # applied term name convention; replaced FileIn by FileInp # Natchaya P-Durden (2018-05-11) # rename function from def.extr.hdf5() to def.hdf5.extr() +# Dave Durden (2018-03-12) +# Adding failsafe for rhdf5 metadata attribute on individual dp0p arrays ############################################################################################################## #Start of function call to extract data from one file and write to another ############################################################################################################## @@ -191,10 +193,19 @@ if(!is.null(FileOut)) { # determine if attributes should be written to output HDF5 if(MethExtrAttr == TRUE){ + lapply(names(rpt$listAttr), function(x){ + if(length(names(rpt$listAttr[[x]])) == 1 && grepl(pattern = "rhdf5", x = names(rpt$listAttr[[x]]))){ + #Remove attribute if rhdf5 attribute is the only one written + rpt$listAttr[[x]] <<- NULL + }#end if logical for single rhdf5 attribute + })#end failsafe for rhdf5 attribute + #Write attributes to the output HDF5 file lapply(names(rpt$listAttr), function(x){ + #print(x) idData <- rhdf5::H5Oopen(idFile, x) base::lapply(names(rpt$listAttr[[x]]), function(y){ + #print(y) #y <- names(rpt$listAttr[[x]])[1] rhdf5::h5writeAttribute(attr = rpt$listAttr[[x]][[y]], h5obj = idData, name = y)}) }) From 56401ed4848740e53838de104cecb9648417237c Mon Sep 17 00:00:00 2001 From: ddurden Date: Wed, 18 Aug 2021 05:12:27 +0000 Subject: [PATCH 124/168] - failsafe for rhdf5 attribute introduced in rhdf5 2.34.0 --- pack/eddy4R.base/R/def.hdf5.copy.para.R | 9 +++++++++ pack/eddy4R.base/R/def.hdf5.extr.R | 1 + 2 files changed, 10 insertions(+) diff --git a/pack/eddy4R.base/R/def.hdf5.copy.para.R b/pack/eddy4R.base/R/def.hdf5.copy.para.R index 12835a5a..7a01d50d 100755 --- a/pack/eddy4R.base/R/def.hdf5.copy.para.R +++ b/pack/eddy4R.base/R/def.hdf5.copy.para.R @@ -39,6 +39,8 @@ # applied term name convention; replaced FileIn by FileInp # Natchaya P-Durden (2018-05-22) # rename function from def.para.hdf5.dp01() to def.hdf5.copy.para() +# Dave Durden (2021-08-17) +# Failsafe to remove rhdf5 attribute from list of attributes written out ############################################################################################################## #Start of function call to read metadata from one file and write to another ############################################################################################################## @@ -74,6 +76,13 @@ base::names(listAttr) <- listGrp #Remove all empty lists listAttr <- listAttr[!base::sapply(listAttr, function(x) base::length(x) == 0)] +#Failsafe to remove rhdf5 attribute +lapply(names(listAttr), function(x){ + if(length(names(listAttr[[x]])) == 1 && grepl(pattern = "rhdf5", x = names(listAttr[[x]]))){ + #Remove attribute if rhdf5 attribute is the only one written + listAttr[[x]] <<- NULL + }#end if logical for single rhdf5 attribute +})#end failsafe for rhdf5 attribute #Open the output file HDF5 link idFile <- rhdf5::H5Fopen(FileOut) diff --git a/pack/eddy4R.base/R/def.hdf5.extr.R b/pack/eddy4R.base/R/def.hdf5.extr.R index 01e3b743..ead8c2e1 100755 --- a/pack/eddy4R.base/R/def.hdf5.extr.R +++ b/pack/eddy4R.base/R/def.hdf5.extr.R @@ -193,6 +193,7 @@ if(!is.null(FileOut)) { # determine if attributes should be written to output HDF5 if(MethExtrAttr == TRUE){ + #Failsafe to remove rhdf5 attribute lapply(names(rpt$listAttr), function(x){ if(length(names(rpt$listAttr[[x]])) == 1 && grepl(pattern = "rhdf5", x = names(rpt$listAttr[[x]]))){ #Remove attribute if rhdf5 attribute is the only one written From 2244a55fd0288c122cfedaf9b347740ef88af19a Mon Sep 17 00:00:00 2001 From: ddurden Date: Wed, 18 Aug 2021 05:13:23 +0000 Subject: [PATCH 125/168] - fixing dp04 attributes that were stored as lists in R4.x --- pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R index f0b5c100..aea3251b 100755 --- a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R +++ b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R @@ -71,6 +71,8 @@ # adding timeBgn and timeEnd attributes # David Durden (2020-05-01) # adding Pfit coefficient output metadata +# David Durden (2021-08-17) +# Fixing attribute issues related to rhdf5 not being able to write lists ############################################################################################## @@ -177,7 +179,7 @@ if(MethDp04 == TRUE){ idFile <- rhdf5::H5Fopen(FileOut) for(idxDp04 in names(inpList$dp04$data)){ - #idxDp04 <- names(inpList$dp04$data)[5] + #idxDp04 <- names(inpList$dp04$data)[1] if(idxDp04 == "foot") { #Adding time to output dataframe rptDp04 <- cbind(timeBgn = outList$data$soni$veloXaxsErth$timeBgn, timeEnd = outList$data$soni$veloXaxsErth$timeEnd, inpList$dp04$data[[idxDp04]]$stat, stringsAsFactors = FALSE) @@ -256,7 +258,7 @@ if(MethDp04 == TRUE){ tmpAttr <- c() attributes(tmpAttr)$unit[["timeBgn"]] <- "NA" attributes(tmpAttr)$unit[["timeEnd"]] <- "NA" - attributes(rptDp04)$unit <- c(attributes(tmpAttr)$unit, attributes(rptDp04)$unit) + attributes(rptDp04)$unit <- base::as.character(c(attributes(tmpAttr)$unit, attributes(rptDp04)$unit)) #Open connection to dp04 data level idDataDp04 <- rhdf5::H5Gopen(idFile,paste0("/", SiteLoca, "/dp04/data/",idxDp04)) @@ -291,7 +293,7 @@ if(MethDp04 == TRUE){ tmpAttr <- c() attributes(tmpAttr)$unit[["timeBgn"]] <- "NA" attributes(tmpAttr)$unit[["timeEnd"]] <- "NA" - attributes(rptDp04Qfqm)$unit <- c(attributes(tmpAttr)$unit, attributes(rptDp04Qfqm)$unit) + attributes(rptDp04Qfqm)$unit <- base::as.character(c(attributes(tmpAttr)$unit, attributes(rptDp04Qfqm)$unit)) #Open connection to dp04 data level idQfqmDp04 <- rhdf5::H5Gopen(idFile,paste0("/", SiteLoca, "/dp04/qfqm/",idxDp04)) From 6c2ef0731eb22448495ec2db40b7392325a5ae0d Mon Sep 17 00:00:00 2001 From: ddurden Date: Wed, 18 Aug 2021 05:35:04 +0000 Subject: [PATCH 126/168] - foot qfqm attribute fix --- pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R index aea3251b..3d34586c 100755 --- a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R +++ b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R @@ -227,7 +227,7 @@ if(MethDp04 == TRUE){ tmpAttr <- c() attributes(tmpAttr)$unit[["timeBgn"]] <- "NA" attributes(tmpAttr)$unit[["timeEnd"]] <- "NA" - attributes(rptDp04Qfqm)$unit <- c(attributes(tmpAttr)$unit, attributes(rptDp04Qfqm)$unit) + attributes(rptDp04Qfqm)$unit <- base::as.character(c(attributes(tmpAttr)$unit, attributes(rptDp04Qfqm)$unit)) #Open connection to dp04 data level idQfqmDp04 <- rhdf5::H5Gopen(idFile,paste0("/", SiteLoca, "/dp04/qfqm/",idxDp04)) @@ -241,7 +241,8 @@ if(MethDp04 == TRUE){ rhdf5::h5writeAttribute(attributes(rptDp04Qfqm)$unit, h5obj = idQfqmDp04Df, name = "unit") - } else { + } + else { #output only flux for fluxCo2 in basic file if (idxDp04 %in% c("fluxCo2", "fluxH2o") & MethExpd == FALSE){ inpList$dp04$data[[idxDp04]]$turb$fluxCor <- NULL From d1e136cdc685825014d033cc2e4d68c8ec38d012 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Thu, 19 Aug 2021 17:33:31 +0000 Subject: [PATCH 127/168] naming convention changes for rtioMoleDryCo2Vali table and adding additional benchmarking regression attributes --- pack/eddy4R.base/R/def.hdf5.wrte.dp01.R | 12 +++-- pack/eddy4R.base/R/def.irga.vali.thsh.R | 63 +++++++++++++++------- pack/eddy4R.base/R/wrap.irga.vali.R | 29 +++++++--- pack/eddy4R.base/R/wrap.unit.conv.out.ec.R | 8 +-- 4 files changed, 77 insertions(+), 35 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R index fa3b4f47..f260b556 100755 --- a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R +++ b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.R @@ -137,10 +137,14 @@ if(MethSubAgr == TRUE){ if (Dp01 == "co2Turb"){ if (!is.null(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$coef) == TRUE){ dgid <- rhdf5::H5Dopen(idData01, "rtioMoleDryCo2Vali") - rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$coef, h5obj = dgid, name = "coef") - rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$coefSe, h5obj = dgid, name = "coefSe") - rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$scal, h5obj = dgid, name = "scal") - rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$qfValiThsh, h5obj = dgid, name = "qfValiThsh") + rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$coef, h5obj = dgid, name = "valiCoef") + rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$coefSe, h5obj = dgid, name = "valiCoefSe") + rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$scal, h5obj = dgid, name = "valiScal") + rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$qfEvalThsh, h5obj = dgid, name = "qfEvalThsh") + rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$evalCoef, h5obj = dgid, name = "evalCoef") + rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$evalCoefSe, h5obj = dgid, name = "evalCoefSe") + rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$evalSlpThsh, h5obj = dgid, name = "evalSlpThsh") + rhdf5::h5writeAttribute(attributes(inpList$dp01AgrSub$data$co2Turb$rtioMoleDryCo2Vali)$evalOfstThsh, h5obj = dgid, name = "evalOfstThsh") }} } ########################################################################################## diff --git a/pack/eddy4R.base/R/def.irga.vali.thsh.R b/pack/eddy4R.base/R/def.irga.vali.thsh.R index 0ea03971..50701986 100644 --- a/pack/eddy4R.base/R/def.irga.vali.thsh.R +++ b/pack/eddy4R.base/R/def.irga.vali.thsh.R @@ -9,8 +9,10 @@ #' @param data List of validation data as a report from eddy4R.base::wrap.irga.vali() #' @param gasRefe List containing the values of the reference gases. [mol mol-1] #' @param DateProc A vector of class "character" containing the processing date. -#' @param bnchSlpMax Maximum acceptable slope of the benchmarking regression -#' @param bnchSlpMin Minimum acceptable slope of the benchmarking regression +#' @param evalSlpMax Maximum acceptable slope of the benchmarking regression +#' @param evalSlpMin Minimum acceptable slope of the benchmarking regression +#' @param evalOfstMax Maximum acceptable offset of the benchmarking regression +#' @param evalOfstMin Minimum acceptable offset of the benchmarking regression #' @return pass/fail criteria for a day's validation @@ -33,14 +35,17 @@ # original creation # Chris Florian (2021-08-09) # adding logic to prevent errors if data are missing +# Chris Florian (2021-08-18) +# updating terms to replace bnch with eval, adding additional coef outputs and adding offset criteria ############################################################################################## def.irga.vali.thsh <- function( data, DateProc, - bnchSlpMax, - bnchSlpMin -) { + evalSlpMax, + evalSlpMin, + evalOfstMax, + evalOfstMin) { #get reference gas values for the processing date (in mol mol-1) @@ -59,38 +64,56 @@ def.irga.vali.thsh <- function( #correct measured LI7200 validation gas data based on calibration coefficients - measZeroCor <- zeroMeas*data$rtioMoleDryCo2Mlf$coef[2] + data$rtioMoleDryCo2Mlf$coef[1] - measLowCor <- lowMeas*data$rtioMoleDryCo2Mlf$coef[2] + data$rtioMoleDryCo2Mlf$coef[1] - measMidCor <- midMeas*data$rtioMoleDryCo2Mlf$coef[2] + data$rtioMoleDryCo2Mlf$coef[1] - measHighCor <- highMeas*data$rtioMoleDryCo2Mlf$coef[2] + data$rtioMoleDryCo2Mlf$coef[1] + meanZeroCor <- zeroMeas*data$rtioMoleDryCo2Mlf$coef[2] + data$rtioMoleDryCo2Mlf$coef[1] + meanLowCor <- lowMeas*data$rtioMoleDryCo2Mlf$coef[2] + data$rtioMoleDryCo2Mlf$coef[1] + meanMidCor <- midMeas*data$rtioMoleDryCo2Mlf$coef[2] + data$rtioMoleDryCo2Mlf$coef[1] + meanHighCor <- highMeas*data$rtioMoleDryCo2Mlf$coef[2] + data$rtioMoleDryCo2Mlf$coef[1] - rtioMoleDryCo2RefeCor <- c(measZeroCor, measLowCor, measMidCor, measHighCor) + meanCor <- c(meanZeroCor, meanLowCor, meanMidCor, meanHighCor) #run benchmarking least squares regression on corrected mean values from the reference gasses vs. the reference values #adding logic to avoid an error when one of the lists passed into lm() is entirely NA - if(all(!is.na(refeVals)) == TRUE & all(!is.na(rtioMoleDryCo2RefeCor)) == TRUE){ - valiLmSlp <- stats::lm(rtioMoleDryCo2RefeCor ~ refeVals)$coefficient[[2]] + if(all(!is.na(refeVals)) == TRUE & all(!is.na(meanCor)) == TRUE){ + valiEval <- stats::lm(meanCor ~ refeVals) + valiEvalSe <- sqrt(diag(vcov(valiEval))) + valiEvalSlp <- valiEval$coefficient[[2]] + valiEvalOfst <- valiEval$coefficient[[1]] } else { - valiLmSlp <- NA + valiEval <- NA + valiEvalSe <- NA + valiEvalSlp <- NA + valiEvalOfst <- NA } + #determine if slope passes + + evalSlpPass <- valiEvalSlp >= evalSlpMin & valiEvalSlp <= evalSlpMax + + #determine if offset passes + + evalOfstPass <- valiEvalOfst >= evalOfstMin & valiEvalOfst <= evalOfstMax + #set valiPass flag, 0 for good validation, 1 for bad, -1 for missing values - if(!is.na(valiLmSlp)){ - if (valiLmSlp >= bnchSlpMin & valiLmSlp <= bnchSlpMax){ - valiPass <- TRUE + if(!is.na(valiEvalSlp)){ + if (evalSlpPass == TRUE & evalOfstPass == TRUE){ + valiEvalPass <- TRUE } else { - valiPass <- FALSE + valiEvalPass <- FALSE } } else { - valiPass <- -1 + valiEvalPass <- -1 } #compile report including validation pass status and the corrected reference files to add to the vali table rpt <- list() - rpt$valiPass <- valiPass - rpt$rtioMoleDryCo2RefeCor <- rtioMoleDryCo2RefeCor + rpt$valiEvalPass <- valiEvalPass + rpt$meanCor <- meanCor + rpt$evalCoef <- c(valiEvalOfst, valiEvalSlp) + rpt$evalCoefSe <- valiEvalSe + rpt$evalSlpThsh <- c(evalSlpMin, evalSlpMax) + rpt$evalOfstThsh <- c(evalOfstMin, evalOfstMax) return(rpt) } diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index 66809163..d2959de8 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -514,24 +514,37 @@ wrap.irga.vali <- function( rpt[[DateProc]]$rtioMoleDryCo2Cor <- eddy4R.base::def.irga.vali.cor(data = data, DateProc = DateProc, coef = tmpCoef, valiData = valiData, valiCrit = valiCrit, ScalMax = ScalMax, FracSlpMax = FracSlpMax, OfstMax = OfstMax, Freq = 20) #run the benchmarking regression to determine if the validation was good - valiPass <- eddy4R.base::def.irga.vali.thsh(data = rpt[[DateProc]], DateProc = DateProc, bnchSlpMax = 1.05, bnchSlpMin = 0.95) + valiEval <- eddy4R.base::def.irga.vali.thsh(data = rpt[[DateProc]], DateProc = DateProc, evalSlpMax = 1.05, evalSlpMin = 0.95, evalOfstMax = 100, evalOfstMin = -100) #remove corrected data if validation fails benchmarking test - if (valiPass$valiPass == FALSE){ + if (valiEval$valiEvalPass == FALSE){ rpt[[DateProc]]$rtioMoleDryCo2Cor <- NaN #raise quality flag in validation table to indicate validation status - rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfValiThsh <- c(NA, 1) - } else if (valiPass$valiPass == TRUE) { - rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfValiThsh <- c(NA, 0) + rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, 1) + } else if (valiEval$valiEvalPass == TRUE) { + rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, 0) } else { - rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfValiThsh <- c(NA, -1) + rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, -1) } + #add additional coefficients to mlf table + rpt[[DateProc]]$rtioMoleDryCo2Mlf$evalCoef <- valiEval$evalCoef + rpt[[DateProc]]$rtioMoleDryCo2Mlf$evalCoefSe <- valiEval$evalCoefSe + rpt[[DateProc]]$rtioMoleDryCo2Mlf$evalSlpThsh <- valiEval$evalSlpThsh + rpt[[DateProc]]$rtioMoleDryCo2Mlf$evalOfstThsh <- valiEval$evalOfstThsh + + #add corrected reference gas values to vali table - rpt[[DateProc]]$rtioMoleDryCo2Vali$rtioMoleDryCo2RefeCor <- c(NaN, valiPass$rtioMoleDryCo2RefeCor) + rpt[[DateProc]]$rtioMoleDryCo2Vali$meanCor <- c(NaN, valiEval$meanCor) #reorder to place the corrected reference values next to the original reference values - rpt[[DateProc]]$rtioMoleDryCo2Vali <- rpt[[DateProc]]$rtioMoleDryCo2Vali[c("mean", "min", "max", "vari", "numSamp", "rtioMoleDryCo2Refe", "rtioMoleDryCo2RefeCor", "timeBgn", "timeEnd")] + rpt[[DateProc]]$rtioMoleDryCo2Vali <- rpt[[DateProc]]$rtioMoleDryCo2Vali[c("mean", "min", "max", "vari", "numSamp", "rtioMoleDryCo2Refe", "meanCor", "timeBgn", "timeEnd")] + + #rename rtioMoleDryCo2Refe to refe, this could be implemented in the rest of the functions in the future + names(rpt[[DateProc]]$rtioMoleDryCo2Vali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "meanCor", "timeBgn", "timeEnd") + + #rename rtioMoleDryH2oRefe to refe to match CO2 + names(rpt[[DateProc]]$rtioMoleDryH2oVali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "timeBgn", "timeEnd") #reset attributes diff --git a/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R b/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R index acd1f2e9..e69af902 100644 --- a/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R +++ b/pack/eddy4R.base/R/wrap.unit.conv.out.ec.R @@ -42,6 +42,8 @@ # adding unit conversion for rtioMoleDryH2o during validation # Chris Florian (2021-08-05) # adding units for rtioMoleDryCo2RefeCor +# Chris Florian (2021-08-18) +# updating naming convention, removing redundant rtioMoleDryCo2 from validation table ############################################################################################ wrap.unit.conv.out.ec <- function( @@ -136,9 +138,9 @@ if(MethType == "ucrt"){ if(MethType == "vali"){ outAttr$co2Turb <- base::list( - "rtioMoleDryCo2Vali"= c("mean" = "umolCo2 mol-1Dry", "min" = "umolCo2 mol-1Dry", "max" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "numSamp" = "NA", "rtioMoleDryCo2Refe" = "umolCo2 mol-1Dry", "rtioMoleDryCo2RefeCor" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA")) + "rtioMoleDryCo2Vali"= c("mean" = "umolCo2 mol-1Dry", "min" = "umolCo2 mol-1Dry", "max" = "umolCo2 mol-1Dry", "vari" = "umolCo2 mol-1Dry", "numSamp" = "NA", "refe" = "umolCo2 mol-1Dry", "meanCor" = "umolCo2 mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA")) outAttr$h2oTurb <- base::list( - "rtioMoleDryH2oVali"= c("mean" = "mmolH2o mol-1Dry", "min" = "mmolH2o mol-1Dry", "max" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "numSamp" = "NA", "rtioMoleDryH2oRefe" = "mmolH2o mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA")) + "rtioMoleDryH2oVali"= c("mean" = "mmolH2o mol-1Dry", "min" = "mmolH2o mol-1Dry", "max" = "mmolH2o mol-1Dry", "vari" = "mmolH2o mol-1Dry", "numSamp" = "NA", "refe" = "mmolH2o mol-1Dry", "timeBgn" = "NA", "timeEnd" = "NA")) } #assign output attributes @@ -213,7 +215,7 @@ for(idxDp in base::names(rpt)){ #refeName <- names(outAttr[[idxDp]][[idxVar]][6]) nameAttr <- c("mean", "min", "max", "vari", "numSamp" , names(outAttr[[idxDp]][[idxVar]][6]), names(outAttr[[idxDp]][[idxVar]][7]), "timeBgn", "timeEnd" ) #wrkAttr[[idxDp]][[idxVar]] <- c("mean"= baseAttr, "min" = baseAttr, "max" = baseAttr, "vari" = baseAttr, "numSamp" = baseAttr, refeName = baseAttr, "timeBgn" = "NA", "timeEnd" = "NA") - wrkAttr[[idxDp]][[idxVar]] <- c(baseAttr, baseAttr, baseAttr, baseAttr, baseAttr, baseAttr, baseAttr, "NA", "NA") + wrkAttr[[idxDp]][[idxVar]] <- c(baseAttr, baseAttr, baseAttr, baseAttr, "NA", baseAttr, baseAttr, "NA", "NA") names(wrkAttr[[idxDp]][[idxVar]]) <- nameAttr } From dd33bcfa7a6f961a2530cb6af0b2589e7519bc80 Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 20 Aug 2021 20:46:46 +0000 Subject: [PATCH 128/168] removing quality indicators from qfFinal determination --- pack/eddy4R.qaqc/R/def.qf.finl.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pack/eddy4R.qaqc/R/def.qf.finl.R b/pack/eddy4R.qaqc/R/def.qf.finl.R index 7811aa4b..41e215d8 100644 --- a/pack/eddy4R.qaqc/R/def.qf.finl.R +++ b/pack/eddy4R.qaqc/R/def.qf.finl.R @@ -49,6 +49,8 @@ # Added exclusion of Null test failures from qmBeta (to avoid double-counting) # Natchaya P-Durden (2018-04-03) # update @param format +# David Durden (2021-08-18) +# Removing quality indicators (qi) from qfFinal determination ############################################################################################## def.qf.finl <- function ( qf, @@ -75,6 +77,9 @@ def.qf.finl <- function ( stop("Input parameter Thsh must be a numeric vector of length 1") } + #Remove quality indicators from being qfFinal determination + qf <- qf[,grep("^qi", x = names(qf), invert = TRUE)] + # Compute Quality metric --------------------------------------------------- #compute qfAlpha and qfBeta qf[,"qfAlph"] <- apply(qf, 1, function(x) ifelse(any(x==1),1,0)) From 1b788e7d1d291384242b6fbc5be39537553eb347 Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 20 Aug 2021 20:47:36 +0000 Subject: [PATCH 129/168] - changing some quality flags to quality indicators --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 7404dd88..7dd94a1f 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -207,7 +207,7 @@ if (MethMeas == "ecte") { setQf$presDiffIrgaTurb <- data.frame("qfRngPresDiff" = qfInp$irgaTurb$qfRngPresDiff, "qfStepPresDiff" = qfInp$irgaTurb$qfStepPresDiff, "qfPersPresDiff" = qfInp$irgaTurb$qfPersPresDiff, - "qfSpkPresDiff" = qfInp$irgaTurb$qfSpkPresDiff, + "qiSpkPresDiff" = qfInp$irgaTurb$qfSpkPresDiff, "qfNullPresDiff" = qfInp$irgaTurb$qfNullPresDiff) #"qfCalPresDiff" = qfInp$irgaTurb$qfCalPresDiff) @@ -291,14 +291,14 @@ if (MethMeas == "ecte") { setQf$ssiCo2 <- data.frame("qfRngSsiCo2" = qfInp$irgaTurb$qfRngSsiCo2, "qfStepSsiCo2" = qfInp$irgaTurb$qfStepSsiCo2, "qfPersSsiCo2" = qfInp$irgaTurb$qfPersSsiCo2, - "qfSpkSsiCo2" = qfInp$irgaTurb$qfSpkSsiCo2, + "qiSpkSsiCo2" = qfInp$irgaTurb$qfSpkSsiCo2, "qfNullSsiCo2" = qfInp$irgaTurb$qfNullSsiCo2) #"qfCalSsiCo2" = qfInp$irgaTurb$qfCalSsiCo2) setQf$ssiH2o <- data.frame("qfRngSsiH2o" = qfInp$irgaTurb$qfRngSsiH2o, "qfStepSsiH2o" = qfInp$irgaTurb$qfStepSsiH2o, "qfPersSsiH2o" = qfInp$irgaTurb$qfPersSsiH2o, - "qfSpkSsiH2o" = qfInp$irgaTurb$qfSpkSsiH2o, + "qiSpkSsiH2o" = qfInp$irgaTurb$qfSpkSsiH2o, "qfNullSsiH2o" = qfInp$irgaTurb$qfNullSsiH2o) #"qfCalSsiH2o" = qfInp$irgaTurb$qfCalSsiH2o) From e4edb0fd58019e0595b22d0c4957bf7f179a760d Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 24 Aug 2021 16:08:23 +0000 Subject: [PATCH 130/168] - changing qf to qi for ancillary data streams in qf grouping --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 150 +++++++++++++++------------ 1 file changed, 85 insertions(+), 65 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 7dd94a1f..6bc503bc 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -90,6 +90,8 @@ # removing flags for external sensors from ECSE qfqm # David Durden (2020-07-14) # Added qfNull and qfSpk for all variables, removed qfNull from ancillary data streams +# David Durden (2021-08-24) +# Changing ancillary data stream ECTE quality flags to quality indicators ############################################################################################## def.dp01.grp.qf <- function( @@ -207,7 +209,7 @@ if (MethMeas == "ecte") { setQf$presDiffIrgaTurb <- data.frame("qfRngPresDiff" = qfInp$irgaTurb$qfRngPresDiff, "qfStepPresDiff" = qfInp$irgaTurb$qfStepPresDiff, "qfPersPresDiff" = qfInp$irgaTurb$qfPersPresDiff, - "qiSpkPresDiff" = qfInp$irgaTurb$qfSpkPresDiff, + "qfSpkPresDiff" = qfInp$irgaTurb$qfSpkPresDiff, "qfNullPresDiff" = qfInp$irgaTurb$qfNullPresDiff) #"qfCalPresDiff" = qfInp$irgaTurb$qfCalPresDiff) @@ -291,14 +293,14 @@ if (MethMeas == "ecte") { setQf$ssiCo2 <- data.frame("qfRngSsiCo2" = qfInp$irgaTurb$qfRngSsiCo2, "qfStepSsiCo2" = qfInp$irgaTurb$qfStepSsiCo2, "qfPersSsiCo2" = qfInp$irgaTurb$qfPersSsiCo2, - "qiSpkSsiCo2" = qfInp$irgaTurb$qfSpkSsiCo2, + "qfSpkSsiCo2" = qfInp$irgaTurb$qfSpkSsiCo2, "qfNullSsiCo2" = qfInp$irgaTurb$qfNullSsiCo2) #"qfCalSsiCo2" = qfInp$irgaTurb$qfCalSsiCo2) setQf$ssiH2o <- data.frame("qfRngSsiH2o" = qfInp$irgaTurb$qfRngSsiH2o, "qfStepSsiH2o" = qfInp$irgaTurb$qfStepSsiH2o, "qfPersSsiH2o" = qfInp$irgaTurb$qfPersSsiH2o, - "qiSpkSsiH2o" = qfInp$irgaTurb$qfSpkSsiH2o, + "qfSpkSsiH2o" = qfInp$irgaTurb$qfSpkSsiH2o, "qfNullSsiH2o" = qfInp$irgaTurb$qfNullSsiH2o) #"qfCalSsiH2o" = qfInp$irgaTurb$qfCalSsiH2o) @@ -445,131 +447,149 @@ if (MethMeas == "ecte") { #grouping qulity flags that related to co2Turb L1 sub-data product if (dp01 == "co2Turb"){ if (TypeMeas == "samp"){ - rpt$densMoleCo2 <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, - setQf$tempAve, setQf$presDiffIrgaTurb, + rpt$densMoleCo2 <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, setQf$densMoleCo2, + "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempAve, setQf$presDiffIrgaTurb, setQf$powrCo2Samp, setQf$powrCo2Refe, - setQf$asrpCo2, setQf$densMoleCo2, + setQf$asrpCo2, setQf$rtioMoleDryCo2, setQf$ssiCo2, - "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, setQf$presAtmMfcSampTurb, - setQf$tempMfcSampTurb) + setQf$presAtmMfcSampTurb, + setQf$tempMfcSampTurb))) - rpt$rtioMoleDryCo2 <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, - setQf$tempAve, setQf$presDiffIrgaTurb, + rpt$rtioMoleDryCo2 <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, setQf$rtioMoleDryCo2, + "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempAve, setQf$presDiffIrgaTurb, setQf$powrH2oSamp, setQf$powrH2oRefe, setQf$asrpH2o, setQf$rtioMoleDryH2o, setQf$powrCo2Samp, setQf$powrCo2Refe, - setQf$asrpCo2, setQf$rtioMoleDryCo2, + setQf$asrpCo2, setQf$ssiCo2, setQf$ssiH2o, - "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, setQf$presAtmMfcSampTurb, - setQf$tempMfcSampTurb) + setQf$presAtmMfcSampTurb, + setQf$tempMfcSampTurb))) rpt$presAtm <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, setQf$presAtmIrgaTurb) rpt$presSum <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, setQf$presSum) rpt$tempAve <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, - setQf$tempIn, setQf$tempOut, - setQf$tempAve) + setQf$tempAve, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempIn, setQf$tempOut))) }#close if statement of TypeMeas == "samp" if (TypeMeas == "vali"){ - rpt$densMoleCo2 <- data.frame(setQf$sensIrgaTurb, setQf$tempAve, + rpt$densMoleCo2 <- data.frame(setQf$sensIrgaTurb, setQf$densMoleCo2, + "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, + "qfRngFrt00" = setQf$frt00MfcValiTurb$qfRngFrt00, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempAve, setQf$presDiffIrgaTurb, setQf$powrCo2Samp, setQf$powrCo2Refe, setQf$asrpCo2 , - setQf$densMoleCo2, setQf$rtioMoleDryCo2, - setQf$ssiCo2, "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, + setQf$rtioMoleDryCo2, + setQf$ssiCo2, setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb, - "qfRngFrt00" = setQf$frt00MfcValiTurb$qfRngFrt00, setQf$presAtmMfcValiTurb, - setQf$tempMfcValiTurb) + setQf$presAtmMfcValiTurb, + setQf$tempMfcValiTurb))) - rpt$rtioMoleDryCo2 <- data.frame(setQf$sensIrgaTurb, setQf$tempAve, + rpt$rtioMoleDryCo2 <- data.frame(setQf$sensIrgaTurb, setQf$rtioMoleDryCo2, + "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, + "qfRngFrt00" = setQf$frt00MfcValiTurb$qfRngFrt00, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempAve, setQf$presDiffIrgaTurb, setQf$powrH2oSamp, setQf$powrH2oRefe, setQf$asrpH2o, setQf$rtioMoleDryH2o, setQf$powrCo2Samp, setQf$powrCo2Refe, setQf$asrpCo2, - setQf$rtioMoleDryCo2, setQf$ssiCo2, - setQf$ssiH2o, "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, + setQf$ssiCo2, + setQf$ssiH2o, setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb, - "qfRngFrt00" = setQf$frt00MfcValiTurb$qfRngFrt00, setQf$presAtmMfcValiTurb, - setQf$tempMfcValiTurb) + setQf$presAtmMfcValiTurb, + setQf$tempMfcValiTurb))) rpt$presAtm <- data.frame(setQf$sensIrgaTurb, setQf$presAtmIrgaTurb) rpt$presSum <- data.frame(setQf$sensIrgaTurb, setQf$presSum) - rpt$tempAve <- data.frame(setQf$sensIrgaTurb, setQf$tempIn, - setQf$tempOut, setQf$tempAve) + rpt$tempAve <- data.frame(setQf$sensIrgaTurb, setQf$tempAve, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempIn, + setQf$tempOut))) }#close if statement of TypeMeas == "vali" - rpt$frt00Samp <- data.frame(setQf$frt00MfcSampTurb, setQf$frtMfcSampTurb, - setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb) + rpt$frt00Samp <- data.frame(setQf$frt00MfcSampTurb, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$frtMfcSampTurb, + setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb))) } #grouping qulity flags that related to h2oTurb L1 sub-data product if (dp01 == "h2oTurb") { if (TypeMeas == "samp"){ - rpt$densMoleH2o <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, - setQf$tempAve, setQf$presDiffIrgaTurb, + rpt$densMoleH2o <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, setQf$densMoleH2o, + "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempAve, setQf$presDiffIrgaTurb, setQf$powrH2oSamp, setQf$powrH2oRefe, - setQf$asrpH2o, setQf$densMoleH2o, - setQf$ssiH2o, "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, - setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb) + setQf$asrpH2o, + setQf$ssiH2o, + setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb))) - rpt$rtioMoleDryH2o <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, - setQf$tempAve, setQf$presDiffIrgaTurb, + rpt$rtioMoleDryH2o <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, setQf$rtioMoleDryH2o, + "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempAve, setQf$presDiffIrgaTurb, setQf$powrH2oSamp, setQf$powrH2oRefe, - setQf$asrpH2o, setQf$rtioMoleDryH2o, - setQf$ssiH2o, "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, - setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb) + setQf$asrpH2o, setQf$ssiH2o, + setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb))) rpt$presAtm <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, setQf$presAtmIrgaTurb) rpt$presSum <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, setQf$presSum) rpt$tempAve <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, - setQf$tempIn, setQf$tempOut, - setQf$tempAve) + setQf$tempAve, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempIn, setQf$tempOut))) rpt$tempDew <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, - setQf$tempAve, setQf$presDiffIrgaTurb, + setQf$tempAve, setQf$rtioMoleDryH2o, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$presDiffIrgaTurb, setQf$presSum, setQf$powrH2oSamp, setQf$powrH2oRefe, setQf$asrpH2o, - setQf$rtioMoleDryH2o, setQf$ssiH2o)#,setQf$soni) Remove until we can deal with differance length + setQf$ssiH2o)))#,setQf$soni) Remove until we can deal with differance length }#close if statement of TypeMeas == "samp" if (TypeMeas == "vali"){ - rpt$densMoleH2o <- data.frame(setQf$sensIrgaTurb, setQf$tempAve, + rpt$densMoleH2o <- data.frame(setQf$sensIrgaTurb, setQf$densMoleH2o, + "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, + "qfRngFrt00" = setQf$frt00MfcValiTurb$qfRngFrt00, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempAve, setQf$presDiffIrgaTurb, setQf$powrH2oSamp, setQf$powrH2oRefe, setQf$asrpH2o, - setQf$densMoleH2o, setQf$ssiH2o, - "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, setQf$presAtmMfcSampTurb, - setQf$tempMfcSampTurb, "qfRngFrt00" = setQf$frt00MfcValiTurb$qfRngFrt00, - setQf$presAtmMfcValiTurb, setQf$tempMfcValiTurb) + setQf$ssiH2o, + setQf$presAtmMfcSampTurb, + setQf$tempMfcSampTurb, + setQf$presAtmMfcValiTurb, setQf$tempMfcValiTurb))) - rpt$rtioMoleDryH2o <- data.frame(setQf$sensIrgaTurb, setQf$tempAve, + rpt$rtioMoleDryH2o <- data.frame(setQf$sensIrgaTurb, setQf$rtioMoleDryH2o, + "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, + "qfRngFrt00" = setQf$frt00MfcValiTurb$qfRngFrt00, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempAve, setQf$presDiffIrgaTurb, setQf$powrH2oSamp, setQf$powrH2oRefe, setQf$asrpH2o, - setQf$rtioMoleDryH2o, setQf$ssiH2o, - "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, setQf$presAtmMfcSampTurb, - setQf$tempMfcSampTurb, "qfRngFrt00" = setQf$frt00MfcValiTurb$qfRngFrt00, - setQf$presAtmMfcValiTurb, setQf$tempMfcValiTurb) + setQf$ssiH2o, + setQf$presAtmMfcSampTurb, + setQf$tempMfcSampTurb, + setQf$presAtmMfcValiTurb, setQf$tempMfcValiTurb))) rpt$presAtm <- data.frame(setQf$sensIrgaTurb, setQf$presAtmIrgaTurb) rpt$presSum <- data.frame(setQf$sensIrgaTurb, setQf$presSum) - rpt$tempAve <- data.frame(setQf$sensIrgaTurb, setQf$tempIn, - setQf$tempOut, setQf$tempAve) + rpt$tempAve <- data.frame(setQf$sensIrgaTurb, setQf$tempAve, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempIn, setQf$tempOut))) - rpt$tempDew <- data.frame(setQf$sensIrgaTurb, setQf$tempAve, - setQf$presDiffIrgaTurb, setQf$presSum, + rpt$tempDew <- data.frame(setQf$sensIrgaTurb, setQf$tempAve, setQf$rtioMoleDryH2o, + eddy4R.qaqc::def.qi.qf(qf = list(setQf$presDiffIrgaTurb, setQf$presSum, setQf$powrH2oSamp,setQf$powrH2oRefe, - setQf$asrpH2o, setQf$rtioMoleDryH2o, - setQf$ssiH2o) #, setQf$soni) Remove until we can deal with the difference length + setQf$asrpH2o, + setQf$ssiH2o))) #, setQf$soni) Remove until we can deal with the difference length }#close if statement of TypeMeas == "vali" - rpt$frt00Samp <- data.frame(setQf$frt00MfcSampTurb, setQf$frtMfcSampTurb, - setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb) + rpt$frt00Samp <- data.frame(setQf$frt00MfcSampTurb, eddy4R.qaqc::def.qi.qf(qf = list(setQf$frtMfcSampTurb, + setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb))) } #remove setQf @@ -779,7 +799,7 @@ if (MethMeas == "ecte") { # setQf$veloSoni, setQf$amrs) rpt$tempAir <- data.frame(setQf$sensSoni, setQf$veloSoni, - setQf$tempSoni) #setQf$irgaTurb) # Removing until we can handle flags of different lengths + setQf$tempSoni, eddy4R.qaqc::def.qi.qf(qf = setQf$irgaTurb)) # Removing until we can handle flags of different lengths rpt$tempSoni <- data.frame(setQf$sensSoni, setQf$veloSoni, setQf$tempSoni) @@ -901,9 +921,9 @@ if (MethMeas == "ecte") { "qfNullAngZaxs" = qfInp$amrs$qfNullAngZaxs) #grouping qulity flags that related to L1 sub-data product - rpt$angNedXaxs <- data.frame(setQf$sensAmrs, setQf$angXaxs) - rpt$angNedYaxs <- data.frame(setQf$sensAmrs, setQf$angYaxs) - rpt$angNedZaxs <- data.frame(setQf$sensAmrs, setQf$angZaxs) + rpt$angNedXaxs <- data.frame(setQf$sensAmrs, setQf$angXaxs, eddy4R.qaqc::def.qi.qf(qf = list(setQf$accXaxsDiff, setQf$avelXaxs))) + rpt$angNedYaxs <- data.frame(setQf$sensAmrs, setQf$angYaxs, eddy4R.qaqc::def.qi.qf(qf = list(setQf$accYaxsDiff, setQf$avelYaxs))) + rpt$angNedZaxs <- data.frame(setQf$sensAmrs, setQf$angZaxs, eddy4R.qaqc::def.qi.qf(qf = list(setQf$accZaxsDiff, setQf$avelZaxs))) }#close if statement of TypeMeas %in% c("samp", "vali") } #close if statement of dp01 == "amrs" } #close if statement of MethMeas == "ecse" From 8749d75328964fd4106e7c45d58ba37b55a02c4f Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 24 Aug 2021 16:08:59 +0000 Subject: [PATCH 131/168] - function for changing qf to qi for ancillary data streams --- pack/eddy4R.qaqc/R/def.qi.qf.R | 58 +++++++++++++++++++++++++++++++ pack/eddy4R.qaqc/man/def.qi.qf.Rd | 47 +++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 pack/eddy4R.qaqc/R/def.qi.qf.R create mode 100644 pack/eddy4R.qaqc/man/def.qi.qf.Rd diff --git a/pack/eddy4R.qaqc/R/def.qi.qf.R b/pack/eddy4R.qaqc/R/def.qi.qf.R new file mode 100644 index 00000000..f78e41ca --- /dev/null +++ b/pack/eddy4R.qaqc/R/def.qi.qf.R @@ -0,0 +1,58 @@ +############################################################################################## +#' @title Definition function: Quality Indicators + +#' @author +#' David Durden \email{eddy4R.info@gmail.com} + +#' @description +#' Function definition. Convert quality flags (qf) to quality indicators (qi) by changing names. Performed for the entire set of input data. + +#' @param qf A data frame or list of data.frames containing quality flags, class integer. Each column contains the quality flag values [-1,0,1] for that flag. Note: This is the Vrbs output from def.plau, def.dspk.wndw, and def.dspk.br86. See def.conv.qf.vrbs for converting from non-verbose to verbose output. + +#' @return A dataframe containing quality indicators of failed (1), pass (0), and NA (-1) for each of the individual flag defined by input \code{qf}. + +#' @references +#' License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007. \cr +#' NEON Algorithm Theoretical Basis Document: Quality Flags and Quality Metrics for TIS Data Products (NEON.DOC.001113) \cr +#' Smith, D.E., Metzger, S., and Taylor, J.R.: A transparent and transferable framework for tracking quality information in large datasets. PLoS ONE, 9(11), e112249.doi:10.1371/journal.pone.0112249, 2014. \cr + +#' @keywords NEON QAQC, quality flags, quality metrics + +#' @examples +#' qfA <- c(0,0,0,0,0,1,1,1,1,1,0,0,0,0,1) +#' qfB <- c(0,0,-1,-1,-1,1,1,0,0,0,0,0,0,0,0) +#' qfC <- c(0,1,1,0,0,0,0,0,0,0,0,0,-1,-1,-1) +#' qfD <- data.frame(qfE = c(0,1,1,0,0,0,0,0,0,0,0,0,-1,-1,-1), qfF = c(0,1,1,0,0,0,0,-1,0,0,0,0,-1,-1,-1)) +#' test<-list() +#' test$dfQf <- data.frame(qfA,qfB,qfC) +#' test$listQf <- list(test$dfQf,qfD) +#' test$qi<- def.qi.qf(qf=test$listQf) + +#' @seealso +#' \code{\link[eddy4R.qaqc]{wrap.qfqm.dp01}} +#' \code{\link[eddy4R.qaqc]{def.dp01.grp.qf}} +#' \code{\link[eddy4R.qaqc]{wrap.dp01.qfqm.eddy}} +#' \code{\link[eddy4R.qaqc]{def.qf.finl.R}} +#' \code{\link[eddy4R.qaqc]{def.qm.R}} + +#' @export + +# changelog and author contributions / copyrights +# David Durden (2021-08-24) +# original creation + +############################################################################################## +def.qi.qf <- function ( + qf # A data.frame or list of data.frames containing quality flags, class integer. Each column contains the quality flag values [-1,0,1] for that flag. + +) { + + #Check if input is a list of data.frames, if TRUE convert to single data frame + if(base::is.list(qf)){qf <- base::cbind.data.frame(qf)} + + #convert quality flags to quality indicators + names(qf) <- base::gsub(pattern = "^qf", replacement = "qi", x = names(qf)) + + #Return output data.frame with updated names + return(qf) +}#End def.qi.qf \ No newline at end of file diff --git a/pack/eddy4R.qaqc/man/def.qi.qf.Rd b/pack/eddy4R.qaqc/man/def.qi.qf.Rd new file mode 100644 index 00000000..c47950a0 --- /dev/null +++ b/pack/eddy4R.qaqc/man/def.qi.qf.Rd @@ -0,0 +1,47 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/def.qi.qf.R +\name{def.qi.qf} +\alias{def.qi.qf} +\title{Definition function: Quality Indicators} +\usage{ +def.qi.qf(qf) +} +\arguments{ +\item{qf}{A data frame or list of data.frames containing quality flags, class integer. Each column contains the quality flag values [-1,0,1] for that flag. Note: This is the Vrbs output from def.plau, def.dspk.wndw, and def.dspk.br86. See def.conv.qf.vrbs for converting from non-verbose to verbose output.} +} +\value{ +A dataframe containing quality indicators of failed (1), pass (0), and NA (-1) for each of the individual flag defined by input \code{qf}. +} +\description{ +Function definition. Convert quality flags (qf) to quality indicators (qi) by changing names. Performed for the entire set of input data. +} +\examples{ +qfA <- c(0,0,0,0,0,1,1,1,1,1,0,0,0,0,1) +qfB <- c(0,0,-1,-1,-1,1,1,0,0,0,0,0,0,0,0) +qfC <- c(0,1,1,0,0,0,0,0,0,0,0,0,-1,-1,-1) +qfD <- data.frame(qfE = c(0,1,1,0,0,0,0,0,0,0,0,0,-1,-1,-1), qfF = c(0,1,1,0,0,0,0,-1,0,0,0,0,-1,-1,-1)) +test<-list() +test$dfQf <- data.frame(qfA,qfB,qfC) +test$listQf <- list(test$dfQf,qfD) +test$qi<- def.qi.qf(qf=test$listQf) +} +\references{ +License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007. \cr +NEON Algorithm Theoretical Basis Document: Quality Flags and Quality Metrics for TIS Data Products (NEON.DOC.001113) \cr +Smith, D.E., Metzger, S., and Taylor, J.R.: A transparent and transferable framework for tracking quality information in large datasets. PLoS ONE, 9(11), e112249.doi:10.1371/journal.pone.0112249, 2014. \cr +} +\seealso{ +\code{\link[eddy4R.qaqc]{wrap.qfqm.dp01}} +\code{\link[eddy4R.qaqc]{def.dp01.grp.qf}} +\code{\link[eddy4R.qaqc]{wrap.dp01.qfqm.eddy}} +\code{\link[eddy4R.qaqc]{def.qf.finl.R}} +\code{\link[eddy4R.qaqc]{def.qm.R}} +} +\author{ +David Durden \email{eddy4R.info@gmail.com} +} +\keyword{NEON} +\keyword{QAQC,} +\keyword{flags,} +\keyword{metrics} +\keyword{quality} From 059c039eb7731482d9a9dd90e5740d8b67dc85b5 Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 24 Aug 2021 16:10:21 +0000 Subject: [PATCH 132/168] - fixing naming convention for qf flag generating function --- pack/eddy4R.qaqc/R/def.qf.ecte.R | 12 +++++++----- pack/eddy4R.qaqc/man/def.qf.ecte.Rd | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.qf.ecte.R b/pack/eddy4R.qaqc/R/def.qf.ecte.R index eedd3951..dfbed865 100644 --- a/pack/eddy4R.qaqc/R/def.qf.ecte.R +++ b/pack/eddy4R.qaqc/R/def.qf.ecte.R @@ -38,13 +38,15 @@ # edited term name # Natchaya P-Durden (2018-04-03) # update @param format +# Dave Durden (2021-08-23) +# update to new ECTE dp01 names ############################################################################################## def.qf.ecte <- function( TimeBgn, TimeEnd, Freq = 20, - Sens = c("soni","irga","irgaMfcSamp","soniAmrs")[1], + Sens = c("soni","irgaTurb","mfcSampTurb","amrs")[1], PcntQf = 0.05 ) { @@ -79,21 +81,21 @@ def.qf.ecte <- function( varName <- c("veloSoni", "veloXaxs","veloYaxs","veloZaxs","tempSoni") qfNameSens <- c("qfSoniUnrs", "qfSoniData", "qfSoniTrig", "qfSoniComm", "qfSoniCode", "qfSoniTemp", "qfSoniSgnlPoor", "qfSoniSgnlHigh","qfSoniSgnlLow" )} - if(Sens == "irga"){ + if(Sens == "irgaTurb"){ varName <- c("asrpCo2", "asrpH2o", "densMoleCo2", "densMoleH2o", "tempRefe", "presAtm","presDiff", "potCool", "rtioMoleDryCo2", "rtioMoleDryH2o", "tempIn","tempOut", "powrH2oSamp", "powrH2oRefe", "powrCo2Samp", "powrCo2Refe","ssiCo2", "ssiH2o","tempMean", "presSum") qfNameSens <- c("qfIrgaHead", "qfIrgaTempOut", "qfIrgaTempIn", "qfIrgaAux", "qfIrgaPres", "qfIrgaChop", "qfIrgaDetc", "qfIrgaPll","qfIrgaSync", "qfIrgaAgc" )} - if(Sens == "irgaMfcSamp"){ + if(Sens == "mfcSampTurb"){ varName <- c("presAtm", "temp", "frt", "frt00", "frtSet00") qfNameSens <- NULL} - if(Sens == "soniAmrs"){ + if(Sens == "amrs"){ varName <- c("angXaxs", "angYaxs", "angZaxs", "accXaxs", "accYaxs", "accZaxs", "accXaxsDiff", "accYaxsDiff", "accZaxsDiff", "avelXaxs", "avelYaxs", "avelZaxs") qfNameSens <- c("qfAmrsVal", "qfAmrsFilt", "qfAmrsVelo", "qfAmrsRng")} ################################################################################################################################ # Name of prefixes for qaqc plausibility tests - qfNamePlau <- c("qfRng","qfStep", "qfPers", "qfCal" ) + qfNamePlau <- c("qfRng","qfStep", "qfPers", "qfNull", "qfSpk" ) #varNameUp <- paste(toupper(substr(varName, 1, 1)), substr(varName, 2, nchar(varName)), sep="") diff --git a/pack/eddy4R.qaqc/man/def.qf.ecte.Rd b/pack/eddy4R.qaqc/man/def.qf.ecte.Rd index fa6f014e..314200d4 100644 --- a/pack/eddy4R.qaqc/man/def.qf.ecte.Rd +++ b/pack/eddy4R.qaqc/man/def.qf.ecte.Rd @@ -8,7 +8,7 @@ def.qf.ecte( TimeBgn, TimeEnd, Freq = 20, - Sens = c("soni", "irga", "irgaMfcSamp", "soniAmrs")[1], + Sens = c("soni", "irgaTurb", "mfcSampTurb", "amrs")[1], PcntQf = 0.05 ) } From f47591eeb395d90006cb276bac9e36f0afb76d3b Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 24 Aug 2021 16:10:49 +0000 Subject: [PATCH 133/168] - repackaging to export function --- pack/eddy4R.qaqc/NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/pack/eddy4R.qaqc/NAMESPACE b/pack/eddy4R.qaqc/NAMESPACE index 7e607b90..ec17e388 100644 --- a/pack/eddy4R.qaqc/NAMESPACE +++ b/pack/eddy4R.qaqc/NAMESPACE @@ -16,6 +16,7 @@ export(def.qf.irga.agc) export(def.qf.irga.vali) export(def.qf.rmv.data) export(def.qf.soni) +export(def.qi.qf) export(def.qm) export(wrap.dp01.qfqm) export(wrap.dp01.qfqm.ecse) From 41dae0311e20875e659e808440a6f364552e45c5 Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 24 Aug 2021 21:15:23 +0000 Subject: [PATCH 134/168] Adding timeDiffUtcLt metadata --- pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R index 3d34586c..98ae0e11 100755 --- a/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R +++ b/pack/eddy4R.base/R/wrap.hdf5.wrte.dp01.R @@ -73,6 +73,8 @@ # adding Pfit coefficient output metadata # David Durden (2021-08-17) # Fixing attribute issues related to rhdf5 not being able to write lists +# David Durden (2021-08-17) +# Adding difference to UTC to output ############################################################################################## @@ -322,11 +324,12 @@ idFile <- rhdf5::H5Fopen(FileOut) #Open connection to dp04 data level idSite <- rhdf5::H5Gopen(idFile, paste0("/", SiteLoca)) -#Write updated Pfit coefficients to output file +#Write updated Pfit coefficients and UTC time diff to output file #Output the attributes rhdf5::h5writeAttribute(round(Meta$Sci$`Pf$AngEnuXaxs`, digits = 6), h5obj = idSite, name = "Pf$AngEnuXaxs") rhdf5::h5writeAttribute(round(Meta$Sci$`Pf$AngEnuYaxs`, digits = 6), h5obj = idSite, name = "Pf$AngEnuYaxs") rhdf5::h5writeAttribute(round(Meta$Sci$`Pf$Ofst`, digits = 6), h5obj = idSite, name = "Pf$Ofst") +rhdf5::h5writeAttribute(Meta$Site$TimeDiffUtcLt, h5obj = idSite, name = "TimeDiffUtcLt") #Close HDF5 connections rhdf5::h5closeAll() From f9f9342e2457874b6028eae8b9738e94506f8f73 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Fri, 27 Aug 2021 15:59:43 +0000 Subject: [PATCH 135/168] adding failsafe for extra validation gas rows --- pack/eddy4R.base/R/wrap.irga.vali.R | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index d2959de8..f67bed63 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -85,6 +85,8 @@ # add thresholding based on benchmarking regression # Chris Florian (2021-08-09) # adding -1 flag for missing validations +# Chris Florian (2021-08-26) +# adding failsafe for extra validation gas rows ############################################################################################## wrap.irga.vali <- function( @@ -535,13 +537,19 @@ wrap.irga.vali <- function( #add corrected reference gas values to vali table - rpt[[DateProc]]$rtioMoleDryCo2Vali$meanCor <- c(NaN, valiEval$meanCor) - #reorder to place the corrected reference values next to the original reference values - rpt[[DateProc]]$rtioMoleDryCo2Vali <- rpt[[DateProc]]$rtioMoleDryCo2Vali[c("mean", "min", "max", "vari", "numSamp", "rtioMoleDryCo2Refe", "meanCor", "timeBgn", "timeEnd")] - - #rename rtioMoleDryCo2Refe to refe, this could be implemented in the rest of the functions in the future - names(rpt[[DateProc]]$rtioMoleDryCo2Vali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "meanCor", "timeBgn", "timeEnd") + if(base::nrow(rpt[[DateProc]]$rtioMoleDryCo2Vali) == base::length(valiEval$meanCor+1)){ # failsafe for row mismatches + + rpt[[DateProc]]$rtioMoleDryCo2Vali$meanCor <- c(NaN, valiEval$meanCor) + + #reorder to place the corrected reference values next to the original reference values + rpt[[DateProc]]$rtioMoleDryCo2Vali <- rpt[[DateProc]]$rtioMoleDryCo2Vali[c("mean", "min", "max", "vari", "numSamp", "rtioMoleDryCo2Refe", "meanCor", "timeBgn", "timeEnd")] + + #rename rtioMoleDryCo2Refe to refe, this could be implemented in the rest of the functions in the future + names(rpt[[DateProc]]$rtioMoleDryCo2Vali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "meanCor", "timeBgn", "timeEnd") + } else { + names(rpt[[DateProc]]$rtioMoleDryCo2Vali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "timeBgn", "timeEnd") + } #rename rtioMoleDryH2oRefe to refe to match CO2 names(rpt[[DateProc]]$rtioMoleDryH2oVali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "timeBgn", "timeEnd") From 820461ea5705b2ab2fe2e77597ee558efb5c40d1 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Fri, 27 Aug 2021 18:52:42 +0000 Subject: [PATCH 136/168] retaining the rest of the rtioMoleDryCo2Cor for failed validations, adding NaNs for meanCor with failed validations to keep structure the same --- pack/eddy4R.base/R/wrap.irga.vali.R | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index f67bed63..0d0746af 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -87,6 +87,9 @@ # adding -1 flag for missing validations # Chris Florian (2021-08-26) # adding failsafe for extra validation gas rows +# Chris Florian (2021-08-27) +# retaining the rest of the rtioMoleDryCo2Cor for failed validations +# adding NaNs for meanCor with failed validations to keep structure the same ############################################################################################## wrap.irga.vali <- function( @@ -520,7 +523,7 @@ wrap.irga.vali <- function( #remove corrected data if validation fails benchmarking test if (valiEval$valiEvalPass == FALSE){ - rpt[[DateProc]]$rtioMoleDryCo2Cor <- NaN + rpt[[DateProc]]$rtioMoleDryCo2Cor$rtioMoleDryCo2Cor <- NaN #raise quality flag in validation table to indicate validation status rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, 1) } else if (valiEval$valiEvalPass == TRUE) { @@ -538,9 +541,9 @@ wrap.irga.vali <- function( #add corrected reference gas values to vali table - if(base::nrow(rpt[[DateProc]]$rtioMoleDryCo2Vali) == base::length(valiEval$meanCor+1)){ # failsafe for row mismatches + if(base::nrow(rpt[[DateProc]]$rtioMoleDryCo2Vali) == base::length(valiEval$meanCor+1)){ # failsafe for row mismatches, valiEval$meanCor will always be one short because the archive gas is not included - rpt[[DateProc]]$rtioMoleDryCo2Vali$meanCor <- c(NaN, valiEval$meanCor) + rpt[[DateProc]]$rtioMoleDryCo2Vali$meanCor <- c(NaN, valiEval$meanCor) # need to add the NaN to account for the archive gas in the first position of the vali table #reorder to place the corrected reference values next to the original reference values rpt[[DateProc]]$rtioMoleDryCo2Vali <- rpt[[DateProc]]$rtioMoleDryCo2Vali[c("mean", "min", "max", "vari", "numSamp", "rtioMoleDryCo2Refe", "meanCor", "timeBgn", "timeEnd")] @@ -548,7 +551,13 @@ wrap.irga.vali <- function( #rename rtioMoleDryCo2Refe to refe, this could be implemented in the rest of the functions in the future names(rpt[[DateProc]]$rtioMoleDryCo2Vali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "meanCor", "timeBgn", "timeEnd") } else { - names(rpt[[DateProc]]$rtioMoleDryCo2Vali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "timeBgn", "timeEnd") + #fill meanCor with NaN if there were extra validation gas rows + rpt[[DateProc]]$rtioMoleDryCo2Vali$meanCor <- NaN + + #reorder to place the corrected reference values next to the original reference values + rpt[[DateProc]]$rtioMoleDryCo2Vali <- rpt[[DateProc]]$rtioMoleDryCo2Vali[c("mean", "min", "max", "vari", "numSamp", "rtioMoleDryCo2Refe", "meanCor", "timeBgn", "timeEnd")] + + names(rpt[[DateProc]]$rtioMoleDryCo2Vali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "meanCor", "timeBgn", "timeEnd") } #rename rtioMoleDryH2oRefe to refe to match CO2 From 08e888b5f5559f323a162b1e278807514aed9f55 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Fri, 27 Aug 2021 23:21:19 +0000 Subject: [PATCH 137/168] correcting typo to move +1 out of the parentheses --- pack/eddy4R.base/R/wrap.irga.vali.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index 0d0746af..f2f0b3fd 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -541,7 +541,7 @@ wrap.irga.vali <- function( #add corrected reference gas values to vali table - if(base::nrow(rpt[[DateProc]]$rtioMoleDryCo2Vali) == base::length(valiEval$meanCor+1)){ # failsafe for row mismatches, valiEval$meanCor will always be one short because the archive gas is not included + if(base::nrow(rpt[[DateProc]]$rtioMoleDryCo2Vali) == base::length(valiEval$meanCor)+1){ # failsafe for row mismatches, valiEval$meanCor will always be one short because the archive gas is not included rpt[[DateProc]]$rtioMoleDryCo2Vali$meanCor <- c(NaN, valiEval$meanCor) # need to add the NaN to account for the archive gas in the first position of the vali table From be5c71a2d222ac96435e9cf01d40b220f55836f7 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Sat, 28 Aug 2021 21:52:45 +0000 Subject: [PATCH 138/168] resetting attributes on rtioMoleDryCo2Cor to fix unit conv issues when corrected data was removed --- pack/eddy4R.base/R/wrap.irga.vali.R | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index f2f0b3fd..0ac6003e 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -90,6 +90,8 @@ # Chris Florian (2021-08-27) # retaining the rest of the rtioMoleDryCo2Cor for failed validations # adding NaNs for meanCor with failed validations to keep structure the same +# Chris Florian (2021-08-27) +# resetting attributes on rtioMoleDryCo2Cor to fix issues when the corrected data was removed ############################################################################################## wrap.irga.vali <- function( @@ -574,7 +576,15 @@ wrap.irga.vali <- function( "molCo2 mol-1Dry",#gasRefeCor "NA", #"timeBgn" "NA")#"timeEnd" - + + attributes(rpt[[DateProc]]$rtioMoleDryCo2Cor)$unit <- c("molCo2 mol-1Dry", #"mean" + "molCo2 mol-1Dry", #"min" + "molCo2 mol-1Dry", #"max" + "molCo2 mol-1Dry",#"vari" + "NA", #"numSamp" + "NA", #"timeBgn" + "NA")#"timeEnd" + #return results return(rpt) } From 608083f377006b4b7f785c0d220cfe52a5749bbd Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Sun, 29 Aug 2021 19:08:42 +0000 Subject: [PATCH 139/168] fixing unit attributes --- pack/eddy4R.base/R/wrap.irga.vali.R | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index 0ac6003e..f1308db3 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -577,13 +577,7 @@ wrap.irga.vali <- function( "NA", #"timeBgn" "NA")#"timeEnd" - attributes(rpt[[DateProc]]$rtioMoleDryCo2Cor)$unit <- c("molCo2 mol-1Dry", #"mean" - "molCo2 mol-1Dry", #"min" - "molCo2 mol-1Dry", #"max" - "molCo2 mol-1Dry",#"vari" - "NA", #"numSamp" - "NA", #"timeBgn" - "NA")#"timeEnd" + attributes(rpt[[DateProc]]$rtioMoleDryCo2Cor$rtioMoleDryCo2Cor)$unit <- "molCo2 mol-1Dry" #return results return(rpt) From 20cf00dde039b01ca17f83cd136d515042466a71 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Tue, 21 Sep 2021 16:46:09 +0000 Subject: [PATCH 140/168] finalizing method switch to run ch4 or not depending on input file structure --- pack/eddy4R.base/R/def.hdf5.pack.R | 10 +++++----- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 10 ++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.pack.R b/pack/eddy4R.base/R/def.hdf5.pack.R index 3ba77ae5..9b5e40af 100644 --- a/pack/eddy4R.base/R/def.hdf5.pack.R +++ b/pack/eddy4R.base/R/def.hdf5.pack.R @@ -122,14 +122,14 @@ if(MethMeas %in% "ecse"){ #idxLvLReso <- names(inpList[[idxDp]])[1] #Check if qm is part of the input list if(exists('qm', where = inpList[[idxDp]][[idxLvLReso]][[1]]) == TRUE){ - + # Add the qm's to tmp list - tmp00[[idxDp]][[idxLvLReso]]$qm <- lapply(names(inpList[[idxDp]][[idxLvLReso]][[1]]$qm), function(idxStat) { + tmp00[[idxDp]][[idxLvLReso]]$qm <- lapply(names(inpList[[idxDp]][[idxLvLReso]][[1]]$qm), function(idxStat) # second call to lapply, targeting the observations to be combined into the result data.frames do.call(rbind, lapply(1:length(inpList[[idxDp]][[idxLvLReso]]), function(idxt) { inpList[[idxDp]][[idxLvLReso]][[idxt]]$qm[[idxStat]] - } ) - )}) + } ) + )) # assign names to data.frames names(tmp00[[idxDp]][[idxLvLReso]]$qm) <- names(inpList[[idxDp]][[idxLvLReso]][[1]]$qm) } @@ -137,7 +137,7 @@ if(MethMeas %in% "ecse"){ #Remove qm from the inpList for(idx in 1:length(inpList[[idxDp]][[idxLvLReso]])) {inpList[[idxDp]][[idxLvLReso]][[idx]]$qm <- NULL} - tmp01[[idxDp]][[idxLvLReso]] <- lapply(names(inpList[[idxDp]][[idxLvLReso]][[1]]), function(idxStat) { + tmp01[[idxDp]][[idxLvLReso]] <- lapply(names(inpList[[idxDp]][[idxLvLReso]][[1]]), function(idxStat) # second call to lapply, targeting the observations to be combined into the result data.frames base::as.data.frame(dplyr::bind_rows(lapply(1:length(inpList[[idxDp]][[idxLvLReso]]), function(idxt) inpList[[idxDp]][[idxLvLReso]][[idxt]][[idxStat]] ))) ) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 456ec5ff..9639bf79 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -94,6 +94,8 @@ # adding ch4Conc to the dp01 list and adding all ch4 qfqm variables # David Durden (2021-08-24) # Changing ancillary data stream ECTE quality flags to quality indicators +# Chris Florian (2021-09-21) +# Adding logic to set CH4 qfs or not depending on if ch4Conc is in the dp01 list ############################################################################################## def.dp01.grp.qf <- function( @@ -1393,7 +1395,7 @@ if (MethMeas == "ecse") { #"qfCalRtioMoleDry13CCo2" = qfInp$crdCo2$qfCalRtioMoleDry13CCo2) - if ("ch4Conc" %in% names(qfInp)){ + if (dp01 == "ch4Conc"){ setQf$rtioMoleDryCh4 <- data.frame("qfRngRtioMoleDryCh4" = qfInp$crdCo2$qfRngRtioMoleDryCh4, "qfStepRtioMoleDryCh4" = qfInp$crdCo2$qfStepRtioMoleDryCh4, "qfPersRtioMoleDryCh4" = qfInp$crdCo2$qfPersRtioMoleDryCh4) @@ -1422,7 +1424,7 @@ if (MethMeas == "ecse") { "qfPersRtioMoleWet13CCo2" = qfInp$crdCo2$qfPersRtioMoleWet13CCo2) #"qfCalRtioMoleWet13CCo2 " = qfInp$crdCo2$qfCalRtioMoleWet13CCo2) - if ("ch4Conc" %in% names(qfInp)){ + if (dp01 == "ch4Conc"){ setQf$rtioMoleWetCh4 <- data.frame("qfRngRtioMoleWetCh4" = qfInp$crdCo2$qfRngRtioMoleWetCh4, "qfStepRtioMoleWetCh4" = qfInp$crdCo2$qfStepRtioMoleWetCh4, "qfPersRtioMoleWetCh4" = qfInp$crdCo2$qfPersRtioMoleWetCh4) @@ -1459,12 +1461,12 @@ if (MethMeas == "ecse") { names(setQf$rtioMoleDryCo2) <- paste0(colnames(setQf$rtioMoleDryCo2), "CrdCo2") names(setQf$rtioMoleDry12CCo2) <- paste0(colnames(setQf$rtioMoleDry12CCo2), "CrdCo2") names(setQf$rtioMoleDry13CCo2) <- paste0(colnames(setQf$rtioMoleDry13CCo2), "CrdCo2") - if ("ch4Conc" %in% names(qfInp)){names(setQf$rtioMoleDryCh4) <- paste0(colnames(setQf$rtioMoleDryCh4), "CrdCo2")} + if (dp01 == "ch4Conc"){names(setQf$rtioMoleDryCh4) <- paste0(colnames(setQf$rtioMoleDryCh4), "CrdCo2")} names(setQf$rtioMoleDryH2o) <- paste0(colnames(setQf$rtioMoleDryH2o), "CrdCo2") names(setQf$rtioMoleWetCo2) <- paste0(colnames(setQf$rtioMoleWetCo2), "CrdCo2") names(setQf$rtioMoleWet12CCo2) <- paste0(colnames(setQf$rtioMoleWet12CCo2), "CrdCo2") names(setQf$rtioMoleWet13CCo2) <- paste0(colnames(setQf$rtioMoleWet13CCo2), "CrdCo2") - if ("ch4Conc" %in% names(qfInp)){names(setQf$rtioMoleWetCh4) <- paste0(colnames(setQf$rtioMoleWetCh4), "CrdCo2")} + if (dp01 == "ch4Conc"){names(setQf$rtioMoleWetCh4) <- paste0(colnames(setQf$rtioMoleWetCh4), "CrdCo2")} names(setQf$rtioMoleWetH2o) <- paste0(colnames(setQf$rtioMoleWetH2o), "CrdCo2") names(setQf$dlta13CCo2) <- paste0(colnames(setQf$dlta13CCo2), "CrdCo2") names(setQf$presCrdCo2) <- paste0(colnames(setQf$presCrdCo2), "CrdCo2") From d2611afde673003fe04018667f553df351aec855 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Tue, 21 Sep 2021 21:38:41 +0000 Subject: [PATCH 141/168] changing whether or not to run CH4 to an environment variable since all CI dp0p files will have ch4 in the structure going forward --- pack/eddy4R.base/R/def.para.flow.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/def.para.flow.R b/pack/eddy4R.base/R/def.para.flow.R index 2db3daf4..1ed0366a 100644 --- a/pack/eddy4R.base/R/def.para.flow.R +++ b/pack/eddy4R.base/R/def.para.flow.R @@ -23,6 +23,7 @@ #' @param MethDp01Api is a logical (TRUE/FALSE) determining if Dp01 reingest data for storage exchange workflow should be gathered from the API. #' @param UrlInpRefe A single-entry vector of class "character" containing the web address of the reference input data zip file to be downloaded. #' @param UrlOutRefe A single-entry vector of class "character" containing the web address of the reference output data zip file to be downloaded. +#' @param MethCh4Conc is a logical (TRUE/FALSE) determining if Dp01 methane concentration from the Picarro G2131 should be run #' @return \code{ParaFlow} is a list returned that indicates the workflow control parameters, including \code{ParaFlow$DirFilePara},\code{ParaFlow$DirInp}, \code{ParaFlow$DirMnt}, \code{ParaFlow$DirOut}, \code{ParaFlow$DirTmp}, \code{ParaFlow$DirWrk}, \code{ParaFlow$DateOut}, \code{ParaFlow$FileOutBase}, \code{ParaFlow$Read}, \code{ParaFlow$VersDp}, \code{ParaFlow$VersEddy}, \code{ParaFlow$MethDp01Api}. @@ -54,6 +55,8 @@ # fixing construction of ParaFlow$DirFilePara for batch-processing (when not using gold file) # Dave Durden (2020-07-06) # adding MethDp01Api parameter +# Chris Florian (2021-09-21) +# adding MethCh4Conc parameter ############################################################################################################## #Start of function call to determine workflow parameters @@ -76,10 +79,11 @@ def.para.flow <- function( MethDp01Api = TRUE, UrlInpRefe, UrlOutRefe, + MethCh4Conc = FALSE, ... ){ - ParaFlow <- list(Deve = Deve, DirFilePara = DirFilePara,DirInp = DirInp,DirMnt = DirMnt,DirOut = DirOut,DirTmp = DirTmp,DirWrk = DirWrk, DateOut = DateOut, FileOutBase = FileOutBase, MethParaFlow = MethParaFlow,Read = Read,VersDp = VersDp,VersEddy = VersEddy, MethDp01Api = MethDp01Api, ...) + ParaFlow <- list(Deve = Deve, DirFilePara = DirFilePara,DirInp = DirInp,DirMnt = DirMnt,DirOut = DirOut,DirTmp = DirTmp,DirWrk = DirWrk, DateOut = DateOut, FileOutBase = FileOutBase, MethParaFlow = MethParaFlow,Read = Read,VersDp = VersDp,VersEddy = VersEddy, MethDp01Api = MethDp01Api, MethCh4Conc = MethCh4Conc, ...) if(MethParaFlow == "EnvVar"){ #Create a list with all the specified function arguments From 3f062d351f3811ffc4d1cf87145d6fb42035de26 Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 8 Oct 2021 15:52:05 +0000 Subject: [PATCH 142/168] - repackage update --- pack/eddy4R.base/man/def.irga.vali.thsh.Rd | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.base/man/def.irga.vali.thsh.Rd b/pack/eddy4R.base/man/def.irga.vali.thsh.Rd index c723fe23..4b765359 100644 --- a/pack/eddy4R.base/man/def.irga.vali.thsh.Rd +++ b/pack/eddy4R.base/man/def.irga.vali.thsh.Rd @@ -4,16 +4,27 @@ \alias{def.irga.vali.thsh} \title{Definition function: Threshold IRGA validation data based on benchmarking regression} \usage{ -def.irga.vali.thsh(data, DateProc, bnchSlpMax, bnchSlpMin) +def.irga.vali.thsh( + data, + DateProc, + evalSlpMax, + evalSlpMin, + evalOfstMax, + evalOfstMin +) } \arguments{ \item{data}{List of validation data as a report from eddy4R.base::wrap.irga.vali()} \item{DateProc}{A vector of class "character" containing the processing date.} -\item{bnchSlpMax}{Maximum acceptable slope of the benchmarking regression} +\item{evalSlpMax}{Maximum acceptable slope of the benchmarking regression} -\item{bnchSlpMin}{Minimum acceptable slope of the benchmarking regression} +\item{evalSlpMin}{Minimum acceptable slope of the benchmarking regression} + +\item{evalOfstMax}{Maximum acceptable offset of the benchmarking regression} + +\item{evalOfstMin}{Minimum acceptable offset of the benchmarking regression} \item{gasRefe}{List containing the values of the reference gases. [mol mol-1]} } From 0c190af7635a736d75c88ad53fb797019ece4602 Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 8 Oct 2021 15:55:19 +0000 Subject: [PATCH 143/168] - not removing qfSpk data for presAtm until issue resolved --- pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R b/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R index 1971f245..a3714e42 100644 --- a/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R +++ b/pack/eddy4R.qaqc/R/wrap.qf.rmv.data.R @@ -43,6 +43,8 @@ # added Sens and qfRmv into the function parameter list # David Durden (2020-07-14) # added despiking routine and output qfSpk and qfNull +# David Durden (2021-10-7) +# not removing identified spike in presAtm data stream as patch for 2021 data release ############################################################################################## @@ -73,7 +75,7 @@ wrap.qf.rmv.data <- function( #Despiking routine base::lapply(Sens, function(x){ - #x <- Sens[2] #for testing + #x <- Sens[1] #for testing #print(x) varDspk <- names(outList[[x]]$inpData)[!names(outList[[x]]$inpData) %in% c("time","idx","frtSet00")] base::lapply(varDspk, function(y){ @@ -89,7 +91,9 @@ base::lapply(Sens, function(x){ # resolution threshold ThshReso = as.numeric(ramattribs(inpList$data[[x]][[y]])$`Dspk$Br86$MaxReso`) ) #Remove high frequency data that is flagged by sensor specific flags or plausibility tests flags + if(!(x == "irgaTurb" & y == "presAtm")){ outList[[x]]$inpData[[y]] <<- tmp$dataOut + } #Not removing qfSpk for irgaTurb presAtm TODO: fix once we have a better solution #Create flag name nameQf <- base::paste0("qfSpk",base::toupper(base::substring(y,1,1)),base::substring(y,2,base::nchar(y))) From 221ab0ff7cf3d754cd563fe096a5cab7e7065002 Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 8 Oct 2021 16:06:09 +0000 Subject: [PATCH 144/168] - update turb qfqm matrices --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 121 ++++++++++++++++----------- 1 file changed, 71 insertions(+), 50 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 6bc503bc..cbcc87a1 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -92,6 +92,8 @@ # Added qfNull and qfSpk for all variables, removed qfNull from ancillary data streams # David Durden (2021-08-24) # Changing ancillary data stream ECTE quality flags to quality indicators +# David Durden (2021-10-08) +# Changing qfSpkPresAtm to quality indicator and fixing soni tempAir flags ############################################################################################## def.dp01.grp.qf <- function( @@ -202,7 +204,7 @@ if (MethMeas == "ecte") { setQf$presAtmIrgaTurb <- data.frame("qfRngPresAtm" = qfInp$irgaTurb$qfRngPresAtm, "qfStepPresAtm" = qfInp$irgaTurb$qfStepPresAtm, "qfPersPresAtm" = qfInp$irgaTurb$qfPersPresAtm, - "qfSpkPresAtm" = qfInp$irgaTurb$qfSpkPresAtm, + "qiSpkPresAtm" = qfInp$irgaTurb$qfSpkPresAtm,#TODO remove hard coded qi for SpkPresAtm "qfNullPresAtm" = qfInp$irgaTurb$qfNullPresAtm) #"qfCalPresAtm" = qfInp$irgaTurb$qfCalPresAtm) @@ -453,7 +455,8 @@ if (MethMeas == "ecte") { setQf$powrCo2Samp, setQf$powrCo2Refe, setQf$asrpCo2, setQf$rtioMoleDryCo2, setQf$ssiCo2, - setQf$presAtmMfcSampTurb, + setQf$presAtmIrgaTurb, + setQf$presSum, setQf$tempMfcSampTurb))) rpt$rtioMoleDryCo2 <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, setQf$rtioMoleDryCo2, @@ -464,7 +467,8 @@ if (MethMeas == "ecte") { setQf$powrCo2Samp, setQf$powrCo2Refe, setQf$asrpCo2, setQf$ssiCo2, setQf$ssiH2o, - setQf$presAtmMfcSampTurb, + setQf$presAtmIrgaTurb, + setQf$presSum, setQf$tempMfcSampTurb))) rpt$presAtm <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, setQf$presAtmIrgaTurb) @@ -478,15 +482,16 @@ if (MethMeas == "ecte") { if (TypeMeas == "vali"){ rpt$densMoleCo2 <- data.frame(setQf$sensIrgaTurb, setQf$densMoleCo2, - "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, + "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, #TODO: qfRngFrt00 needs to be reconciled, vali qf not currently output "qfRngFrt00" = setQf$frt00MfcValiTurb$qfRngFrt00, eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempAve, setQf$presDiffIrgaTurb, setQf$powrCo2Samp, setQf$powrCo2Refe, setQf$asrpCo2 , setQf$rtioMoleDryCo2, setQf$ssiCo2, - setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb, - setQf$presAtmMfcValiTurb, + setQf$presAtmIrgaTurb, + setQf$presSum, setQf$tempMfcSampTurb, + setQf$presAtmMfcValiTurb, setQf$tempMfcValiTurb))) rpt$rtioMoleDryCo2 <- data.frame(setQf$sensIrgaTurb, setQf$rtioMoleDryCo2, @@ -499,7 +504,8 @@ if (MethMeas == "ecte") { setQf$powrCo2Refe, setQf$asrpCo2, setQf$ssiCo2, setQf$ssiH2o, - setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb, + setQf$presAtmIrgaTurb, + setQf$presSum, setQf$tempMfcSampTurb, setQf$presAtmMfcValiTurb, setQf$tempMfcValiTurb))) @@ -526,14 +532,14 @@ if (MethMeas == "ecte") { setQf$powrH2oSamp, setQf$powrH2oRefe, setQf$asrpH2o, setQf$ssiH2o, - setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb))) + setQf$presAtmIrgaTurb, setQf$presSum, setQf$tempMfcSampTurb))) rpt$rtioMoleDryH2o <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, setQf$rtioMoleDryH2o, "qfRngFrt00" = setQf$frt00MfcSampTurb$qfRngFrt00, eddy4R.qaqc::def.qi.qf(qf = list(setQf$tempAve, setQf$presDiffIrgaTurb, setQf$powrH2oSamp, setQf$powrH2oRefe, setQf$asrpH2o, setQf$ssiH2o, - setQf$presAtmMfcSampTurb, setQf$tempMfcSampTurb))) + setQf$presAtmIrgaTurb, setQf$presSum, setQf$tempMfcSampTurb))) rpt$presAtm <- data.frame(setQf$sensIrgaTurb, setQf$sensIrgaTurbExt, setQf$presAtmIrgaTurb) @@ -559,7 +565,8 @@ if (MethMeas == "ecte") { setQf$presDiffIrgaTurb, setQf$powrH2oSamp, setQf$powrH2oRefe, setQf$asrpH2o, setQf$ssiH2o, - setQf$presAtmMfcSampTurb, + setQf$presAtmIrgaTurb, + setQf$presSum, setQf$tempMfcSampTurb, setQf$presAtmMfcValiTurb, setQf$tempMfcValiTurb))) @@ -570,7 +577,8 @@ if (MethMeas == "ecte") { setQf$presDiffIrgaTurb, setQf$powrH2oSamp, setQf$powrH2oRefe, setQf$asrpH2o, setQf$ssiH2o, - setQf$presAtmMfcSampTurb, + setQf$presAtmIrgaTurb, + setQf$presSum, setQf$tempMfcSampTurb, setQf$presAtmMfcValiTurb, setQf$tempMfcValiTurb))) @@ -659,33 +667,40 @@ if (MethMeas == "ecte") { "qfIrgaTurbSync" = qfInp$irgaTurb$qfIrgaTurbSync, "qfIrgaTurbAgc" = qfInp$irgaTurb$qfIrgaTurbAgc, "qfIrgaTurbVali" = qfInp$irgaTurb$qfIrgaTurbVali, - "qfRngTempMean" = qfInp$irgaTurb$qfRngTempMean, - "qfStepTempMean" = qfInp$irgaTurb$qfStepTempMean, - "qfPersTempMean" = qfInp$irgaTurb$qfPersTempMean, + # "qfRngTempMean" = qfInp$irgaTurb$qfRngTempMean, + # "qfStepTempMean" = qfInp$irgaTurb$qfStepTempMean, + # "qfPersTempMean" = qfInp$irgaTurb$qfPersTempMean, + # "qfSpkTempMean" = qfInp$irgaTurb$qfSpkTempMean, #"qfCalTempMean" = qfInp$irgaTurb$qfCalTempMean, - "qfRngPresDiff" = qfInp$irgaTurb$qfRngPresDiff, - "qfStepPresDiff" = qfInp$irgaTurb$qfStepPresDiff, - "qfPersPresDiff" = qfInp$irgaTurb$qfPersPresDiff, - #"qfCalPresDiff" = qfInp$irgaTurb$qfCalPresDiff, - "qfRngPowrH2oSamp" = qfInp$irgaTurb$qfRngPowrH2oSamp, - "qfStepPowrH2oSamp" = qfInp$irgaTurb$qfStepPowrH2oSamp, - "qfPersPowrH2oSamp" = qfInp$irgaTurb$qfPersPowrH2oSamp, + "qfRngPresAtm" = qfInp$irgaTurb$qfRngPresAtm, + "qfStepPresAtm" = qfInp$irgaTurb$qfStepPresAtm, + "qfPersPresAtm" = qfInp$irgaTurb$qfPersPresAtm, + "qfSpkPresAtm" = qfInp$irgaTurb$qfSpkPresAtm, + "qfRngPresSum" = qfInp$irgaTurb$qfRngPresSum, + "qfStepPresSum" = qfInp$irgaTurb$qfStepPresSum, + "qfPersPresSum" = qfInp$irgaTurb$qfPersPresSum, + "qfSpkPresSum" = qfInp$irgaTurb$qfSpkPresSum, + # #"qfCalPresDiff" = qfInp$irgaTurb$qfCalPresDiff, + # "qfRngPowrH2oSamp" = qfInp$irgaTurb$qfRngPowrH2oSamp, + # "qfStepPowrH2oSamp" = qfInp$irgaTurb$qfStepPowrH2oSamp, + # "qfPersPowrH2oSamp" = qfInp$irgaTurb$qfPersPowrH2oSamp, #"qfCalPowrH2oSamp" = qfInp$irgaTurb$qfCalPowrH2oSamp, - "qfRngPowrH2oRefe" = qfInp$irgaTurb$qfRngPowrH2oRefe, - "qfStepPowrH2oRefe" = qfInp$irgaTurb$qfStepPowrH2oRefe, - "qfPersPowrH2oRefe" = qfInp$irgaTurb$qfPersPowrH2oRefe, + # "qfRngPowrH2oRefe" = qfInp$irgaTurb$qfRngPowrH2oRefe, + # "qfStepPowrH2oRefe" = qfInp$irgaTurb$qfStepPowrH2oRefe, + # "qfPersPowrH2oRefe" = qfInp$irgaTurb$qfPersPowrH2oRefe, #"qfCalPowrH2oRefe" = qfInp$irgaTurb$qfCalPowrH2oRefe, - "qfRngAsrpH2o" = qfInp$irgaTurb$qfRngAsrpH2o, - "qfStepAsrpH2o" = qfInp$irgaTurb$qfStepAsrpH2o, - "qfPersAsrpH2o" = qfInp$irgaTurb$qfPersAsrpH2o, + # "qfRngAsrpH2o" = qfInp$irgaTurb$qfRngAsrpH2o, + # "qfStepAsrpH2o" = qfInp$irgaTurb$qfStepAsrpH2o, + # "qfPersAsrpH2o" = qfInp$irgaTurb$qfPersAsrpH2o, #"qfCalAsrpH2o" = qfInp$irgaTurb$qfCalAsrpH2o, "qfRngDensMoleH2o" = qfInp$irgaTurb$qfRngDensMoleH2o, "qfStepDensMoleH2o" = qfInp$irgaTurb$qfStepDensMoleH2o, - "qfPersDensMoleH2o" = qfInp$irgaTurb$qfPersDensMoleH2o, + "qfPersDensMoleH2o" = qfInp$irgaTurb$qfPersDensMoleH2o, + "qfSpkDensMoleH2o" = qfInp$irgaTurb$qfSpkDensMoleH2o)#, #"qfCalDensMoleH2o" = qfInp$irgaTurb$qfCalDensMoleH2o, - "qfRngSsiH2o" = qfInp$irgaTurb$qfRngSsiH2o, - "qfStepSsiH2o" = qfInp$irgaTurb$qfStepSsiH2o, - "qfPersSsiH2o" = qfInp$irgaTurb$qfPersSsiH2o) + #"qfRngSsiH2o" = qfInp$irgaTurb$qfRngSsiH2o, + #"qfStepSsiH2o" = qfInp$irgaTurb$qfStepSsiH2o, + ##"qfPersSsiH2o" = qfInp$irgaTurb$qfPersSsiH2o) #"qfCalSsiH2o" = qfInp$irgaTurb$qfCalSsiH2o) } else { setQf$irgaTurb <- data.frame("qfIrgaTurbHead" = -1, @@ -699,33 +714,39 @@ if (MethMeas == "ecte") { "qfIrgaTurbSync" = -1, "qfIrgaTurbAgc" = -1, "qfIrgaTurbVali" = -1, - "qfRngTempMean" = -1, - "qfStepTempMean" = -1, - "qfPersTempMean" = -1, + # "qfRngTempMean" = -1, + # "qfStepTempMean" = -1, + # "qfPersTempMean" = -1, #"qfCalTempMean" = -1, - "qfRngPresDiff" = -1, - "qfStepPresDiff" = -1, - "qfPersPresDiff" = -1, + "qfRngPresAtm" = -1, + "qfStepPresAtm" = -1, + "qfPersPresAtm" = -1, + "qfSpkPresAtm" = -1, + "qfRngPresSum" = -1, + "qfStepPresSum" = -1, + "qfPersPresSum" = -1, + "qfSpkPresSum" = -1, #"qfCalPresDiff" = -1, - "qfRngPowrH2oSamp" = -1, - "qfStepPowrH2oSamp" = -1, - "qfPersPowrH2oSamp" = -1, + # "qfRngPowrH2oSamp" = -1, + # "qfStepPowrH2oSamp" = -1, + # "qfPersPowrH2oSamp" = -1, #"qfCalPowrH2oSamp" = -1, - "qfRngPowrH2oRefe" = -1, - "qfStepPowrH2oRefe" = -1, - "qfPersPowrH2oRefe" = -1, + # "qfRngPowrH2oRefe" = -1, + # "qfStepPowrH2oRefe" = -1, + # "qfPersPowrH2oRefe" = -1, #"qfCalPowrH2oRefe" = -1, - "qfRngAsrpH2o" = -1, - "qfStepAsrpH2o" = -1, - "qfPersAsrpH2o" = -1, + # "qfRngAsrpH2o" = -1, + # "qfStepAsrpH2o" = -1, + # "qfPersAsrpH2o" = -1, #"qfCalAsrpH2o" = -1, "qfRngDensMoleH2o" = -1, "qfStepDensMoleH2o" = -1, - "qfPersDensMoleH2o" = -1, + "qfPersDensMoleH2o" = -1, + "qfSpkDensMoleH2o" = -1)#, #"qfCalDensMoleH2o" = -1, - "qfRngSsiH2o" = -1, - "qfStepSsiH2o" = -1, - "qfPersSsiH2o" = -1) + # "qfRngSsiH2o" = -1, + # "qfStepSsiH2o" = -1, + # "qfPersSsiH2o" = -1) #"qfCalSsiH2o" = -1) }#close if else statement for irgaTurb ##TO DO##Considering later when the AMRS is collaborating to correct the SONI data From 35e0b3883b779e493d5deadabe4e7250d39ebb09 Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 8 Oct 2021 16:18:59 +0000 Subject: [PATCH 145/168] - adding flowrate flag --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 32a79ef7..e94a5ee5 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -706,7 +706,8 @@ if (MethMeas == "ecte") { "qfRngDensMoleH2o" = qfInp$irgaTurb$qfRngDensMoleH2o, "qfStepDensMoleH2o" = qfInp$irgaTurb$qfStepDensMoleH2o, "qfPersDensMoleH2o" = qfInp$irgaTurb$qfPersDensMoleH2o, - "qfSpkDensMoleH2o" = qfInp$irgaTurb$qfSpkDensMoleH2o)#, + "qfSpkDensMoleH2o" = qfInp$irgaTurb$qfSpkDensMoleH2o, + "qfRngFrt00" = qfInp$mfcSampTurb$qfRngFrt00)#, #"qfCalDensMoleH2o" = qfInp$irgaTurb$qfCalDensMoleH2o, #"qfRngSsiH2o" = qfInp$irgaTurb$qfRngSsiH2o, #"qfStepSsiH2o" = qfInp$irgaTurb$qfStepSsiH2o, @@ -752,7 +753,8 @@ if (MethMeas == "ecte") { "qfRngDensMoleH2o" = -1, "qfStepDensMoleH2o" = -1, "qfPersDensMoleH2o" = -1, - "qfSpkDensMoleH2o" = -1)#, + "qfSpkDensMoleH2o" = -1, + "qfRngFrt00" = -1)#, #"qfCalDensMoleH2o" = -1, # "qfRngSsiH2o" = -1, # "qfStepSsiH2o" = -1, From e4c9caaf68e16ad4291d276fe1389056dcfa551d Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 8 Oct 2021 16:28:17 +0000 Subject: [PATCH 146/168] - repackaging updates --- pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd | 6 +++--- pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd | 3 ++- pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd | 4 ++-- pack/eddy4R.stor/man/wrap.dp01.ecse.Rd | 3 ++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd b/pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd index 84421aad..f29f81c9 100644 --- a/pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd +++ b/pack/eddy4R.qaqc/man/def.dp01.grp.qf.Rd @@ -8,8 +8,8 @@ def.dp01.grp.qf( qfInp = list(), MethMeas = c("ecte", "ecse")[1], TypeMeas = c("samp", "vali")[1], - dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "isoH2o", - "soni", "amrs", "tempAirLvl", "tempAirTop")[1], + dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "ch4Conc", + "isoH2o", "soni", "amrs", "tempAirLvl", "tempAirTop")[1], idGas = NULL ) } @@ -21,7 +21,7 @@ def.dp01.grp.qf( \item{TypeMeas}{A vector of class "character" containing the name of measurement type (sampling or validation), TypeMeas = c("samp", "ecse"). Defaults to "samp". [-]} \item{dp01}{A vector of class "character" containing the name of NEON ECTE and ECSE L1 data products which the flags are being grouped, \cr -c("envHut", "co2Turb", "h2oTurb", "isoCo2", "isoH2o", "soni", "amrs", "tempAirLvl", "tempAirTop"). Defaults to "co2Turb". [-]} +c("envHut", "co2Turb", "h2oTurb", "isoCo2", "ch4Conc", isoH2o", "soni", "amrs", "tempAirLvl", "tempAirTop"). Defaults to "co2Turb". [-]} \item{idGas}{A data frame contianing gas ID for isoCo2 measurement. Need to provide when dp01 = "isoCo2". Default to NULL. [-]} } diff --git a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd index eedc6015..3d6a44a1 100644 --- a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd +++ b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.ecse.Rd @@ -5,7 +5,8 @@ \title{Wrapper function: Preprocessing and calculating quality metrics, alpha and beta quality metrics, and final quality flag for the NEON eddy-covariance stroage exchange L1 data products} \usage{ wrap.dp01.qfqm.ecse( - dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], + dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o", + "ch4Conc")[1], RptExpd = FALSE, lvl, lvlMfcSampStor = NULL, diff --git a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd index a6149daa..0a9a1df5 100644 --- a/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd +++ b/pack/eddy4R.qaqc/man/wrap.dp01.qfqm.eddy.Rd @@ -9,8 +9,8 @@ wrap.dp01.qfqm.eddy( MethMeas = c("ecte", "ecse")[1], TypeMeas = c("samp", "vali")[1], RptExpd = FALSE, - dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "isoH2o", - "soni", "soniAmrs", "tempAirLvl", "tempAirTop")[1], + dp01 = c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "isoCo2", "ch4Conc", + "isoH2o", "soni", "soniAmrs", "tempAirLvl", "tempAirTop")[1], idGas = NULL ) } diff --git a/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd b/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd index c15f4b59..1e8518e0 100644 --- a/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd +++ b/pack/eddy4R.stor/man/wrap.dp01.ecse.Rd @@ -5,7 +5,8 @@ \title{Wrapper function: Preprocessing and computing NEON eddy-covariance stroage exchange L1 data product descriptive statistics} \usage{ wrap.dp01.ecse( - dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o")[1], + dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o", + "ch4Conc")[1], lvl, lvlMfcSampStor = NULL, lvlEnvHut = NULL, From 3c5192f88bcfd83340e0738d658ea545443f9c0c Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 8 Oct 2021 16:33:25 +0000 Subject: [PATCH 147/168] - updating package version numbers --- pack/eddy4R.base/DESCRIPTION | 2 +- pack/eddy4R.qaqc/DESCRIPTION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.base/DESCRIPTION b/pack/eddy4R.base/DESCRIPTION index 75fc2e49..66328832 100644 --- a/pack/eddy4R.base/DESCRIPTION +++ b/pack/eddy4R.base/DESCRIPTION @@ -1,6 +1,6 @@ Package: eddy4R.base Title: Eddy-covariance calculation for R: Base package -Version: 0.2.23 +Version: 0.2.24 Authors@R: c( person("Stefan", "Metzger", email = "eddy4R.info@gmail.com", role = c("aut", "cre")), person("David", "Durden", email = "ddurden@battelleecology.org", role = c("aut")), person("Natchaya", "Pingintha-Durden", email = "ndurden@battelleecology.org", role = c("aut")), diff --git a/pack/eddy4R.qaqc/DESCRIPTION b/pack/eddy4R.qaqc/DESCRIPTION index 642c11e1..7d0096be 100644 --- a/pack/eddy4R.qaqc/DESCRIPTION +++ b/pack/eddy4R.qaqc/DESCRIPTION @@ -1,6 +1,6 @@ Package: eddy4R.qaqc Title: Eddy-covariance calculation for R: Quality assurance and quality control -Version: 0.2.13 +Version: 0.2.14 Authors@R: c( person("Cove", "Sturtevant", email = "eddy4R.info@gmail.com", role = c("aut", "cre")), person("Stefan", "Metzger", email = "eddy4R.info@gmail.com", role = c("aut")), person("Natchaya", "Pingintha-Durden", email = "ndurden@battelleecology.org", role = c("aut")), From 629e4d45cf269b7d80dd82d680e5a7e6d946e182 Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 8 Oct 2021 16:34:24 +0000 Subject: [PATCH 148/168] - adding IRGA quality metrics --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 112 +++++++++++++++------------ 1 file changed, 61 insertions(+), 51 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index e94a5ee5..bb3da6b0 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -677,36 +677,41 @@ if (MethMeas == "ecte") { "qfIrgaTurbSync" = qfInp$irgaTurb$qfIrgaTurbSync, "qfIrgaTurbAgc" = qfInp$irgaTurb$qfIrgaTurbAgc, "qfIrgaTurbVali" = qfInp$irgaTurb$qfIrgaTurbVali, + "qfRngRtioMoleDryH2o" = qfInp$irgaTurb$qfRngRtioMoleDryH2o, + "qfStepRtioMoleDryH2o" = qfInp$irgaTurb$qfStepRtioMoleDryH2o, + "qfPersRtioMoleDryH2o" = qfInp$irgaTurb$qfPersRtioMoleDryH2o, + "qfSpkRtioMoleDryH2o" = qfInp$irgaTurb$qfSpkRtioMoleDryH2o, + "qfNullRtioMoleDryH2o" = qfInp$irgaTurb$qfNullRtioMoleDryH2o, # "qfRngTempMean" = qfInp$irgaTurb$qfRngTempMean, # "qfStepTempMean" = qfInp$irgaTurb$qfStepTempMean, # "qfPersTempMean" = qfInp$irgaTurb$qfPersTempMean, # "qfSpkTempMean" = qfInp$irgaTurb$qfSpkTempMean, #"qfCalTempMean" = qfInp$irgaTurb$qfCalTempMean, - "qfRngPresAtm" = qfInp$irgaTurb$qfRngPresAtm, - "qfStepPresAtm" = qfInp$irgaTurb$qfStepPresAtm, - "qfPersPresAtm" = qfInp$irgaTurb$qfPersPresAtm, - "qfSpkPresAtm" = qfInp$irgaTurb$qfSpkPresAtm, - "qfRngPresSum" = qfInp$irgaTurb$qfRngPresSum, - "qfStepPresSum" = qfInp$irgaTurb$qfStepPresSum, - "qfPersPresSum" = qfInp$irgaTurb$qfPersPresSum, - "qfSpkPresSum" = qfInp$irgaTurb$qfSpkPresSum, - # #"qfCalPresDiff" = qfInp$irgaTurb$qfCalPresDiff, - # "qfRngPowrH2oSamp" = qfInp$irgaTurb$qfRngPowrH2oSamp, - # "qfStepPowrH2oSamp" = qfInp$irgaTurb$qfStepPowrH2oSamp, - # "qfPersPowrH2oSamp" = qfInp$irgaTurb$qfPersPowrH2oSamp, - #"qfCalPowrH2oSamp" = qfInp$irgaTurb$qfCalPowrH2oSamp, - # "qfRngPowrH2oRefe" = qfInp$irgaTurb$qfRngPowrH2oRefe, - # "qfStepPowrH2oRefe" = qfInp$irgaTurb$qfStepPowrH2oRefe, - # "qfPersPowrH2oRefe" = qfInp$irgaTurb$qfPersPowrH2oRefe, - #"qfCalPowrH2oRefe" = qfInp$irgaTurb$qfCalPowrH2oRefe, - # "qfRngAsrpH2o" = qfInp$irgaTurb$qfRngAsrpH2o, - # "qfStepAsrpH2o" = qfInp$irgaTurb$qfStepAsrpH2o, - # "qfPersAsrpH2o" = qfInp$irgaTurb$qfPersAsrpH2o, - #"qfCalAsrpH2o" = qfInp$irgaTurb$qfCalAsrpH2o, - "qfRngDensMoleH2o" = qfInp$irgaTurb$qfRngDensMoleH2o, - "qfStepDensMoleH2o" = qfInp$irgaTurb$qfStepDensMoleH2o, - "qfPersDensMoleH2o" = qfInp$irgaTurb$qfPersDensMoleH2o, - "qfSpkDensMoleH2o" = qfInp$irgaTurb$qfSpkDensMoleH2o, + # "qfRngPresAtm" = qfInp$irgaTurb$qfRngPresAtm, + # "qfStepPresAtm" = qfInp$irgaTurb$qfStepPresAtm, + # "qfPersPresAtm" = qfInp$irgaTurb$qfPersPresAtm, + # "qfSpkPresAtm" = qfInp$irgaTurb$qfSpkPresAtm, + # "qfRngPresSum" = qfInp$irgaTurb$qfRngPresSum, + # "qfStepPresSum" = qfInp$irgaTurb$qfStepPresSum, + # "qfPersPresSum" = qfInp$irgaTurb$qfPersPresSum, + # "qfSpkPresSum" = qfInp$irgaTurb$qfSpkPresSum, + # # #"qfCalPresDiff" = qfInp$irgaTurb$qfCalPresDiff, + # # "qfRngPowrH2oSamp" = qfInp$irgaTurb$qfRngPowrH2oSamp, + # # "qfStepPowrH2oSamp" = qfInp$irgaTurb$qfStepPowrH2oSamp, + # # "qfPersPowrH2oSamp" = qfInp$irgaTurb$qfPersPowrH2oSamp, + # #"qfCalPowrH2oSamp" = qfInp$irgaTurb$qfCalPowrH2oSamp, + # # "qfRngPowrH2oRefe" = qfInp$irgaTurb$qfRngPowrH2oRefe, + # # "qfStepPowrH2oRefe" = qfInp$irgaTurb$qfStepPowrH2oRefe, + # # "qfPersPowrH2oRefe" = qfInp$irgaTurb$qfPersPowrH2oRefe, + # #"qfCalPowrH2oRefe" = qfInp$irgaTurb$qfCalPowrH2oRefe, + # # "qfRngAsrpH2o" = qfInp$irgaTurb$qfRngAsrpH2o, + # # "qfStepAsrpH2o" = qfInp$irgaTurb$qfStepAsrpH2o, + # # "qfPersAsrpH2o" = qfInp$irgaTurb$qfPersAsrpH2o, + # #"qfCalAsrpH2o" = qfInp$irgaTurb$qfCalAsrpH2o, + # "qfRngDensMoleH2o" = qfInp$irgaTurb$qfRngDensMoleH2o, + # "qfStepDensMoleH2o" = qfInp$irgaTurb$qfStepDensMoleH2o, + # "qfPersDensMoleH2o" = qfInp$irgaTurb$qfPersDensMoleH2o, + # "qfSpkDensMoleH2o" = qfInp$irgaTurb$qfSpkDensMoleH2o, "qfRngFrt00" = qfInp$mfcSampTurb$qfRngFrt00)#, #"qfCalDensMoleH2o" = qfInp$irgaTurb$qfCalDensMoleH2o, #"qfRngSsiH2o" = qfInp$irgaTurb$qfRngSsiH2o, @@ -725,35 +730,40 @@ if (MethMeas == "ecte") { "qfIrgaTurbSync" = -1, "qfIrgaTurbAgc" = -1, "qfIrgaTurbVali" = -1, + "qfRngRtioMoleDryH2o" = -1, + "qfStepRtioMoleDryH2o" = -1, + "qfPersRtioMoleDryH2o" = -1, + "qfSpkRtioMoleDryH2o" = -1, + "qfNullRtioMoleDryH2o" = -1, # "qfRngTempMean" = -1, # "qfStepTempMean" = -1, # "qfPersTempMean" = -1, #"qfCalTempMean" = -1, - "qfRngPresAtm" = -1, - "qfStepPresAtm" = -1, - "qfPersPresAtm" = -1, - "qfSpkPresAtm" = -1, - "qfRngPresSum" = -1, - "qfStepPresSum" = -1, - "qfPersPresSum" = -1, - "qfSpkPresSum" = -1, - #"qfCalPresDiff" = -1, - # "qfRngPowrH2oSamp" = -1, - # "qfStepPowrH2oSamp" = -1, - # "qfPersPowrH2oSamp" = -1, - #"qfCalPowrH2oSamp" = -1, - # "qfRngPowrH2oRefe" = -1, - # "qfStepPowrH2oRefe" = -1, - # "qfPersPowrH2oRefe" = -1, - #"qfCalPowrH2oRefe" = -1, - # "qfRngAsrpH2o" = -1, - # "qfStepAsrpH2o" = -1, - # "qfPersAsrpH2o" = -1, - #"qfCalAsrpH2o" = -1, - "qfRngDensMoleH2o" = -1, - "qfStepDensMoleH2o" = -1, - "qfPersDensMoleH2o" = -1, - "qfSpkDensMoleH2o" = -1, + # "qfRngPresAtm" = -1, + # "qfStepPresAtm" = -1, + # "qfPersPresAtm" = -1, + # "qfSpkPresAtm" = -1, + # "qfRngPresSum" = -1, + # "qfStepPresSum" = -1, + # "qfPersPresSum" = -1, + # "qfSpkPresSum" = -1, + # #"qfCalPresDiff" = -1, + # # "qfRngPowrH2oSamp" = -1, + # # "qfStepPowrH2oSamp" = -1, + # # "qfPersPowrH2oSamp" = -1, + # #"qfCalPowrH2oSamp" = -1, + # # "qfRngPowrH2oRefe" = -1, + # # "qfStepPowrH2oRefe" = -1, + # # "qfPersPowrH2oRefe" = -1, + # #"qfCalPowrH2oRefe" = -1, + # # "qfRngAsrpH2o" = -1, + # # "qfStepAsrpH2o" = -1, + # # "qfPersAsrpH2o" = -1, + # #"qfCalAsrpH2o" = -1, + # "qfRngDensMoleH2o" = -1, + # "qfStepDensMoleH2o" = -1, + # "qfPersDensMoleH2o" = -1, + # "qfSpkDensMoleH2o" = -1, "qfRngFrt00" = -1)#, #"qfCalDensMoleH2o" = -1, # "qfRngSsiH2o" = -1, @@ -832,7 +842,7 @@ if (MethMeas == "ecte") { # setQf$veloSoni, setQf$amrs) rpt$tempAir <- data.frame(setQf$sensSoni, setQf$veloSoni, - setQf$tempSoni, eddy4R.qaqc::def.qi.qf(qf = setQf$irgaTurb)) # Removing until we can handle flags of different lengths + setQf$tempSoni, setQf$irgaTurb) # Removing until we can handle flags of different lengths rpt$tempSoni <- data.frame(setQf$sensSoni, setQf$veloSoni, setQf$tempSoni) From c2e4af4877216f8512dd301de5c1cdc00a2ff0e2 Mon Sep 17 00:00:00 2001 From: ddurden Date: Fri, 8 Oct 2021 16:35:00 +0000 Subject: [PATCH 149/168] - repackage --- pack/eddy4R.base/man/def.para.flow.Rd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pack/eddy4R.base/man/def.para.flow.Rd b/pack/eddy4R.base/man/def.para.flow.Rd index d307be92..20e4fece 100644 --- a/pack/eddy4R.base/man/def.para.flow.Rd +++ b/pack/eddy4R.base/man/def.para.flow.Rd @@ -21,6 +21,7 @@ def.para.flow( MethDp01Api = TRUE, UrlInpRefe, UrlOutRefe, + MethCh4Conc = FALSE, ... ) } @@ -56,6 +57,8 @@ def.para.flow( \item{UrlInpRefe}{A single-entry vector of class "character" containing the web address of the reference input data zip file to be downloaded.} \item{UrlOutRefe}{A single-entry vector of class "character" containing the web address of the reference output data zip file to be downloaded.} + +\item{MethCh4Conc}{is a logical (TRUE/FALSE) determining if Dp01 methane concentration from the Picarro G2131 should be run} } \value{ \code{ParaFlow} is a list returned that indicates the workflow control parameters, including \code{ParaFlow$DirFilePara},\code{ParaFlow$DirInp}, \code{ParaFlow$DirMnt}, \code{ParaFlow$DirOut}, \code{ParaFlow$DirTmp}, \code{ParaFlow$DirWrk}, \code{ParaFlow$DateOut}, \code{ParaFlow$FileOutBase}, \code{ParaFlow$Read}, \code{ParaFlow$VersDp}, \code{ParaFlow$VersEddy}, \code{ParaFlow$MethDp01Api}. From 1443bbee80a8abee60dd8f59b60f51154c1044a5 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Fri, 8 Oct 2021 17:59:41 +0000 Subject: [PATCH 150/168] reducing qmBeta weighting for picarro data products --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R index bf3d0e0e..90158a15 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R @@ -72,6 +72,8 @@ # adding one row with qf = -1 in the empty dataframe to eliminate code break in def.qf.finl() # Chris Florian (2021-04-09) # adding ch4Conc to the dp01 list +# Chris Florian (2021-12-08) +# adding logic to allow for more missing data due to variable picarro sampling frequency ############################################################################################## wrap.dp01.qfqm.eddy <- function( @@ -93,7 +95,15 @@ wrap.dp01.qfqm.eddy <- function( lapply(names(inp), function(x) if (nrow(inp[[x]]) == 0) inp[[x]][1,] <<- -1) #calculate qmAlpha, qmBeta, qfFinl - tmp <- lapply(inp, FUN = eddy4R.qaqc::def.qf.finl) + if (dp01 %in% c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "soni", "soniAmrs", "tempAirLvl", "tempAirTop")){ + tmp <- lapply(inp, FUN = eddy4R.qaqc::def.qf.finl) + } + + #set qmBeta weight lower for picarro data products to account for variable sampling frequency + if (dp01 %in% c("isoCo2", "ch4Conc", "isoH2o")){ + tmp <- lapply(inp, FUN = eddy4R.qaqc::def.qf.finl, WghtAlphBeta=c(2,0.2)) + } + #assign default qfSciRevw lapply(names(tmp), function(x) tmp[[x]]$qfqm$qfSciRevw <<- 0) From ef5b24565cbd92849ec5cf08010f02b77b505deb Mon Sep 17 00:00:00 2001 From: ddurden Date: Tue, 12 Oct 2021 19:59:31 +0000 Subject: [PATCH 151/168] - copying global attribute to dp04 files --- pack/eddy4R.base/R/def.hdf5.copy.para.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pack/eddy4R.base/R/def.hdf5.copy.para.R b/pack/eddy4R.base/R/def.hdf5.copy.para.R index 7a01d50d..b41eb2a3 100755 --- a/pack/eddy4R.base/R/def.hdf5.copy.para.R +++ b/pack/eddy4R.base/R/def.hdf5.copy.para.R @@ -41,6 +41,8 @@ # rename function from def.para.hdf5.dp01() to def.hdf5.copy.para() # Dave Durden (2021-08-17) # Failsafe to remove rhdf5 attribute from list of attributes written out +# Dave Durden (2021-10-12) +# Copy global attributes by adding file level to listGrp ############################################################################################################## #Start of function call to read metadata from one file and write to another ############################################################################################################## @@ -65,6 +67,8 @@ listPara <- rhdf5::h5ls(FileInp, datasetinfo = FALSE) #listPara <- listPara[listPara$otype == "H5I_GROUP",] #Used to grab metadata if it is only attached to the group level listGrp <- base::paste(listPara$group, listPara$name, sep = "/") # Combining output +#Append global attribute level +listGrp <- append("/", listGrp) # read attributes from input file listAttr <- base::lapply(listGrp, rhdf5::h5readAttributes, file = FileInp) From b4ef820127306879331400013f175d1a0c491828 Mon Sep 17 00:00:00 2001 From: ddurden Date: Wed, 13 Oct 2021 02:10:17 +0000 Subject: [PATCH 152/168] - adding global attributes --- pack/eddy4R.base/R/def.hdf5.extr.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pack/eddy4R.base/R/def.hdf5.extr.R b/pack/eddy4R.base/R/def.hdf5.extr.R index ead8c2e1..5a1c398a 100755 --- a/pack/eddy4R.base/R/def.hdf5.extr.R +++ b/pack/eddy4R.base/R/def.hdf5.extr.R @@ -54,6 +54,8 @@ # rename function from def.extr.hdf5() to def.hdf5.extr() # Dave Durden (2018-03-12) # Adding failsafe for rhdf5 metadata attribute on individual dp0p arrays +# Dave Durden (2021-10-12) +# Copy global attributes by adding file level to listGrp ############################################################################################################## #Start of function call to extract data from one file and write to another ############################################################################################################## @@ -90,6 +92,9 @@ if(base::is.null(rpt)) { #List of all object names listObjName <- base::paste(listObj$group, listObj$name, sep = "/") + + #Append global attribute level + listObjName <- append("/", listObjName) # Groups for HDF5 group structure From 35677288e68351a3e62890d52bee2784d46f5f6b Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Fri, 12 Nov 2021 21:35:21 +0000 Subject: [PATCH 153/168] Addressing qmBeta overflagging from step test and sampling frequency in the picarro data products --- pack/eddy4R.qaqc/R/def.dp01.grp.qf.R | 40 +++++++++++++----------- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R | 10 +++--- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R index 9639bf79..b6ef05e8 100644 --- a/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R +++ b/pack/eddy4R.qaqc/R/def.dp01.grp.qf.R @@ -96,6 +96,8 @@ # Changing ancillary data stream ECTE quality flags to quality indicators # Chris Florian (2021-09-21) # Adding logic to set CH4 qfs or not depending on if ch4Conc is in the dp01 list +# Chris Florian (2021-11-12) +# Removing the step test from Picarro data products, it was not working as intended due to NaNs introduced during regularization ############################################################################################## def.dp01.grp.qf <- function( @@ -1380,24 +1382,24 @@ if (MethMeas == "ecse") { #setQf for crdCo2 setQf$rtioMoleDryCo2 <- data.frame("qfRngRtioMoleDryCo2" = qfInp$crdCo2$qfRngRtioMoleDryCo2, - "qfStepRtioMoleDryCo2" = qfInp$crdCo2$qfStepRtioMoleDryCo2, + #"qfStepRtioMoleDryCo2" = qfInp$crdCo2$qfStepRtioMoleDryCo2, "qfPersRtioMoleDryCo2" = qfInp$crdCo2$qfPersRtioMoleDryCo2) #"qfCalRtioMoleDryCo2" = qfInp$crdCo2$qfCalRtioMoleDryCo2) setQf$rtioMoleDry12CCo2 <- data.frame("qfRngRtioMoleDry12CCo2" = qfInp$crdCo2$qfRngRtioMoleDry12CCo2, - "qfStepRtioMoleDry12CCo2" = qfInp$crdCo2$qfStepRtioMoleDry12CCo2, + #"qfStepRtioMoleDry12CCo2" = qfInp$crdCo2$qfStepRtioMoleDry12CCo2, "qfPersRtioMoleDry12CCo2" = qfInp$crdCo2$qfPersRtioMoleDry12CCo2) #"qfCalRtioMoleDry12CCo2" = qfInp$crdCo2$qfCalRtioMoleDry12CCo2) setQf$rtioMoleDry13CCo2 <- data.frame("qfRngRtioMoleDry13CCo2" = qfInp$crdCo2$qfRngRtioMoleDry13CCo2, - "qfStepRtioMoleDry13CCo2" = qfInp$crdCo2$qfStepRtioMoleDry13CCo2, + #"qfStepRtioMoleDry13CCo2" = qfInp$crdCo2$qfStepRtioMoleDry13CCo2, "qfPersRtioMoleDry13CCo2" = qfInp$crdCo2$qfPersRtioMoleDry13CCo2) #"qfCalRtioMoleDry13CCo2" = qfInp$crdCo2$qfCalRtioMoleDry13CCo2) if (dp01 == "ch4Conc"){ setQf$rtioMoleDryCh4 <- data.frame("qfRngRtioMoleDryCh4" = qfInp$crdCo2$qfRngRtioMoleDryCh4, - "qfStepRtioMoleDryCh4" = qfInp$crdCo2$qfStepRtioMoleDryCh4, + #"qfStepRtioMoleDryCh4" = qfInp$crdCo2$qfStepRtioMoleDryCh4, "qfPersRtioMoleDryCh4" = qfInp$crdCo2$qfPersRtioMoleDryCh4) #"qfCalRtioMoleDryCh4" = qfInp$crdCo2$qfCalRtioMoleDryCh4) } @@ -1410,23 +1412,23 @@ if (MethMeas == "ecse") { #"qfCalRtioMoleDryH2o" = qfInp$crdCo2$qfCalRtioMoleDryH2o) setQf$rtioMoleWetCo2 <- data.frame("qfRngRtioMoleWetCo2" = qfInp$crdCo2$qfRngRtioMoleWetCo2, - "qfStepRtioMoleWetCo2" = qfInp$crdCo2$qfStepRtioMoleWetCo2, + #"qfStepRtioMoleWetCo2" = qfInp$crdCo2$qfStepRtioMoleWetCo2, "qfPersRtioMoleWetCo2" = qfInp$crdCo2$qfPersRtioMoleWetCo2) #"qfCalRtioMoleWetCo2" = qfInp$crdCo2$qfCalRtioMoleWetCo2) setQf$rtioMoleWet12CCo2 <- data.frame("qfRngRtioMoleWet12CCo2" = qfInp$crdCo2$qfRngRtioMoleWet12CCo2, - "qfStepRtioMoleWet12CCo2" = qfInp$crdCo2$qfStepRtioMoleWet12CCo2, + #"qfStepRtioMoleWet12CCo2" = qfInp$crdCo2$qfStepRtioMoleWet12CCo2, "qfPersRtioMoleWet12CCo2" = qfInp$crdCo2$qfPersRtioMoleWet12CCo2) #"qfCalRtioMoleWet12CCo2" = qfInp$crdCo2$qfCalRtioMoleWet12CCo2) setQf$rtioMoleWet13CCo2 <- data.frame("qfRngRtioMoleWet13CCo2" = qfInp$crdCo2$qfRngRtioMoleWet13CCo2, - "qfStepRtioMoleWet13CCo2" = qfInp$crdCo2$qfStepRtioMoleWet13CCo2, + #"qfStepRtioMoleWet13CCo2" = qfInp$crdCo2$qfStepRtioMoleWet13CCo2, "qfPersRtioMoleWet13CCo2" = qfInp$crdCo2$qfPersRtioMoleWet13CCo2) #"qfCalRtioMoleWet13CCo2 " = qfInp$crdCo2$qfCalRtioMoleWet13CCo2) if (dp01 == "ch4Conc"){ setQf$rtioMoleWetCh4 <- data.frame("qfRngRtioMoleWetCh4" = qfInp$crdCo2$qfRngRtioMoleWetCh4, - "qfStepRtioMoleWetCh4" = qfInp$crdCo2$qfStepRtioMoleWetCh4, + #"qfStepRtioMoleWetCh4" = qfInp$crdCo2$qfStepRtioMoleWetCh4, "qfPersRtioMoleWetCh4" = qfInp$crdCo2$qfPersRtioMoleWetCh4) #"qfCalRtioMoleWetCh4" = qfInp$crdCo2$qfCalRtioMoleWetCh4) } @@ -1437,22 +1439,22 @@ if (MethMeas == "ecse") { #"qfCalRtioMoleWetH2o" = qfInp$crdCo2$qfCalRtioMoleWetH2o) setQf$dlta13CCo2 <- data.frame("qfRngDlta13CCo2" = qfInp$crdCo2$qfRngDlta13CCo2, - "qfStepDlta13CCo2" = qfInp$crdCo2$qfStepDlta13CCo2, + #"qfStepDlta13CCo2" = qfInp$crdCo2$qfStepDlta13CCo2, "qfPersDlta13CCo2" = qfInp$crdCo2$qfPersDlta13CCo2) #"qfCalDlta13CCo2" = qfInp$crdCo2$qfCalDlta13CCo2) setQf$presCrdCo2 <- data.frame("qfRngPres" = qfInp$crdCo2$qfRngPres, - "qfStepPres" = qfInp$crdCo2$qfStepPres, + #"qfStepPres" = qfInp$crdCo2$qfStepPres, "qfPersPres" = qfInp$crdCo2$qfPersPres) #"qfCalPres" = qfInp$crdCo2$qfCalPres) setQf$tempCrdCo2 <- data.frame("qfRngTemp" = qfInp$crdCo2$qfRngTemp, - "qfStepTemp" = qfInp$crdCo2$qfStepTemp, + #"qfStepTemp" = qfInp$crdCo2$qfStepTemp, "qfPersTemp" = qfInp$crdCo2$qfPersTemp) #"qfCalTemp" = qfInp$crdCo2$qfCalTemp) setQf$tempWbox <- data.frame("qfRngTempWbox" = qfInp$crdCo2$qfRngTempWbox, - "qfStepTempWbox" = qfInp$crdCo2$qfStepTempWbox, + #"qfStepTempWbox" = qfInp$crdCo2$qfStepTempWbox, "qfPersTempWbox" = qfInp$crdCo2$qfPersTempWbox) #"qfCalTempWbox" = qfInp$crdCo2$qfCalTempWbox) setQf$sensCrdCo2 <- data.frame("qfSensStus" = qfInp$crdCo2$qfSensStus) @@ -2245,37 +2247,37 @@ if (MethMeas == "ecse") { #setQf for crdH2o setQf$rtioMoleDryH2o <- data.frame("qfRngRtioMoleDryH2o" = qfInp$crdH2o$qfRngRtioMoleDryH2o, - "qfStepRtioMoleDryH2o" = qfInp$crdH2o$qfStepRtioMoleDryH2o, + #"qfStepRtioMoleDryH2o" = qfInp$crdH2o$qfStepRtioMoleDryH2o, "qfPersRtioMoleDryH2o" = qfInp$crdH2o$qfPersRtioMoleDryH2o) #"qfCalRtioMoleDryH2o" = qfInp$crdH2o$qfCalRtioMoleDryH2o) setQf$rtioMoleWetH2o <- data.frame("qfRngRtioMoleWetH2o" = qfInp$crdH2o$qfRngRtioMoleWetH2o, - "qfStepRtioMoleWetH2o" = qfInp$crdH2o$qfStepRtioMoleWetH2o, + #"qfStepRtioMoleWetH2o" = qfInp$crdH2o$qfStepRtioMoleWetH2o, "qfPersRtioMoleWetH2o" = qfInp$crdH2o$qfPersRtioMoleWetH2o) #"qfCalRtioMoleWetH2o" = qfInp$crdH2o$qfCalRtioMoleWetH2o) setQf$dlta18OH2o <- data.frame("qfRngDlta18OH2o" = qfInp$crdH2o$qfRngDlta18OH2o, - "qfStepDlta18OH2o" = qfInp$crdH2o$qfStepDlta18OH2o, + #"qfStepDlta18OH2o" = qfInp$crdH2o$qfStepDlta18OH2o, "qfPersDlta18OH2o" = qfInp$crdH2o$qfPersDlta18OH2o) #"qfCalDlta18OH2o" = qfInp$crdH2o$qfCalDlta18OH2o) setQf$dlta2HH2o <- data.frame("qfRngDlta2HH2o" = qfInp$crdH2o$qfRngDlta2HH2o, - "qfStepDlta2HH2o" = qfInp$crdH2o$qfStepDlta2HH2o, + #"qfStepDlta2HH2o" = qfInp$crdH2o$qfStepDlta2HH2o, "qfPersDlta2HH2o" = qfInp$crdH2o$qfPersDlta2HH2o) #"qfCalDlta2HH2o" = qfInp$crdH2o$qfCalDlta2HH2o) setQf$presCrdH2o <- data.frame("qfRngPres" = qfInp$crdH2o$qfRngPres, - "qfStepPres" = qfInp$crdH2o$qfStepPres, + #"qfStepPres" = qfInp$crdH2o$qfStepPres, "qfPersPres" = qfInp$crdH2o$qfPersPres) #"qfCalPres" = qfInp$crdH2o$qfCalPres) setQf$tempCrdH2o <- data.frame("qfRngTemp" = qfInp$crdH2o$qfRngTemp, - "qfStepTemp" = qfInp$crdH2o$qfStepTemp, + #"qfStepTemp" = qfInp$crdH2o$qfStepTemp, "qfPersTemp" = qfInp$crdH2o$qfPersTemp) #"qfCalTemp" = qfInp$crdH2o$qfCalTemp) setQf$tempWbox <- data.frame("qfRngTempWbox" = qfInp$crdH2o$qfRngTempWbox, - "qfStepTempWbox" = qfInp$crdH2o$qfStepTempWbox, + #"qfStepTempWbox" = qfInp$crdH2o$qfStepTempWbox, "qfPersTempWbox" = qfInp$crdH2o$qfPersTempWbox) #"qfCalTempWbox" = qfInp$crdH2o$qfCalTempWbox) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R index 90158a15..b0babe25 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R @@ -72,8 +72,10 @@ # adding one row with qf = -1 in the empty dataframe to eliminate code break in def.qf.finl() # Chris Florian (2021-04-09) # adding ch4Conc to the dp01 list -# Chris Florian (2021-12-08) +# Chris Florian (2021-11-08) # adding logic to allow for more missing data due to variable picarro sampling frequency +# Chris Florian (2021-11-12) +# setting the ch4Conc qmBeta weighting to 0.2, this is the lowest weighing we can assign while also flagging intervals that are fully missing ############################################################################################## wrap.dp01.qfqm.eddy <- function( @@ -95,12 +97,12 @@ wrap.dp01.qfqm.eddy <- function( lapply(names(inp), function(x) if (nrow(inp[[x]]) == 0) inp[[x]][1,] <<- -1) #calculate qmAlpha, qmBeta, qfFinl - if (dp01 %in% c("envHut", "co2Turb", "h2oTurb", "co2Stor", "h2oStor", "soni", "soniAmrs", "tempAirLvl", "tempAirTop")){ + if (dp01 %in% c("envHut", "co2Turb", "h2oTurb", "co2Stor", "isoCo2", "isoH2o", "h2oStor", "soni", "soniAmrs", "tempAirLvl", "tempAirTop")){ tmp <- lapply(inp, FUN = eddy4R.qaqc::def.qf.finl) } - #set qmBeta weight lower for picarro data products to account for variable sampling frequency - if (dp01 %in% c("isoCo2", "ch4Conc", "isoH2o")){ + #set qmBeta weight lower methane to account for lower sampling frequency + if (dp01 %in% c("ch4Conc")){ tmp <- lapply(inp, FUN = eddy4R.qaqc::def.qf.finl, WghtAlphBeta=c(2,0.2)) } From 5d01959cad0059770531d03970b9470b76f0adc5 Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 15 Nov 2021 14:28:31 +0000 Subject: [PATCH 154/168] moving dp0p download script --- flow/tool/flow.dnld.dp0p.hdf5.R | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 flow/tool/flow.dnld.dp0p.hdf5.R diff --git a/flow/tool/flow.dnld.dp0p.hdf5.R b/flow/tool/flow.dnld.dp0p.hdf5.R new file mode 100644 index 00000000..a77cbe12 --- /dev/null +++ b/flow/tool/flow.dnld.dp0p.hdf5.R @@ -0,0 +1,58 @@ +############################################################################################## +#' @title Workflow for downloading dp0p data from S3 + +#' @author +#' David Durden \email{eddy4R.info@gmail.com} + +#' @description +#' Workflow. Downloading dp0p data from S3. + +#' @param Currently none + +#' @return Currently none + +#' @references + +#' @keywords eddy-covariance, NEON + +#' @examples Currently none + +#' @seealso Currently none + +# changelog and author contributions / copyrights +# David (2020-01-25) +# original creation +############################################################################################## + +#site to download data for +site <- "STEI" +#domain +dom <- "D05" +#SAE system (ecte vs. ecse) +sys <- "ecte" + +#Create download folder, create if it doesn't exist +DirDnld <- paste0("~/eddy/data/turbTow/inpRefe/",site) +if(!dir.exists(DirDnld)) dir.create(DirDnld, recursive = TRUE) + +#Create data download string +DateBgn <- as.Date("2019-09-11") +DateEnd <- as.Date("2019-09-21") +DateSeq <- seq.Date(from = DateBgn,to = DateEnd, by = "day") +PrdWndwDnld <- base::as.character(DateSeq) + + + +#Filename base +fileInBase <- paste0("NEON.",dom,".",site,".IP0.00200.001.",sys,".") + +#Create URL for data files +urlDnld <- paste0("https://neon-ec-files.s3.data.neonscience.org/ods/dataproducts/IP0/",PrdWndwDnld,"/",site,"/",fileInBase,PrdWndwDnld,".l0p.h5") + +#Download filename (full path) +fileDnld <- paste0(DirDnld,"/",base::toupper(sys),"_dp0p_",site,"_",PrdWndwDnld,".h5") + +#Download files +sapply(seq_along(urlDnld), function(x){ +download.file(url = urlDnld[x], destfile = fileDnld[x]) +}) From 697db46c96405c1ab11342304f2d15869c307034 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Mon, 22 Nov 2021 17:30:05 +0000 Subject: [PATCH 155/168] changing qmBeta weighing assignment logic to if else so data products that get standard weights don't need to be specified by name --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R index b0babe25..fa997ed3 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.eddy.R @@ -97,13 +97,12 @@ wrap.dp01.qfqm.eddy <- function( lapply(names(inp), function(x) if (nrow(inp[[x]]) == 0) inp[[x]][1,] <<- -1) #calculate qmAlpha, qmBeta, qfFinl - if (dp01 %in% c("envHut", "co2Turb", "h2oTurb", "co2Stor", "isoCo2", "isoH2o", "h2oStor", "soni", "soniAmrs", "tempAirLvl", "tempAirTop")){ - tmp <- lapply(inp, FUN = eddy4R.qaqc::def.qf.finl) - } - #set qmBeta weight lower methane to account for lower sampling frequency + #set qmBeta weight lower for methane to account for lower sampling frequency, use default 2:1 weighing for all other data products if (dp01 %in% c("ch4Conc")){ tmp <- lapply(inp, FUN = eddy4R.qaqc::def.qf.finl, WghtAlphBeta=c(2,0.2)) + } else { + tmp <- lapply(inp, FUN = eddy4R.qaqc::def.qf.finl) } From 60c8297241db0ea3e00b90eb53599734f8efbf2f Mon Sep 17 00:00:00 2001 From: Liangying Zhang Date: Wed, 9 Feb 2022 19:51:43 -0700 Subject: [PATCH 156/168] missing commits from 1.3.0-rc7 --- pack/eddy4R.base/R/wrap.irga.vali.R | 37 ++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index d2959de8..f1308db3 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -85,6 +85,13 @@ # add thresholding based on benchmarking regression # Chris Florian (2021-08-09) # adding -1 flag for missing validations +# Chris Florian (2021-08-26) +# adding failsafe for extra validation gas rows +# Chris Florian (2021-08-27) +# retaining the rest of the rtioMoleDryCo2Cor for failed validations +# adding NaNs for meanCor with failed validations to keep structure the same +# Chris Florian (2021-08-27) +# resetting attributes on rtioMoleDryCo2Cor to fix issues when the corrected data was removed ############################################################################################## wrap.irga.vali <- function( @@ -518,7 +525,7 @@ wrap.irga.vali <- function( #remove corrected data if validation fails benchmarking test if (valiEval$valiEvalPass == FALSE){ - rpt[[DateProc]]$rtioMoleDryCo2Cor <- NaN + rpt[[DateProc]]$rtioMoleDryCo2Cor$rtioMoleDryCo2Cor <- NaN #raise quality flag in validation table to indicate validation status rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, 1) } else if (valiEval$valiEvalPass == TRUE) { @@ -535,13 +542,25 @@ wrap.irga.vali <- function( #add corrected reference gas values to vali table - rpt[[DateProc]]$rtioMoleDryCo2Vali$meanCor <- c(NaN, valiEval$meanCor) - #reorder to place the corrected reference values next to the original reference values - rpt[[DateProc]]$rtioMoleDryCo2Vali <- rpt[[DateProc]]$rtioMoleDryCo2Vali[c("mean", "min", "max", "vari", "numSamp", "rtioMoleDryCo2Refe", "meanCor", "timeBgn", "timeEnd")] - - #rename rtioMoleDryCo2Refe to refe, this could be implemented in the rest of the functions in the future - names(rpt[[DateProc]]$rtioMoleDryCo2Vali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "meanCor", "timeBgn", "timeEnd") + if(base::nrow(rpt[[DateProc]]$rtioMoleDryCo2Vali) == base::length(valiEval$meanCor)+1){ # failsafe for row mismatches, valiEval$meanCor will always be one short because the archive gas is not included + + rpt[[DateProc]]$rtioMoleDryCo2Vali$meanCor <- c(NaN, valiEval$meanCor) # need to add the NaN to account for the archive gas in the first position of the vali table + + #reorder to place the corrected reference values next to the original reference values + rpt[[DateProc]]$rtioMoleDryCo2Vali <- rpt[[DateProc]]$rtioMoleDryCo2Vali[c("mean", "min", "max", "vari", "numSamp", "rtioMoleDryCo2Refe", "meanCor", "timeBgn", "timeEnd")] + + #rename rtioMoleDryCo2Refe to refe, this could be implemented in the rest of the functions in the future + names(rpt[[DateProc]]$rtioMoleDryCo2Vali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "meanCor", "timeBgn", "timeEnd") + } else { + #fill meanCor with NaN if there were extra validation gas rows + rpt[[DateProc]]$rtioMoleDryCo2Vali$meanCor <- NaN + + #reorder to place the corrected reference values next to the original reference values + rpt[[DateProc]]$rtioMoleDryCo2Vali <- rpt[[DateProc]]$rtioMoleDryCo2Vali[c("mean", "min", "max", "vari", "numSamp", "rtioMoleDryCo2Refe", "meanCor", "timeBgn", "timeEnd")] + + names(rpt[[DateProc]]$rtioMoleDryCo2Vali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "meanCor", "timeBgn", "timeEnd") + } #rename rtioMoleDryH2oRefe to refe to match CO2 names(rpt[[DateProc]]$rtioMoleDryH2oVali) <- c("mean", "min", "max", "vari", "numSamp", "refe", "timeBgn", "timeEnd") @@ -557,7 +576,9 @@ wrap.irga.vali <- function( "molCo2 mol-1Dry",#gasRefeCor "NA", #"timeBgn" "NA")#"timeEnd" - + + attributes(rpt[[DateProc]]$rtioMoleDryCo2Cor$rtioMoleDryCo2Cor)$unit <- "molCo2 mol-1Dry" + #return results return(rpt) } From 50e37cdc40ff03ea5fef030d500d245ccf7d9e88 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Tue, 15 Feb 2022 20:08:10 +0000 Subject: [PATCH 157/168] fixing bug in logic to not run evaluation if there aren't enough refe and meas values, removing data if the valiEvalThsh is -1 --- pack/eddy4R.base/R/def.irga.vali.thsh.R | 2 +- pack/eddy4R.base/R/wrap.irga.vali.R | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.base/R/def.irga.vali.thsh.R b/pack/eddy4R.base/R/def.irga.vali.thsh.R index 50701986..ecf06553 100644 --- a/pack/eddy4R.base/R/def.irga.vali.thsh.R +++ b/pack/eddy4R.base/R/def.irga.vali.thsh.R @@ -75,7 +75,7 @@ def.irga.vali.thsh <- function( #run benchmarking least squares regression on corrected mean values from the reference gasses vs. the reference values #adding logic to avoid an error when one of the lists passed into lm() is entirely NA - if(all(!is.na(refeVals)) == TRUE & all(!is.na(meanCor)) == TRUE){ + if(sum(!is.na(refeVals)) > 1 & sum(!is.na(meanCor)) > 0){ #lm() will fail if one list is entirely NA, or if both lists have only one value. valiEval <- stats::lm(meanCor ~ refeVals) valiEvalSe <- sqrt(diag(vcov(valiEval))) valiEvalSlp <- valiEval$coefficient[[2]] diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index f1308db3..b594d9e1 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -525,13 +525,14 @@ wrap.irga.vali <- function( #remove corrected data if validation fails benchmarking test if (valiEval$valiEvalPass == FALSE){ - rpt[[DateProc]]$rtioMoleDryCo2Cor$rtioMoleDryCo2Cor <- NaN + rpt[[DateProc]]$rtioMoleDryCo2Cor$rtioMoleDryCo2Cor <- NaN #data are removed if the validation does not pass the thresholds set for evaluation slope and offset #raise quality flag in validation table to indicate validation status rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, 1) } else if (valiEval$valiEvalPass == TRUE) { - rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, 0) + rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, 0) #corrected data will be included in teh processed file in this case } else { rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, -1) + rpt[[DateProc]]$rtioMoleDryCo2Cor$rtioMoleDryCo2Cor <- NaN #also remove data in the -1 missing validation case, prevents unexpected inclusion of questionable validations and also removes data if the eval regression can't run due to lack of span gasses } #add additional coefficients to mlf table From 4623f1711b84c1e2f90226d010b19310f5fdb9ab Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Wed, 16 Feb 2022 01:25:58 +0000 Subject: [PATCH 158/168] adding log messages --- pack/eddy4R.base/R/def.irga.vali.thsh.R | 4 ++++ pack/eddy4R.base/R/wrap.irga.vali.R | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pack/eddy4R.base/R/def.irga.vali.thsh.R b/pack/eddy4R.base/R/def.irga.vali.thsh.R index ecf06553..5206d96e 100644 --- a/pack/eddy4R.base/R/def.irga.vali.thsh.R +++ b/pack/eddy4R.base/R/def.irga.vali.thsh.R @@ -37,6 +37,8 @@ # adding logic to prevent errors if data are missing # Chris Florian (2021-08-18) # updating terms to replace bnch with eval, adding additional coef outputs and adding offset criteria +# Chris Florian (2021-02-15) +# updating logic for failsafe to prevent lm() error due to missing values ############################################################################################## def.irga.vali.thsh <- function( @@ -81,6 +83,8 @@ def.irga.vali.thsh <- function( valiEvalSlp <- valiEval$coefficient[[2]] valiEvalOfst <- valiEval$coefficient[[1]] } else { + msg <- paste0("valiEval coefficients set to NA beacuse of insufficent refe or measured values") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) valiEval <- NA valiEvalSe <- NA valiEvalSlp <- NA diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index b594d9e1..ceafd67d 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -92,6 +92,8 @@ # adding NaNs for meanCor with failed validations to keep structure the same # Chris Florian (2021-08-27) # resetting attributes on rtioMoleDryCo2Cor to fix issues when the corrected data was removed +# Chris Florian (2021-02-15) +# setting corrected data to NaN if qfEvalThsh is -1 to prevent bad data passing through if the evaluation doesn't run ############################################################################################## wrap.irga.vali <- function( @@ -528,6 +530,8 @@ wrap.irga.vali <- function( rpt[[DateProc]]$rtioMoleDryCo2Cor$rtioMoleDryCo2Cor <- NaN #data are removed if the validation does not pass the thresholds set for evaluation slope and offset #raise quality flag in validation table to indicate validation status rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, 1) + msg <- paste0("validation did not pass evaluation threshold, corrected data were set to NaN") + tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) } else if (valiEval$valiEvalPass == TRUE) { rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, 0) #corrected data will be included in teh processed file in this case } else { From f2e1de29446466acae8c1b9fa4fe952f710e5936 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Thu, 3 Mar 2022 05:07:01 +0000 Subject: [PATCH 159/168] adding slope filters back to validation to account for observed data patterns that are not caught by the evaluation regression check --- pack/eddy4R.base/R/def.irga.vali.cor.R | 16 +++++++++------- pack/eddy4R.base/R/wrap.irga.vali.R | 18 ++++++++++++++---- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/pack/eddy4R.base/R/def.irga.vali.cor.R b/pack/eddy4R.base/R/def.irga.vali.cor.R index efaf4266..47b5d6ca 100644 --- a/pack/eddy4R.base/R/def.irga.vali.cor.R +++ b/pack/eddy4R.base/R/def.irga.vali.cor.R @@ -12,7 +12,7 @@ #' @param coef List consists of linear regression coefficients (slope and offset) for DateProc - 1, DateProc, and DateProc + 1. #' @param valiCrit A logical stating if there are more than one validation occurred within DateProc. #' @param ScalMax Maximum scale value. The validation correction will not apply if scale (resulted from maximum-likelihood fitting of a functional relationship (MLFR)) is greater than ScalMax or ScalMax = FALSE. Defaults to FALSE. -#' @param FracSlpMax Maximum fraction of slope value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the FracSlpMax or FracSlpMax = FALSE. Defaults to FALSE. +#' @param FracSlp Upper and lower bounds of slope values. The validation correction will not apply if slope (resulted from regression fitting) is greater/lower than the FracSlp maximum or minimum value or FracSlp = FALSE. Defaults to FALSE. #' @param OfstMax Maximum offset value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the OfstMax (unit in mol mol-1) or OfstMax = FALSE. Defaults to FALSE. #' @param Freq Measurement frequency. Defaults to 20. [Hz] @@ -59,6 +59,8 @@ # adding logical to handle the period that falling into the last day and first day of year # David Durden (2020-05-26) # Failsafe for when the valve is switched, but no validation occurs +# Chris Florian (2022-03-02) +# Updating the slope filter to allow for values not evenly centered around 1 ############################################################################################## def.irga.vali.cor <- function( data, @@ -67,7 +69,7 @@ def.irga.vali.cor <- function( valiData, valiCrit = FALSE, ScalMax = FALSE, - FracSlpMax = FALSE, + FracSlp = FALSE, OfstMax = FALSE, Freq = 20 ){ @@ -86,7 +88,7 @@ def.irga.vali.cor <- function( #create a list to keep all filters filt <- list() filt$ScalMax <- ScalMax - filt$FracSlpMax <- FracSlpMax + filt$FracSlp <- FracSlp filt$OfstMax <- OfstMax @@ -110,10 +112,10 @@ def.irga.vali.cor <- function( } }#end ScalMax - if (idxFilt == "FracSlpMax"){ + if (idxFilt == "FracSlp"){ #calculate minimum and maximum slope - minSlp <- 1 - FracSlpMax - maxSlp <- 1 + FracSlpMax + minSlp <- base::min(FracSlp) + maxSlp <- base::max(FracSlp) if (!is.na(coef[[idxDate]][[idxData]]$coef[2]) & (coef[[idxDate]][[idxData]]$coef[2] >= minSlp & coef[[idxDate]][[idxData]]$coef[2] <= maxSlp)){ coef[[idxDate]][[idxData]] <- coef[[idxDate]][[idxData]] } else { @@ -121,7 +123,7 @@ def.irga.vali.cor <- function( coef[[idxDate]][[idxData]]$se <- NA coef[[idxDate]][[idxData]]$scal <- NA } - }#end of FracSlpMax + }#end of FracSlp if (idxFilt == "OfstMax"){ if (!is.na(coef[[idxDate]][[idxData]]$coef[1]) & (abs(coef[[idxDate]][[idxData]]$coef[1]) <= OfstMax)){ diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index ceafd67d..ceb5d25c 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -11,7 +11,7 @@ #' @param gasRefe List containing the values of the reference gases. [mol mol-1] #' @param DateProc A vector of class "character" containing the processing date. #' @param ScalMax Maximum scale value. The validation correction will not apply if scale (resulted from maximum-likelihood fitting of a functional relationship (MLFR)) is greater than ScalMax or ScalMax = FALSE. Defaults to FALSE. -#' @param FracSlpMax Maximum fraction of slope value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the FracSlpMax or FracSlpMax = FALSE. Defaults to FALSE. +#' @param FracSlp Upper and lower bounds of slope values. The validation correction will not apply if slope (resulted from regression fitting) is greater/lower than the FracSlp maximum or minimum value or FracSlp = FALSE. Defaults to FALSE. #' @param OfstMax Maximum offset value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the OfstMax (unit in mol mol-1) or OfstMax = FALSE. Defaults to FALSE. @@ -94,6 +94,8 @@ # resetting attributes on rtioMoleDryCo2Cor to fix issues when the corrected data was removed # Chris Florian (2021-02-15) # setting corrected data to NaN if qfEvalThsh is -1 to prevent bad data passing through if the evaluation doesn't run +# Chris Florian (2022-03-02) +# Updating the slope filter to allow for values not evenly centered around 1 ############################################################################################## wrap.irga.vali <- function( @@ -102,7 +104,7 @@ wrap.irga.vali <- function( gasRefe, DateProc, ScalMax = FALSE, - FracSlpMax = FALSE, + FracSlp = FALSE, OfstMax = FALSE ) { @@ -520,7 +522,7 @@ wrap.irga.vali <- function( #applying the calculated coefficients to measured data #Calculate time-series (20Hz) of slope and zero offset - rpt[[DateProc]]$rtioMoleDryCo2Cor <- eddy4R.base::def.irga.vali.cor(data = data, DateProc = DateProc, coef = tmpCoef, valiData = valiData, valiCrit = valiCrit, ScalMax = ScalMax, FracSlpMax = FracSlpMax, OfstMax = OfstMax, Freq = 20) + rpt[[DateProc]]$rtioMoleDryCo2Cor <- eddy4R.base::def.irga.vali.cor(data = data, DateProc = DateProc, coef = tmpCoef, valiData = valiData, valiCrit = valiCrit, ScalMax = ScalMax, FracSlp = FracSlp, OfstMax = OfstMax, Freq = 20) #run the benchmarking regression to determine if the validation was good valiEval <- eddy4R.base::def.irga.vali.thsh(data = rpt[[DateProc]], DateProc = DateProc, evalSlpMax = 1.05, evalSlpMin = 0.95, evalOfstMax = 100, evalOfstMin = -100) @@ -533,12 +535,20 @@ wrap.irga.vali <- function( msg <- paste0("validation did not pass evaluation threshold, corrected data were set to NaN") tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) } else if (valiEval$valiEvalPass == TRUE) { - rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, 0) #corrected data will be included in teh processed file in this case + rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, 0) #corrected data will be included in the processed file in this case } else { rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, -1) rpt[[DateProc]]$rtioMoleDryCo2Cor$rtioMoleDryCo2Cor <- NaN #also remove data in the -1 missing validation case, prevents unexpected inclusion of questionable validations and also removes data if the eval regression can't run due to lack of span gasses } + #force qfValiEval to -1 if slope is outside the threshold because this validation can't be applied + + if (rpt[[DateProc]]$rtioMoleDryCo2Mlf$coef[2] < base::min(FracSlp) | rpt[[DateProc]]$rtioMoleDryCo2Mlf$coef[2] > base::max(FracSlp)){ + rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, -1) + } + + + #add additional coefficients to mlf table rpt[[DateProc]]$rtioMoleDryCo2Mlf$evalCoef <- valiEval$evalCoef rpt[[DateProc]]$rtioMoleDryCo2Mlf$evalCoefSe <- valiEval$evalCoefSe From ccaae04b0390048cefa9131f450c2f26a2a604b6 Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 21 Mar 2022 14:55:26 +0000 Subject: [PATCH 160/168] - updating GCS --- flow/tool/flow.dnld.dp0p.hdf5.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow/tool/flow.dnld.dp0p.hdf5.R b/flow/tool/flow.dnld.dp0p.hdf5.R index a77cbe12..50bc649b 100644 --- a/flow/tool/flow.dnld.dp0p.hdf5.R +++ b/flow/tool/flow.dnld.dp0p.hdf5.R @@ -47,7 +47,7 @@ PrdWndwDnld <- base::as.character(DateSeq) fileInBase <- paste0("NEON.",dom,".",site,".IP0.00200.001.",sys,".") #Create URL for data files -urlDnld <- paste0("https://neon-ec-files.s3.data.neonscience.org/ods/dataproducts/IP0/",PrdWndwDnld,"/",site,"/",fileInBase,PrdWndwDnld,".l0p.h5") +urlDnld <- paste0("https://storage.cloud.google.com/neon-sae-files/ods/dataproducts/IP0/",PrdWndwDnld,"/",site,"/",fileInBase,PrdWndwDnld,".l0p.h5") #Download filename (full path) fileDnld <- paste0(DirDnld,"/",base::toupper(sys),"_dp0p_",site,"_",PrdWndwDnld,".h5") From 769205e306923e7dcc22d396aaa696c63c8804bb Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Tue, 29 Mar 2022 19:09:30 +0000 Subject: [PATCH 161/168] add NA check to slope thresholding --- pack/eddy4R.base/R/wrap.irga.vali.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.base/R/wrap.irga.vali.R b/pack/eddy4R.base/R/wrap.irga.vali.R index ceb5d25c..5ef04bf1 100644 --- a/pack/eddy4R.base/R/wrap.irga.vali.R +++ b/pack/eddy4R.base/R/wrap.irga.vali.R @@ -543,12 +543,14 @@ wrap.irga.vali <- function( #force qfValiEval to -1 if slope is outside the threshold because this validation can't be applied - if (rpt[[DateProc]]$rtioMoleDryCo2Mlf$coef[2] < base::min(FracSlp) | rpt[[DateProc]]$rtioMoleDryCo2Mlf$coef[2] > base::max(FracSlp)){ - rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, -1) + if(!is.na(rpt[[DateProc]]$rtioMoleDryCo2Mlf$coef[2])){ # only run if there are coefficients to check + + if (rpt[[DateProc]]$rtioMoleDryCo2Mlf$coef[2] < base::min(FracSlp) | rpt[[DateProc]]$rtioMoleDryCo2Mlf$coef[2] > base::max(FracSlp)){ + rpt[[DateProc]]$rtioMoleDryCo2Mlf$qfEvalThsh <- c(NA, -1) + } } - #add additional coefficients to mlf table rpt[[DateProc]]$rtioMoleDryCo2Mlf$evalCoef <- valiEval$evalCoef rpt[[DateProc]]$rtioMoleDryCo2Mlf$evalCoefSe <- valiEval$evalCoefSe From e39a70adad283bc24d8ee74d00117e8fe10e1794 Mon Sep 17 00:00:00 2001 From: daviddurden Date: Tue, 19 Apr 2022 16:18:17 +0000 Subject: [PATCH 162/168] - updating goldfile links to GCS --- pack/eddy4R.base/R/def.hdf5.crte.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack/eddy4R.base/R/def.hdf5.crte.R b/pack/eddy4R.base/R/def.hdf5.crte.R index adea1618..5dfa3d42 100755 --- a/pack/eddy4R.base/R/def.hdf5.crte.R +++ b/pack/eddy4R.base/R/def.hdf5.crte.R @@ -104,7 +104,7 @@ def.hdf5.crte <- function( DirTmp <- tempdir() #Download file description readme and object list - eddy4R.base::def.dld.zip(Inp = list(Url = "https://s3.data.neonscience.org/neon-ec-goldfiles/EC-turbulence-processing/fileDesc.zip", Dir = DirTmp)) + eddy4R.base::def.dld.zip(Inp = list(Url = "https://storage.googleapis.com/neon-ec-goldfiles/EC-turbulence-processing/fileDesc.zip", Dir = DirTmp)) #Store the path to the readme file FileNameReadMe <- base::list.files( path = base::paste0(DirTmp,"/fileDesc"), pattern = ".txt", full.names = TRUE) From 0f7d42e3f7c728977e45e41d17a6188137fa15ae Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Tue, 10 May 2022 00:52:12 +0000 Subject: [PATCH 163/168] updating to use SOM API function --- pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R | 69 ++++++++++++++++++++- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R index abbf8e61..44358ba3 100755 --- a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R +++ b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R @@ -49,6 +49,8 @@ # convert qmBeta and qmAlph to fraction # David Durden(2020-07-02) # updating function to check physical locations of reingest sensors exist before pulling from API +# Chris Florian (2022-05-09) +# updating to use SOM API function due to Noble package bug that replicated data from the highest horver in a missing horver ############################################################################################## def.hdf5.wrte.dp01.api <- function( @@ -74,7 +76,7 @@ date <- lubridate::as_datetime(date) #get only year and month yearMnth <- as.character.Date(date, format = "%Y-%m") -timeBgn <- date - lubridate::seconds(1) +timeBgn <- date timeEnd <- date + lubridate::days(1) @@ -117,10 +119,71 @@ if(DpName == "presBaro") TblName <- c("presCor", "presAtm") #Grab 30 minute data to be written msg <- paste0("downloading ", TimeAgr, " min data from the portal") tryCatch({rlog$debug(msg)}, error=function(cond){print(msg)}) -data <- try(expr = Noble::pull.date(site = SiteLoca, dpID = DpNum, bgn.date = timeBgn, end.date = timeEnd, package = "expanded", time.agr = TimeAgr), silent = TRUE) #Currently requires to subtract 1 minute otherwise (1 index will be cut from the beginning) +#old Noble data pull +#data <- try(expr = Noble::pull.date(site = SiteLoca, dpID = DpNum, bgn.date = timeBgn, end.date = timeEnd, package = "expanded", time.agr = TimeAgr), silent = TRUE) #Currently requires to subtract 1 minute otherwise (1 index will be cut from the beginning) + +data <- list() + +for(idxLvl in LvlTowr[[DpName]]){ + #idxLvl <- LvlTowr[[DpName]][2] + #extract hor and ver for each data product as a character string of three values e.g. "000" and "010" + locHor <- substr(idxLvl, start = 1, stop = 3) + locVer <- substr(idxLvl, start = 5, stop = 7) + #pad TimeAgr with zero/s to fit the expected three digit format for wndwAgr + if(nchar(TimeAgr) == 1){ + wndwAgr <- paste0("00", TimeAgr) + } else if(nchar(TimeAgr) == 2){ + wndwAgr <- paste0("0", TimeAgr) + } + + data[[idxLvl]] <- try(expr = som::def.neon.api.get.data(site = SiteLoca, idDpMain = DpNum, locHor = locHor, locVer = locVer, wndwAgr = wndwAgr, year = lubridate::year(timeBgn), mnth = lubridate::month(timeBgn), Pack = "expanded"), silent = TRUE) #need to generalize TimeAgr to wndwAgr, Time Agr is 1,30 and wndwAgr needs "001" and "030" + +} + +#compile noble-like data format if not all the datasets have a try-error class +if(!all(sapply(data, class) == "try-error")){ + #fill in the try error datasets and paste horver to names + for(idxLvl in 1:length(data)){ + if(class(data[[idxLvl]]) == "try-error"){ + #find the first dataset that wasn't a try error + whrData <- which(lapply(data,class) == "data.frame")[1] + #get timestamps + timeBgnOut <- data[[whrData]][which(grepl(x = names(data[[whrData]]), pattern = "startdatetime", ignore.case = T))] + timeEndOut <- data[[whrData]][which(grepl(x = names(data[[whrData]]), pattern = "enddatetime", ignore.case = T))] + colNamesOut <- colnames(data[[whrData]]) + #create dataframe of NaNs to fill with + dataFill <- data.frame(matrix("NaN", nrow=nrow(timeBgnOut), ncol=length(colnames(data[[whrData]])[which(!grepl(x = names(data[[whrData]]), pattern = "time", ignore.case = T))]))) + #create placeholder data.frame + data[[idxLvl]] <- data.frame(timeBgnOut, timeEndOut, dataFill) + #apply names + colnames(data[[idxLvl]]) <- colNamesOut + #remove data fill + rm(dataFill) + #fill QFQM + data[[idxLvl]]$alphaQM <- 0.0 + data[[idxLvl]]$betaQM <- 1.0 + data[[idxLvl]]$finalQF <- 1L + data[[idxLvl]]$finalQFSciRvw <- 0L + } + #idxLvl <- 1 + LocMeas <- gsub("\\_", ".", names(data[idxLvl])) + #append horver to names of each ML's dataset + colnames(data[[idxLvl]])[which(!grepl(x = names(data[[idxLvl]]), pattern = "time", ignore.case = T))] <- + paste0(colnames(data[[idxLvl]][which(!grepl(x = names(data[[idxLvl]]), pattern = "time", ignore.case = T))]), ".", LocMeas) + } +} + +#join list of data into wide format + +data <- data.frame(base::Reduce(function(x, y) merge(x, y, all=TRUE), data)) + +#restrict API data to the processing date, TODO: is there any way to grab data from the API for just one day? + +data <- data[grep(pattern = date, x = data$startDateTime),] + #Failsafe test if API pull produced an error -if(class(data) == "try-error"){ +if(all(sapply(data, class) == "try-error")){ #Initialize lists rpt <- list(data = list(), qfqm = list(), ucrt = list()) #get sensor HOR and VER From fa80b10e1fa9522ba19bfc5bf8a31c670a5d12a7 Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Tue, 10 May 2022 18:43:46 +0000 Subject: [PATCH 164/168] fixing issues found in testing --- pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R index 44358ba3..9d0160ab 100755 --- a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R +++ b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R @@ -152,7 +152,7 @@ if(!all(sapply(data, class) == "try-error")){ timeEndOut <- data[[whrData]][which(grepl(x = names(data[[whrData]]), pattern = "enddatetime", ignore.case = T))] colNamesOut <- colnames(data[[whrData]]) #create dataframe of NaNs to fill with - dataFill <- data.frame(matrix("NaN", nrow=nrow(timeBgnOut), ncol=length(colnames(data[[whrData]])[which(!grepl(x = names(data[[whrData]]), pattern = "time", ignore.case = T))]))) + dataFill <- data.frame(matrix(NaN, nrow=nrow(timeBgnOut), ncol=length(colnames(data[[whrData]])[which(!grepl(x = names(data[[whrData]]), pattern = "time", ignore.case = T))]))) #create placeholder data.frame data[[idxLvl]] <- data.frame(timeBgnOut, timeEndOut, dataFill) #apply names @@ -171,15 +171,18 @@ if(!all(sapply(data, class) == "try-error")){ colnames(data[[idxLvl]])[which(!grepl(x = names(data[[idxLvl]]), pattern = "time", ignore.case = T))] <- paste0(colnames(data[[idxLvl]][which(!grepl(x = names(data[[idxLvl]]), pattern = "time", ignore.case = T))]), ".", LocMeas) } + + #join list of data into wide format + + data <- data.frame(base::Reduce(function(x, y) merge(x, y, all=TRUE), data)) + + #restrict API data to the processing date, TODO: is there any way to grab data from the API for just one day? + + data <- data[grep(pattern = date, x = data$startDateTime),] + } -#join list of data into wide format - -data <- data.frame(base::Reduce(function(x, y) merge(x, y, all=TRUE), data)) - -#restrict API data to the processing date, TODO: is there any way to grab data from the API for just one day? -data <- data[grep(pattern = date, x = data$startDateTime),] #Failsafe test if API pull produced an error @@ -253,7 +256,7 @@ if(all(sapply(data, class) == "try-error")){ } else { #Convert times to POSIXct -data$startDateTime <- as.POSIXct(data$startDateTime) +data$startDateTime <- as.POSIXct(data$startDateTime, format = "%Y-%m-%dT%H:%M:%OSZ", tz = "UTC") data$endDateTime <- as.POSIXct(data$endDateTime, format = "%Y-%m-%dT%H:%M:%OSZ", tz = "UTC") From 31722b3128077e895c7ccf42fe90a1e8a163bdbe Mon Sep 17 00:00:00 2001 From: cflorian1 Date: Sat, 21 May 2022 00:09:27 +0000 Subject: [PATCH 165/168] timestamp formatting bug fix --- pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R index 9d0160ab..2ba18901 100755 --- a/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R +++ b/pack/eddy4R.base/R/def.hdf5.wrte.dp01.api.R @@ -199,10 +199,10 @@ if(all(sapply(data, class) == "try-error")){ names(LvlMeasOut) <- LvlMeas #Create the timeBgn vector for aggregation period specified (1, 30 minutes) - timeBgnOut <- seq(from = lubridate::ymd_hms(timeBgn) + lubridate::seconds(1), to = base::as.POSIXlt(timeEnd) - lubridate::minutes(TimeAgr), by = paste(TimeAgr, "mins", sep = " ")) + timeBgnOut <- seq(from = timeBgn + lubridate::seconds(1), to = base::as.POSIXlt(timeEnd) - lubridate::minutes(TimeAgr), by = paste(TimeAgr, "mins", sep = " ")) #Create the timeEnd vector for aggregation period specified (1, 30 minutes) - timeEndOut <- seq(from = lubridate::ymd_hms(timeBgn) + lubridate::minutes(TimeAgr)+ lubridate::seconds(1), to = base::as.POSIXlt(timeEnd), by = paste(TimeAgr, "mins", sep = " ")) + timeEndOut <- seq(from = timeBgn + lubridate::minutes(TimeAgr)+ lubridate::seconds(1), to = base::as.POSIXlt(timeEnd), by = paste(TimeAgr, "mins", sep = " ")) #Creating a vector of NaN's to fill data.frames dataNa <- rep(x = NaN, length = length(timeBgnOut)) From 71f5b903dc7195e00a25aa5500befa638768f805 Mon Sep 17 00:00:00 2001 From: Rich Fiorella Date: Tue, 20 Sep 2022 13:22:46 -0600 Subject: [PATCH 166/168] Change isoCo2 to 6 minute product following ATM ISO TWG analysis --- pack/eddy4R.stor/R/wrap.dp01.ecse.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index a8e6e804..f226663d 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -80,6 +80,8 @@ # adding rtioMoleDryCh4Refe data to validation time period # Chris Florian # updating the columns used to select data from 15 to 8 for ch4Conc to get rid of extra dataframes +# Rich Fiorella (2022-09-20) +# based on analysis done for ATM ISO TWG, changing isoCo2 to 6 minute product from 9 minute ############################################################################################## wrap.dp01.ecse <- function( dp01 = c("co2Stor", "h2oStor", "tempAirLvl", "tempAirTop", "isoCo2", "isoH2o", "ch4Conc")[1], @@ -634,16 +636,16 @@ wrap.dp01.ecse <- function( #subset only wrk$qfqm$crdCo2 <- qfInp$crdCo2[[lvl]] - if (PrdMeas == PrdAgr) { - #PrdAgr <- 9 - #9 minutely sampling data + if (PrdMeas == PrdAgr) { + #PrdAgr <- 6 # RF - now a 6 minute product based on TWG input! + #6 minutely sampling data #idxLvLPrdAgr <- paste0(lvl, "_", sprintf("%02d", PrdAgr), "m") #rpt[[dp01]][[idxLvLPrdAgr]] <- list() #if there is at least one measurement if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ #determine the index of each measurement - wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 240) #delete row if last timeBgn and timeEnd is NA wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] #if last timeEnd is NA, replce that time to the last time value in data$time From faa74ccd90c433a577aca2a983fdb0dfc6415541 Mon Sep 17 00:00:00 2001 From: ddurden Date: Wed, 9 Nov 2022 19:56:01 +0000 Subject: [PATCH 167/168] - updating time removal at beginning of measurements for isoCo2 and correcting total time for qfqm and ucrt --- pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R | 8 ++++---- pack/eddy4R.stor/R/wrap.dp01.ecse.R | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R index 23be24be..418fd5b1 100644 --- a/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R +++ b/pack/eddy4R.qaqc/R/wrap.dp01.qfqm.ecse.R @@ -721,7 +721,7 @@ wrap.dp01.qfqm.ecse <- function( #if there is at least one measurement if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ #determine the index of each measurement - wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 240) #delete row if last timeBgn and timeEnd is NA wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] #replace last idxEnd > 86400 by 86400 @@ -808,7 +808,7 @@ wrap.dp01.qfqm.ecse <- function( if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ #determine the index of each measurement - wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 240) #delete row if last timeBgn and timeEnd is NA wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] #if last timeEnd is NA, replce that time to the last time value in data$time @@ -909,7 +909,7 @@ wrap.dp01.qfqm.ecse <- function( #if there is at least one measurement if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ #determine the end time of each measurement - wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 240) #delete row if last timeBgn and timeEnd is NA wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] #if last timeEnd is NA, replce that time to the last time value in data$time @@ -999,7 +999,7 @@ wrap.dp01.qfqm.ecse <- function( #if there is at least one measurement if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ # #determine the end time of each measurement - wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 240) #delete row if last timeBgn and timeEnd is NA wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] #if last timeEnd is NA, replce that time to the last time value in data$time diff --git a/pack/eddy4R.stor/R/wrap.dp01.ecse.R b/pack/eddy4R.stor/R/wrap.dp01.ecse.R index f226663d..0bbd1832 100644 --- a/pack/eddy4R.stor/R/wrap.dp01.ecse.R +++ b/pack/eddy4R.stor/R/wrap.dp01.ecse.R @@ -730,7 +730,7 @@ wrap.dp01.ecse <- function( if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ #determine the index of each measurement - wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 240) #delete row if last timeBgn and timeEnd is NA wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] #if last timeEnd is NA, replce that time to the last time value in data$time @@ -840,7 +840,7 @@ wrap.dp01.ecse <- function( #if there is at least one measurement if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ #determine the end time of each measurement - wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 240) #delete row if last timeBgn and timeEnd is NA wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] #if last timeEnd is NA, replce that time to the last time value in data$time @@ -918,7 +918,7 @@ wrap.dp01.ecse <- function( #if there is at least one measurement if(length(which(!is.na(wrk$qfqm$crdCo2$qfRngTemp))) > 0){ # #determine the end time of each measurement - wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 60) + wrk$idx <- eddy4R.base::def.idx.agr(time = data$time, PrdAgr = (PrdMeas*60), FreqLoca = 1, MethIdx = "specBgn", data = wrk$qfqm$crdCo2$qfRngTemp, CritTime = 240) #delete row if last timeBgn and timeEnd is NA wrk$idx <- wrk$idx[rowSums(is.na(wrk$idx)) != 2,] #if last timeEnd is NA, replce that time to the last time value in data$time From 02d8a4ae5ddb085f16b5e20a5ce45095e78d2e1c Mon Sep 17 00:00:00 2001 From: ddurden Date: Mon, 14 Nov 2022 05:33:20 +0000 Subject: [PATCH 168/168] - repackaging --- pack/eddy4R.base/man/def.irga.vali.cor.Rd | 4 ++-- pack/eddy4R.base/man/wrap.irga.vali.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pack/eddy4R.base/man/def.irga.vali.cor.Rd b/pack/eddy4R.base/man/def.irga.vali.cor.Rd index be94dd21..d88f5f4c 100644 --- a/pack/eddy4R.base/man/def.irga.vali.cor.Rd +++ b/pack/eddy4R.base/man/def.irga.vali.cor.Rd @@ -11,7 +11,7 @@ def.irga.vali.cor( valiData, valiCrit = FALSE, ScalMax = FALSE, - FracSlpMax = FALSE, + FracSlp = FALSE, OfstMax = FALSE, Freq = 20 ) @@ -29,7 +29,7 @@ def.irga.vali.cor( \item{ScalMax}{Maximum scale value. The validation correction will not apply if scale (resulted from maximum-likelihood fitting of a functional relationship (MLFR)) is greater than ScalMax or ScalMax = FALSE. Defaults to FALSE.} -\item{FracSlpMax}{Maximum fraction of slope value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the FracSlpMax or FracSlpMax = FALSE. Defaults to FALSE.} +\item{FracSlp}{Upper and lower bounds of slope values. The validation correction will not apply if slope (resulted from regression fitting) is greater/lower than the FracSlp maximum or minimum value or FracSlp = FALSE. Defaults to FALSE.} \item{OfstMax}{Maximum offset value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the OfstMax (unit in mol mol-1) or OfstMax = FALSE. Defaults to FALSE.} diff --git a/pack/eddy4R.base/man/wrap.irga.vali.Rd b/pack/eddy4R.base/man/wrap.irga.vali.Rd index d53301fb..177d7805 100644 --- a/pack/eddy4R.base/man/wrap.irga.vali.Rd +++ b/pack/eddy4R.base/man/wrap.irga.vali.Rd @@ -10,7 +10,7 @@ wrap.irga.vali( gasRefe, DateProc, ScalMax = FALSE, - FracSlpMax = FALSE, + FracSlp = FALSE, OfstMax = FALSE ) } @@ -25,7 +25,7 @@ wrap.irga.vali( \item{ScalMax}{Maximum scale value. The validation correction will not apply if scale (resulted from maximum-likelihood fitting of a functional relationship (MLFR)) is greater than ScalMax or ScalMax = FALSE. Defaults to FALSE.} -\item{FracSlpMax}{Maximum fraction of slope value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the FracSlpMax or FracSlpMax = FALSE. Defaults to FALSE.} +\item{FracSlp}{Upper and lower bounds of slope values. The validation correction will not apply if slope (resulted from regression fitting) is greater/lower than the FracSlp maximum or minimum value or FracSlp = FALSE. Defaults to FALSE.} \item{OfstMax}{Maximum offset value. The validation correction will not apply if slope (resulted from regression fitting) is greater than the OfstMax (unit in mol mol-1) or OfstMax = FALSE. Defaults to FALSE.} }