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?
Francomano_et_al_2023_PAM_for_Penguins/IDLE_File_Segmentation_Script.R
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
131 lines (109 sloc)
7.6 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
###################################################################### | |
# Code from Francomano et al. (IBIS 2023) # | |
###################################################################### | |
# IDLE File Segmentation Script # | |
###################################################################### | |
# Created by: Dante Francomano (dfrancomano@alumni.purdue.edu) | |
# Date: 20191116 | |
###################################################################### | |
###################################################################### | |
# Load packages | |
.libPaths("E:/Dante/R_3_5_3_Library") | |
library(tuneR) | |
library(parallel) | |
library(mailR) | |
# Create function to read and write waves, converting hourly recordings to 1 minute every 5 minutes | |
waveSegmentation<-function(fileName,writeDirectory) | |
{ | |
for(i in seq(0,55,5)) | |
{ | |
tempWave<-readWave(fileName,from=i,to=i+1,units="minutes") | |
if(i<10) writeWave(tempWave,paste(writeDirectory,substr(fileName,1,21),i,"00.wav",sep="")) | |
if(i>5) writeWave(tempWave,paste(writeDirectory,substr(fileName,1,20),i,"00.wav",sep="")) | |
} | |
} | |
# Run segmentation | |
# PM 01 | |
setwd("J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Raw_Data/PM_01/S4A00449_20181113_144528") | |
writeDirectory<-"J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Trimmed_Data/PM_01/" | |
firstGood<-"S4A00449_20181208_190000.wav" | |
lastGood<-"S4A00449_20181218_120000.wav" | |
goodFiles<-paste(substr(firstGood,1,9),strftime(seq.POSIXt(strptime(substr(firstGood,10,24),"%Y%m%d_%H%M%S"),strptime(substr(lastGood,10,24),"%Y%m%d_%H%M%S"),"hour"),"%Y%m%d_%H%M%S"),".wav",sep="") | |
cl<-makeCluster(8,type="SOCK") | |
clusterExport(cl,list("goodFiles","writeDirectory","waveSegmentation","readWave","writeWave")) | |
parSapply(cl=cl,goodFiles,waveSegmentation,writeDirectory=writeDirectory) | |
gc() | |
stopCluster(cl) | |
send.mail("dfrancomano@gmail.com","dfrancomano@gmail.com","PM 01 complete","Let's see if it actually worked...",smtp=list(host.name="smtp.gmail.com",port=465,user.name="dfrancomano",passwd="*****",ssl=TRUE),authenticate=TRUE,send=TRUE) | |
# PM 02 | |
setwd("J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Raw_Data/PM_02/S4A00440_20181113_144630") | |
writeDirectory<-"J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Trimmed_Data/PM_02/" | |
firstGood<-"S4A00440_20181208_180000.wav" | |
lastGood<-"S4A00440_20181218_120000.wav" | |
goodFiles<-paste(substr(firstGood,1,9),strftime(seq.POSIXt(strptime(substr(firstGood,10,24),"%Y%m%d_%H%M%S"),strptime(substr(lastGood,10,24),"%Y%m%d_%H%M%S"),"hour"),"%Y%m%d_%H%M%S"),".wav",sep="") | |
cl<-makeCluster(8,type="SOCK") | |
clusterExport(cl,list("goodFiles","writeDirectory","waveSegmentation","readWave","writeWave")) | |
parSapply(cl=cl,goodFiles,waveSegmentation,writeDirectory=writeDirectory) | |
gc() | |
stopCluster(cl) | |
send.mail("dfrancomano@gmail.com","dfrancomano@gmail.com","PM 02 complete","Let's see if it actually worked...",smtp=list(host.name="smtp.gmail.com",port=465,user.name="dfrancomano",passwd="*****",ssl=TRUE),authenticate=TRUE,send=TRUE) | |
# PPA 02 | |
setwd("J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Raw_Data/PPA_02/S4A03851_20181203_185612") | |
writeDirectory<-"J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Trimmed_Data/PPA_02/" | |
firstGood<-"S4A03851_20181208_210000.wav" | |
lastGood<-"S4A03851_20181218_100000.wav" | |
goodFiles<-paste(substr(firstGood,1,9),strftime(seq.POSIXt(strptime(substr(firstGood,10,24),"%Y%m%d_%H%M%S"),strptime(substr(lastGood,10,24),"%Y%m%d_%H%M%S"),"hour"),"%Y%m%d_%H%M%S"),".wav",sep="") | |
cl<-makeCluster(8,type="SOCK") | |
clusterExport(cl,list("goodFiles","writeDirectory","waveSegmentation","readWave","writeWave")) | |
parSapply(cl=cl,goodFiles,waveSegmentation,writeDirectory=writeDirectory) | |
gc() | |
stopCluster(cl) | |
send.mail("dfrancomano@gmail.com","dfrancomano@gmail.com","PPA 02 complete","Let's see if it actually worked...",smtp=list(host.name="smtp.gmail.com",port=465,user.name="dfrancomano",passwd="*****",ssl=TRUE),authenticate=TRUE,send=TRUE) | |
# PPA 03 | |
setwd("J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Raw_Data/PPA_03/S4A00466_20181113_144627") | |
writeDirectory<-"J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Trimmed_Data/PPA_03/" | |
firstGood<-"S4A00466_20181207_130000.wav" | |
lastGood<-"S4A00466_20181217_170000.wav" | |
goodFiles<-paste(substr(firstGood,1,9),strftime(seq.POSIXt(strptime(substr(firstGood,10,24),"%Y%m%d_%H%M%S"),strptime(substr(lastGood,10,24),"%Y%m%d_%H%M%S"),"hour"),"%Y%m%d_%H%M%S"),".wav",sep="") | |
cl<-makeCluster(8,type="SOCK") | |
clusterExport(cl,list("goodFiles","writeDirectory","waveSegmentation","readWave","writeWave")) | |
parSapply(cl=cl,goodFiles,waveSegmentation,writeDirectory=writeDirectory) | |
gc() | |
stopCluster(cl) | |
send.mail("dfrancomano@gmail.com","dfrancomano@gmail.com","PPA 03 complete","Let's see if it actually worked...",smtp=list(host.name="smtp.gmail.com",port=465,user.name="dfrancomano",passwd="*****",ssl=TRUE),authenticate=TRUE,send=TRUE) | |
# PPA 05 | |
setwd("J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Raw_Data/PPA_05/S4A03852_20181113_144215") | |
writeDirectory<-"J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Trimmed_Data/PPA_05/" | |
firstGood<-"S4A03852_20181208_230000.wav" | |
lastGood<-"S4A03852_20181218_090000.wav" | |
goodFiles<-paste(substr(firstGood,1,9),strftime(seq.POSIXt(strptime(substr(firstGood,10,24),"%Y%m%d_%H%M%S"),strptime(substr(lastGood,10,24),"%Y%m%d_%H%M%S"),"hour"),"%Y%m%d_%H%M%S"),".wav",sep="") | |
cl<-makeCluster(8,type="SOCK") | |
clusterExport(cl,list("goodFiles","writeDirectory","waveSegmentation","readWave","writeWave")) | |
parSapply(cl=cl,goodFiles,waveSegmentation,writeDirectory=writeDirectory) | |
gc() | |
stopCluster(cl) | |
send.mail("dfrancomano@gmail.com","dfrancomano@gmail.com","PPA 05 complete","Let's see if it actually worked...",smtp=list(host.name="smtp.gmail.com",port=465,user.name="dfrancomano",passwd="*****",ssl=TRUE),authenticate=TRUE,send=TRUE) | |
# PPA 06 | |
setwd("J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Raw_Data/PPA_06/S4A00436_20181113_144328") | |
writeDirectory<-"J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Trimmed_Data/PPA_06/" | |
firstGood<-"S4A00436_20181207_150000.wav" | |
lastGood<-"S4A00436_20181217_160000.wav" | |
goodFiles<-paste(substr(firstGood,1,9),strftime(seq.POSIXt(strptime(substr(firstGood,10,24),"%Y%m%d_%H%M%S"),strptime(substr(lastGood,10,24),"%Y%m%d_%H%M%S"),"hour"),"%Y%m%d_%H%M%S"),".wav",sep="") | |
cl<-makeCluster(8,type="SOCK") | |
clusterExport(cl,list("goodFiles","writeDirectory","waveSegmentation","readWave","writeWave")) | |
parSapply(cl=cl,goodFiles,waveSegmentation,writeDirectory=writeDirectory) | |
gc() | |
stopCluster(cl) | |
send.mail("dfrancomano@gmail.com","dfrancomano@gmail.com","PPA 06 complete","Let's see if it actually worked...",smtp=list(host.name="smtp.gmail.com",port=465,user.name="dfrancomano",passwd="*****",ssl=TRUE),authenticate=TRUE,send=TRUE) | |
# PPA 07 | |
setwd("J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Raw_Data/PPA_07/S4A00433_20181113_144512") | |
writeDirectory<-"J:/Dante/Pinguinos/Datos_Acusticos/Isla_de_los_Estados/Trimmed_Data/PPA_07/" | |
firstGood<-"S4A00433_20181208_120000.wav" | |
lastGood<-"S4A00433_20181218_080000.wav" | |
goodFiles<-paste(substr(firstGood,1,9),strftime(seq.POSIXt(strptime(substr(firstGood,10,24),"%Y%m%d_%H%M%S"),strptime(substr(lastGood,10,24),"%Y%m%d_%H%M%S"),"hour"),"%Y%m%d_%H%M%S"),".wav",sep="") | |
cl<-makeCluster(8,type="SOCK") | |
clusterExport(cl,list("goodFiles","writeDirectory","waveSegmentation","readWave","writeWave")) | |
parSapply(cl=cl,goodFiles,waveSegmentation,writeDirectory=writeDirectory) | |
gc() | |
stopCluster(cl) | |
send.mail("dfrancomano@gmail.com","dfrancomano@gmail.com","PPA 07 complete","Let's see if it actually worked...",smtp=list(host.name="smtp.gmail.com",port=465,user.name="dfrancomano",passwd="*****",ssl=TRUE),authenticate=TRUE,send=TRUE) |