-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHAMAC-B2-AttribACT2GPS.R
More file actions
87 lines (66 loc) · 2.31 KB
/
Copy pathHAMAC-B2-AttribACT2GPS.R
File metadata and controls
87 lines (66 loc) · 2.31 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
78
79
80
81
82
83
84
85
86
87
###################
## HAMAC Routine ##
###################
## ACT aggregation to GPS
## A. SCRIBAN & ChatGPT - Janvier 2024
### Libraries
library(lubridate)
library(dplyr)
library(furrr)
library(data.table)
### Paths
inDir <- "./1_IntermeData"
outDir <- "./1_IntermeData"
filesPrefix <- "/HAMAC-SN-"
### Functions
## Fonction qui moyenne les donn?es acc?l?ro
calcul_moyenne_accelero <- function(ligne_GPS) {
closest_rows <- ACT_par_anx[[ligne_GPS[["ID"]]]] %>%
arrange(abs(DHACQ - ymd_hms(ligne_GPS[["DHACQ"]]))) %>%
slice_head(n = nbACTpts)
mean_data <- colMeans(closest_rows[,noms_col_2_add], na.rm = TRUE)
return(mean_data)
}
### Execution
#### Importation données classées par animal
# GPS
GPS_par_anx <- read.table(
paste0(inDir, filesPrefix, "GPSpANX.csv"),
sep=";",header=T, skip=0,na.strings = "N/A")
GPS_par_anx$DHACQ<-ymd_hms(GPS_par_anx$DHACQ)
head(GPS_par_anx)
# ACT
## Ne marche pas en l'état mais flemme, plutôt runner Animal segmentation
# ACT_par_anx <- read.table(
# paste0(sourceDir, "HAMAC-SN-ACTpANX.csv"),
# sep=";",header=T, skip=0,na.strings = "N/A")
# ACT_par_anx$DHACQ<-ymd_hms(ACT_par_anx$DHACQ)
# head(ACT_par_anx)
#### Parametres
nbACTpts <- 5 # Nombre de points ACT autour du point GPS
noms_col_2_add <- c("AcX", "AcY", "AcZ", "TMP")
nThreads <- 22
#### Init la table de sortie
GPS_ACT_par_anx <- GPS_par_anx
# GPS_ACT_par_anx <- GPS_par_anx[1:1000,]
colnames(GPS_ACT_par_anx)[colnames(GPS_ACT_par_anx) == 'TMP'] <- "GPS_TMP"
for (col_name in noms_col_2_add) {
GPS_ACT_par_anx <- mutate(GPS_ACT_par_anx, !!col_name := NA) # ChatGPT magic
}
head(GPS_ACT_par_anx)
#### Execution
print(paste0("Debut d'association : ", date()))
debAssoc <- Sys.time()
plan(multisession, workers = nThreads) # Début parallelisation sur workers threads
listesAccMoyenne <- asplit(GPS_ACT_par_anx, 1) %>% future_map(calcul_moyenne_accelero)
plan(sequential) # Fin parallelisation
print(paste0("Fin d'association : ", date()))
print(Sys.time() - debAssoc)
setDT(GPS_ACT_par_anx) # Assigne les valeurs calculées à la BD
GPS_ACT_par_anx[, (noms_col_2_add) := transpose(listesAccMoyenne)]
print(Sys.time() - debAssoc)
head(GPS_ACT_par_anx)
#### Intermediate data save
write.table(GPS_ACT_par_anx,
paste0(outDir, filesPrefix, "GPSnACTpANX.csv"),
sep=";", row.names=FALSE)