read.gt3x.Rd
Read activity samples from a GT3X file as a matrix.
Please note that all timestamps are in local time (of the device)
even though they are represented as POSIXct
with GMT timezone.
read.gt3x( path, verbose = FALSE, asDataFrame = FALSE, imputeZeroes = FALSE, cleanup = FALSE, ..., add_light = FALSE )
path | Path to gt3x folder |
---|---|
verbose | print diagnostic messages |
asDataFrame | convert to an |
imputeZeroes | Impute zeros in case there are missingness? Default is FALSE, in which case the time series will be incomplete in case there is missingness. |
cleanup | should any unzipped files be deleted? |
... | additional arguments to pass to |
add_light | add light data to the |
A numeric matrix with 3 columns (X, Y, Z) and the following attributes:
start_time
: Start time from info file in POSIXct
format.
subject_name
: Subject name from info file
time_zone
: Time zone from info file
missingness
: Named integer vector. Names are POSIXct
timestamps and values are the number of missing values.
The timestamps in the .gt3x data format are saved in .NET format, which is
nanoseconds in local time since 0001-01-01.
This is a bit tricky to parse into an R datetime format. DateTimes are
therefore represented as POSIXct
format with the
'GMT' timezone attribute, which is false; the datetime actually
represents local time.
Other gt3x-parsers:
as.data.frame.activity()
,
parse_gt3x_info()
,
print.gt3x_info()
gt3xfile <- system.file( "extdata", "TAS1H30182785_2019-09-17.gt3x", package = "read.gt3x") is_gt3x(gt3xfile)#> /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpW9yqzD/temp_libpath85592ead099f/read.gt3x/extdata/TAS1H30182785_2019-09-17.gt3x #> TRUE#> [1] TRUEx <- read.gt3x(gt3xfile, imputeZeroes = FALSE, asDataFrame = FALSE, verbose = TRUE)#>#>#>#>#>#> GT3X information #> $ Serial Number :"TAS1H30182785" #> $ Device Type :"Link" #> $ Firmware :"1.7.2" #> $ Battery Voltage :"4.18" #> $ Sample Rate :100 #> $ Start Date : POSIXct, format: "2019-09-17 18:40:00" #> $ Stop Date : POSIXct, format: "2019-09-18 19:00:00" #> $ Last Sample Time : POSIXct, format: "2019-09-17 19:20:05" #> $ TimeZone :"-04:00:00" #> $ Download Date : POSIXct, format: "2019-09-17 19:20:05" #> $ Board Revision :"8" #> $ Unexpected Resets :"0" #> $ Acceleration Scale:256 #> $ Acceleration Min :"-8.0" #> $ Acceleration Max :"8.0" #> $ Subject Name :"suffix_85" #> $ Serial Prefix :"TAS"#>#> ---GT3X PARAMETERS #> address: 0 key: 6 value: 1 #> address: 0 key: 7 value: 54703161 #> address: 0 key: 8 value: 8 #> address: 0 key: 9 value: 1534154836 #> address: 0 key: 13 value: 17235970 #> address: 0 key: 16 value: 3791650816 #> address: 0 key: 20 value: 0 #> address: 0 key: 21 value: 0 #> address: 0 key: 22 value: 0 #> address: 0 key: 23 value: 0 #> address: 0 key: 26 value: 2 #> address: 0 key: 28 value: 262013 #> address: 0 key: 29 value: 255 #> address: 0 key: 32 value: 16908288 #> address: 0 key: 37 value: 1024 #> address: 0 key: 38 value: 0 #> address: 0 key: 49 value: 2048 #> address: 0 key: 50 value: 88181047 #> address: 0 key: 51 value: 6.82667 #> address: 0 key: 55 value: 256 #> address: 0 key: 57 value: 333.87 #> address: 0 key: 58 value: 21 #> address: 0 key: 61 value: 2 #> address: 1 key: 0 value: 0 #> address: 1 key: 1 value: 872668711 #> address: 1 key: 2 value: 388 #> address: 1 key: 3 value: 1 #> address: 1 key: 4 value: 4294967131 #> address: 1 key: 5 value: 4294967095 #> address: 1 key: 6 value: 4294967149 #> address: 1 key: 7 value: 298 #> address: 1 key: 8 value: 286 #> address: 1 key: 9 value: 300 #> address: 1 key: 10 value: 100 #> address: 1 key: 12 (start time) value: 1568745600 #> address: 1 key: 13 value: 1568833200 #> address: 1 key: 14 value: 1568745556 #> address: 1 key: 15 value: 74 #> address: 1 key: 16 value: 40 #> address: 1 key: 17 value: 72 #> address: 1 key: 20 value: 0 #> address: 1 key: 21 value: 0 #> address: 1 key: 33 value: 60000 #> address: 1 key: 34 value: 4294965247 #> address: 1 key: 35 value: 4294965190 #> address: 1 key: 36 value: 4294965237 #> address: 1 key: 37 value: 2051 #> address: 1 key: 38 value: 2000 #> address: 1 key: 39 value: 2048 #> address: 1 key: 40 value: 0 #> address: 1 key: 41 value: 1 #> address: 1 key: 42 value: 0 #> address: 1 key: 43 value: 4294967283 #> address: 1 key: 44 value: 0 #> address: 1 key: 45 value: 0 #> address: 1 key: 46 value: 0 #> ---END PARAMETERS #> #> Activity with Sample Size of 0 #> payload start: 1568747741 #> total_records: 31800 #> max_samples: 240500 #> Activity with Sample Size of 0 #> payload start: 1568747759 #> total_records: 33000 #> max_samples: 240500 #> Total Records: 33000 #> Scaling... #> Removing excess rows #> Sum of missingness is: 183000 #> Finding missingness amount: 24500 #> Creating dimnames #> CPP returning#>#>#>#> Sampling Rate: 100Hz #> Firmware Version: 1.7.2 #> Serial Number Prefix: TAS #> time X Y Z #> 1 2019-09-17 18:40:00.00 0.000 0.008 0.996 #> 2 2019-09-17 18:40:00.00 0.016 0.000 1.008 #> 3 2019-09-17 18:40:00.01 0.020 -0.008 1.004 #> 4 2019-09-17 18:40:00.02 0.016 -0.012 1.012 #> 5 2019-09-17 18:40:00.03 0.016 -0.008 1.008 #> 6 2019-09-17 18:40:00.04 0.008 -0.008 1.008#> used (Mb) gc trigger (Mb) limit (Mb) max used (Mb) #> Ncells 764228 40.9 1197268 64 NA 1197268 64.0 #> Vcells 1562101 12.0 8388608 64 65536 2829812 21.6#> used (Mb) gc trigger (Mb) limit (Mb) max used (Mb) #> Ncells 764240 40.9 1197268 64 NA 1197268 64.0 #> Vcells 1562166 12.0 8388608 64 65536 2829812 21.6#> used (Mb) gc trigger (Mb) limit (Mb) max used (Mb) #> Ncells 764138 40.9 1197268 64 NA 1197268 64.0 #> Vcells 1429986 11.0 8388608 64 65536 2829812 21.6x <- read.gt3x(gt3xfile, imputeZeroes = TRUE, asDataFrame = TRUE, verbose = TRUE)#>#>#>#>#>#> GT3X information #> $ Serial Number :"TAS1H30182785" #> $ Device Type :"Link" #> $ Firmware :"1.7.2" #> $ Battery Voltage :"4.18" #> $ Sample Rate :100 #> $ Start Date : POSIXct, format: "2019-09-17 18:40:00" #> $ Stop Date : POSIXct, format: "2019-09-18 19:00:00" #> $ Last Sample Time : POSIXct, format: "2019-09-17 19:20:05" #> $ TimeZone :"-04:00:00" #> $ Download Date : POSIXct, format: "2019-09-17 19:20:05" #> $ Board Revision :"8" #> $ Unexpected Resets :"0" #> $ Acceleration Scale:256 #> $ Acceleration Min :"-8.0" #> $ Acceleration Max :"8.0" #> $ Subject Name :"suffix_85" #> $ Serial Prefix :"TAS"#>#> ---GT3X PARAMETERS #> address: 0 key: 6 value: 1 #> address: 0 key: 7 value: 54703161 #> address: 0 key: 8 value: 8 #> address: 0 key: 9 value: 1534154836 #> address: 0 key: 13 value: 17235970 #> address: 0 key: 16 value: 3791650816 #> address: 0 key: 20 value: 0 #> address: 0 key: 21 value: 0 #> address: 0 key: 22 value: 0 #> address: 0 key: 23 value: 0 #> address: 0 key: 26 value: 2 #> address: 0 key: 28 value: 262013 #> address: 0 key: 29 value: 255 #> address: 0 key: 32 value: 16908288 #> address: 0 key: 37 value: 1024 #> address: 0 key: 38 value: 0 #> address: 0 key: 49 value: 2048 #> address: 0 key: 50 value: 88181047 #> address: 0 key: 51 value: 6.82667 #> address: 0 key: 55 value: 256 #> address: 0 key: 57 value: 333.87 #> address: 0 key: 58 value: 21 #> address: 0 key: 61 value: 2 #> address: 1 key: 0 value: 0 #> address: 1 key: 1 value: 872668711 #> address: 1 key: 2 value: 388 #> address: 1 key: 3 value: 1 #> address: 1 key: 4 value: 4294967131 #> address: 1 key: 5 value: 4294967095 #> address: 1 key: 6 value: 4294967149 #> address: 1 key: 7 value: 298 #> address: 1 key: 8 value: 286 #> address: 1 key: 9 value: 300 #> address: 1 key: 10 value: 100 #> address: 1 key: 12 (start time) value: 1568745600 #> address: 1 key: 13 value: 1568833200 #> address: 1 key: 14 value: 1568745556 #> address: 1 key: 15 value: 74 #> address: 1 key: 16 value: 40 #> address: 1 key: 17 value: 72 #> address: 1 key: 20 value: 0 #> address: 1 key: 21 value: 0 #> address: 1 key: 33 value: 60000 #> address: 1 key: 34 value: 4294965247 #> address: 1 key: 35 value: 4294965190 #> address: 1 key: 36 value: 4294965237 #> address: 1 key: 37 value: 2051 #> address: 1 key: 38 value: 2000 #> address: 1 key: 39 value: 2048 #> address: 1 key: 40 value: 0 #> address: 1 key: 41 value: 1 #> address: 1 key: 42 value: 0 #> address: 1 key: 43 value: 4294967283 #> address: 1 key: 44 value: 0 #> address: 1 key: 45 value: 0 #> address: 1 key: 46 value: 0 #> ---END PARAMETERS #> #> Activity with Sample Size of 0 #> payload start: 1568747741 #> total_records: 214100 #> max_samples: 240500 #> Activity with Sample Size of 0 #> payload start: 1568747759 #> total_records: 215900 #> max_samples: 240500 #> Total Records: 216000 #> Scaling... #> Creating dimnames #> CPP returning#>if (FALSE) { # first unzip, then read datadir <- gt3x_datapath() gt3xfolders <- unzip.gt3x(datadir) gt3xfile <- gt3xfolders[2] # temporary unzip, read, convert to a data frame gt3xfile <- gt3x_datapath(1) memory.limit() df <- read.gt3x(gt3xfile, asDataFrame = FALSE, verbose = 2) head(df) rm(df); gc(); gc() df <- read.gt3x(gt3xfile, asDataFrame = TRUE, verbose = 2) head(df) } if (FALSE) { url <- paste0("https://github.com/THLfi/read.gt3x/", "files/", "3522749/", "GT3X%2B.01.day.gt3x.zip") destfile <- tempfile(fileext = ".zip") dl <- download.file(url, destfile = destfile, mode = "wb") gt3x_file <- unzip(destfile, exdir = tempdir()) gt3x_file <- gt3x_file[!grepl("__MACOSX", gt3x_file)] path <- gt3x_file res <- read.gt3x(path) gz <- R.utils::gzip(path, remove = FALSE, overwrite = FALSE) df2 <- read.gt3x(gz, asDataFrame = FALSE, verbose = 2) head(df2) rm(df2); gc(); gc() }