add example of a xeno-canto downloader
This commit is contained in:
70
warbleR_xeno-canto/warbleR_xeno-canto.r
Normal file
70
warbleR_xeno-canto/warbleR_xeno-canto.r
Normal file
@@ -0,0 +1,70 @@
|
||||
library(warbleR)
|
||||
|
||||
# Create a new folder inside a new tempdir and set it to your working dir
|
||||
wd <- file.path(tempdir(), "xeno-canto_example")
|
||||
dir.create(wd)
|
||||
setwd(wd)
|
||||
|
||||
##
|
||||
# Do the queries
|
||||
##
|
||||
|
||||
# Query xeno-canto for all Phaethornis recordings (e.g., by genus)
|
||||
Phae <- query_xc(qword = "Phaethornis", download = FALSE)
|
||||
# Check out the structure of resulting the data frame
|
||||
str(Phae)
|
||||
# Query xeno-canto for all Phaethornis longirostris recordings
|
||||
Phae.lon <- query_xc(qword = "Phaethornis longirostris", download = FALSE)
|
||||
# Check out the structure of resulting the data frame
|
||||
str(Phae.lon)
|
||||
|
||||
##
|
||||
# filter xeno-canto recordings by quality, signal type and locality
|
||||
##
|
||||
|
||||
# How many recordings are available for Phaethornis longirostris?
|
||||
nrow(Phae.lon)
|
||||
# How many signal types exist in the xeno-canto metadata?
|
||||
unique(Phae.lon$Vocalization_type)
|
||||
# How many recordings per signal type?
|
||||
table(Phae.lon$Vocalization_type)
|
||||
|
||||
##
|
||||
# Filter the metadata to select the signals we want to retain
|
||||
##
|
||||
|
||||
# First by quality
|
||||
Phae.lon <- Phae.lon[Phae.lon$Quality == "A", ]
|
||||
nrow(Phae.lon)
|
||||
# Then by signal type
|
||||
Phae.lon.song <- Phae.lon[grep("song", Phae.lon$Vocalization_type, ignore.case = TRUE), ]
|
||||
nrow(Phae.lon.song)
|
||||
# Finally by locality
|
||||
Phae.lon.LS <- Phae.lon.song[grep("La Selva Biological Station, Sarapiqui, Heredia", Phae.lon.song$Locality, ignore.case = FALSE), ]
|
||||
nrow(Phae.lon.LS)
|
||||
# Check resulting data frame, 3 recordings remain
|
||||
str(Phae.lon.LS)
|
||||
# check the location
|
||||
map_xc(Phae.lon.LS, img = FALSE)
|
||||
|
||||
|
||||
##
|
||||
# Once we're sure the recordings fit, it's time to download the files, also save
|
||||
# the metadata as .csv file
|
||||
##
|
||||
|
||||
# Download sound files
|
||||
query_xc(X = Phae.lon.LS)
|
||||
# Save the metadata object as a .csv file
|
||||
write.csv(Phae.lon.LS, "Phae_lon.LS.csv", row.names = FALSE)
|
||||
|
||||
##
|
||||
# xeno-canto maintains recordings in mp3 format due to file size restrictions.
|
||||
# However, we require wav format for all downstream analyses
|
||||
##
|
||||
|
||||
# here we are downsampling the original sampling rate of 44.1 kHz
|
||||
# to speed up downstream analyses in the vignette series
|
||||
mp32wav(samp.rate = 22.05)
|
||||
# Use checkwavs to see if wav files can be read
|
||||
check_wavs()
|
||||
Reference in New Issue
Block a user