-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataParsing_Script.R
More file actions
77 lines (67 loc) · 2.74 KB
/
DataParsing_Script.R
File metadata and controls
77 lines (67 loc) · 2.74 KB
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
68
69
70
71
72
73
74
75
76
77
### Code for Data parsing & Prep associated with Seidel et al. 2019
### "Mesoscale movement and recursion behaviors of Namibian black rhinos"
### (submitted to Movement Ecology, BioMove Special Edition)
### Author: Dana Paige Seidel
library(tidyverse)
library(sf)
library(lubridate)
library(magrittr)
conflicted::conflict_prefer("select", "dplyr")
conflicted::conflict_prefer("filter", "dplyr")
# Metadata regarding file index and location of MODIS imagery
# MODIS imagery is freely available from NASA.gov
filemetadata <- read_csv("MODIS_metadata.csv")
# downloaded from http://ecoregions2017.appspot.com/, Licensed under CC-BY 4.0
ecoregions <- read_sf("Ecoregions2017.shp")
# functional water data - available upon reasonable request
# not public in order to protect endangered species
water_utm <- st_read("functional water.shp", crs = 4326) %>%
st_transform(32733)
# rhino data - available upon reasonable request
# not public in order to protect endangered species
rhinos_pre2017 <- read_sf("Data/clean_rhino_points.shp")
rhinos_1718 <- read_csv("Data/clean_2017-18.csv") %>%
mutate(
id = (Tag %>% str_remove(" ") %>% str_remove("IR-")),
local_date = strftime(with_tz(timestamp, tzone = "Africa/Windhoek"), format = "%m/%d/%y"),
local_time = strftime(with_tz(timestamp, tzone = "Africa/Windhoek"), format = "%T")
) %>%
st_as_sf(., coords = c("Longitude", "Latitude"), na.fail = FALSE, crs = 4326) %>%
st_transform(32733) %>%
mutate(
x = st_coordinates(.)[, 1],
y = st_coordinates(.)[, 2]
) %>%
dplyr::select(names(rhinos_pre2017))
# combine datasets
all_rhinos <- rbind(rhinos_pre2017, rhinos_1718) %>%
mutate(
date = mdy_hms(paste(local_date, local_time)),
local_date = mdy(local_date)
) %>% # filter 4 white rhinos + 679 which only has 1 pt from future analyses
filter(!(id %in% c("SAT469", "SAT676", "SAT677", "SAT678", "SAT679")))
# Custom function to build a extent/bounding-box polygon from a simple features dataset
sf_polyfrombbox <- function(sf, buffer = 0) {
if (buffer == 0) {
bbox <- st_bbox(sf) %>% as.numeric()
} else {
bbox0 <- st_bbox(sf) %>% as.numeric()
bbox <- bbox0 + c(-buffer, -buffer, buffer, buffer)
}
coords <- list(matrix(c(
bbox[1], bbox[2],
bbox[3], bbox[2],
bbox[3], bbox[4],
bbox[1], bbox[4],
bbox[1], bbox[2]
),
ncol = 2, byrow = TRUE
))
st_polygon(coords) %>% st_sfc(crs = st_crs(sf))
}
# transform rhinos to latlong, way faster than projecting the ecoregions shpfile
lat_rhinos <- all_rhinos %>% st_transform(4326)
# Crop the ecoregions shapefile with a small buffer
namib_eco <- st_intersection(ecoregions,
sf_polyfrombbox(st_bbox(lat_rhinos),
buffer = .25)) # ~50km buffer