library(readr)
library(GGIR)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(pycwa)
library(read.cwa)
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
destfile = file.path(tempdir(), "accsamp.zip")
file = file.path(tempdir(), "accsamp.cwa")
if (!file.exists(file)) {
if (!file.exists(destfile)) {
download.file("https://biobank.ctsu.ox.ac.uk/crystal/crystal/examples/accsamp.zip",
destfile = destfile, quiet = FALSE)
}
unz = unzip(destfile, exdir = tempdir(), overwrite = TRUE)
}
xyz = c("x", "y", "z")
round_to_seconds = function(df) {
df %>% mutate(time = lubridate::floor_date(time, "1 second"))
}
get_ranges = function(x) {
sapply(x[xyz], range)
}
############################################
# Reader from OpenMovement/om
############################################
om = read_cwa(file, verbose = FALSE)
om = om$data
colnames(om) = tolower(colnames(om))
om = om[, c("time", xyz)]
nrow(om)
#> [1] 62227320
get_ranges(om)
#> x y z
#> [1,] -8.000000 -8.000000 -8.000000
#> [2,] 7.984375 7.984375 7.984375
om = round_to_seconds(om)
############################################
# Reader from https://github.com/activityMonitoring/biobankAccelerometerAnalysis
############################################
py = py_read_cwa(file, verbose = FALSE)
py = py[, c("time", xyz)]
nrow(py)
#> [1] 60477000
get_ranges(py)
#> x y z
#> [1,] -8.000 -8.000 -8.000
#> [2,] 7.984 7.984 7.984
py = round_to_seconds(py)
head(om)
#> # A tibble: 6 x 4
#> time x y z
#> <dttm> <dbl> <dbl> <dbl>
#> 1 2013-07-13 10:00:05 -0.672 0.125 -1.30
#> 2 2013-07-13 10:00:05 -0.0312 -0.109 0.844
#> 3 2013-07-13 10:00:05 -0.0469 -0.125 0.891
#> 4 2013-07-13 10:00:05 -0.0312 -0.125 0.891
#> 5 2013-07-13 10:00:05 -0.0312 -0.125 0.891
#> 6 2013-07-13 10:00:05 -0.0312 -0.125 0.891
head(py)
#> # A tibble: 6 x 4
#> time x y z
#> <dttm> <dbl> <dbl> <dbl>
#> 1 2013-07-13 09:00:05 -0.672 0.125 -1.30
#> 2 2013-07-13 09:00:05 -0.031 -0.109 0.844
#> 3 2013-07-13 09:00:05 -0.047 -0.125 0.891
#> 4 2013-07-13 09:00:05 -0.031 -0.125 0.891
#> 5 2013-07-13 09:00:05 -0.031 -0.125 0.891
#> 6 2013-07-13 09:00:05 -0.031 -0.125 0.891
# need to add because of DST
py$time = py$time + as.period(1, "hour")
om %>% filter(time <= time[1] + as.period(30, "seconds")) %>% group_by(time) %>% count()
#> # A tibble: 31 x 2
#> # Groups: time [31]
#> time n
#> <dttm> <int>
#> 1 2013-07-13 10:00:05 23
#> 2 2013-07-13 10:00:06 101
#> 3 2013-07-13 10:00:07 103
#> 4 2013-07-13 10:00:08 103
#> 5 2013-07-13 10:00:09 104
#> 6 2013-07-13 10:00:10 103
#> 7 2013-07-13 10:00:11 104
#> 8 2013-07-13 10:00:12 103
#> 9 2013-07-13 10:00:13 104
#> 10 2013-07-13 10:00:14 104
#> # … with 21 more rows
py %>% filter(time <= time[1] + as.period(30, "seconds")) %>% group_by(time) %>% count()
#> # A tibble: 31 x 2
#> # Groups: time [31]
#> time n
#> <dttm> <int>
#> 1 2013-07-13 10:00:05 23
#> 2 2013-07-13 10:00:06 100
#> 3 2013-07-13 10:00:07 100
#> 4 2013-07-13 10:00:08 100
#> 5 2013-07-13 10:00:09 100
#> 6 2013-07-13 10:00:10 100
#> 7 2013-07-13 10:00:11 100
#> 8 2013-07-13 10:00:12 100
#> 9 2013-07-13 10:00:13 100
#> 10 2013-07-13 10:00:14 100
#> # … with 21 more rows
gg = GGIR::g.cwaread(file, end = Inf, progressBar = TRUE, desiredtz = "UTC")
#> | | | 0% | | | 1% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |== | 4% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 9% | |======= | 10% | |======= | 11% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========= | 14% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 16% | |============ | 17% | |============ | 18% | |============= | 18% | |============= | 19% | |============== | 19% | |============== | 20% | |============== | 21% | |=============== | 21% | |=============== | 22% | |================ | 22% | |================ | 23% | |================ | 24% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |=================== | 26% | |=================== | 27% | |=================== | 28% | |==================== | 28% | |==================== | 29% | |===================== | 29% | |===================== | 30% | |===================== | 31% | |====================== | 31% | |====================== | 32% | |======================= | 32% | |======================= | 33% | |======================= | 34% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 36% | |========================== | 37% | |========================== | 38% | |=========================== | 38% | |=========================== | 39% | |============================ | 39% | |============================ | 40% | |============================ | 41% | |============================= | 41% | |============================= | 42% | |============================== | 42% | |============================== | 43% | |============================== | 44% | |=============================== | 44% | |=============================== | 45% | |================================ | 45% | |================================ | 46% | |================================= | 46% | |================================= | 47% | |================================= | 48% | |================================== | 48% | |================================== | 49% | |=================================== | 49% | |=================================== | 50% | |=================================== | 51% | |==================================== | 51% | |==================================== | 52% | |===================================== | 52% | |===================================== | 53% | |===================================== | 54% | |====================================== | 54% | |====================================== | 55% | |======================================= | 55% | |======================================= | 56% | |======================================== | 56% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 59% | |========================================== | 60% | |========================================== | 61% | |=========================================== | 61% | |=========================================== | 62% | |============================================ | 62% | |============================================ | 63% | |============================================ | 64% | |============================================= | 64% | |============================================= | 65% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 66% | |=============================================== | 67% | |=============================================== | 68% | |================================================ | 68% | |================================================ | 69% | |================================================= | 69% | |================================================= | 70% | |================================================= | 71% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 72% | |=================================================== | 73% | |=================================================== | 74% | |==================================================== | 74% | |==================================================== | 75% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 76% | |====================================================== | 77% | |====================================================== | 78%
gg = gg$data
gg$time = lubridate::as_datetime(gg$time)
gg %>% filter(time <= time[1] + as.period(30, "seconds")) %>%
round_to_seconds() %>% group_by(time) %>% count()
#> # A tibble: 31 x 2
#> # Groups: time [31]
#> time n
#> <dttm> <int>
#> 1 2013-07-13 10:00:05 23
#> 2 2013-07-13 10:00:06 100
#> 3 2013-07-13 10:00:07 100
#> 4 2013-07-13 10:00:08 100
#> 5 2013-07-13 10:00:09 100
#> 6 2013-07-13 10:00:10 100
#> 7 2013-07-13 10:00:11 100
#> 8 2013-07-13 10:00:12 100
#> 9 2013-07-13 10:00:13 100
#> 10 2013-07-13 10:00:14 100
#> # … with 21 more rows
library(readr)
library(GGIR)
library(dplyr)
library(pycwa)
library(read.cwa)
library(lubridate)
destfile = file.path(tempdir(), "accsamp.zip")
file = file.path(tempdir(), "accsamp.cwa")
if (!file.exists(file)) {
if (!file.exists(destfile)) {
download.file("https://biobank.ctsu.ox.ac.uk/crystal/crystal/examples/accsamp.zip",
destfile = destfile, quiet = FALSE)
}
unz = unzip(destfile, exdir = tempdir(), overwrite = TRUE)
}
xyz = c("x", "y", "z")
round_to_seconds = function(df) {
df %>% mutate(time = lubridate::floor_date(time, "1 second"))
}
get_ranges = function(x) {
sapply(x[xyz], range)
}
############################################
# Reader from OpenMovement/om
############################################
om = read_cwa(file, verbose = FALSE)
om = om$data
colnames(om) = tolower(colnames(om))
om = om[, c("time", xyz)]
nrow(om)
get_ranges(om)
om = round_to_seconds(om)
############################################
# Reader from https://github.com/activityMonitoring/biobankAccelerometerAnalysis
############################################
py = py_read_cwa(file, verbose = FALSE)
py = py[, c("time", xyz)]
nrow(py)
get_ranges(py)
py = round_to_seconds(py)
head(om)
head(py)
# need to add because of DST
py$time = py$time + as.period(1, "hour")
om %>% filter(time <= time[1] + as.period(30, "seconds")) %>% group_by(time) %>% count()
py %>% filter(time <= time[1] + as.period(30, "seconds")) %>% group_by(time) %>% count()
gg = GGIR::g.cwaread(file, end = Inf, progressBar = TRUE, desiredtz = "UTC")
gg = gg$data
gg$time = lubridate::as_datetime(gg$time)
gg %>% filter(time <= time[1] + as.period(30, "seconds")) %>%
round_to_seconds() %>% group_by(time) %>% count()