Title: | Connecting R and 'Raven' Sound Analysis Software |
---|---|
Description: | A tool to exchange data between R and 'Raven' sound analysis software (Cornell Lab of Ornithology). Functions work on data formats compatible with the R package 'warbleR'. |
Authors: | Marcelo Araya-Salas [aut, cre] |
Maintainer: | Marcelo Araya-Salas <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.14 |
Built: | 2024-11-18 05:11:03 UTC |
Source: | https://github.com/marce10/rraven |
exp_empty_sels
exports a 'Raven' selection data in .txt format that includes empty selections for all sound files in a folder.
exp_empty_sels(path = NULL, file.name = NULL, sound.files = NULL, pb = TRUE)
exp_empty_sels(path = NULL, file.name = NULL, sound.files = NULL, pb = TRUE)
path |
A character string indicating the path of the directory in which to look for sound files. If not provided (default) the function will use the current working directory. |
file.name |
Name of the output .txt file. If |
sound.files |
character vector indicating the sound files that will be included. If |
pb |
Logical argument to control progress bar. Default is |
The function saves a selection file in '.txt' format (that can be directly opened in Raven) that will display all sound files in the provided directory (argument 'path'). Useful to simplify the making of selections from several sound files that need to be displayed simultaneously (e.g. several recordings from the same individual). The selection file is saved in the provided directory ('path').
The function saves a selection table in '.txt' format that can be directly opened in Raven. No objects are returned in the R environment.
Marcelo Araya-Salas ([email protected])
# Load data library(NatureSounds) library(warbleR) data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "lbh_selec_table")) ## Export a single selection table including multiple files #save sound files tuneR::writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav"), extensible = FALSE) tuneR::writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav"), extensible = FALSE) tuneR::writeWave(Phae.long3, file.path(tempdir(), "Phae.long3.wav"), extensible = FALSE) tuneR::writeWave(Phae.long4, file.path(tempdir(), "Phae.long4.wav"), extensible = FALSE) # export with no file name exp_empty_sels(path = tempdir()) # export with file name exp_empty_sels(file.name = "Phaethornis.longirostris", path = tempdir())
# Load data library(NatureSounds) library(warbleR) data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "lbh_selec_table")) ## Export a single selection table including multiple files #save sound files tuneR::writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav"), extensible = FALSE) tuneR::writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav"), extensible = FALSE) tuneR::writeWave(Phae.long3, file.path(tempdir(), "Phae.long3.wav"), extensible = FALSE) tuneR::writeWave(Phae.long4, file.path(tempdir(), "Phae.long4.wav"), extensible = FALSE) # export with no file name exp_empty_sels(path = tempdir()) # export with file name exp_empty_sels(file.name = "Phaethornis.longirostris", path = tempdir())
exp_est
exports wave objects of an extended selection table as sound files
exp_est(X, file.name = NULL, path = NULL, single.file = FALSE, selection.table = TRUE, pb = TRUE, normalize = TRUE, parallel = 1, wave.object = FALSE)
exp_est(X, file.name = NULL, path = NULL, single.file = FALSE, selection.table = TRUE, pb = TRUE, normalize = TRUE, parallel = 1, wave.object = FALSE)
X |
object of class 'extended_selection_table' (objects produced by |
file.name |
character string indicating the name of the sound file (if |
path |
A character string indicating the path of the directory where sound files and/or selection table will be saved. If not provided the
function uses the current working directory. Default is |
single.file |
Logical argument to control if all wave objects are pooled together in a
single sound file (if |
selection.table |
Logical argument to determine if a Raven sound selection table ('.txt' file) is also exported.
Default is |
pb |
Logical argument to control progress bar when exporting multiple sound files. Default is |
normalize |
Logical argument to control if wave objects are individually normalized before exporting (or before being pasted together if |
parallel |
Numeric. Controls whether parallel computing is applied. It specifies the number of cores to be used. Default is 1 (i.e. no parallel computing). |
wave.object |
Logical argument to control if ONLY a single wave object is returned in the R environment (TRUE) instead of a wave file in the working directory (and a selection table if |
The function takes wave objects contained as attributes in extended selection tables and saves them as sound files in '.wav' format. A single or several sound files can be produced (see 'single.file' argument). In addition, a Raven sound selection table can be saved along with the sound files. The exported selection table can be open in Raven for exploring/manipulating selections in 'X'.
Sound file(s) are saved in the provided path or current working directory. If selection.table = TRUE
a Raven sound selection table with the data in 'X' will also be saved.
Marcelo Araya-Salas ([email protected])
## Not run: # load example data data(list = "lbh.est", package = "NatureSounds") # subset to 10 selections X <- lbh.est[1:10, ] # Export data to a single sound file exp_est(X, file.name = "test", single.file = TRUE, path = tempdir()) # Export data to a single sound file and normalizing, no pb exp_est(X, file.name = "test2", single.file = TRUE, normalize = TRUE, pb = FALSE, path = tempdir()) # several files exp_est(X, single.file = FALSE, file.name = "test3", path = tempdir()) ## End(Not run)
## Not run: # load example data data(list = "lbh.est", package = "NatureSounds") # subset to 10 selections X <- lbh.est[1:10, ] # Export data to a single sound file exp_est(X, file.name = "test", single.file = TRUE, path = tempdir()) # Export data to a single sound file and normalizing, no pb exp_est(X, file.name = "test2", single.file = TRUE, normalize = TRUE, pb = FALSE, path = tempdir()) # several files exp_est(X, single.file = FALSE, file.name = "test3", path = tempdir()) ## End(Not run)
exp_raven
exports selection tables as 'Raven' selection data in .txt format.
exp_raven(X, path = NULL, file.name = NULL, khz.to.hz = TRUE, sound.file.path = NULL, single.file = TRUE, parallel = 1, pb = TRUE)
exp_raven(X, path = NULL, file.name = NULL, khz.to.hz = TRUE, sound.file.path = NULL, single.file = TRUE, parallel = 1, pb = TRUE)
X |
Object of class data frame or |
path |
A character string indicating the path of the directory in which to save the selection files. If not provided (default) the function saves the file into the current working directory. |
file.name |
Name of the output .txt file. If |
khz.to.hz |
Logical. Controls if frequency variables should be converted from kHz (the unit used by other bioacoustic analysis R packages like |
sound.file.path |
A character string indicating the path of the
directory containing the sound file(s). Providing this information allows
to open both sound file and selection table simultaneously. This can be
done by using the 'File > Open selection table' option in 'Raven' (or drag/drop the
selection file into Raven). Default is |
single.file |
Logical. Controls whether a single selection file ( |
parallel |
Numeric. Controls whether parallel computing is applied. It specifies the number of cores to be used. Default is 1 (i.e. no parallel computing). |
pb |
Logical argument to control progress bar. Default is |
The function exports selection tables (as the ones used in the R
package warbleR
) into the 'Raven' selection file format ('.txt').
This can be useful to obtain additional Raven
measurements on existing selections by adding new measurements to the
selection table once in Raven. Note that selection labels must be numeric and non-duplicated
when exporting them to Raven. If that is not the case the function will
relabeled the selections and the previous selection labels will be retained in a new column ('old.selec').
The function saves a selection table in '.txt' format that can be directly opened in Raven. If several sound files are available users can either export them as a single selection file or as multiple selection files (one for each sound file). No objects are returned in the R environment.
Marcelo Araya-Salas ([email protected])
# Load data library(warbleR) data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "lbh_selec_table")) # Select data for a single sound file st1 <- lbh_selec_table[lbh_selec_table$sound.files == "Phae.long1.wav", ] # Export data of a single sound file exp_raven(st1, file.name = "Phaethornis 1", path = tempdir()) # Export a single selection table including multiple files tuneR::writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav"), extensible = FALSE) #save sound files tuneR::writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav"), extensible = FALSE) tuneR::writeWave(Phae.long3, file.path(tempdir(), "Phae.long3.wav"), extensible = FALSE) tuneR::writeWave(Phae.long4, file.path(tempdir(), "Phae.long4.wav"), extensible = FALSE) # export raven selection as single file exp_raven(X = lbh_selec_table, file.name = "Phaethornis multiple sound files", single.file = TRUE, sound.file.path = tempdir(), path = tempdir())
# Load data library(warbleR) data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "lbh_selec_table")) # Select data for a single sound file st1 <- lbh_selec_table[lbh_selec_table$sound.files == "Phae.long1.wav", ] # Export data of a single sound file exp_raven(st1, file.name = "Phaethornis 1", path = tempdir()) # Export a single selection table including multiple files tuneR::writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav"), extensible = FALSE) #save sound files tuneR::writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav"), extensible = FALSE) tuneR::writeWave(Phae.long3, file.path(tempdir(), "Phae.long3.wav"), extensible = FALSE) tuneR::writeWave(Phae.long4, file.path(tempdir(), "Phae.long4.wav"), extensible = FALSE) # export raven selection as single file exp_raven(X = lbh_selec_table, file.name = "Phaethornis multiple sound files", single.file = TRUE, sound.file.path = tempdir(), path = tempdir())
extract_ts
extracts time series parameters from data imported from 'Raven' bioacoustic software.
extract_ts(X, ts.column, equal.length = FALSE, as.time.series = FALSE, length.out = 30, parallel = 1, pb = TRUE)
extract_ts(X, ts.column, equal.length = FALSE, as.time.series = FALSE, length.out = 30, parallel = 1, pb = TRUE)
X |
Data frame imported from Raven. It should include at least columns for: sound file names, selection labels, a parameters encoded as a time series (e.g. several numbers separated by semicolon) |
ts.column |
Name of the column with the time series data to be extracted.
Default is |
equal.length |
Logical. Controls whether time series are kept as in the original data (most of the
time with unequal lengths) or numbers are interpolated to equalize series length (using the |
as.time.series |
Logical. Controls if data is converted to the time series format (using the |
length.out |
A numeric vector of length 1 giving the number of measurements to be
interpolated (the length of the time series). default is 30. Ignored if equal.length is |
parallel |
Numeric. Controls whether parallel computing is applied. It specifies the number of cores to be used. Default is 1 (i.e. no parallel computing). |
pb |
Logical argument to control progress bar. Default is |
The function extracts parameters encoded as time series in 'Raven' selection files. The resulting data frame can be directly input into functions for time series analysis of acoustic signals as freq_DTW
.
A data frame with columns for sound file name (sound.files), selection label (selec) and the time series for each selection.
Marcelo Araya-Salas ([email protected])
## Not run: # Load data data(selection_files) #save 'Raven' selection tables in the temporary directory writeLines(selection_files[[5]], con = file.path(tempdir(), names(selection_files)[5])) # import data to R rvn.dat <- imp_raven(all.data = TRUE, path = tempdir()) # Peak freq dif length extract_ts(X = rvn.dat, ts.column = "Peak Freq Contour (Hz)") # Peak freq equal length extract_ts(X = rvn.dat, ts.column = "Peak Freq Contour (Hz)", equal.length = T) # Peak freq equal length 10 measurements extract_ts(X = rvn.dat, ts.column = "Peak Freq Contour (Hz)", equal.length = TRUE, length.out = 10) ## End(Not run)
## Not run: # Load data data(selection_files) #save 'Raven' selection tables in the temporary directory writeLines(selection_files[[5]], con = file.path(tempdir(), names(selection_files)[5])) # import data to R rvn.dat <- imp_raven(all.data = TRUE, path = tempdir()) # Peak freq dif length extract_ts(X = rvn.dat, ts.column = "Peak Freq Contour (Hz)") # Peak freq equal length extract_ts(X = rvn.dat, ts.column = "Peak Freq Contour (Hz)", equal.length = T) # Peak freq equal length 10 measurements extract_ts(X = rvn.dat, ts.column = "Peak Freq Contour (Hz)", equal.length = TRUE, length.out = 10) ## End(Not run)
fix_path
modifies the path column in selection tables and sound selection tables
fix_path(path = NULL, dest.path = NULL, recursive = FALSE, parallel = 1, pb = TRUE, new.begin.path, sound.file.col, files = NULL)
fix_path(path = NULL, dest.path = NULL, recursive = FALSE, parallel = 1, pb = TRUE, new.begin.path, sound.file.col, files = NULL)
path |
A character string indicating the path of the directory in which to look for the 'Raven' selection (text) files. If not provided (default) the function searches into the current working directory. |
dest.path |
A character string indicating the path of the directory in which sound selection tables will be saved. If not supplied selection files will be overwritten with the new begin path. If not provided (default) files will be save in the current directory. |
recursive |
Logical. If |
parallel |
Numeric. Controls whether parallel computing is applied. It specifies the number of cores to be used. Default is 1 (i.e. no parallel computing). |
pb |
Logical argument to control progress bar. Default is |
new.begin.path |
A character string indicating the path of the directory where sound files would be located. This argument is required. |
sound.file.col |
A character string with the name of the column containing the sound file names in the selection text files. Required. |
files |
Character vector indicating the name of selection files (in .txt format) to be imported. Optional. Default is |
The function modifies the path field in Raven's selection tables or sound selection tables. This is useful when sound files have been moved to a different location (or computer). Note that the ability to open selections and sound files simultaneously works as long as the "begin.path" column is referring to the directory containing the sound files.
Selection table file(s) saved in 'dest.path' or in the working directory (by default, which overwrites existing files).
Marcelo Araya-Salas ([email protected])
{ # load warbleR for sound file examples library(NatureSounds) #load data data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "selection_files")) # save sound files tuneR::writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav"), extensible = FALSE) tuneR::writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav"), extensible = FALSE) tuneR::writeWave(Phae.long3, file.path(tempdir(), "Phae.long3.wav"), extensible = FALSE) tuneR::writeWave(Phae.long4, file.path(tempdir(), "Phae.long4.wav"), extensible = FALSE) # save 'Raven' selection tables in the temporary directory out <- lapply(1:2, function(x) writeLines(selection_files[[x]], con = file.path(tempdir(), names(selection_files)[x]))) # try drag and drop selection files into Raven (shouldn't work) # now fix files fix_path(path = tempdir(), sound.file.col = "Begin File", new.begin.path = "YOUR NEW LOCATION HERE") # try drag and drop into Raven again (should work now) }
{ # load warbleR for sound file examples library(NatureSounds) #load data data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "selection_files")) # save sound files tuneR::writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav"), extensible = FALSE) tuneR::writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav"), extensible = FALSE) tuneR::writeWave(Phae.long3, file.path(tempdir(), "Phae.long3.wav"), extensible = FALSE) tuneR::writeWave(Phae.long4, file.path(tempdir(), "Phae.long4.wav"), extensible = FALSE) # save 'Raven' selection tables in the temporary directory out <- lapply(1:2, function(x) writeLines(selection_files[[x]], con = file.path(tempdir(), names(selection_files)[x]))) # try drag and drop selection files into Raven (shouldn't work) # now fix files fix_path(path = tempdir(), sound.file.col = "Begin File", new.begin.path = "YOUR NEW LOCATION HERE") # try drag and drop into Raven again (should work now) }
imp_corr_mat
imports the output of 'Raven' batch correlator.
imp_corr_mat(file, path = NULL)
imp_corr_mat(file, path = NULL)
file |
A character string with the name of the output '.txt' file generated by Raven. |
path |
A character string indicating the path of the directory in which to look for the text files. If not provided (default) the function searches into the current working directory. |
The function imports the output of a batch correlation routine in Raven. Both the correlation and lag matrices contained in the output ' .txt' file are read and both waveform and spectrogram (cross-correlation) correlations can be imported.
A list with 2 matrices. The first one contains the correlation coefficients and the second one the time lags of the peak correlations.
Marcelo Araya-Salas ([email protected])
## Not run: # Load data library(NatureSounds) data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "lbh_selec_table")) tuneR::writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav"), extensible = FALSE) #save sound files tuneR::writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav"), extensible = FALSE) tuneR::writeWave(Phae.long3, file.path(tempdir(), "Phae.long3.wav"), extensible = FALSE) tuneR::writeWave(Phae.long4, file.path(tempdir(), "Phae.long4.wav"), extensible = FALSE) #create new folder to put cuts dir.create(file.path(tempdir(), "cuts")) # cut files cut_sels(X = lbh_selec_table, mar = 0.05, path = tempdir(), dest.path = file.path(tempdir(), "cuts")) #Now run 'Raven' batch correlator un the cuts and save the output in the same folder # Import output (change the name of the file if you used a different one) xcorr.rav <- imp_corr_mat(file = "BatchCorrOutput.txt", path = file.path(tempdir(), "cuts")) # check results ## correlation matrix xcorr.rav[[1]] ## time lag matrix xcorr.rav[[2]] ## End(Not run)
## Not run: # Load data library(NatureSounds) data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "lbh_selec_table")) tuneR::writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav"), extensible = FALSE) #save sound files tuneR::writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav"), extensible = FALSE) tuneR::writeWave(Phae.long3, file.path(tempdir(), "Phae.long3.wav"), extensible = FALSE) tuneR::writeWave(Phae.long4, file.path(tempdir(), "Phae.long4.wav"), extensible = FALSE) #create new folder to put cuts dir.create(file.path(tempdir(), "cuts")) # cut files cut_sels(X = lbh_selec_table, mar = 0.05, path = tempdir(), dest.path = file.path(tempdir(), "cuts")) #Now run 'Raven' batch correlator un the cuts and save the output in the same folder # Import output (change the name of the file if you used a different one) xcorr.rav <- imp_corr_mat(file = "BatchCorrOutput.txt", path = file.path(tempdir(), "cuts")) # check results ## correlation matrix xcorr.rav[[1]] ## time lag matrix xcorr.rav[[2]] ## End(Not run)
imp_raven
imports several 'Raven' selection files simultaneously. Files must be in '.txt' format.
imp_raven(path = NULL, warbler.format = FALSE, all.data = FALSE, files = NULL, only.spectro.view = TRUE, recursive = FALSE, name.from.file = FALSE, ext.case = NULL, freq.cols = TRUE, waveform = FALSE, parallel = 1, pb = TRUE, unread = FALSE, rm.dup = FALSE, sound.file.col = NULL)
imp_raven(path = NULL, warbler.format = FALSE, all.data = FALSE, files = NULL, only.spectro.view = TRUE, recursive = FALSE, name.from.file = FALSE, ext.case = NULL, freq.cols = TRUE, waveform = FALSE, parallel = 1, pb = TRUE, unread = FALSE, rm.dup = FALSE, sound.file.col = NULL)
path |
A character string indicating the path of the directory in which to look for the 'Raven' selection (text) files. If not provided (default) the function searches into the current working directory. |
warbler.format |
Logical. If |
all.data |
Logical. If |
files |
Character vector indicating the name of selection files (in .txt format) to be imported. Optional. Default is |
only.spectro.view |
Logical. If |
recursive |
Logical. If |
name.from.file |
Logical. If |
ext.case |
Character string of length 1 to specify whether sound file extensions are in upper or lower case. This should match the extension of the
of the .wav files from which the selection were made. It must be either 'upper' or 'lower'. Only needed when 'name.from.file' is |
freq.cols |
Logical. If |
waveform |
Logical to control if waveform view data should be included (this data is typically duplicated in spectrogram view data). Default is |
parallel |
Numeric. Controls whether parallel computing is applied. It specifies the number of cores to be used. Default is 1 (i.e. no parallel computing). |
pb |
Logical argument to control progress bar. Default is |
unread |
DEPRECATED. Logical. If |
rm.dup |
Logical. If |
sound.file.col |
A character string with the name of the column containing the sound files in
the selection text files. Default is |
The function import 'Raven' selection data from many files simultaneously. All selection files in the working directory or 'path' supplied will be imported (unless 'files' argument is also supplied). It has been created using Raven Pro 1.5 and tested on Raven 1.6. Selection tables created with other versions might not be read properly. Files must be in '.txt' format. Selection files including data from multiple recordings can also be imported although they must contained a 'File Offset (s)' column. Selections that span across multiple sound files are not recommended as they will be assigned to the first sound file, which would produce errors for downstream analyses as those from the 'warbleR' package. Empty '.txt' files are ignored.
A single data frame with information of the selection files. If some selection files were not read they will be listed in .Options$Rraven
.
If 'warbler.format' argument is set to TRUE
the data frame contains the following columns: sound.files, selec, channel,start, end, top.freq, bottom.freq and selec.file. If all.data is set to TRUE
then all columns in the 'Raven' selection files are returned.
If individual selection files contain information about multiple sound files the function will import the file and correct the time
parameters (start and end) only if 1) the 'File Offset (s)' is found in the selection table.
Marcelo Araya-Salas ([email protected])
# load data data(selection_files) # save 'Raven' selection tables in the temporary directory out <- lapply(1:2, function(x) writeLines(selection_files[[x]], con = file.path(tempdir(), names(selection_files)[x]))) # providing the name of the column with the sound file names rvn.dat <- imp_raven(sound.file.col = "Begin.File", all.data = FALSE, path = tempdir()) # View(rvn.dat)
# load data data(selection_files) # save 'Raven' selection tables in the temporary directory out <- lapply(1:2, function(x) writeLines(selection_files[[x]], con = file.path(tempdir(), names(selection_files)[x]))) # providing the name of the column with the sound file names rvn.dat <- imp_raven(sound.file.col = "Begin.File", all.data = FALSE, path = tempdir()) # View(rvn.dat)
imp_syrinx
imports 'Syrinx' selection data from many files simultaneously.
All files must have the same columns.
imp_syrinx(path = NULL, all.data = FALSE, recursive = FALSE, exclude = FALSE, hz.to.khz = TRUE, parallel = 1, pb = TRUE)
imp_syrinx(path = NULL, all.data = FALSE, recursive = FALSE, exclude = FALSE, hz.to.khz = TRUE, parallel = 1, pb = TRUE)
path |
A character string indicating the path of the directory in which to look for the text files.
If not provided (default) the function searches into the current working directory. Default is |
all.data |
Logical. If |
recursive |
Logical. If |
exclude |
Logical. Controls whether files that cannot be read are ignored ( |
hz.to.khz |
Logical. Controls if frequency variables should be converted from Hz (the unit used by Syrinx) to kHz (the unit used by warbleR and other bioacoustic analysis packages in R). Default if |
parallel |
Numeric. Controls whether parallel computing is applied. It specifies the number of cores to be used. Default is 1 (i.e. no parallel computing). |
pb |
Logical argument to control progress bar. Default is |
A single data frame with information of the selection files. If all.data argument is set to FALSE
the data
frame contains the following columns: selec, start, end, and selec.file. If sound.file.col is provided the data frame
will also contain a 'sound.files' column. If all.data is set to TRUE
then all
columns in selection files are returned.
Marcelo Araya-Salas ([email protected])
## Not run: #load data data(selection_files) #save 'Raven' selection tables in the temporary directory writeLines(selection_files[[7]], con = file.path(tempdir(), names(selection_files)[7])) syr.dat <- imp_syrinx(all.data = FALSE) # View(syr.dat) #getting all the data syr.dat <- imp_syrinx(all.data = TRUE) # View(syr.dat) ## End(Not run)
## Not run: #load data data(selection_files) #save 'Raven' selection tables in the temporary directory writeLines(selection_files[[7]], con = file.path(tempdir(), names(selection_files)[7])) syr.dat <- imp_syrinx(all.data = FALSE) # View(syr.dat) #getting all the data syr.dat <- imp_syrinx(all.data = TRUE) # View(syr.dat) ## End(Not run)
match_wav_case
fixes the extension case of sound files in a selection table.
match_wav_case(X, path = NULL, output = "data.frame", verbose = TRUE)
match_wav_case(X, path = NULL, output = "data.frame", verbose = TRUE)
X |
Data frame containing columns for sound file (sound.files) and selection
(selec). See example data 'lbh_selec_table' in the |
path |
A character string indicating the path of the directory in which to look for sound files. If not provided (default) the function searches into the current working directory. |
output |
Character string. Controls whether a complete data frame ('data.frame') or only the sound file names ("names") are returned. Default is 'data.frame'. |
verbose |
Logical to control if messages are printed ( |
The function returns the data from the input data frame with extension file names in the 'sound.files' column matching those of the sound files (in case there was any mismatch). The function needs the path to the sound files to compare extension names.
The same data as in the input data frame but with the case of the extension file names in the 'sound.files' column matching those of the sound files themselves.
Marcelo Araya-Salas ([email protected])
{ library(warbleR) data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "lbh_selec_table")) tuneR::writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav"), extensible = FALSE) #save sound files tuneR::writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav"), extensible = FALSE) tuneR::writeWave(Phae.long3, file.path(tempdir(), "Phae.long3.wav"), extensible = FALSE) tuneR::writeWave(Phae.long4, file.path(tempdir(), "Phae.long4.wav"), extensible = FALSE) # change one extension lbh_selec_table$sound.files <- as.character(lbh_selec_table$sound.files) lbh_selec_table$sound.files[1] <- gsub(".wav$", ".WAV", lbh_selec_table$sound.files[1]) # fixed extension an return data frame match_wav_case(X = lbh_selec_table, path = tempdir()) # fixed extension an return sound file names match_wav_case(X = lbh_selec_table, output = "names", path = tempdir()) }
{ library(warbleR) data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "lbh_selec_table")) tuneR::writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav"), extensible = FALSE) #save sound files tuneR::writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav"), extensible = FALSE) tuneR::writeWave(Phae.long3, file.path(tempdir(), "Phae.long3.wav"), extensible = FALSE) tuneR::writeWave(Phae.long4, file.path(tempdir(), "Phae.long4.wav"), extensible = FALSE) # change one extension lbh_selec_table$sound.files <- as.character(lbh_selec_table$sound.files) lbh_selec_table$sound.files[1] <- gsub(".wav$", ".WAV", lbh_selec_table$sound.files[1]) # fixed extension an return data frame match_wav_case(X = lbh_selec_table, path = tempdir()) # fixed extension an return sound file names match_wav_case(X = lbh_selec_table, output = "names", path = tempdir()) }
raven_batch_detec
Runs 'Raven' batch detector on multiple sound files sequentially
raven_batch_detec(raven.path = NULL, sound.files, path = NULL, detector.type, detector.preset = "Default", view.preset = "Default", relabel_colms = TRUE, pb = TRUE, parallel = 1)
raven_batch_detec(raven.path = NULL, sound.files, path = NULL, detector.type, detector.preset = "Default", view.preset = "Default", relabel_colms = TRUE, pb = TRUE, parallel = 1)
raven.path |
A character string indicating the path of the directory in which to look for the 'Raven' executable file (where 'Raven' was installed). |
sound.files |
character vector indicating the files that will be analyzed.
In OSX (mac) only one file at the time can be run (use loops instead!). If |
path |
A character string indicating the path of the directory in which to look for
the sound files. If not provided (default) the function searches into the current working
directory. Default is |
detector.type |
Character string specifying the type of detector to be called. There are 3 options available in 'Raven': 'Amplitude Detector', 'Band Limited Energy Detector' and 'Band Limited Entropy Detector'. Must be provided. |
detector.preset |
Character string specifying the name of the customized detector to be called.
If |
view.preset |
Character string specifying the name of the window preset to be used. Not require for 'Amplitude Detector' (see 'detector.type' argument).
If |
relabel_colms |
Logical. If |
pb |
Logical argument to control progress bar. Default is |
parallel |
Numeric. Controls whether parallel computing is applied. It specifies the number of cores to be used. Default is 1 (i.e. no parallel computing). |
The function runs 'Raven' sound analysis software (Cornell Lab of Ornithology), detector on multiple sound files sequentially. 'Raven' Pro must be installed. Note that batch detection in 'Raven' can also take sound files in 'mp3', 'flac' and 'aif' format.
A data frame with the selections produced during the detection. See imp_raven
for more details on how selections are imported.
Marcelo Araya-Salas ([email protected])
imp_raven
; imp_syrinx
; run_raven
## Not run: # here replace with path where 'Raven' is installed in your computer raven.path <- "PATH_TO_RAVEN_DIRECTORY_HERE" # Run detector on raven example sound files # single sound file using 'Amplitude Detector' detec.res <- raven_batch_detec(raven.path = raven.path, sound.files = "BlackCappedVireo.aif", path = file.path(raven.path, "Examples"), detector.type = "Amplitude Detector") # on raven examples 2 files detec.res <- raven_batch_detec(raven.path = raven.path, sound.files = c("BlackCappedVireo.aif", "CanyonWren.wav"), path = file.path(raven.path, "Examples"), detector.type = "Amplitude Detector") # using 'Band Limited Energy Detector' detec.res <- raven_batch_detec(raven.path = raven.path, sound.files = c("BlackCappedVireo.aif", "CanyonWren.wav"), path = file.path(raven.path, "Examples"), detector = "Band Limited Energy Detector") ## End(Not run)
## Not run: # here replace with path where 'Raven' is installed in your computer raven.path <- "PATH_TO_RAVEN_DIRECTORY_HERE" # Run detector on raven example sound files # single sound file using 'Amplitude Detector' detec.res <- raven_batch_detec(raven.path = raven.path, sound.files = "BlackCappedVireo.aif", path = file.path(raven.path, "Examples"), detector.type = "Amplitude Detector") # on raven examples 2 files detec.res <- raven_batch_detec(raven.path = raven.path, sound.files = c("BlackCappedVireo.aif", "CanyonWren.wav"), path = file.path(raven.path, "Examples"), detector.type = "Amplitude Detector") # using 'Band Limited Energy Detector' detec.res <- raven_batch_detec(raven.path = raven.path, sound.files = c("BlackCappedVireo.aif", "CanyonWren.wav"), path = file.path(raven.path, "Examples"), detector = "Band Limited Energy Detector") ## End(Not run)
relabel_colms
relabels columns to match the selection table format (as in the R package warbleR
)
relabel_colms(X, extra.cols.name = NULL, extra.cols.new.name = NULL, khz.to.hz = FALSE, hz.to.khz = FALSE, waveform = FALSE)
relabel_colms(X, extra.cols.name = NULL, extra.cols.new.name = NULL, khz.to.hz = FALSE, hz.to.khz = FALSE, waveform = FALSE)
X |
Data frame imported from Raven. |
extra.cols.name |
Character vector with the names of additional columns to be relabeled. Default is |
extra.cols.new.name |
Character vector with the new names for the additional columns to be relabeled.
Default is |
khz.to.hz |
Logical. Controls if frequency variables ('top.freq' and 'bottom.freq') should be converted from kHz
(the unit used by other bioacoustic analysis R packages like |
hz.to.khz |
Logical. Controls if frequency variables ('top.freq' and 'bottom.freq') should be converted from Hz
(the unit used by other bioacoustic analysis R packages like Raven) to kHz (the unit used by |
waveform |
Logical to control if 'waveform' related data should be included (this data is typically duplicated in 'spectrogram' data). Default is |
This function relabels columns to match the selection table format to match then ones used by other bioacoustic analysis R packages like warbleR
.
The function returns the input data frame with new column names for time and frequency 'coordinates' and sound files and selections.
Marcelo Araya-Salas ([email protected])
# Load data data(selection_files) #save 'Raven' selection tables in the temporary directory writeLines(selection_files[[5]], con = file.path(tempdir(), names(selection_files)[5])) #'# import data to R rvn.dat <- imp_raven(all.data = TRUE, path = tempdir()) names(rvn.dat) # Select data for a single sound file rvn.dat2 <- relabel_colms(rvn.dat) names(rvn.dat2) # plus 1 additional column rvn.dat2 <- relabel_colms(rvn.dat, extra.cols.name = "selec.file", "Raven selection file") names(rvn.dat2) # plus 2 additional column rvn.dat2 <- relabel_colms(rvn.dat, extra.cols.name = c("selec.file", "View"), c("Raven selection file", "Raven view")) names(rvn.dat2)
# Load data data(selection_files) #save 'Raven' selection tables in the temporary directory writeLines(selection_files[[5]], con = file.path(tempdir(), names(selection_files)[5])) #'# import data to R rvn.dat <- imp_raven(all.data = TRUE, path = tempdir()) names(rvn.dat) # Select data for a single sound file rvn.dat2 <- relabel_colms(rvn.dat) names(rvn.dat2) # plus 1 additional column rvn.dat2 <- relabel_colms(rvn.dat, extra.cols.name = "selec.file", "Raven selection file") names(rvn.dat2) # plus 2 additional column rvn.dat2 <- relabel_colms(rvn.dat, extra.cols.name = c("selec.file", "View"), c("Raven selection file", "Raven view")) names(rvn.dat2)
run_raven
opens several sound files in 'Raven' sound analysis software
run_raven(raven.path = NULL, sound.files = NULL, path = NULL, at.the.time = 10, import = FALSE, redo = FALSE, view.preset = NULL, pb = TRUE, ...)
run_raven(raven.path = NULL, sound.files = NULL, path = NULL, at.the.time = 10, import = FALSE, redo = FALSE, view.preset = NULL, pb = TRUE, ...)
raven.path |
A character string indicating the path of the directory in which to look for the 'Raven' executable file (where 'Raven' was installed). |
sound.files |
character vector indicating the files that will be analyzed. If |
path |
A character string indicating the path of the directory in which to look for
the sound files. If not provided (default) the function searches into the current working
directory. Default is |
at.the.time |
Numeric vector of length 1 controlling how many files will be open in 'Raven' at the same time. Note that opening too many files at once could make 'Raven' run out of memory. You need to close 'Raven' every time the batch of files is analyzed, so the next batch is opened. Default is 10. Not available in OSX (mac). |
import |
Logical. Controls if the selection tables generated should be returned as a
data frame into the R environment. This only works if the selections are saved in the
"Selections" folder in the 'Raven' directory. This argument calls the |
redo |
Logical. Controls whether only the subset of files with no 'Raven' selections (.txt file) in the 'Raven' 'selections' folder
are analyzed (if |
view.preset |
Character string defining the 'Raven' view preset to be used. It should match exactly the name of the present in the 'Raven' folder 'Presets/Sound Window'. If not provided the default view preset is used. |
pb |
Logical argument to control progress bar. Default is |
... |
Additional arguments to be passed to |
The function runs 'Raven' sound analysis software (Cornell Lab of
Ornithology), opening many files simultaneously. 'Raven' will still run if no
sound files are provided (i.e. sound.files = NULL
). At the end of the
analysis the data can be automatically imported back into R using the 'import'
argument. 'Raven' Pro must be installed. Note that 'Raven' can also take sound files in 'mp3', 'flac' and
'aif' format.
If import = TRUE
a data frame with the selections produced during the analysis will be return as an data frame. See imp_raven
for more details on how selections are imported.
Marcelo Araya-Salas ([email protected])
## Not run: # save sound files library(NatureSounds) data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4")) tuneR::writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav"), extensible = FALSE) tuneR::writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav"), extensible = FALSE) # here replace with the path where 'Raven' is install in your computer raven.path <- "PATH_TO_RAVEN_DIRECTORY_HERE" # run function run_raven(raven.path = raven.path, sound.files = c("Phae.long1.wav", "Phae.long2.wav"), at.the.time = 2, import = T, name.from.file = T, ext.case = "upper", all.data = TRUE, path = tempdir()) #getting all the data rav.dat <- run_raven(all.data = TRUE, raven.path = raven.path) # View(rav.dat) ## End(Not run)
## Not run: # save sound files library(NatureSounds) data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4")) tuneR::writeWave(Phae.long1, file.path(tempdir(), "Phae.long1.wav"), extensible = FALSE) tuneR::writeWave(Phae.long2, file.path(tempdir(), "Phae.long2.wav"), extensible = FALSE) # here replace with the path where 'Raven' is install in your computer raven.path <- "PATH_TO_RAVEN_DIRECTORY_HERE" # run function run_raven(raven.path = raven.path, sound.files = c("Phae.long1.wav", "Phae.long2.wav"), at.the.time = 2, import = T, name.from.file = T, ext.case = "upper", all.data = TRUE, path = tempdir()) #getting all the data rav.dat <- run_raven(all.data = TRUE, raven.path = raven.path) # View(rav.dat) ## End(Not run)
List of 'Raven' and 'Syrinx' selection tables containing
Phaethornis longirostris (Long-billed Hermit) songs from the
example sound files included in the warbleR
package (times 1 to 5),
a 'Raven' correlation matrix (item 6) and one selection from cane-brake wrens
(item 7; no sound file available).
data(selection_files)
data(selection_files)
List of 7 selection tables. The first 5 items are 'Raven' selection tables of Long billed hermit songs. The 5th table contains a multiple sound file selection table. The 6th item is a 'Raven' correlation matrix and the last one a table in 'Syrinx' format.
Marcelo Araya-Salas
to_sound_selection
converts Raven's selection files into sound selection files
to_sound_selection(path = NULL, dest.path = NULL, recursive = FALSE, parallel = 1, pb = TRUE, sound.file.path, sound.file.col)
to_sound_selection(path = NULL, dest.path = NULL, recursive = FALSE, parallel = 1, pb = TRUE, sound.file.path, sound.file.col)
path |
A character string indicating the path of the directory in which to look for the 'Raven' selection (text) files. If not provided (default) the function searches into the current working directory. |
dest.path |
A character string indicating the path of the directory in which sound selection tables will be saved. If not provided (default) files will be saved in directory where the original raven selections were found. |
recursive |
Logical. If |
parallel |
Numeric. Controls whether parallel computing is applied. It specifies the number of cores to be used. Default is 1 (i.e. no parallel computing). |
pb |
Logical argument to control progress bar. Default is |
sound.file.path |
A character string indicating the path of the directory containing the sound file(s). This argument is required. |
sound.file.col |
A character string with the name of the column containing the sound file names in the selection text files. Required. |
The function converts Raven's selection tables to sound selection tables. Sound selection table is a more convenient format as it can be open directly in Raven (or drag-and-drop) and will automatically open the associated sound file. Multiple files can be simultaneously converted. Files must be in '.txt' format. Selection files including data from multiple recordings can be converted only if all the correspondent sound files are found in the same directory. Note that no data is imported into the R environment.
Sound selection table file(s) saved in 'dest.path' or in the working directory.
Marcelo Araya-Salas ([email protected])
{ #load data data(selection_files) # save 'Raven' selection tables in the temporary directory out <- lapply(1:2, function(x) writeLines(selection_files[[x]], con = file.path(tempdir(), names(selection_files)[x]))) # try drag and drop selection files into Raven (shouldn't work) # now convert files to_sound_selection(sound.file.path = tempdir(), sound.file.col = "Begin Path", path = tempdir()) # try drag and drop into Raven again (should work now) }
{ #load data data(selection_files) # save 'Raven' selection tables in the temporary directory out <- lapply(1:2, function(x) writeLines(selection_files[[x]], con = file.path(tempdir(), names(selection_files)[x]))) # try drag and drop selection files into Raven (shouldn't work) # now convert files to_sound_selection(sound.file.path = tempdir(), sound.file.col = "Begin Path", path = tempdir()) # try drag and drop into Raven again (should work now) }