Skip to content

Commit

Permalink
pass inspectfile obj into g.calibrate, don't rerun
Browse files Browse the repository at this point in the history
  • Loading branch information
l-k- committed Aug 28, 2023
1 parent 2690427 commit 738ba40
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
51 changes: 28 additions & 23 deletions R/g.calibrate.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
g.calibrate = function(datafile, params_rawdata = c(),
params_general = c(),
params_cleaning = c(),
inspectfileobject = c(),
verbose = TRUE,
...) {

Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions R/g.part1.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion man/g.calibrate.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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}{
Expand All @@ -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
Expand Down

0 comments on commit 738ba40

Please sign in to comment.