Open in github.dev
Open in a new github.dev tab
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
AKDE-wolves/Data_preparation.R
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
277 lines (198 sloc)
10.7 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(lubridate) | |
| library(dplyr) | |
| library(adehabitatHR) | |
| library(sf) | |
| ## 27 | |
| data_1 <- read.table("36927.csv", header = T, sep = ";", dec = ",") # | |
| data_1$UTC.Date <- as.POSIXct(data_1$UTC.Date, format = "%d.%m.%Y") | |
| data_1$timestamp <- with(data_1, ymd(UTC.Date) + hms(UTC.Time)) # merge date and time | |
| data_1$timestamp <- round_date(data_1$timestamp, "30 mins") # rounding of time to 30 mins | |
| data_1 <- data_1[data_1$DOP < 6 ,] # DOP < 6 | |
| data_1 <- data_1 %>% filter(timestamp >= "2021-11-02 00:30:00") #removal of the observation before putting on the collar | |
| data_1 <- data_1 [,c("CollarID", "timestamp", "Longitude", "Latitude")] | |
| data_1$Longitude <- as.numeric(sub(",", ".", data_1$Longitude, fixed = TRUE)) # converting to numeric | |
| data_1$Latitude <- as.numeric(sub(",", ".", data_1$Latitude, fixed = TRUE)) | |
| data_1 <- data_1[!is.na(data_1$Longitude),] # removal of NA values | |
| data_1 <- data_1[!is.na(data_1$Latitude),] # removal of NA values | |
| data_1sf <- st_as_sf(data_1, coords=c("Longitude","Latitude")) # converting to a sf object | |
| # defining the coordinate system (4326 is a code of WGS84 coordinate system, in which GPS is measuring) | |
| data_1sf <- st_set_crs(data_1sf, 4326) | |
| plot(st_geometry(data_1sf)) | |
| # projecting to ETRS89 European coordinate system | |
| data_1sf <- st_transform(data_1sf, 3035) | |
| plot(st_geometry(data_1sf)) | |
| # creating the input data frame | |
| xy_1 <- st_coordinates(data_1sf) | |
| data_1 <- data.frame(ID = data_1sf$CollarID, | |
| x=xy_1[,1], | |
| y=xy_1[,2], | |
| timestamp=data_1sf$timestamp, | |
| Longitude=data_1$Longitude, | |
| Latitude=data_1$Latitude) | |
| # adding years, months, hours | |
| data_1$month <- format(data_1$timestamp, "%m") | |
| data_1$year <- format(data_1$timestamp, "%Y") | |
| data_1$hour <- format(data_1$timestamp, "%H:%M") | |
| data_1$month <- as.numeric((data_1$month)) | |
| data_1$year <- as.numeric((data_1$year)) | |
| ## 28 | |
| data_2 <- read.table("36928.csv", header = T, sep = ";", dec = ",") | |
| data_2$UTC.Date <- as.POSIXct(data_2$UTC.Date, format = "%d.%m.%Y") | |
| data_2$timestamp <- with(data_2, ymd(UTC.Date) + hms(UTC.Time)) # merge date and time | |
| data_2$timestamp <- round_date(data_2$timestamp, "30 mins") # rounding of time to 30 mins | |
| data_2 <- data_2[data_2$DOP < 6 ,] # DOP < 6 | |
| data_2 <- data_2 %>% filter(timestamp >= "2022-05-02 03:00:00") #removal of the observation before putting on the collar | |
| data_2 <- data_2 [,c("CollarID", "timestamp", "Longitude", "Latitude")] | |
| data_2$Longitude <- as.numeric(sub(",", ".", data_2$Longitude, fixed = TRUE)) # converting to numeric | |
| data_2$Latitude <- as.numeric(sub(",", ".", data_2$Latitude, fixed = TRUE)) | |
| data_2 <- data_2[!is.na(data_2$Longitude),] # removal of NA values | |
| data_2sf <- st_as_sf(data_2, coords=c("Longitude","Latitude")) # converting to a sf object | |
| # defining the coordinate system (4326 is a code of WGS84 coordinate system, in which GPS is measuring) | |
| data_2sf <- st_set_crs(data_2sf, 4326) | |
| plot(st_geometry(data_2sf)) | |
| # projecting to ETRS89 European coordinate system | |
| data_2sf <- st_transform(data_2sf, 5513) | |
| plot(st_geometry(data_2sf)) | |
| # creating the input data frame | |
| xy_2 <- st_coordinates(data_2sf) | |
| data_2 <- data.frame(ID = data_2$CollarID, | |
| x=xy_2[,1], | |
| y=xy_2[,2], | |
| timestamp=data_2$timestamp, | |
| Longitude=data_2$Longitude, | |
| Latitude=data_2$Latitude) | |
| # adding years, months, hours | |
| data_2$month <- format(data_2$timestamp, "%m") | |
| data_2$year <- format(data_2$timestamp, "%Y") | |
| data_2$hour <- format(data_2$timestamp, "%H:%M") | |
| data_2$month <- as.numeric((data_2$month)) | |
| data_2$year <- as.numeric((data_2$year)) | |
| ## 30 | |
| data_3 <- read.table("36930.csv", header = T, sep = ";", dec = ",") | |
| data_3$UTC.Date <- as.POSIXct(data_3$UTC.Date, format = "%d.%m.%Y") | |
| data_3$timestamp <- with(data_3, ymd(UTC.Date) + hms(UTC.Time)) # merge date and time | |
| data_3$timestamp <- round_date(data_3$timestamp, "30 mins") # rounding of time to 30 mins | |
| data_3 <- data_3[data_3$DOP < 6 ,] # DOP < 6 | |
| data_3 <- data_3 %>% filter(timestamp >= "2020-11-30 18:00:00") #removal of the observation before putting on the collar | |
| data_3 <- data_3 [,c("CollarID", "timestamp", "Longitude", "Latitude")] | |
| data_3$Longitude <- as.numeric(sub(",", ".", data_3$Longitude, fixed = TRUE)) # converting to numeric | |
| data_3$Latitude <- as.numeric(sub(",", ".", data_3$Latitude, fixed = TRUE)) | |
| data_3 <- data_3[!is.na(data_3$Longitude),] # removal of NA values | |
| data_3sf <- st_as_sf(data_3, coords=c("Longitude","Latitude")) # converting to a sf object | |
| # defining the coordinate system (4326 is a code of WGS84 coordinate system, in which GPS is measuring) | |
| data_3sf <- st_set_crs(data_3sf, 4326) | |
| plot(st_geometry(data_3sf)) | |
| # projecting to ETRS89 European coordinate system | |
| data_3sf <- st_transform(data_3sf, 3035) | |
| plot(st_geometry(data_3sf)) | |
| # creating the input data frame | |
| xy_3 <- st_coordinates(data_3sf) | |
| data_3 <- data.frame(ID = data_3$CollarID, | |
| x=xy_3[,1], | |
| y=xy_3[,2], | |
| timestamp=data_3$timestamp, | |
| Longitude=data_3$Longitude, | |
| Latitude=data_3$Latitude) | |
| # adding years, months, hours | |
| data_3$month <- format(data_3$timestamp, "%m") | |
| data_3$year <- format(data_3$timestamp, "%Y") | |
| data_3$hour <- format(data_3$timestamp, "%H:%M") | |
| data_3$month <- as.numeric((data_3$month)) | |
| data_3$year <- as.numeric((data_3$year)) | |
| ## 31 | |
| data_4 <- read.table("36931.csv", header = T, sep = ";", dec = ",") | |
| data_4$UTC.Date <- as.POSIXct(data_4$UTC.Date, format = "%d.%m.%Y") | |
| data_4$timestamp <- with(data_4, ymd(UTC.Date) + hms(UTC.Time)) # merge date and time | |
| data_4$timestamp <- round_date(data_4$timestamp, "30 mins") # rounding of time to 30 mins | |
| data_4 <- data_4[data_4$DOP < 6 ,] # DOP < 6 | |
| data_4 <- data_4 %>% filter(timestamp >= "2021-10-24 04:30:00") #removal of the observation before putting on the collar | |
| data_4 <- data_4 [,c("CollarID", "timestamp", "Longitude", "Latitude")] | |
| data_4$Longitude <- as.numeric(sub(",", ".", data_4$Longitude, fixed = TRUE)) # converting to numeric | |
| data_4$Latitude <- as.numeric(sub(",", ".", data_4$Latitude, fixed = TRUE)) | |
| data_4 <- data_4[!is.na(data_4$Longitude),] # removal of NA values | |
| data_4sf <- st_as_sf(data_4, coords=c("Longitude","Latitude")) # converting to a sf object | |
| # defining the coordinate system (4326 is a code of WGS84 coordinate system, in which GPS is measuring) | |
| data_4sf <- st_set_crs(data_4sf, 4326) | |
| plot(st_geometry(data_4sf)) | |
| # projecting to ETRS89 European coordinate system | |
| data_4sf <- st_transform(data_4sf, 3035) | |
| plot(st_geometry(data_4sf)) | |
| # creating the input data frame | |
| xy_4 <- st_coordinates(data_4sf) | |
| data_4 <- data.frame(ID = data_4$CollarID, | |
| x=xy_4[,1], | |
| y=xy_4[,2], | |
| timestamp=data_4$timestamp, | |
| Longitude=data_4$Longitude, | |
| Latitude=data_4$Latitude) | |
| # adding years, months, hours | |
| data_4$month <- format(data_4$timestamp, "%m") | |
| data_4$year <- format(data_4$timestamp, "%Y") | |
| data_4$hour <- format(data_4$timestamp, "%H:%M") | |
| data_4$month <- as.numeric((data_4$month)) | |
| data_4$year <- as.numeric((data_4$year)) | |
| ##32 | |
| data_5 <- read.table("36932.csv", header = T, sep = ";", dec = ",") | |
| data_5$UTC.Date <- as.POSIXct(data_5$UTC.Date, format = "%d.%m.%Y") | |
| data_5$timestamp <- with(data_5, ymd(UTC.Date) + hms(UTC.Time)) # merge date and time | |
| data_5$timestamp <- round_date(data_5$timestamp, "30 mins") # rounding of time to 30 mins | |
| data_5 <- data_5[data_5$DOP < 6 ,] # DOP < 6 | |
| data_5 <- data_5 %>% filter(timestamp >= "2022-05-08 23:30:00") #removal of the observation before putting on the collar | |
| data_5 <- data_5 [,c("CollarID", "timestamp", "Longitude", "Latitude")] | |
| data_5$Longitude <- as.numeric(sub(",", ".", data_5$Longitude, fixed = TRUE)) # converting to numeric | |
| data_5$Latitude <- as.numeric(sub(",", ".", data_5$Latitude, fixed = TRUE)) | |
| data_5 <- data_5[!is.na(data_5$Longitude),] # removal of NA values | |
| data_5sf <- st_as_sf(data_5, coords=c("Longitude","Latitude")) # converting to a sf object | |
| # defining the coordinate system (4326 is a code of WGS84 coordinate system, in which GPS is measuring) | |
| data_5sf <- st_set_crs(data_5sf, 4326) | |
| plot(st_geometry(data_5sf)) | |
| # projecting to ETRS89 European coordinate system | |
| data_5sf <- st_transform(data_5sf, 3035) | |
| plot(st_geometry(data_5sf)) | |
| # creating the input data frame | |
| xy_5 <- st_coordinates(data_5sf) | |
| data_5 <- data.frame(ID = data_5$CollarID, | |
| x=xy_5[,1], | |
| y=xy_5[,2], | |
| timestamp=data_5$timestamp, | |
| Longitude=data_5$Longitude, | |
| Latitude=data_5$Latitude) | |
| # adding years, months, hours | |
| data_5$month <- format(data_5$timestamp, "%m") | |
| data_5$year <- format(data_5$timestamp, "%Y") | |
| data_5$hour <- format(data_5$timestamp, "%H:%M") | |
| data_5$month <- as.numeric((data_5$month)) | |
| data_5$year <- as.numeric((data_5$year)) | |
| ## 29456 | |
| data_6 <- read.table("29456 .csv", header = T, sep =";", dec =".") | |
| data_6$UTC.Date <- as.POSIXct(data_6$UTC.Date, format = "%d.%m.%Y") | |
| data_6$timestamp <- with(data_6, ymd(UTC.Date) + hms(UTC.Time)) # merge date and time | |
| data_6$timestamp <- round_date(data_6$timestamp, "30 mins") # rounding of time to 30 mins | |
| data_6 <- data_6 [,c("CollarID", "timestamp", "Longitude", "Latitude")] | |
| data_6$Longitude <- as.numeric(sub(",", ".", data_6$Longitude, fixed = TRUE)) # converting to numeric | |
| data_6$Latitude <- as.numeric(sub(",", ".", data_6$Latitude, fixed = TRUE)) | |
| data_6 <- data_6[!is.na(data_6$Longitude),] # removal of NA values | |
| data_6sf <- st_as_sf(data_6, coords=c("Longitude","Latitude")) # converting to a sf object | |
| # defining the coordinate system (4326 is a code of WGS84 coordinate system, in which GPS is measuring) | |
| data_6sf <- st_set_crs(data_6sf, 4326) | |
| plot(st_geometry(data_6sf)) | |
| # projecting to ETRS89 European coordinate system | |
| data_6sf <- st_transform(data_6sf, 3035) | |
| plot(st_geometry(data_6sf)) | |
| # creating the input data frame | |
| xy_6 <- st_coordinates(data_6sf) | |
| data_6 <- data.frame(ID = data_6$CollarID, | |
| x=xy_6[,1], | |
| y=xy_6[,2], | |
| timestamp=data_6$timestamp, | |
| Longitude=data_6$Longitude, | |
| Latitude=data_6$Latitude) | |
| # adding years, months, hours | |
| data_6$month <- format(data_6$timestamp, "%m") | |
| data_6$year <- format(data_6$timestamp, "%Y") | |
| data_6$hour <- format(data_6$timestamp, "%H:%M") | |
| data_6$month <- as.numeric((data_6$month)) | |
| data_6$year <- as.numeric((data_6$year)) | |
| ## spojení do listu | |
| wolves <- list(data_1, data_2, data_3,data_4,data_5, data_6) | |
| save(wolves, file = "wolves.RData") |