-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #872 from wadpac/issue871_cleanup_part5
Clean up g.part5()
- Loading branch information
Showing
7 changed files
with
749 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
g.part5_initialise_ts = function(IMP, M, params_247, params_general) { | ||
|
||
# extract key variables from the mile-stone data: time, acceleration and elevation angle | ||
# note that this is imputed ACCELERATION because we use this for describing behaviour: | ||
scale = ifelse(test = grepl("^Brond|^Neishabouri|^ZC", params_general[["acc.metric"]]), yes = 1, no = 1000) | ||
# if (length(which(names(IMP$metashort) == "anglez")) == 0 & verbose == TRUE) { | ||
# cat("Warning: anglez not extracted. Please check that do.anglez == TRUE") | ||
# } | ||
|
||
if ("anglez" %in% names(IMP$metashort)) { | ||
ts = data.frame(time = IMP$metashort[,1], ACC = IMP$metashort[,params_general[["acc.metric"]]] * scale, | ||
guider = rep("unknown", nrow(IMP$metashort)), | ||
angle = as.numeric(as.matrix(IMP$metashort[,which(names(IMP$metashort) == "anglez")]))) | ||
} else { | ||
ts = data.frame(time = IMP$metashort[,1], ACC = IMP$metashort[,params_general[["acc.metric"]]] * scale, | ||
guider = rep("unknown", nrow(IMP$metashort))) | ||
} | ||
Nts = nrow(ts) | ||
# add non-wear column | ||
nonwear = IMP$rout[,5] | ||
nonwear = rep(nonwear, each = (IMP$windowsizes[2]/IMP$windowsizes[1])) | ||
if (length(nonwear) > Nts) { | ||
nonwear = nonwear[1:Nts] | ||
} else if (length(nonwear) < Nts) { | ||
nonwear = c(nonwear, rep(0, (Nts - length(nonwear)))) | ||
} | ||
ts$nonwear = 0 # initialise column | ||
ts$nonwear = nonwear | ||
lightpeak_available = "lightpeak" %in% colnames(M$metalong) | ||
# Check if temperature and light are availble | ||
if (lightpeak_available == TRUE) { | ||
luz = M$metalong$lightpeak | ||
if (length(params_247[["LUX_cal_constant"]]) > 0 & | ||
length(params_247[["LUX_cal_exponent"]]) > 0) { # re-calibrate light | ||
luz = params_247[["LUX_cal_constant"]] * exp(params_247[["LUX_cal_exponent"]] * luz) | ||
} | ||
handle_luz_extremes = g.part5.handle_lux_extremes(luz) | ||
luz = handle_luz_extremes$lux | ||
correction_log = handle_luz_extremes$correction_log | ||
# repeate values to match resolution of other data | ||
repeatvalues = function(x, windowsizes, Nts) { | ||
x = rep(x, each = (windowsizes[2]/windowsizes[1])) | ||
if (length(x) > Nts) { | ||
x = x[1:Nts] | ||
} else if (length(x) < Nts) { | ||
x = c(x, rep(0, (Nts - length(x)))) | ||
} | ||
return(x) | ||
} | ||
luz = repeatvalues(x = luz, windowsizes = IMP$windowsizes, Nts) | ||
correction_log = repeatvalues(x = correction_log, windowsizes = IMP$windowsizes, Nts) | ||
ts$lightpeak_imputationcode = ts$lightpeak = 0 # initialise column | ||
ts$lightpeak = luz | ||
ts$lightpeak_imputationcode = correction_log | ||
} | ||
return(ts) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
\name{g.part5_analyseSegment} | ||
\alias{g.part5_analyseSegment} | ||
\title{ | ||
Analyses the time series per time segment for part 5 | ||
} | ||
\description{ | ||
Not intended for direct use by GGIR users, part of \link{g.part5}. | ||
} | ||
\usage{ | ||
g.part5_analyseSegment(indexlog, timeList, levelList, | ||
segments, | ||
segments_names, | ||
dsummary, ds_names, | ||
params_general, params_output, | ||
params_sleep, params_247, | ||
params_phyact, | ||
sumSleep, sibDef, | ||
fullFilename, | ||
add_one_day_to_next_date, | ||
lightpeak_available, | ||
tail_expansion_log, | ||
foldernamei) | ||
} | ||
\arguments{ | ||
\item{indexlog}{ | ||
List of objects related to indices of window, file, and segment that | ||
are passed on from \link{g.part5} to aid selecting time segments or keeping track | ||
of where in file the code is. | ||
} | ||
\item{timeList}{ | ||
List of objects related to time series passed on from \link{g.part5}. | ||
} | ||
\item{levelList}{ | ||
List of objects related to intensity levels passed on from \link{g.part5}. | ||
} | ||
\item{segments}{ | ||
List produced by \link{g.part5} | ||
} | ||
\item{segments_names}{ | ||
Vector produced by \link{g.part5} | ||
} | ||
\item{dsummary}{ | ||
Matrix to hold all daysummary (and segment summary) | ||
} | ||
\item{ds_names}{ | ||
Character vector with column names of the dsummary matrix. The code collects | ||
these separately in this vector and assigns them at the end. | ||
} | ||
\item{params_general}{ | ||
See \link{GGIR} | ||
} | ||
\item{params_output}{ | ||
See \link{GGIR} | ||
} | ||
\item{params_sleep}{ | ||
See \link{GGIR} | ||
} | ||
\item{params_247}{ | ||
See \link{GGIR} | ||
} | ||
\item{params_phyact}{ | ||
See \link{GGIR} | ||
} | ||
\item{sumSleep}{ | ||
Section of data.frame produced by \link{g.part4} passed on from \link{g.part5}. | ||
} | ||
\item{sibDef}{ | ||
Character to identify sib definition. | ||
} | ||
\item{fullFilename}{ | ||
Character with full filename being processed | ||
} | ||
\item{add_one_day_to_next_date}{ | ||
Boolean to indicate whether one day should be added to next date | ||
} | ||
\item{lightpeak_available}{ | ||
Boolean to indicate whether light peak is available | ||
} | ||
\item{tail_expansion_log}{ | ||
Object generated in \link{g.part1} and passed on to \link{g.part5} when | ||
argument \code{recordingEndSleepHour} is used. | ||
} | ||
\item{foldernamei}{ | ||
Character with folder name in which the data file is stored. | ||
} | ||
} | ||
\value{ | ||
List with objects: indexlog, timeList, and the matrix with the prelimenary results | ||
and column names (dsummary and ds_names, see input arguments above) | ||
} | ||
\keyword{internal} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
\name{g.part5_initialise_ts} | ||
\alias{g.part5_initialise_ts} | ||
\title{ | ||
Initialise time series data from for part 5 | ||
} | ||
\description{ | ||
Initialise time series dataframe ts, part of \link{g.part5}. | ||
} | ||
\usage{ | ||
g.part5_initialise_ts(IMP, M, params_247, params_general) | ||
} | ||
\arguments{ | ||
\item{IMP}{ | ||
Object derived from \link{g.part2} | ||
} | ||
\item{M}{ | ||
Object derived from \link{g.part1}. | ||
} | ||
\item{params_247}{ | ||
See \link{GGIR} | ||
} | ||
\item{params_general}{ | ||
See \link{GGIR} | ||
} | ||
} | ||
\value{ | ||
Data.frame ts | ||
} | ||
\keyword{internal} |