Skip to content

Commit e9b13ef

Browse files
author
Bart
committed
add tests with mb and add persp plot
1 parent 84b4de3 commit e9b13ef

File tree

7 files changed

+51
-50
lines changed

7 files changed

+51
-50
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
env:
1616
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
17+
MBPWD: ${{ secrets.MBPWD }}
1718
R_KEEP_PKG_SOURCE: yes
1819
steps:
1920
- uses: actions/checkout@v4

.github/workflows/pkgdown.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ jobs:
3838
needs: website
3939

4040
- name: Build site
41-
env:
42-
MBPWD: ${{ secrets.MBPWD }}
4341
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
4442
shell: Rscript {0}
4543

.github/workflows/test-coverage.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
env:
1616
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
17+
MBPWD: ${{ secrets.MBPWD }}
1718

1819
steps:
1920
- uses: actions/checkout@v4

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Suggests:
2424
knitr,
2525
move2,
2626
rmarkdown,
27-
testthat (>= 3.0.0)
27+
testthat (>= 3.0.0),
28+
withr
2829
Config/testthat/edition: 3
2930
RoxygenNote: 7.3.2
3031
VignetteBuilder: knitr

tests/testthat/test-acc.R

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -34,47 +34,3 @@ test_that("properties are correctly calculated",{
3434

3535
})
3636

37-
test_that("multiplication works", {
38-
skip("To work on")
39-
acc(list(
40-
matrix(1:12, ncol = 3, dimnames = list(NULL, letters[1:3])),
41-
matrix(1:8, ncol = 2, dimnames = list(NULL, letters[4:5]))
42-
), frequency = 2:3)
43-
new_acc(list(
44-
matrix(units::set_units(1:12, "g"), ncol = 3),
45-
matrix(units::set_units(1:8, "g"), ncol = 2)
46-
))
47-
new_acc(list(
48-
structure(units::set_units(1:10, "g"), dim = c(5L, 2L)),
49-
structure(units::set_units(1:15, "g"), dim = c(5L, 3L))
50-
), frequency = c(20, 30), axes = list(c("x", "y"), c("x", "y", "z")))
51-
new_acc(list(
52-
structure(units::set_units(1:10, "m/s"), dim = c(5L, 2L)),
53-
structure(units::set_units(1:15, "m/s"), dim = c(5L, 3L))
54-
))
55-
})
56-
test_that("size", {
57-
skip()
58-
# aa <- move2::movebank_retrieve("study_attribute", study_id = 4502577, sensor_type_id = 2365683) |>
59-
# dplyr::pull("short_name") |>
60-
# grep(pat = "eobs_acceler", value = T)
61-
# a <- move2::movebank_download_study(4502577, attributes = aa)
62-
# matrixList <- a$eobs_accelerations_raw |>
63-
# tail() |>
64-
# strsplit(" ") |>
65-
# lapply(as.integer) |>
66-
# lapply(matrix, ncol = 3, byrow = T)
67-
# new_acc(matrixList)
68-
# aaa <- a$eobs_accelerations_raw[100000 + 1:1000]
69-
# aac <- as_acc(aaa)
70-
# pryr::object_size(aaa)
71-
# pryr::object_size(aac)
72-
# pryr::object_size(unlist(aac))
73-
# pryr::object_size(packBits(lapply(lapply(unlist(aac), intToBits), head, 12) |> unlist(), "integer"))
74-
# l <- array(unlist(aac), c(68, 3, 1000))
75-
# c(apply(l, 2:3, mean))
76-
# bench::mark(
77-
# unlist(lapply(aac, apply, 2, mean)),
78-
# c(apply(l, 2:3, mean))
79-
# )
80-
})

tests/testthat/test-plot_time.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
test_that("plot_time", {
2+
x <- acc(list(
3+
matrix(1:12, ncol = 3, dimnames = list(NULL, letters[1:3])),
4+
matrix(1:8, ncol = 2, dimnames = list(NULL, letters[4:5]))
5+
), frequency = units::set_units(2:3,'Hz'))
6+
expect_silent(graph<-plot_time(x, Sys.time()+c(0,10)))
7+
expect_s3_class(graph,"dygraphs")
8+
9+
})

vignettes/moveAcc.Rmd

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ vignette: >
77
%\VignetteEncoding{UTF-8}
88
---
99

10-
```{r, include = FALSE}
10+
```{r setup, include = FALSE}
1111
knitr::opts_chunk$set(
1212
collapse = TRUE,
1313
comment = "#>"
@@ -23,7 +23,7 @@ if (Sys.getenv("MBPWD") != "") {
2323
Sys.setlocale("LC_TIME", "en_US.utf8")
2424
```
2525

26-
```{r setup}
26+
```{r load}
2727
library(moveAcc)
2828
```
2929
The goal of the package is to create a vector representation of acceleration bursts in R. Acceleration bursts are a frequently collected by animal tracking devices and consist of measurements of the acceleration in one till three axis. These measurements are recorded with a fixed frequency for a few seconds. These burst are frequently considered one "instantaneous" sample of the activity or behavior of an animal.
@@ -103,7 +103,42 @@ mt_stack(lbbg_data, kinkajous_data)
103103

104104
With the `plot_time` function it is possible to explor the acceleration bursts. In this plot you can zoom using your mouse.
105105

106-
```{r plot}
106+
```{r plot, fig.width=6}
107107
plot_time(lbbg_data$acceleration, mt_time(lbbg_data))
108108
```
109109

110+
Alternatively you can plot one burst directly, in this case showing the clear wing beats on the z axis.
111+
112+
113+
```{r plot_one, fig.width=6}
114+
plot_time(lbbg_data$acceleration[340], mt_time(lbbg_data)[340])
115+
```
116+
We can also visualize one burst in three dimensions showing the cyclic patterns in the acceleration.
117+
118+
```{r plot3d, fig.width=6, fig.height=6}
119+
bb<-vctrs::field(lbbg_data$acceleration[340],"bursts")[[1]]
120+
b<-units::drop_units(bb)
121+
e<-0.1
122+
persp(z=matrix(min(b[,'tilt_z'])-e, ncol=2, nrow=2),
123+
x=range(b[,'tilt_x']),
124+
y=range(b[,'tilt_y']),
125+
xlim=range(b[,'tilt_x'])+c(-e,e),
126+
ylim=range(b[,'tilt_y'])+c(-e,e),
127+
zlim=range(b[,'tilt_z'])+c(-e,e),
128+
border=NA,
129+
xlab=paste0("X [",as.character(units(bb)),']'),
130+
ticktype = "detailed", cex.axis = 0.65,
131+
ylab=paste0("Y [",as.character(units(bb)),']'),
132+
zlab=paste0("Z [",as.character(units(bb)),']'),
133+
theta = -160, phi = 20, expand = 0.5, col = "white", scale=F)->p
134+
# Draw line on bottom of plot
135+
lines(trans3d(b[,'tilt_x'],b[,'tilt_y'],min(b[,'tilt_z'])-e,p), col="tomato")
136+
# Lines to connect observations to bottom
137+
apply(b,1, function(x, bottom){
138+
lines(trans3d(x['tilt_x'],x['tilt_y'],c(x['tilt_z'], bottom-e),p), col="gray")
139+
}, bottom=min(b[,'tilt_z']))
140+
141+
lines(trans3d(b[,'tilt_x'],b[,'tilt_y'],b[,'tilt_z'],p), col="red")
142+
points(trans3d(b[,'tilt_x'],b[,'tilt_y'],b[,'tilt_z'],p), col="red", pch=19)
143+
144+
```

0 commit comments

Comments
 (0)