-
Notifications
You must be signed in to change notification settings - Fork 7
/
outliers.Rmd
67 lines (56 loc) 路 1.36 KB
/
outliers.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: "Mark outliers in Movebank formatted data"
author:
- Tanja Milotic
- Peter Desmet
date: "`r Sys.Date()`"
output:
html_document:
toc: true
toc_depth: 3
toc_float: true
number_sections: true
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
```
Load libraries:
```{r}
library(tidyverse)
library(here)
library(lubridate)
library(sp)
library(trip)
library(geosphere)
```
Set values:
```{r}
project_id <- "O_WESTERSCHELDE"
```
Load custom function to mark outliers:
```{r}
source(here::here("src", "functions", "mark_outliers.R"))
```
Process files:
```{r}
files <- list.files(here::here("data", "processed", project_id, "gps"), full.names = TRUE)
for (file in files) {
data <- readr::read_csv(file, col_types = readr::cols(
timestamp = readr::col_datetime(),
`location-lat` = readr::col_double(),
`location-long` = readr::col_double(),
.default = readr::col_character() # Don't interpret/alter the other columns
))
print(file)
# Mark outliers when speed is above 45 m/s or at a sharp angle (30掳) at 15 m/s
processed_data <- mark_outliers(
data,
max_speed = 45,
min_angle_above_speed = c(30, 15),
max_runs = 10
)
# Change output dir
file <- stringr::str_replace(file, "/gps", "/gps_outliers")
readr::write_csv(processed_data, file, na = "")
}
```