From 738ba40412fb276d9b9cbe8aeb3b15b4f9ec51b2 Mon Sep 17 00:00:00 2001 From: l-k- Date: Wed, 23 Aug 2023 11:45:19 -0400 Subject: [PATCH] pass inspectfile obj into g.calibrate, don't rerun --- R/g.calibrate.R | 51 +++++++++++++++++++++++++--------------------- R/g.part1.R | 7 +++++-- man/g.calibrate.Rd | 5 ++++- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/R/g.calibrate.R b/R/g.calibrate.R index d05f7acab..f3a0ee276 100644 --- a/R/g.calibrate.R +++ b/R/g.calibrate.R @@ -1,6 +1,7 @@ g.calibrate = function(datafile, params_rawdata = c(), params_general = c(), params_cleaning = c(), + inspectfileobject = c(), verbose = TRUE, ...) { @@ -46,29 +47,33 @@ g.calibrate = function(datafile, params_rawdata = c(), op <- options(stringsAsFactors = FALSE) on.exit(options(op)) options(warn = -1) #turn off warnings - INFI = g.inspectfile(datafile, desiredtz = params_general[["desiredtz"]], - rmc.dec = params_rawdata[["rmc.dec"]], - rmc.firstrow.acc = params_rawdata[["rmc.firstrow.acc"]], - rmc.firstrow.header = params_rawdata[["rmc.firstrow.header"]], - rmc.header.length = params_rawdata[["rmc.header.length"]], - rmc.col.acc = params_rawdata[["rmc.col.acc"]], - rmc.col.temp = params_rawdata[["rmc.col.temp"]], - rmc.col.time = params_rawdata[["rmc.col.time"]], - rmc.unit.acc = params_rawdata[["rmc.unit.acc"]], - rmc.unit.temp = params_rawdata[["rmc.unit.temp"]], - rmc.unit.time = params_rawdata[["rmc.unit.time"]], - rmc.format.time = params_rawdata[["rmc.format.time"]], - rmc.bitrate = params_rawdata[["rmc.bitrate"]], - rmc.dynamic_range = params_rawdata[["rmc.dynamic_range"]], - rmc.unsignedbit = params_rawdata[["rmc.unsignedbit"]], - rmc.origin = params_rawdata[["rmc.origin"]], - rmc.desiredtz = params_general[["rmc.desiredtz"]], - rmc.sf = params_rawdata[["rmc.sf"]], - rmc.headername.sf = params_rawdata[["rmc.headername.sf"]], - rmc.headername.sn = params_rawdata[["rmc.headername.sn"]], - rmc.headername.recordingid = params_rawdata[["rmc.headername.sn"]], - rmc.header.structure = params_rawdata[["rmc.header.structure"]], - rmc.check4timegaps = params_rawdata[["rmc.check4timegaps"]]) # Check which file type and monitor brand it is + if (length(inspectfileobject) > 0) { + INFI = inspectfileobject + } else { + INFI = g.inspectfile(datafile, desiredtz = params_general[["desiredtz"]], + rmc.dec = params_rawdata[["rmc.dec"]], + rmc.firstrow.acc = params_rawdata[["rmc.firstrow.acc"]], + rmc.firstrow.header = params_rawdata[["rmc.firstrow.header"]], + rmc.header.length = params_rawdata[["rmc.header.length"]], + rmc.col.acc = params_rawdata[["rmc.col.acc"]], + rmc.col.temp = params_rawdata[["rmc.col.temp"]], + rmc.col.time = params_rawdata[["rmc.col.time"]], + rmc.unit.acc = params_rawdata[["rmc.unit.acc"]], + rmc.unit.temp = params_rawdata[["rmc.unit.temp"]], + rmc.unit.time = params_rawdata[["rmc.unit.time"]], + rmc.format.time = params_rawdata[["rmc.format.time"]], + rmc.bitrate = params_rawdata[["rmc.bitrate"]], + rmc.dynamic_range = params_rawdata[["rmc.dynamic_range"]], + rmc.unsignedbit = params_rawdata[["rmc.unsignedbit"]], + rmc.origin = params_rawdata[["rmc.origin"]], + rmc.desiredtz = params_general[["rmc.desiredtz"]], + rmc.sf = params_rawdata[["rmc.sf"]], + rmc.headername.sf = params_rawdata[["rmc.headername.sf"]], + rmc.headername.sn = params_rawdata[["rmc.headername.sn"]], + rmc.headername.recordingid = params_rawdata[["rmc.headername.sn"]], + rmc.header.structure = params_rawdata[["rmc.header.structure"]], + rmc.check4timegaps = params_rawdata[["rmc.check4timegaps"]]) # Check which file type and monitor brand it is + } options(warn = 0) #turn on warnings mon = INFI$monc if (mon == 6) mon = 3 diff --git a/R/g.part1.R b/R/g.part1.R index 959a3c615..ca3d88029 100644 --- a/R/g.part1.R +++ b/R/g.part1.R @@ -123,7 +123,7 @@ g.part1 = function(datadir = c(), metadatadir = c(), f0 = 1, f1 = c(), myfun = c options(warn = 0) #turn on warnings if (verbose == TRUE) cat(paste0("\nP1 file ",i)) turn.do.cal.back.on = FALSE - if (params_rawdata[["do.cal"]] == TRUE & I$dformc == 3) { # do not do the auto-calibration for wav files (because already done in pre-processign) + if (params_rawdata[["do.cal"]] == TRUE & I$dformc == FORMAT$WAV) { # do not do the auto-calibration for wav files (because already done in pre-processign) params_rawdata[["do.cal"]] = FALSE turn.do.cal.back.on = TRUE } @@ -154,6 +154,7 @@ g.part1 = function(datadir = c(), metadatadir = c(), f0 = 1, f1 = c(), myfun = c params_rawdata = params_rawdata, params_general = params_general, params_cleaning = params_cleaning, + inspectfileobject = I, verbose = verbose) } else { C = list(cal.error.end = 0, cal.error.start = 0) @@ -234,7 +235,9 @@ g.part1 = function(datadir = c(), metadatadir = c(), f0 = 1, f1 = c(), myfun = c C = g.calibrate(datafile, params_rawdata = params_rawdata, params_general = params_general, - params_cleaning = params_cleaning) + params_cleaning = params_cleaning, + inspectfileobject = I, + verbose = verbose) } } } diff --git a/man/g.calibrate.Rd b/man/g.calibrate.Rd index 5154ea101..89fb4041a 100755 --- a/man/g.calibrate.Rd +++ b/man/g.calibrate.Rd @@ -11,7 +11,7 @@ } \usage{ g.calibrate(datafile, params_rawdata = c(), params_general = c(), - params_cleaning = c(), verbose = TRUE, ...) + params_cleaning = c(), inspectfileobject = c(), verbose = TRUE, ...) } \arguments{ \item{datafile}{ @@ -26,6 +26,9 @@ \item{params_cleaning}{ See \link{g.part1} } + \item{inspectfileobject}{ + Output from the function \link{g.inspectfile}. + } \item{verbose}{ Boolean (default = TRUE). to indicate whether console message should be printed. Note that warnings and error are always printed and can be suppressed with