From de1596fef689e99037ef2df8a69fc4d271247aed Mon Sep 17 00:00:00 2001 From: amcook Date: Fri, 8 May 2020 13:02:06 -0300 Subject: [PATCH 01/11] Adding in functionality for RODBC and use_local files. Also added some more error catches --- DESCRIPTION | 5 ++-- NAMESPACE | 3 ++- R/ilts.operations.R | 56 +++++++++++++++++++++++++++++++++------------ Readme.txt | 21 ++++++++++++----- 4 files changed, 62 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5d0afae..f3c9f65 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,8 +14,9 @@ Imports: tcltk, gWidgets2, gWidgets2tcltk, - ROracle, DBI, netmensuration, lubridate, - stringr + stringr, + RODBC, + ROracle diff --git a/NAMESPACE b/NAMESPACE index ea94497..9785c69 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,10 +6,11 @@ export(get.oracle.table) export(ilts.format.merge) export(init.project.vars) import(DBI) -import(ROracle) import(gWidgets2) import(gWidgets2tcltk) import(lubridate) import(netmensuration) import(stringr) import(tcltk) +import(RODBC) +import(ROracle) \ No newline at end of file diff --git a/R/ilts.operations.R b/R/ilts.operations.R index 16ca604..f1c2ab7 100644 --- a/R/ilts.operations.R +++ b/R/ilts.operations.R @@ -4,6 +4,7 @@ assign('manual.archive', "", pkg.env) assign('oracle.server', "", pkg.env) assign('oracle.user', "", pkg.env) assign('oracle.password', "", pkg.env) +options(stringsAsFactors = F) #' @title init.project.vars #' @description Set global database variables by user account @@ -13,9 +14,9 @@ init.project.vars = function() { if(exists("bio.datadirectory.ilts")){ assign('manual.archive', bio.datadirectory.ilts , pkg.env) } - else{ + if(!exists("bio.datadirectory.ilts")){ + print('A window will open that you need to choose the working folder.') assign('manual.archive', gWidgets2::gfile(text = "Select project work directory", type = "selectdir"), pkg.env) - } #Take from snowcrab users .Rprofile.site @@ -79,22 +80,28 @@ esonar2df = function(esonar = NULL) { return(esonar) } -#' @title get.acoustic.releases +#' @title get.oracle.table #' @description Get data from Oracle Database table -#' @import ROracle DBI +#' @import ROracle DBI RODBC #' @param tn tablename to get #' @param oracle.user your oracle username #' @param oracle.password your oracle password #' @return dataframe #' @export -get.oracle.table = function(tn = "",server = pkg.env$oracle.server, user =pkg.env$oracle.user, password = pkg.env$oracle.password){ +get.oracle.table = function(tn = "",server = pkg.env$oracle.server, user =pkg.env$oracle.user, password = pkg.env$oracle.password, RODBC=F){ if(tn == "")stop("You must provide a tablename to 'get.oracle.table'!!") - +if(!RODBC){ drv <- dbDriver("Oracle") con <- ROracle::dbConnect(drv, username = user, password = password, dbname = server) res <- ROracle::dbSendQuery(con, paste("select * from ", tn, sep="")) res <- fetch(res) ROracle::dbDisconnect(con) +} +if(RODBC) { + drv = odbcConnect(dsn = server ,uid = user, pwd = password) + res = sqlQuery(drv,paste("select * from ", tn,";", sep="")) + odbcCloseAll() + } return(res) } @@ -107,7 +114,7 @@ get.oracle.table = function(tn = "",server = pkg.env$oracle.server, user =pkg.en #' @import netmensuration lubridate #' @return list of lists. Format (top to bottom) year-set-data #' @export -ilts.format.merge = function(update = TRUE, user = "", years = ""){ +ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, use_local=F, sensor.file='ILTS_SENSORS_TEMP.csv', minilog.file = 'MINILOG_TEMP.csv', seabird.file = 'ILTS_TEMPERATURE.csv'){ #Set up database server, user and password init.project.vars() @@ -133,12 +140,19 @@ ilts.format.merge = function(update = TRUE, user = "", years = ""){ plotdata = F #Alternative plotting that we do not require #Pull in the sensor data, this will be formatted and looped thru by trip then set. - esona = get.oracle.table(tn = "FRAILC.ILTS_SENSORS_TEMP") + if(!use_local) { esona = get.oracle.table(tn = "FRAILC.ILTS_SENSORS_TEMP", RODBC=use_RODBC) + write.csv(esona,file=file.path(pkg.env$manual.archive, 'raw', 'ILTS_SENSORS_TEMP.csv'),row.names = F) + } + if(use_local) esona = read.csv(file.path(pkg.env$manual.archive, 'raw', sensor.file)) + esona$GPSTIME[which(nchar(esona$GPSTIME)==5)] = paste("0", esona$GPSTIME[which(nchar(esona$GPSTIME)==5)], sep="") esona$timestamp = lubridate::ymd_hms(paste(as.character(lubridate::date(esona$GPSDATE)), esona$GPSTIME, sep=" "), tz="UTC" ) esona = esona[ order(esona$timestamp , decreasing = FALSE ),] err = which(is.na(esona$timestamp)) - if(length(err)>0)esona = esona[-err,] + if(length(err)>0){ + cat(paste('Errors in time stamps for TRIP_NO--SETS'),unique(paste(esona$TRIP_ID[err],'--',esona$SET_NO[err],sep=""))) + esona = esona[-err,] + } esona$LATITUDE = format.lol(x = esona$LATITUDE) esona$LONGITUDE = format.lol(x = esona$LONGITUDE) #If specific years desired filter unwanted @@ -148,18 +162,27 @@ ilts.format.merge = function(update = TRUE, user = "", years = ""){ if(length(yind)>0)esona = esona[yind,] if(length(esona$timestamp)==0)stop("No data found for your year selection!") } - mini = get.oracle.table(tn = "FRAILC.MINILOG_TEMP") + if(!use_local) { + mini = get.oracle.table(tn = "FRAILC.MINILOG_TEMP", RODBC = use_RODBC) + write.csv(mini,file=file.path(pkg.env$manual.archive, 'raw', 'MINILOG_TEMP.csv'),row.names = F) + } + if(use_local) mini = read.csv(file.path(pkg.env$manual.archive, 'raw', minilog.file)) + #rebuild datetime column as it is incorrect and order mini$timestamp = lubridate::ymd_hms(paste(as.character(lubridate::date(mini$TDATE)), mini$TIME, sep=" "), tz="UTC" ) mini = mini[ order(mini$timestamp , decreasing = FALSE ),] #seab = get.oracle.table(tn = "LOBSTER.ILTS_TEMPERATURE") - - seabf = get.oracle.table(tn = "FRAILC.ILTS_TEMPERATURE") + if(!use_local) { + seabf = get.oracle.table(tn = "FRAILC.ILTS_TEMPERATURE",RODBC = use_RODBC) + write.csv(seabf,file=file.path(pkg.env$manual.archive, 'raw', 'ILTS_TEMPERATURE.csv'),row.names = F) + } + if(use_local) seabf = read.csv(file.path(pkg.env$manual.archive, 'raw', seabird.file)) + #rebuild datetime column as it is incorrect and order seabf$timestamp = lubridate::ymd_hms(paste(as.character(lubridate::date(seabf$UTCDATE)), seabf$UTCTIME, sep=" "), tz="UTC" ) seabf = seabf[ order(seabf$timestamp , decreasing = FALSE ),] - + #Loop through each esonar file to convert and merge with temp eson = split(esona, esona$TRIP_ID) for(i in 1:length(eson)){ @@ -218,7 +241,11 @@ ilts.format.merge = function(update = TRUE, user = "", years = ""){ mergset = merge(mergset, timestamp, "timestamp", all = TRUE) mergset$timestamp = lubridate::ymd_hms(as.character(mergset$timestamp), tz="UTC" ) #Find deepest point and extend possible data from that out to 20min on either side - aredown = mergset$timestamp[which(mergset$depth == max(mergset$depth, na.rm = T))] + + NoDeps = all(is.na(mergset$depth)) + if(NoDeps) cat("\n",paste('No depth info for Trip-Setno='),unique(paste(mergset$Trip,mergset$Setno,sep="-"))) + if(!NoDeps){ + aredown = mergset$timestamp[which(mergset$depth == max(mergset$depth, na.rm = T))] time.gate = list( t0=as.POSIXct(aredown)-lubridate::dminutes(20), t1=as.POSIXct(aredown)+lubridate::dminutes(20) ) # Build the variables need for the proper execution of the bottom contact function from @@ -310,6 +337,7 @@ ilts.format.merge = function(update = TRUE, user = "", years = ""){ } iltsStats[[paste(unique(na.omit(set$Trip)), unique(na.omit(set$Setno)),sep=".")]] = bc + } #end if no depth }#END Update clause } }#END Set subset diff --git a/Readme.txt b/Readme.txt index e75ceee..193137b 100644 --- a/Readme.txt +++ b/Readme.txt @@ -5,7 +5,7 @@ To Install library(devtools) install_github("jae0/netmensuration") install_github("brent0/ILTS.sensor") - install_github("brent0/ILTS.sensor", INSTALL_opts=c("--no-multiarch")) + install_github(""brent0/ILTS.sensor"", INSTALL_opts=c("--no-multiarch")) To Develop @@ -13,17 +13,26 @@ To Develop enter this url https://github.com/brent0/ILTS.sensor.git let me know so I can add your git account as contributor or you can fork the code for your own project. -To Avoid entering project variables in the dialog prompts, set the following in your Rprofile.site file +To Avoid entering project variables in the dialog prompts, set the following in your Rprofile.site file or to the top of your script. - oracle.snowcrab.server = "ptran" + oracle.snowcrab.server = "ptran" oracle.snowcrab.user = "your oracle username" oracle.snowcrab.password = "your oracle password" - bio.datadirectory.ilts = file.path( "C:", "bio.data", "ilts") replace with desired path + bio.datadirectory.ilts = file.path( "C:", "bio.data", "ilts") #replace with desired path + dir.create(file.path(bio.datadirectory.ilts,'raw'),showWarnings = F) + +You can work using ODBC connections through ROracle, RODBC or work locally. To work remotely you need select access to the following tables: + + FRAILC.ILTS_SENSORS_TEMP FRAILC.MINILOG_TEMP and FRAILC.ILTS_TEMPERATURE. + +If you run the code through the ODBC connections you will automatically create local copies for use later with use_local=T. + +If you are working on local copies you need to create a folder in bio.datadirectory.ilts called 'raw'where the output of the ILTS_SENSORS_TEMP.csv, MINILOG_TEMP.csv and ILTS_TEMPERATURE.csv reside. To start determining bottom touchdown, or to redo any previously determined sets: - ilts.format.merge(update = TRUE, user = "brent" ) Set user to whatever you like. +ilts.format.merge(update = TRUE, user = "brent", use_RODBC = F, use_local = F ) #Set user to whatever you like and indicate how you want to access the data. To stop just click the top right x in the plot window at any time @@ -52,4 +61,4 @@ ERRORS L04092019 set 4 did plot before did when testing expanded plot - + \ No newline at end of file From 704da1eea739800af82cc377ad80cb3e65c24913 Mon Sep 17 00:00:00 2001 From: Cook Date: Tue, 12 May 2020 12:36:56 -0300 Subject: [PATCH 02/11] Removing ROracle import --- DESCRIPTION | 3 +-- NAMESPACE | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f3c9f65..9e3b0a0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,5 +18,4 @@ Imports: netmensuration, lubridate, stringr, - RODBC, - ROracle + RODBC \ No newline at end of file diff --git a/NAMESPACE b/NAMESPACE index 9785c69..7dba9a9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,4 +13,3 @@ import(netmensuration) import(stringr) import(tcltk) import(RODBC) -import(ROracle) \ No newline at end of file From 41d08c8e7cca8cb8a3b13e13553d8f93d94d5311 Mon Sep 17 00:00:00 2001 From: Cook Date: Tue, 12 May 2020 13:39:41 -0300 Subject: [PATCH 03/11] dir.create statements --- R/ilts.operations.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/R/ilts.operations.R b/R/ilts.operations.R index f1c2ab7..b1c58c3 100644 --- a/R/ilts.operations.R +++ b/R/ilts.operations.R @@ -13,12 +13,13 @@ options(stringsAsFactors = F) init.project.vars = function() { if(exists("bio.datadirectory.ilts")){ assign('manual.archive', bio.datadirectory.ilts , pkg.env) - } + } if(!exists("bio.datadirectory.ilts")){ print('A window will open that you need to choose the working folder.') assign('manual.archive', gWidgets2::gfile(text = "Select project work directory", type = "selectdir"), pkg.env) - } - + } + dir.create(pkg.env$manual.archive, showWarnings = F) + #Take from snowcrab users .Rprofile.site if(exists("oracle.snowcrab.server")){ assign('oracle.server', oracle.snowcrab.server, pkg.env) @@ -140,6 +141,8 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, plotdata = F #Alternative plotting that we do not require #Pull in the sensor data, this will be formatted and looped thru by trip then set. + dir.create(file.path(pkg.env$manual.archive,'raw'), showWarnings = F) + if(!use_local) { esona = get.oracle.table(tn = "FRAILC.ILTS_SENSORS_TEMP", RODBC=use_RODBC) write.csv(esona,file=file.path(pkg.env$manual.archive, 'raw', 'ILTS_SENSORS_TEMP.csv'),row.names = F) } From c6ab28708516c90e62c0678f3b7d4be0c45beb07 Mon Sep 17 00:00:00 2001 From: amcook Date: Tue, 19 May 2020 10:30:26 -0300 Subject: [PATCH 04/11] added depth only plots to the args --- R/ilts.operations.R | 10 ++++++++-- Readme.txt | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/R/ilts.operations.R b/R/ilts.operations.R index b1c58c3..4cb5070 100644 --- a/R/ilts.operations.R +++ b/R/ilts.operations.R @@ -115,7 +115,7 @@ if(RODBC) { #' @import netmensuration lubridate #' @return list of lists. Format (top to bottom) year-set-data #' @export -ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, use_local=F, sensor.file='ILTS_SENSORS_TEMP.csv', minilog.file = 'MINILOG_TEMP.csv', seabird.file = 'ILTS_TEMPERATURE.csv'){ +ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, use_local=F, depth.only.plot=F, sensor.file='ILTS_SENSORS_TEMP.csv', minilog.file = 'MINILOG_TEMP.csv', seabird.file = 'ILTS_TEMPERATURE.csv'){ #Set up database server, user and password init.project.vars() @@ -185,7 +185,7 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, #rebuild datetime column as it is incorrect and order seabf$timestamp = lubridate::ymd_hms(paste(as.character(lubridate::date(seabf$UTCDATE)), seabf$UTCTIME, sep=" "), tz="UTC" ) seabf = seabf[ order(seabf$timestamp , decreasing = FALSE ),] - + browser() #Loop through each esonar file to convert and merge with temp eson = split(esona, esona$TRIP_ID) for(i in 1:length(eson)){ @@ -251,6 +251,12 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, aredown = mergset$timestamp[which(mergset$depth == max(mergset$depth, na.rm = T))] time.gate = list( t0=as.POSIXct(aredown)-lubridate::dminutes(20), t1=as.POSIXct(aredown)+lubridate::dminutes(20) ) + if(depth.only.plot){ + pdf(file.path(pkg.env$manual.archive, paste(unique(na.omit(mergset$Trip)), unique(na.omit(mergset$Setno)), 'pdf',sep="."))) + with(subset(mergset, !is.na(depth)),plot(timestamp,depth, type='l')) + dev.off() + next() + } # Build the variables need for the proper execution of the bottom contact function from # the netmensuration package bcp = list( diff --git a/Readme.txt b/Readme.txt index 193137b..9f95e3e 100644 --- a/Readme.txt +++ b/Readme.txt @@ -34,6 +34,11 @@ To start determining bottom touchdown, or to redo any previously determined sets ilts.format.merge(update = TRUE, user = "brent", use_RODBC = F, use_local = F ) #Set user to whatever you like and indicate how you want to access the data. +If you want to get only the depth and timestamp plots for each set run: + +ilts.format.merge(update = TRUE, user = "brent", use_RODBC = F, use_local = F,depth.only.plot=T ) + + To stop just click the top right x in the plot window at any time To continue determining bottom touchdown, picking up any uncompleted sets: From adacc52f422f340015a6e26b76c6971e73f6b81d Mon Sep 17 00:00:00 2001 From: amcook Date: Tue, 19 May 2020 11:09:44 -0300 Subject: [PATCH 05/11] fixes --- R/ilts.operations.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/ilts.operations.R b/R/ilts.operations.R index 4cb5070..dad488d 100644 --- a/R/ilts.operations.R +++ b/R/ilts.operations.R @@ -185,7 +185,6 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, #rebuild datetime column as it is incorrect and order seabf$timestamp = lubridate::ymd_hms(paste(as.character(lubridate::date(seabf$UTCDATE)), seabf$UTCTIME, sep=" "), tz="UTC" ) seabf = seabf[ order(seabf$timestamp , decreasing = FALSE ),] - browser() #Loop through each esonar file to convert and merge with temp eson = split(esona, esona$TRIP_ID) for(i in 1:length(eson)){ From 3e088ff84253cbc79db94ce6779633cce3c2059f Mon Sep 17 00:00:00 2001 From: amcook Date: Tue, 19 May 2020 11:20:32 -0300 Subject: [PATCH 06/11] fixes --- R/ilts.operations.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/ilts.operations.R b/R/ilts.operations.R index dad488d..83d3c7e 100644 --- a/R/ilts.operations.R +++ b/R/ilts.operations.R @@ -118,6 +118,7 @@ if(RODBC) { ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, use_local=F, depth.only.plot=F, sensor.file='ILTS_SENSORS_TEMP.csv', minilog.file = 'MINILOG_TEMP.csv', seabird.file = 'ILTS_TEMPERATURE.csv'){ #Set up database server, user and password init.project.vars() + options(stringsAsFactors=F) cont=TRUE if(user == "")stop("You must call this function with a user. exa. ilts.format.merge(update = TRUE, user = 'John'" ) @@ -254,6 +255,7 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, pdf(file.path(pkg.env$manual.archive, paste(unique(na.omit(mergset$Trip)), unique(na.omit(mergset$Setno)), 'pdf',sep="."))) with(subset(mergset, !is.na(depth)),plot(timestamp,depth, type='l')) dev.off() + write.csv(mergset,file=file.path(pkg.env$manual.archive, paste(unique(na.omit(mergset$Trip)), unique(na.omit(mergset$Setno)), 'csv',sep="."))) next() } # Build the variables need for the proper execution of the bottom contact function from From 8f9420ae041a62f46c32ca56dcdec361f5fc9acb Mon Sep 17 00:00:00 2001 From: Cook Date: Wed, 20 May 2020 12:32:40 -0300 Subject: [PATCH 07/11] Column naming conventions flawed' --- R/ilts.operations.R | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/R/ilts.operations.R b/R/ilts.operations.R index b1c58c3..7e7ed89 100644 --- a/R/ilts.operations.R +++ b/R/ilts.operations.R @@ -6,6 +6,17 @@ assign('oracle.user', "", pkg.env) assign('oracle.password', "", pkg.env) options(stringsAsFactors = F) +#' @title rename.df +#' @description renaming columns +#' @export +rename.df = function(x, n0, n1) { + if(!length(n0)== length(n1)) stop('length of names and renames need to be the same length') + for(i in 1:length(n0)){ + names(x)[which(names(x)==n0[i])] = n1[i] + } + return(x) +} + #' @title init.project.vars #' @description Set global database variables by user account #' @import tcltk gWidgets2 gWidgets2tcltk @@ -49,8 +60,9 @@ init.project.vars = function() { #' @return dataframe #' @export esonar2df = function(esonar = NULL) { - names(esonar) - colnames(esonar) = c("CPUDateTime","GPSDate","GPSTime","Latitude","Longitude","Speed","Heading","Validity","TransducerName","SensorName","SensorValue","ErrorCode","Hydrophone","SignalStrength", "setno", "latedit", "trip", "datetime") + + esonar = rename.df(esonar, c( 'CPUDATEANDTIME','GPSTIME','LATITUDE','LONGITUDE','SPEED','HEADING','VALIDITY','TRANSDUCERNAME','SENSORNAME','SENSORVALUE','ERRORCODE','HYDROPHONE','SIGNALSTRENGTH','SET_NO','LATEDIT','TRIP_ID','GPSDATE','timestamp'), + c("CPUDateTime","GPSTime","Latitude","Longitude","Speed","Heading","Validity","TransducerName","SensorName","SensorValue","ErrorCode","Hydrophone","SignalStrength", "setno", "latedit", "trip", "GPSDate","datetime")) esonar$primary = NA #Headline esonar$secondary = NA #Is nothing but may need in file @@ -76,7 +88,8 @@ esonar2df = function(esonar = NULL) { esonar$Validity = NULL esonar$ErrorCode = NULL esonar$Heading = NULL - colnames(esonar) = c("Date","Time","Latitude","Longitude","Speed", "Setno", "latedit","Trip","timestamp", "Primary","Secondary","WingSpread","Roll", "Pitch") + esonar = rename.df(esonar, c('GPSTime','Latitude','Longitude','Speed','setno','latedit','trip','GPSDate','datetime','primary','secondary','wingspread','STBDRoll','STBDPitch'), + c("Time","Latitude","Longitude","Speed", "Setno", "latedit","Trip","Date","timestamp", "Primary","Secondary","WingSpread","Roll", "Pitch")) return(esonar) } @@ -115,7 +128,7 @@ if(RODBC) { #' @import netmensuration lubridate #' @return list of lists. Format (top to bottom) year-set-data #' @export -ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, use_local=F, sensor.file='ILTS_SENSORS_TEMP.csv', minilog.file = 'MINILOG_TEMP.csv', seabird.file = 'ILTS_TEMPERATURE.csv'){ +ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, use_local=F, depth.only.plot=F, sensor.file='ILTS_SENSORS_TEMP.csv', minilog.file = 'MINILOG_TEMP.csv', seabird.file = 'ILTS_TEMPERATURE.csv'){ #Set up database server, user and password init.project.vars() @@ -177,7 +190,7 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, #seab = get.oracle.table(tn = "LOBSTER.ILTS_TEMPERATURE") if(!use_local) { - seabf = get.oracle.table(tn = "FRAILC.ILTS_TEMPERATURE",RODBC = use_RODBC) + seabf = get.oracle.table(tn = "frailc.ILTS_TEMPERATURE",RODBC = use_RODBC) write.csv(seabf,file=file.path(pkg.env$manual.archive, 'raw', 'ILTS_TEMPERATURE.csv'),row.names = F) } if(use_local) seabf = read.csv(file.path(pkg.env$manual.archive, 'raw', seabird.file)) @@ -188,6 +201,7 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, #Loop through each esonar file to convert and merge with temp eson = split(esona, esona$TRIP_ID) + for(i in 1:length(eson)){ if(cont){ #Condition fails if program exited trip = data.frame(eson[[i]]) @@ -196,7 +210,6 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, if(cont){ #Condition fails if program exited set = data.frame(trip[[j]]) set = esonar2df(set) - #Dont continue if update is false and station is already complete if((paste(unique(na.omit(set$Setno)), unique(na.omit(set$Trip)), sep = ".") %in% paste(current$station, current$trip, sep = ".")) & (update==FALSE)){ @@ -218,20 +231,21 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, names(minisub) = c("temperature","timestamp") } } - + if(unique(set$Trip)=="100055173" & unique(set$Setno)==6) browser() + seabsub = NULL #Get seabird indicies and extend ?? mins on either side so that depth profile isn't cut off seab.ind.0 = which(seabf$timestamp>set$timestamp[1]-lubridate::minutes(15))[1] seab.ind.1 = which(seabf$timestamp>set$timestamp[length(set$timestamp)]+lubridate::minutes(15))[1]-1 - if(!(is.na(seab.ind.0) | is.na(seab.ind.0))){ - - seabsub = seabf[c(seab.ind.0:seab.ind.1),] + seabsub = seabf[c(seab.ind.0:seab.ind.1),] seabsub = seabsub[,which(names(seabsub) %in% c("timestamp", "TEMPC", "DEPTHM"))] names(seabsub) = c("temperature","depth","timestamp") + } + if(is.null(seabsub) && is.null(minisub)){ + print(paste("No temperature/depth file found for trip - set: ", unique(na.omit(set$Trip)), " - ", unique(na.omit(set$Setno)), sep="")) + next() } - - if(is.null(seabsub) && is.null(minisub))stop(paste("No temperature/depth file found for trip - set: ", unique(na.omit(set$Trip)), " - ", unique(na.omit(set$Setno)), sep="")) if(is.null(seabsub)) seabsub = minisub #Remove depths = <0 #Not sure why but came accross stations with low depth values mixed in with real bottom depths. seabsub$depth[which(seabsub$depth <= 2)] = NA @@ -250,7 +264,12 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, if(!NoDeps){ aredown = mergset$timestamp[which(mergset$depth == max(mergset$depth, na.rm = T))] time.gate = list( t0=as.POSIXct(aredown)-lubridate::dminutes(20), t1=as.POSIXct(aredown)+lubridate::dminutes(20) ) - +if(depth.only.plot){ + pdf(file.path(pkg.env$manual.archive,paste(unique(na.omit(mergset$Trip)),unique(na.omit(mergset$Setno)),'pdf', sep="."))) + with(subset(mergset,!is.na(depth)),plot(timestamp, depth ,type='l')) + dev.off() + next() + } # Build the variables need for the proper execution of the bottom contact function from # the netmensuration package bcp = list( From 9e981427c8460db086aed815df9d2636a1e55bca Mon Sep 17 00:00:00 2001 From: Cook Date: Wed, 20 May 2020 12:54:22 -0300 Subject: [PATCH 08/11] Date fixes --- R/ilts.operations.R | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/R/ilts.operations.R b/R/ilts.operations.R index bec68ee..f630aff 100644 --- a/R/ilts.operations.R +++ b/R/ilts.operations.R @@ -231,13 +231,14 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, names(minisub) = c("temperature","timestamp") } } - if(unique(set$Trip)=="100055173" & unique(set$Setno)==6) browser() - + seabsub = NULL #Get seabird indicies and extend ?? mins on either side so that depth profile isn't cut off seab.ind.0 = which(seabf$timestamp>set$timestamp[1]-lubridate::minutes(15))[1] seab.ind.1 = which(seabf$timestamp>set$timestamp[length(set$timestamp)]+lubridate::minutes(15))[1]-1 - if(!(is.na(seab.ind.0) | is.na(seab.ind.0))){ + if(is.na(seab.ind.1)) seab.ind.1 = which(seabf$timestamp>set$timestamp[length(set$timestamp)]+lubridate::minutes(4))[1]-1 + + if(!(is.na(seab.ind.0) | is.na(seab.ind.0))){ seabsub = seabf[c(seab.ind.0:seab.ind.1),] seabsub = seabsub[,which(names(seabsub) %in% c("timestamp", "TEMPC", "DEPTHM"))] names(seabsub) = c("temperature","depth","timestamp") @@ -265,14 +266,6 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, aredown = mergset$timestamp[which(mergset$depth == max(mergset$depth, na.rm = T))] time.gate = list( t0=as.POSIXct(aredown)-lubridate::dminutes(20), t1=as.POSIXct(aredown)+lubridate::dminutes(20) ) -if(depth.only.plot){ - pdf(file.path(pkg.env$manual.archive,paste(unique(na.omit(mergset$Trip)),unique(na.omit(mergset$Setno)),'pdf', sep="."))) - with(subset(mergset,!is.na(depth)),plot(timestamp, depth ,type='l')) - dev.off() - next() - } - - if(depth.only.plot){ pdf(file.path(pkg.env$manual.archive, paste(unique(na.omit(mergset$Trip)), unique(na.omit(mergset$Setno)), 'pdf',sep="."))) with(subset(mergset, !is.na(depth)),plot(timestamp,depth, type='l')) From 223d4325be08ad16670d16775cf4422034e83c68 Mon Sep 17 00:00:00 2001 From: Cook Date: Thu, 21 May 2020 14:17:18 -0300 Subject: [PATCH 09/11] Removing call to minilog, and cleaning time stamps from seabird --- R/ilts.operations.R | 82 ++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/R/ilts.operations.R b/R/ilts.operations.R index f630aff..bafdf17 100644 --- a/R/ilts.operations.R +++ b/R/ilts.operations.R @@ -179,15 +179,15 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, if(length(yind)>0)esona = esona[yind,] if(length(esona$timestamp)==0)stop("No data found for your year selection!") } - if(!use_local) { - mini = get.oracle.table(tn = "FRAILC.MINILOG_TEMP", RODBC = use_RODBC) - write.csv(mini,file=file.path(pkg.env$manual.archive, 'raw', 'MINILOG_TEMP.csv'),row.names = F) - } - if(use_local) mini = read.csv(file.path(pkg.env$manual.archive, 'raw', minilog.file)) + #if(!use_local) { + # mini = get.oracle.table(tn = "FRAILC.MINILOG_TEMP", RODBC = use_RODBC) + # write.csv(mini,file=file.path(pkg.env$manual.archive, 'raw', 'MINILOG_TEMP.csv'),row.names = F) + # } + #if(use_local) mini = read.csv(file.path(pkg.env$manual.archive, 'raw', minilog.file)) #rebuild datetime column as it is incorrect and order - mini$timestamp = lubridate::ymd_hms(paste(as.character(lubridate::date(mini$TDATE)), mini$TIME, sep=" "), tz="UTC" ) - mini = mini[ order(mini$timestamp , decreasing = FALSE ),] + #mini$timestamp = lubridate::ymd_hms(paste(as.character(lubridate::date(mini$TDATE)), mini$TIME, sep=" "), tz="UTC" ) + #mini = mini[ order(mini$timestamp , decreasing = FALSE ),] #seab = get.oracle.table(tn = "LOBSTER.ILTS_TEMPERATURE") if(!use_local) { @@ -197,10 +197,17 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, if(use_local) seabf = read.csv(file.path(pkg.env$manual.archive, 'raw', seabird.file)) #rebuild datetime column as it is incorrect and order + seabf$UTCTIME[which(nchar(seabf$UTCTIME)==5)] = paste("0", seabf$UTCTIME[which(nchar(seabf$UTCTIME)==5)], sep="") + seabf$UTCTIME[which(nchar(seabf$UTCTIME)==4)] = paste("00", seabf$UTCTIME[which(nchar(seabf$UTCTIME)==4)], sep="") + seabf$UTCTIME[which(nchar(seabf$UTCTIME)==3)] = paste("000", seabf$UTCTIME[which(nchar(seabf$UTCTIME)==3)], sep="") + seabf$UTCTIME[which(nchar(seabf$UTCTIME)==2)] = paste("0000", seabf$UTCTIME[which(nchar(seabf$UTCTIME)==2)], sep="") + seabf$UTCTIME[which(nchar(seabf$UTCTIME)==1)] = paste("00000", seabf$UTCTIME[which(nchar(seabf$UTCTIME)==1)], sep="") + seabf$timestamp = lubridate::ymd_hms(paste(as.character(lubridate::date(seabf$UTCDATE)), seabf$UTCTIME, sep=" "), tz="UTC" ) seabf = seabf[ order(seabf$timestamp , decreasing = FALSE ),] #Loop through each esonar file to convert and merge with temp eson = split(esona, esona$TRIP_ID) + seabf$id = paste(seabf$TRIP_ID,seabf$SET_NO,sep="_") for(i in 1:length(eson)){ if(cont){ #Condition fails if program exited @@ -210,56 +217,61 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, if(cont){ #Condition fails if program exited set = data.frame(trip[[j]]) set = esonar2df(set) + set$id = paste(set$Trip, set$Setno, sep="_") + sseab = subset(seabf, id == na.omit(unique(set$id))) + sseab = sseab[order(sseab$timestamp),] #Dont continue if update is false and station is already complete if((paste(unique(na.omit(set$Setno)), unique(na.omit(set$Trip)), sep = ".") %in% paste(current$station, current$trip, sep = ".")) & (update==FALSE)){ message(paste("Set:",unique(na.omit(set$Setno))," Trip:", unique(na.omit(set$Trip)), " Already added call with update = TRUE to redo.", sep = "")) } else{ - minisub = NULL - mini.ind.0 = which(mini$timestamp>set$timestamp[1])[1] - mini.ind.1 = which(mini$timestamp>set$timestamp[length(set$timestamp)])[1]-1 - if(!(is.na(mini.ind.0) | is.na(mini.ind.0))){ - minisub = mini[c(mini.ind.0:mini.ind.1),] + # minisub = NULL + # mini.ind.0 = which(mini$timestamp>set$timestamp[1])[1] + # mini.ind.1 = which(mini$timestamp>set$timestamp[length(set$timestamp)])[1]-1 + # if(!(is.na(mini.ind.0) | is.na(mini.ind.0))){ + # minisub = mini[c(mini.ind.0:mini.ind.1),] #### Only keep relevant data, If you encounter a minilog file # depth, add that column to the following line to catch that case - if("depth" %in% names(minisub)){ - minisub = minisub[,which(names(minisub) %in% c("datetime", "TEMP_C", "depth"))] - names(minisub) = c("temperature","depth","timestamp") - } - else{ - minisub = minisub[,which(names(minisub) %in% c("datetime", "TEMP_C"))] - names(minisub) = c("temperature","timestamp") - } - } - - seabsub = NULL + # if("depth" %in% names(minisub)){ + # minisub = minisub[,which(names(minisub) %in% c("datetime", "TEMP_C", "depth"))] + # names(minisub) = c("temperature","depth","timestamp") + # } + # else{ + # minisub = minisub[,which(names(minisub) %in% c("datetime", "TEMP_C"))] + # names(minisub) = c("temperature","timestamp") + # } + # } + seabsub = NULL #Get seabird indicies and extend ?? mins on either side so that depth profile isn't cut off - seab.ind.0 = which(seabf$timestamp>set$timestamp[1]-lubridate::minutes(15))[1] - seab.ind.1 = which(seabf$timestamp>set$timestamp[length(set$timestamp)]+lubridate::minutes(15))[1]-1 - if(is.na(seab.ind.1)) seab.ind.1 = which(seabf$timestamp>set$timestamp[length(set$timestamp)]+lubridate::minutes(4))[1]-1 + #seab.ind.0 = which(seabf$timestamp>set$timestamp[1]-lubridate::minutes(15))[1] + #seab.ind.1 = which(seabf$timestamp>set$timestamp[length(set$timestamp)]+lubridate::minutes(15))[1]-1 + #if(is.na(seab.ind.1)) seab.ind.1 = which(seabf$timestamp>set$timestamp[length(set$timestamp)]+lubridate::minutes(4))[1]-1 - if(!(is.na(seab.ind.0) | is.na(seab.ind.0))){ - seabsub = seabf[c(seab.ind.0:seab.ind.1),] - seabsub = seabsub[,which(names(seabsub) %in% c("timestamp", "TEMPC", "DEPTHM"))] + # if(!(is.na(seab.ind.0) | is.na(seab.ind.0))){ + # seabsub = seabf[c(seab.ind.0:seab.ind.1),] + seabsub = sseab + seabsub = seabsub[,which(names(seabsub) %in% c("timestamp", "TEMPC", "DEPTHM"))] names(seabsub) = c("temperature","depth","timestamp") - } - if(is.null(seabsub) && is.null(minisub)){ + # } + if(is.null(seabsub)){ #&& is.null(minisub)){ print(paste("No temperature/depth file found for trip - set: ", unique(na.omit(set$Trip)), " - ", unique(na.omit(set$Setno)), sep="")) next() } - if(is.null(seabsub)) seabsub = minisub + #if(is.null(seabsub)) seabsub = minisub #Remove depths = <0 #Not sure why but came accross stations with low depth values mixed in with real bottom depths. seabsub$depth[which(seabsub$depth <= 2)] = NA - + mergset = NULL #Merge sensor data. mergset = merge(seabsub, set, "timestamp", all = TRUE) #Build the full, unbroken timeseries and merge - timestamp = data.frame(seq(min(mergset$timestamp), max(mergset$timestamp), 1)) + timestamp = data.frame(seq(min(mergset$timestamp), max(mergset$timestamp), 1)) names(timestamp) = c("timestamp") mergset = merge(mergset, timestamp, "timestamp", all = TRUE) mergset$timestamp = lubridate::ymd_hms(as.character(mergset$timestamp), tz="UTC" ) #Find deepest point and extend possible data from that out to 20min on either side - + print(paste(unique(mergset$Trip), unique(mergset$Setno))) + + if(all(na.omit(unique(mergset$Trip))=='100051989' && na.omit(unique(mergset$Setno))==102))browser() NoDeps = all(is.na(mergset$depth)) if(NoDeps) cat("\n",paste('No depth info for Trip-Setno='),unique(paste(mergset$Trip,mergset$Setno,sep="-"))) if(!NoDeps){ From dade7843cd924f531ff4c8a8299250caa9fdfee5 Mon Sep 17 00:00:00 2001 From: Cook Date: Fri, 22 May 2020 09:02:53 -0300 Subject: [PATCH 10/11] Writing all output --- R/ilts.operations.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/ilts.operations.R b/R/ilts.operations.R index bafdf17..b7f26f7 100644 --- a/R/ilts.operations.R +++ b/R/ilts.operations.R @@ -202,7 +202,6 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, seabf$UTCTIME[which(nchar(seabf$UTCTIME)==3)] = paste("000", seabf$UTCTIME[which(nchar(seabf$UTCTIME)==3)], sep="") seabf$UTCTIME[which(nchar(seabf$UTCTIME)==2)] = paste("0000", seabf$UTCTIME[which(nchar(seabf$UTCTIME)==2)], sep="") seabf$UTCTIME[which(nchar(seabf$UTCTIME)==1)] = paste("00000", seabf$UTCTIME[which(nchar(seabf$UTCTIME)==1)], sep="") - seabf$timestamp = lubridate::ymd_hms(paste(as.character(lubridate::date(seabf$UTCDATE)), seabf$UTCTIME, sep=" "), tz="UTC" ) seabf = seabf[ order(seabf$timestamp , decreasing = FALSE ),] #Loop through each esonar file to convert and merge with temp @@ -269,11 +268,13 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, mergset = merge(mergset, timestamp, "timestamp", all = TRUE) mergset$timestamp = lubridate::ymd_hms(as.character(mergset$timestamp), tz="UTC" ) #Find deepest point and extend possible data from that out to 20min on either side - print(paste(unique(mergset$Trip), unique(mergset$Setno))) - if(all(na.omit(unique(mergset$Trip))=='100051989' && na.omit(unique(mergset$Setno))==102))browser() NoDeps = all(is.na(mergset$depth)) - if(NoDeps) cat("\n",paste('No depth info for Trip-Setno='),unique(paste(mergset$Trip,mergset$Setno,sep="-"))) + if(NoDeps) { + cat("\n",paste('No depth info for Trip-Setno='),unique(paste(mergset$Trip,mergset$Setno,sep="-"))) + write.csv(mergset,file=file.path(pkg.env$manual.archive, paste(unique(na.omit(mergset$Trip)), unique(na.omit(mergset$Setno)), 'csv',sep="."))) + + } if(!NoDeps){ aredown = mergset$timestamp[which(mergset$depth == max(mergset$depth, na.rm = T))] time.gate = list( t0=as.POSIXct(aredown)-lubridate::dminutes(20), t1=as.POSIXct(aredown)+lubridate::dminutes(20) ) From e7f5e026af1ede25320268a972091f2dee4561dd Mon Sep 17 00:00:00 2001 From: Cook Date: Fri, 29 May 2020 10:13:19 -0300 Subject: [PATCH 11/11] Adding temperature plots --- R/ilts.operations.R | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/R/ilts.operations.R b/R/ilts.operations.R index b7f26f7..aeb3d68 100644 --- a/R/ilts.operations.R +++ b/R/ilts.operations.R @@ -128,7 +128,7 @@ if(RODBC) { #' @import netmensuration lubridate #' @return list of lists. Format (top to bottom) year-set-data #' @export -ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, use_local=F, depth.only.plot=F, sensor.file='ILTS_SENSORS_TEMP.csv', minilog.file = 'MINILOG_TEMP.csv', seabird.file = 'ILTS_TEMPERATURE.csv'){ +ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, use_local=F, depth.plot=F,temperature.plot=F, sensor.file='ILTS_SENSORS_TEMP.csv', minilog.file = 'MINILOG_TEMP.csv', seabird.file = 'ILTS_TEMPERATURE.csv'){ #Set up database server, user and password init.project.vars() options(stringsAsFactors=F) @@ -163,9 +163,15 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, if(use_local) esona = read.csv(file.path(pkg.env$manual.archive, 'raw', sensor.file)) esona$GPSTIME[which(nchar(esona$GPSTIME)==5)] = paste("0", esona$GPSTIME[which(nchar(esona$GPSTIME)==5)], sep="") + esona$GPSTIME[which(nchar(esona$GPSTIME)==5)] = paste("0", esona$GPSTIME[which(nchar(esona$GPSTIME)==5)], sep="") + esona$GPSTIME[which(nchar(esona$GPSTIME)==4)] = paste("00", esona$GPSTIME[which(nchar(esona$GPSTIME)==4)], sep="") + esona$GPSTIME[which(nchar(esona$GPSTIME)==3)] = paste("000", esona$GPSTIME[which(nchar(esona$GPSTIME)==3)], sep="") + esona$GPSTIME[which(nchar(esona$GPSTIME)==2)] = paste("0000", esona$GPSTIME[which(nchar(esona$GPSTIME)==2)], sep="") + esona$GPSTIME[which(nchar(esona$GPSTIME)==1)] = paste("00000", esona$GPSTIME[which(nchar(esona$GPSTIME)==1)], sep="") + esona$timestamp = lubridate::ymd_hms(paste(as.character(lubridate::date(esona$GPSDATE)), esona$GPSTIME, sep=" "), tz="UTC" ) esona = esona[ order(esona$timestamp , decreasing = FALSE ),] - err = which(is.na(esona$timestamp)) + err = which(is.na(esona$timestamp)) if(length(err)>0){ cat(paste('Errors in time stamps for TRIP_NO--SETS'),unique(paste(esona$TRIP_ID[err],'--',esona$SET_NO[err],sep=""))) esona = esona[-err,] @@ -195,7 +201,6 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, write.csv(seabf,file=file.path(pkg.env$manual.archive, 'raw', 'ILTS_TEMPERATURE.csv'),row.names = F) } if(use_local) seabf = read.csv(file.path(pkg.env$manual.archive, 'raw', seabird.file)) - #rebuild datetime column as it is incorrect and order seabf$UTCTIME[which(nchar(seabf$UTCTIME)==5)] = paste("0", seabf$UTCTIME[which(nchar(seabf$UTCTIME)==5)], sep="") seabf$UTCTIME[which(nchar(seabf$UTCTIME)==4)] = paste("00", seabf$UTCTIME[which(nchar(seabf$UTCTIME)==4)], sep="") @@ -224,22 +229,6 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, if((paste(unique(na.omit(set$Setno)), unique(na.omit(set$Trip)), sep = ".") %in% paste(current$station, current$trip, sep = ".")) & (update==FALSE)){ message(paste("Set:",unique(na.omit(set$Setno))," Trip:", unique(na.omit(set$Trip)), " Already added call with update = TRUE to redo.", sep = "")) } else{ - # minisub = NULL - # mini.ind.0 = which(mini$timestamp>set$timestamp[1])[1] - # mini.ind.1 = which(mini$timestamp>set$timestamp[length(set$timestamp)])[1]-1 - # if(!(is.na(mini.ind.0) | is.na(mini.ind.0))){ - # minisub = mini[c(mini.ind.0:mini.ind.1),] - #### Only keep relevant data, If you encounter a minilog file - # depth, add that column to the following line to catch that case - # if("depth" %in% names(minisub)){ - # minisub = minisub[,which(names(minisub) %in% c("datetime", "TEMP_C", "depth"))] - # names(minisub) = c("temperature","depth","timestamp") - # } - # else{ - # minisub = minisub[,which(names(minisub) %in% c("datetime", "TEMP_C"))] - # names(minisub) = c("temperature","timestamp") - # } - # } seabsub = NULL #Get seabird indicies and extend ?? mins on either side so that depth profile isn't cut off #seab.ind.0 = which(seabf$timestamp>set$timestamp[1]-lubridate::minutes(15))[1] @@ -252,7 +241,7 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, seabsub = seabsub[,which(names(seabsub) %in% c("timestamp", "TEMPC", "DEPTHM"))] names(seabsub) = c("temperature","depth","timestamp") # } - if(is.null(seabsub)){ #&& is.null(minisub)){ + if(is.null(seabsub)){ print(paste("No temperature/depth file found for trip - set: ", unique(na.omit(set$Trip)), " - ", unique(na.omit(set$Setno)), sep="")) next() } @@ -269,6 +258,18 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, mergset$timestamp = lubridate::ymd_hms(as.character(mergset$timestamp), tz="UTC" ) #Find deepest point and extend possible data from that out to 20min on either side + NoT = all(is.na(mergset$temperature)) + if(NoT) { + cat("\n",paste('No temperature info for Trip-Setno='),unique(paste(mergset$Trip,mergset$Setno,sep="-"))) + } + if(!NoT){ + if(temperature.plot){ + pdf(file.path(pkg.env$manual.archive, paste(unique(na.omit(mergset$Trip)), unique(na.omit(mergset$Setno)), 'Temperature.pdf',sep="."))) + with(subset(mergset, !is.na(temperature)),plot(timestamp,temperature, type='l')) + dev.off() + } + } + NoDeps = all(is.na(mergset$depth)) if(NoDeps) { cat("\n",paste('No depth info for Trip-Setno='),unique(paste(mergset$Trip,mergset$Setno,sep="-"))) @@ -279,7 +280,7 @@ ilts.format.merge = function(update = TRUE, user = "", years = "", use_RODBC=F, aredown = mergset$timestamp[which(mergset$depth == max(mergset$depth, na.rm = T))] time.gate = list( t0=as.POSIXct(aredown)-lubridate::dminutes(20), t1=as.POSIXct(aredown)+lubridate::dminutes(20) ) - if(depth.only.plot){ + if(depth.plot){ pdf(file.path(pkg.env$manual.archive, paste(unique(na.omit(mergset$Trip)), unique(na.omit(mergset$Setno)), 'pdf',sep="."))) with(subset(mergset, !is.na(depth)),plot(timestamp,depth, type='l')) dev.off()