Last data update: 2014.03.03

R: Extract an interval of data.
get.intervalsR Documentation

Extract an interval of data.

Description

Function for extracting sub intervals of data, and implementation of just-in-time loading.

Usage

get.intervals(x, start=0, end = 1, length = NULL, time.format = c("auto", "seconds", "days", "proportion", "measurements", "time"), incl.date = FALSE, simplify = TRUE ,read.from.file=FALSE, size=Inf, ...)

Arguments

x

Object to process. Can be array,

start

Start of interval.

end

End of interval.

length

Length of interval.

time.format

Method with which start and end should be understood.

incl.date

logical. Include a column denoting time?

simplify

logical. If TRUE, output an array. Otherwise output a AccData object.

read.from.file

logical. If TRUE, re-read the relevant time interval from the original bin file.

size

Desired number of samples in output.

...

Additional arguments to be passed to read.bin, if read.from.file is TRUE.

Details

The function extracts the desired analysis time window specified by start and end. If length is specified, then the end is set to a point length units after start. The times are interpreted in terms of time.format. For convenience, a variety of time window formats are accepted:

"seconds": Seconds since start of dataset.

"days": Days since start of dataset.

"proportion": Proportional point within dataset, given as a numeric between 0 and 1.

"measurements": Raw number of samples since start of dataset.

"time": Time string, as understood via parse.time.

"auto": Default - attempt to determine time format from size and type of start.

Some capacity for using mixed types of inputs for start and length in particular is present.

The input object x is typically an "AccData" object, though arrays are also accepted. "VirtAccData" are dealt with by using the timestamp and call information recorded within them to do a new read of the original bin file, assuming this is still available. This is useful for 'just in time' reads of data. "AccData" can be dealt with in this way by setting read.from.file.

Note that for read.from.file, only "time" and "proportion" time.format are presently supported.

Value

With simplify = FALSE, an "AccData" S3 object with the desired records.

Otherwise, an array containing either 3 or 4 columns, containing the x, y, z acceleration vectors and optionally a time vector.

See Also

read.bin, [.AccData, get.intervals

Examples


binfile  = system.file("binfile/TESTfile.bin", package = "GENEAread")[1]

#Read in a highly downsampled version of the file
procfile<-read.bin(binfile, downsample = 100)
print(procfile)
#Plot the x component
plot(procfile[,1:2], type = "l")

#Overlay some segments in different colour
lines(get.intervals(procfile, start = 0.4, end = 0.5, time.format = "prop", incl.date = TRUE)[,1:2], col=2) 
lines(get.intervals(procfile, start = 0.4, end = 5, time.format = "sec", incl.date = TRUE)[,1:2], col=3) 
lines(get.intervals(procfile, start = "16:51", end = "16:52", time.format = "time", incl.date = TRUE)[,1:2], col=4) 
#Note that measurements will depend on the downsampling rate, not the original sampling rate of the data
lines(get.intervals(procfile, start = 100, length = 10, time.format = "measurement", incl.date = TRUE)[,1:2], col=5) 
#This is also understood
lines(get.intervals(procfile, start = "16:52:10", 30,  incl.date = TRUE)[,1:2], col=6) 

#Now load in virtually
virtfile<-read.bin(binfile, virtual = TRUE)
#Notice that get.intervals with simplify = FALSE gives a genuine AccData object
realfile = get.intervals(virtfile, start = 0.5, end = 1, simplify = FALSE)
virtfile
realfile
#get.intervals calls read.bin automatically
points(get.intervals(virtfile, start = "16:52:10", "16:52:40",  incl.date = TRUE)[,1:2], col=4, pch = ".") 

#Alternatively, re-read procfile at a different resampling rate.
lines(get.intervals(procfile, start = "16:49:00", "16:49:30",  incl.date = TRUE, read.from.file = TRUE, downsample = 300)[,1:2], col=2) 


Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(GENEAread)
Loading required package: bitops
GENEAread 1.1.1 loaded

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GENEAread/get.intervals.Rd_%03d_medium.png", width=480, height=480)
> ### Name: get.intervals
> ### Title: Extract an interval of data.
> ### Aliases: get.intervals print.VirtAccData VirtAccData
> ### Keywords: manip
> 
> ### ** Examples
> 
> 
> binfile  = system.file("binfile/TESTfile.bin", package = "GENEAread")[1]
> 
> #Read in a highly downsampled version of the file
> procfile<-read.bin(binfile, downsample = 100)
Loading required package: mmap
Downsampling to  1  Hz 
Number of pages in binary file: 104 
Calculated page references... 
Processing...
================================================================================
Processing took: 0.05 secs .
Loaded 312 records (Approx  0 MB of RAM)
12-05-23 16:47:50.000 (Wed)  to  12-05-23 16:53:01.000 (Wed) 
Warning message:
In FUN(newX[, i], ...) : NAs introduced by coercion
> print(procfile)
GENEAread dataset:  312 records at 1 Hz (Approx  0 MB of RAM)
12-05-23 16:47:50.000 (Wed)  to  12-05-23 16:53:01.000 (Wed) 
[ TESTfile.bin ]
> #Plot the x component
> plot(procfile[,1:2], type = "l")
> 
> #Overlay some segments in different colour
> lines(get.intervals(procfile, start = 0.4, end = 0.5, time.format = "prop", incl.date = TRUE)[,1:2], col=2) 
Extracting time interval:  16:49:54 16:50:25 
> lines(get.intervals(procfile, start = 0.4, end = 5, time.format = "sec", incl.date = TRUE)[,1:2], col=3) 
Extracting time interval:  47:50.000 47:54.000 
> lines(get.intervals(procfile, start = "16:51", end = "16:52", time.format = "time", incl.date = TRUE)[,1:2], col=4) 
Extracting time interval:  16:51:00 16:52:01 
> #Note that measurements will depend on the downsampling rate, not the original sampling rate of the data
> lines(get.intervals(procfile, start = 100, length = 10, time.format = "measurement", incl.date = TRUE)[,1:2], col=5) 
Extracting time interval:  16:49:29 16:49:39 
> #This is also understood
> lines(get.intervals(procfile, start = "16:52:10", 30,  incl.date = TRUE)[,1:2], col=6) 
Extracting time interval:  16:52:10 16:52:40 
> 
> #Now load in virtually
> virtfile<-read.bin(binfile, virtual = TRUE)
Number of pages in binary file: 104 
Calculated page references... 
Processing...

Virtually loaded 31200 records at 100 Hz (Will take up approx  2 MB of RAM)
12-05-23 16:47:50.000 (Wed)  to  12-05-23 16:53:02.000 (Wed) 
> #Notice that get.intervals with simplify = FALSE gives a genuine AccData object
> realfile = get.intervals(virtfile, start = 0.5, end = 1, simplify = FALSE)
Number of pages in binary file: 104 
Calculated page references... 
Processing...
================================================================================
Processing took: 0.012 secs .
Loaded 15900 records (Approx  1 MB of RAM)
12-05-23 16:50:23.000 (Wed)  to  12-05-23 16:53:01.990 (Wed) 
> virtfile
[Virtual GENEAread dataset]:  31200 records at 100 Hz (Approx  2 MB of RAM)
12-05-23 16:47:50.000 (Wed)  to  12-05-23 16:53:02.000 (Wed) 
[ TESTfile.bin ]
> realfile
GENEAread dataset:  15900 records at 100 Hz (Approx  1 MB of RAM)
12-05-23 16:50:23.000 (Wed)  to  12-05-23 16:53:01.990 (Wed) 
[ TESTfile.bin ]
> #get.intervals calls read.bin automatically
> points(get.intervals(virtfile, start = "16:52:10", "16:52:40",  incl.date = TRUE)[,1:2], col=4, pch = ".") 
Number of pages in binary file: 104 
Calculated page references... 
Processing...
================================================================================
Processing took: 0.003 secs .
Loaded 3600 records (Approx  0 MB of RAM)
12-05-23 16:52:08.000 (Wed)  to  12-05-23 16:52:43.990 (Wed) 
Extracting time interval:  16:52:08 16:52:43 
> 
> #Alternatively, re-read procfile at a different resampling rate.
> lines(get.intervals(procfile, start = "16:49:00", "16:49:30",  incl.date = TRUE, read.from.file = TRUE, downsample = 300)[,1:2], col=2) 
Downsampling to  0.33  Hz 
Number of pages in binary file: 104 
Calculated page references... 
Processing...
================================================================================
Processing took: 0.002 secs .
Loaded 12 records (Approx  0 MB of RAM)
12-05-23 16:48:59.000 (Wed)  to  12-05-23 16:49:32.000 (Wed) 
Extracting time interval:  16:48:59 16:49:32 
> 
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>