Skip to content

Instantly share code, notes, and snippets.

@monogenea
Created March 28, 2020 18:25
Show Gist options
  • Save monogenea/eb3b8610962d90c7e667a96eedeb5ded to your computer and use it in GitHub Desktop.
Save monogenea/eb3b8610962d90c7e667a96eedeb5ded to your computer and use it in GitHub Desktop.
#### Download HQ male song recordings > 30s long from Europe ####
query <- querxc("type:song type:male len_gt:30 q_gt:C area:europe")
query$Species <- with(query, paste(Genus, Specific_epithet))
# Select top 50 most abundant bird species
speciesCount <- sort(table(query$Species), decreasing = T)
topSpecies <- names(speciesCount)[1:50]
query <- query[query$Species %in% topSpecies, ]
# Downsample to min size among the 50 classes
balancedClasses <- lapply(topSpecies, function(x){
set.seed(100)
sample(which(query$Species == x), min(table(query$Species)))
}) %>% unlist()
# Subset accordingly
query <- query[balancedClasses, ]
# Download using updated query
querxc(X = query, download = T, path = "mp3/", parallel = 8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment