Code
<- consolidate(path = "/media/m/Backup Plus/Campo abierto CUS/",
cns dest.path = "/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/",
parallel = 10)
Stress-amphetamine
<- consolidate(path = "/media/m/Backup Plus/Campo abierto CUS/",
cns dest.path = "/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/",
parallel = 10)
fix_wavs(samp.rate = 200, bit.depth = 16)
::feature_acoustic_data(path = .Options$warbleR$path)
ohun
<- ohun::split_acoustic_data(sgmt.dur = 5 * 60, cores = 10, path = .Options$warbleR$path)
ssf
write.csv(ssf, file.path(.Options$warbleR$path, "/5min_clip_info.csv"), row.names = FALSE)
warbleR_options(wav.path = "/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/5min_clips/")
<- energy_detector(
detection path = .Options$warbleR$path,
thinning = 0.5,
bp = c(35, 90),
smooth = 1,
threshold = 2.5,
hold.time = 3,
min.duration = 1,
max.duration = 200,
cores = 5
)
saveRDS(
detection,"/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/detection_55kHz_with_bedding_CUIDO_MATERNO.RDS"
)
<- readRDS("/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/detection_55kHz_with_bedding_CUIDO_MATERNO.RDS")
detection
# measure spectrographic parameters
<- spectro_analysis(detection, bp = c(35, 85), fast = TRUE, ovlp = 70, parallel = 22)
spectral_parameters
# leer el modelo
<- readRDS("/home/m/Dropbox/Projects/rat_ultrasonic_vocalizations/data/processed/random_forest_55kHz_with_bedding.RDS")
rf_model
sapply(spectral_parameters, function(x) sum(is.na(x)))
<- detection[!is.na(spectral_parameters$meandom), ]
detection
<- spectral_parameters[!is.na(spectral_parameters$meandom), ]
spectral_parameters
write.csv(spectral_parameters, "/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/spectral_parameters.csv", row.names = FALSE)
# aplicarlo sobre las detecciones nuevas
$class <-predict(object = rf_model, data = spectral_parameters)$predictions
detection
# remover los sonidos clasificados como ruido de fondo
<- detection[detection$class == "true.positive", ]
filtered_detection
saveRDS(filtered_detection, "/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/random_forest_filtered_detection_55kHz_with_bedding.RDS")
write.csv(filtered_detection, "/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/filtered_detection_55kHz_with_bedding.csv", row.names = FALSE)
<- aggregate(selec ~ sound.files, filtered_detection, length)
counts names(counts)[2] <- "55khz.call.count"
write.csv(counts, "/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/counts_per_sound_files_detection_55kHz_with_bedding.csv", row.names = FALSE)
<- readRDS("/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/random_forest_filtered_detection_55kHz_with_bedding.RDS")
filtered_detection_55
<- read.csv("/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/5min_clip_info.csv")
orgf
<- reassemble_detection(detection = filtered_detection_55, Y = orgf, pb = FALSE)
reass_detec
# counts per minute
<- vocal_rate(X = reass_detec, time.window = 60, time.resolution = 60, path = "/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/", files = list.files("/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/", pattern = "\\.wav$"))
count_min
# convert to minute rate
$minute <- count_min$start / 60 + 1
count_min
<- reshape(count_min[, c("counts", "minute", "sound.files")], direction = "wide", idvar = "sound.files", timevar = "minute")
wide_count_min
names(wide_count_min) <- c("sound.files", paste("min", 1:max(count_min$minute)))
print_kable(wide_count_min)
sound.files | min 1 | min 2 | min 3 | min 4 | min 5 | min 6 | min 7 | min 8 | min 9 | min 10 | min 11 | min 12 | min 13 | min 14 | min 15 | min 16 | min 17 | min 18 | min 19 | min 20 | min 21 | min 22 | min 23 | min 24 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
T0000001-1.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | |||||||
T0000001-2.wav | 1 | 0 | 0 | 0 | 0 | 6 | 0 | 0 | 0 | 1 | 0 | 2 | 2 | 4 | 4 | 0 | 0 | |||||||
T0000001-3.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||
T0000001-4.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||
T0000002-1.wav | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 0 | 2 | 1 | 0 | 2 | 3 | 0 | 0 | 0 | |||||||
T0000002-2.wav | 25 | 45 | 50 | 44 | 46 | 0 | 0 | 0 | 0 | 0 | 22 | 27 | 16 | 4 | 0 | 0 | 0 | |||||||
T0000002-3.wav | 0 | 0 | 0 | 0 | 0 | 18 | 16 | 12 | 4 | 20 | 18 | 47 | 20 | 19 | 37 | 19 | 0 | |||||||
T0000002-4.wav | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||
T0000003-1.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||
T0000003-2.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||
T0000003-3.wav | 0 | 0 | 0 | 1 | 9 | 28 | 119 | 71 | 59 | 26 | 68 | 100 | 6 | 3 | 30 | 0 | ||||||||
T0000003-4.wav | 0 | 0 | 0 | 0 | 1 | 0 | 22 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||
T0000004-1.wav | 0 | 1 | 0 | 0 | 2 | 1 | 3 | 2 | 1 | 0 | 2 | 10 | 2 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
T0000004-2.wav | 1 | 8 | 47 | 66 | 63 | 67 | 65 | 24 | 22 | 41 | 58 | 32 | 21 | 30 | 21 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
T0000004-3.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
T0000004-4.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 3 | 5 | 3 | 12 | 3 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 |
T0000005-1.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||
T0000005-2.wav | 0 | 0 | 1 | 3 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 7 | 7 | 1 | 0 | ||||||||
T0000005-3.wav | 0 | 3 | 21 | 74 | 52 | 31 | 3 | 0 | 0 | 1 | 5 | 0 | 0 | 0 | 0 | 0 | ||||||||
T0000005-4.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||
T0000006-1.wav | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||
T0000006-2.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 3 | 8 | 1 | 1 | 0 | 0 | ||||||||
T0000006-3.wav | 0 | 0 | 0 | 0 | 13 | 10 | 4 | 2 | 4 | 1 | 2 | 1 | 0 | 0 | 0 | 0 | ||||||||
T0000006-4.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||
T0000007-1.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||
T0000007-2.wav | 0 | 4 | 24 | 48 | 76 | 39 | 9 | 71 | 27 | 137 | 11 | 60 | 89 | 29 | 0 | 7 | ||||||||
T0000007-3.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | ||||||||
T0000007-4.wav | 0 | 0 | 0 | 0 | 0 | 1 | 4 | 3 | 9 | 13 | 24 | 18 | 25 | 51 | 18 | 0 | ||||||||
T0000008-1.wav | 19 | 32 | 29 | 110 | 80 | 36 | 93 | 148 | 144 | 37 | 13 | 80 | 86 | 33 | 100 | 75 | 5 | |||||||
T0000008-2.wav | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 10 | 5 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | |||||||
T0000008-3.wav | 0 | 2 | 11 | 27 | 11 | 28 | 29 | 83 | 52 | 29 | 9 | 32 | 60 | 19 | 33 | 12 | 3 | |||||||
T0000008-4.wav | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
<- vocal_rate(X = reass_detec, time.window = 60, time.resolution = 1, path = "/media/m/Backup Plus/Campo abierto CUS/consolidated_sound_files/")
vr
# rate per minute
$rate <- vr$rate * 60
vr
# get highest per sound file
<- vr[vr$duration == 60, ]
sub_vr
# get the row with the highest rate per sound file
<- do.call(rbind, lapply(split(sub_vr, sub_vr$sound.files), function(x) x[which.max(x$rate), ]))
highes_min
print_kable(highes_min)
sound.files | start | end | counts | duration | rate |
---|---|---|---|---|---|
T0000001-1.wav | 912 | 972 | 3 | 60 | 3 |
T0000001-2.wav | 271 | 331 | 6 | 60 | 6 |
T0000002-1.wav | 737 | 797 | 3 | 60 | 3 |
T0000002-2.wav | 47 | 107 | 61 | 60 | 61 |
T0000002-3.wav | 634 | 694 | 51 | 60 | 51 |
T0000002-4.wav | 54 | 114 | 1 | 60 | 1 |
T0000003-3.wav | 383 | 443 | 143 | 60 | 143 |
T0000003-4.wav | 357 | 417 | 22 | 60 | 22 |
T0000004-1.wav | 676 | 736 | 12 | 60 | 12 |
T0000004-2.wav | 335 | 395 | 102 | 60 | 102 |
T0000004-3.wav | 909 | 969 | 1 | 60 | 1 |
T0000004-4.wav | 752 | 812 | 15 | 60 | 15 |
T0000005-2.wav | 726 | 786 | 9 | 60 | 9 |
T0000005-3.wav | 200 | 260 | 88 | 60 | 88 |
T0000006-1.wav | 0 | 60 | 2 | 60 | 2 |
T0000006-2.wav | 614 | 674 | 8 | 60 | 8 |
T0000006-3.wav | 261 | 321 | 15 | 60 | 15 |
T0000007-2.wav | 541 | 601 | 140 | 60 | 140 |
T0000007-3.wav | 572 | 632 | 1 | 60 | 1 |
T0000007-4.wav | 775 | 835 | 57 | 60 | 57 |
T0000008-1.wav | 410 | 470 | 165 | 60 | 165 |
T0000008-2.wav | 500 | 560 | 15 | 60 | 15 |
T0000008-3.wav | 419 | 479 | 84 | 60 | 84 |
Session information
R version 4.5.0 (2025-04-11)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.5 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0 LAPACK version 3.10.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=es_CR.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=es_CR.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=es_CR.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=es_CR.UTF-8 LC_IDENTIFICATION=C
time zone: America/Costa_Rica
tzcode source: system (glibc)
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] ggplot2_3.5.2 ohun_1.0.3 DT_0.33
[4] kableExtra_1.4.0 ranger_0.17.0 readxl_1.4.5
[7] svMisc_1.4.3 rfigshare_0.3.8 viridis_0.6.5
[10] viridisLite_0.4.2 Rraven_1.0.14 pbapply_1.7-4
[13] bioacoustics_0.2.8.9000 warbleR_1.1.35 NatureSounds_1.0.5
[16] knitr_1.50 seewave_2.2.3 tuneR_1.4.7
[19] devtools_2.4.5 usethis_3.1.0
loaded via a namespace (and not attached):
[1] DBI_1.2.3 bitops_1.0-9 gridExtra_2.3
[4] remotes_2.5.0 testthat_3.2.3 rlang_1.1.6
[7] magrittr_2.0.3 e1071_1.7-16 compiler_4.5.0
[10] systemfonts_1.2.3 vctrs_0.6.5 stringr_1.5.1
[13] profvis_0.4.0 pkgconfig_2.0.3 crayon_1.5.3
[16] fastmap_1.2.0 backports_1.5.0 ellipsis_0.3.2
[19] promises_1.3.3 rmarkdown_2.29 sessioninfo_1.2.3
[22] purrr_1.0.4 xfun_0.52 cachem_1.1.0
[25] jsonlite_2.0.0 later_1.4.2 R6_2.6.1
[28] stringi_1.8.7 RColorBrewer_1.1-3 pkgload_1.4.0
[31] brio_1.1.5 cellranger_1.1.0 Rcpp_1.1.0
[34] httpuv_1.6.16 Matrix_1.7-3 igraph_2.1.4
[37] tidyselect_1.2.1 rstudioapi_0.17.1 yaml_2.3.10
[40] dtw_1.23-1 miniUI_0.1.2 curl_6.4.0
[43] pkgbuild_1.4.8 lattice_0.22-7 tibble_3.3.0
[46] shiny_1.10.0 withr_3.0.2 evaluate_1.0.3
[49] signal_1.8-1 moments_0.14.1 sf_1.0-21
[52] sketchy_1.0.5 units_0.8-7 proxy_0.4-27
[55] urlchecker_1.0.1 xml2_1.3.8 pillar_1.11.0
[58] packrat_0.9.2 KernSmooth_2.23-26 checkmate_2.3.2
[61] generics_0.1.4 RCurl_1.98-1.17 scales_1.4.0
[64] xtable_1.8-4 class_7.3-23 glue_1.8.0
[67] tools_4.5.0 xaringanExtra_0.8.0 fs_1.6.6
[70] XML_3.99-0.18 grid_4.5.0 RJSONIO_2.0.0
[73] cli_3.6.5 svglite_2.1.3 dplyr_1.1.4
[76] gtable_0.3.6 fftw_1.0-9 digest_0.6.37
[79] classInt_0.4-11 rjson_0.2.23 htmlwidgets_1.6.4
[82] farver_2.1.2 memoise_2.0.1 htmltools_0.5.8.1
[85] lifecycle_1.0.4 httr_1.4.7 mime_0.13
[88] MASS_7.3-65