Title: | Load and Process Passive Acoustic Data |
---|---|
Description: | Tools for loading and processing passive acoustic data. Read in data that has been processed in 'Pamguard' (<https://www.pamguard.org/>), apply a suite processing functions, and export data for reports or external modeling tools. Parameter calculations implement methods by Oswald et al (2007) <doi:10.1121/1.2743157>, Griffiths et al (2020) <doi:10.1121/10.0001229> and Baumann-Pickering et al (2010) <doi:10.1121/1.3479549>. |
Authors: | Taiki Sakai [aut, cre], Jay Barlow [ctb], Emily Griffiths [ctb], Michael Oswald [ctb], Simone Baumann-Pickering [ctb], Julie Oswald [ctb] |
Maintainer: | Taiki Sakai <[email protected]> |
License: | GNU General Public License |
Version: | 1.4.4 |
Built: | 2025-02-06 06:13:23 UTC |
Source: | https://github.com/taikisan21/pampal |
AcousticEvent
ClassAn S4 class storing acoustic detections from an Acoustic Event as well as other related metadata
id
unique id or name for this event
detectors
a list of data frames that have acoustic detections and any measurements calculated on those detections. Each data frame is named by the detector that made the detection
localizations
a named list storing localizations, named by method
settings
a list of recorder settings
species
a list of species classifications for this event, named by classification method (ie. BANTER model, visual ID)
files
a list of files used to create this object, named by the type of file (ie. binaries, database)
ancillary
a list of miscellaneous extra stuff. Store whatever you want here
Taiki Sakai [email protected]
AcousticStudy
ClassAn S4 class storing acoustic data from an entire AcousticStudy
id
a unique id for the study
events
a list of AcousticEvent objects with detections from the AcousticStudy
files
a list of folders and files containing the AcousticStudy data
gps
a data frame of gps coordinates for the entire AcousticStudy
pps
the PAMpalSettings object used to create this object
settings
a named list of various settings for detectors, localizers, etc.
effort
something about effort lol
models
a place to store any models run on your data
ancillary
miscellaneous extra data
Taiki Sakai [email protected]
Adds annotation data to an AcousticStudy
object, usually in preparation for exporting to an external source.
Most pieces of the annotation form will be filled in by the user when
the function is called, but lat
, lon
, time_start
,
time_end
, freq_low
, freq_high
, source_id
,
and annotation_id
will be filled in automatically based on data
in each AcousticEvent. Annotations are stored for each
event in the ancillary
slot.
addAnnotation(x, anno, verbose = TRUE) prepAnnotation( x, specMap = NULL, mode = c("event", "detection"), interactive = FALSE, ... ) getAnnotation(x) checkAnnotation(x) export_annomate(x, file = NULL) matchRecordingUrl(anno, rec)
addAnnotation(x, anno, verbose = TRUE) prepAnnotation( x, specMap = NULL, mode = c("event", "detection"), interactive = FALSE, ... ) getAnnotation(x) checkAnnotation(x) export_annomate(x, file = NULL) matchRecordingUrl(anno, rec)
x |
an AcousticStudy or AcousticEvent object |
anno |
an annotation dataframe |
verbose |
logical flag to print messages |
specMap |
data.frame to map species ids in |
mode |
one of |
interactive |
logical flag to fill annotation data interactively (not recommended) |
... |
additional named arguments to fill in annotation data. If names match a column in the annotation, that value will be used for all events or detections in the annotation |
file |
file to write a CSV of the annotations to, if |
rec |
dataframe of recording url information. Must have column
|
The same object as x
with an $annotation
item added
the the ancillary
slot of each event in x
Taiki Sakai [email protected]
Adds more binary files to the "binaries" slot of a PAMpalSettings object. Interactively asks user to supply folder location if not provided.
addBinaries(pps, folder = NULL, verbose = TRUE)
addBinaries(pps, folder = NULL, verbose = TRUE)
pps |
a PAMpalSettings object to add binary files to |
folder |
a folder of binaries to add, all subfolders will also be added |
verbose |
logical flag to show messages |
the same PAMpalSettings object as pps, with the binary
files contained in folder
added to the "binaries" slot. Only
binary files for Click Detector and WhistlesMoans modules will be added,
since these are the only types PAMpal currently knows how to process
Taiki Sakai [email protected]
# not recommended to create PPS like this, for example only pps <- new('PAMpalSettings') binFolder <- system.file('extdata', 'Binaries', package='PAMpal') pps <- addBinaries(pps, binFolder) pps
# not recommended to create PPS like this, for example only pps <- new('PAMpalSettings') binFolder <- system.file('extdata', 'Binaries', package='PAMpal') pps <- addBinaries(pps, binFolder) pps
Adds a new calibration function to the "calibration" slot of a PAMpalSettings object. Interactively asks user to supply file and other parameters if not supplied.
addCalibration( pps, calFile = NULL, module = "ClickDetector", calName = NULL, all = FALSE, units = NULL ) applyCalibration(pps, module = "ClickDetector", all = FALSE)
addCalibration( pps, calFile = NULL, module = "ClickDetector", calName = NULL, all = FALSE, units = NULL ) applyCalibration(pps, module = "ClickDetector", all = FALSE)
pps |
a PAMpalSettings object to add a database to |
calFile |
a calibration file name. Must be csv format with two columns.
The first column must be the frequency (in Hz), and the second column must be the
sensitivity (in dB), and the columns should be labeled |
module |
the Pamguard module type this calibration should be applied to, for now this is only for ClickDetector modules. This is left as an option for future-proofing purposes but should not be needed. |
calName |
the name to assign to the calibration function, defaults to the file name and only needs to be set if supplying a dataframe instead of a csv file |
all |
logical flag whether or not to apply calibration to all functions
without asking individually, recommended to stay as |
units |
a number from 1 to 3 specifying the units of the calibration file, number corresponds to dB re V/uPa, uPa/Counts, or uPa/FullScale respectively. A NULL (default) or other value will prompt user to select units. |
When adding a calibration, you will be asked what units your calibration value is in. The wave clips stored by Pamguard are values from -1 to 1, so if your calibration is expecting different units then this needs to be accounted for in order to get an accurate SPL value. For V / uPa you must know the voltage range of your recording equipment, and for calibrations expecting Count data you must know the bit rate of your recordings. If your calibration is already relative to full-scale, then nothing needs to be adjusted. If you don't know the units of your calibration and you are only interested in relative dB levels, then you can select the Full-Scale options.
The calibration function created takes frequency (in Hz) as input and outputs the associated dB value that needs to be added to correct the power spectrum of a signal. If the input is a matrix or dataframe, the first column is assumed to be frequency.
the same PAMpalSettings object as pps, with the calibration
function added to the calibration
slot.
Taiki Sakai [email protected]
pps <- new('PAMpalSettings') calFile <- system.file('extdata', 'calibration.csv', package='PAMpal') pps <- addCalibration(pps, calFile, all = TRUE, units=3) calClick <- function(data, calibration=NULL) { standardClickCalcs(data, calibration=calibration, filterfrom_khz = 0) } pps <- addFunction(pps, calClick, module = 'ClickDetector') pps <- applyCalibration(pps, all=TRUE) pps
pps <- new('PAMpalSettings') calFile <- system.file('extdata', 'calibration.csv', package='PAMpal') pps <- addCalibration(pps, calFile, all = TRUE, units=3) calClick <- function(data, calibration=NULL) { standardClickCalcs(data, calibration=calibration, filterfrom_khz = 0) } pps <- addFunction(pps, calClick, module = 'ClickDetector') pps <- applyCalibration(pps, all=TRUE) pps
Adds a new function to the "function" slot in a PAMpalSettings object. Interactively asks for database files if none are supplied as input
addDatabase(pps, db = NULL, verbose = TRUE)
addDatabase(pps, db = NULL, verbose = TRUE)
pps |
a PAMpalSettings object to add a database to |
db |
database(s) to add, or single directory containing databases |
verbose |
logical flag to show messages |
the same PAMpalSettings object as pps, with the database
db
added to the "db" slot
Taiki Sakai [email protected]
# not recommended to create a pps like this, for example only pps <- new('PAMpalSettings') db <- system.file('extdata', 'Example.sqlite3', package='PAMpal') pps <- addDatabase(pps, db) pps
# not recommended to create a pps like this, for example only pps <- new('PAMpalSettings') db <- system.file('extdata', 'Example.sqlite3', package='PAMpal') pps <- addDatabase(pps, db) pps
Adds data from FPOD detector CSV files to an
AcousticStudy object as new detectors of type
"fpod"
addFPOD(x, fpod, detectorName = "FPOD")
addFPOD(x, fpod, detectorName = "FPOD")
x |
an AcousticStudy object |
fpod |
path(s) to CSV files containing FPOD detector output |
detectorName |
name for the detector, the default |
FPOD detections are added to events based on their times. All detections
between the start and end times events. NOTE: most PAMpal
functions were designed
with only PAMGuard data in mind, there is a chance that adding FPOD detections will
cause other advanced functionality to not work.
Behavior is slightly different depending
on how the original AcousticStudy was created. For those processed with
mode='db'
, the start and end times for each event are just determined
by the times of detections within the event.
For those processed with
mode='recording'
or mode='time'
, the start and end times for
each event are determined by the start/end times of the recording files or
the grouping file provided initially. This means that it is possible that
there are events which initially had zero PAMGuard detections that now have
FPOD detections. In these cases a new AcousticEvent will be created that only
has FPOD detections, these events may not work with a variety of other PAMpal
functions.
the same object as x
with FPOD detector data added
Taiki Sakai [email protected]
Adds a new function to the "function" slot in a PAMpalSettings object. Must be run interactively, user will be prompted to assign values for any parameters in the function to be added
addFunction(pps, fun, module = NULL, verbose = TRUE, default = FALSE, ...)
addFunction(pps, fun, module = NULL, verbose = TRUE, default = FALSE, ...)
pps |
a PAMpalSettings object to add a function to |
fun |
function to add OR another PAMpalSettings object.
In this case all functions from the second object will be added to |
module |
Pamguard module output this function should act on, one of
ClickDetector, WhistlesMoans, Cepstrum, or GPLDetector. If |
verbose |
logical flag to show messages |
default |
logical flag to use default function parameters if present |
... |
named arguments to pass to function being added |
the same PAMpalSettings object as pps, with the function
fun
added to the "functions" slot
Taiki Sakai [email protected]
# not recommended to create a pps like this, for example only pps <- new('PAMpalSettings') if(interactive()) pps <- addFunction(pps, standardClickCalcs) pps <- addFunction(pps, roccaWhistleCalcs, module='WhistlesMoans')
# not recommended to create a pps like this, for example only pps <- new('PAMpalSettings') if(interactive()) pps <- addFunction(pps, standardClickCalcs) pps <- addFunction(pps, roccaWhistleCalcs, module='WhistlesMoans')
Add GPS Lat / Long to an AcousticStudy or AcousticEvent. If GPS data is not present in any of the databases, user will interactively be asked to provide GPS data to add
addGps(x, gps = NULL, thresh = 3600, ...) ## S4 method for signature 'data.frame' addGps(x, gps, thresh = 3600, keepDiff = FALSE, ...) ## S4 method for signature 'AcousticEvent' addGps(x, gps = NULL, thresh = 3600, ...) ## S4 method for signature 'list' addGps(x, gps = NULL, thresh = 3600, ...) ## S4 method for signature 'AcousticStudy' addGps(x, gps = NULL, thresh = 3600, ...) ## S4 method for signature 'ANY' addGps(x, gps = NULL, thresh = 3600, ...)
addGps(x, gps = NULL, thresh = 3600, ...) ## S4 method for signature 'data.frame' addGps(x, gps, thresh = 3600, keepDiff = FALSE, ...) ## S4 method for signature 'AcousticEvent' addGps(x, gps = NULL, thresh = 3600, ...) ## S4 method for signature 'list' addGps(x, gps = NULL, thresh = 3600, ...) ## S4 method for signature 'AcousticStudy' addGps(x, gps = NULL, thresh = 3600, ...) ## S4 method for signature 'ANY' addGps(x, gps = NULL, thresh = 3600, ...)
x |
data to add GPS coordinates to. Must have a column |
gps |
a data frame of GPS coordinates to match to data from |
thresh |
maximum time apart in seconds for matching GPS coordinates to
data, if the closest coordinate is more than |
... |
additional arguments for other methods |
keepDiff |
logical flag to keep time difference column (between GPS time and data time) |
Latitude and Longitude coordinates will be matched to the data by interpolating between points in the provided GPS data. After the interpolating is done, the time difference between the matched rows is checked and any that are greater than the set threshold are set to NA. This is done to prevent accidentally matching weird things if an incomplete set of GPS data is provided. An approximate distance between the interpolated points and the closest known GPS point is provided as a "gpsUncertainty" column (distance in meters).
If x
is an AcousticEvent or AcousticStudy,
then gps
can be omitted and will be read from the databases contained
in the files
slot of x
. If x
is an AcousticStudy,
then the gps data will also be saved to the gps
slot of the object, and
an additional argument bounds
can be provided. This is a length two vector
of POSIXct
class times that will bound the times of gps data to store, gps
data outside this range will not be stored (to reduce the potentially very large
amount of data stored in the gps
slot)
the same data as x
, with Lat/Long data added. AcousticStudy objects
will have all GPS data used added to the "gps" slot, and all AcousticEvents will
have Latitude and Longitude added to all detector dataframes
Taiki Sakai [email protected]
data(exStudy) # need to update database file to local directory db <- system.file('extdata', 'Example.sqlite3', package='PAMpal') exStudy <- updateFiles(exStudy, db=db, bin=NA, verbose=FALSE) exStudy <- addGps(exStudy) head(gps(exStudy))
data(exStudy) # need to update database file to local directory db <- system.file('extdata', 'Example.sqlite3', package='PAMpal') exStudy <- updateFiles(exStudy, db=db, bin=NA, verbose=FALSE) exStudy <- addGps(exStudy) head(gps(exStudy))
Add hydrophone depth to an AcousticStudy or AcousticEvent
addHydrophoneDepth(x, depth = NULL, depthCol = NULL, thresh = 60, ...)
addHydrophoneDepth(x, depth = NULL, depthCol = NULL, thresh = 60, ...)
x |
an AcousticStudy to add depth data to |
depth |
a CSV or data frame of depth values to match to data from |
depthCol |
the name of the column containing depth in the dataframe or
database. If left as |
thresh |
maximum time apart in seconds for matching depth to
data, if the closest value is more than |
... |
additional arguments for other methods |
Depth values will be matched to the data
by using data.table's rolling join with roll='nearest'
. After the
join is done, the time difference between the matched rows is checked
and any that are greater than the set threshold are set to NA. This is
done to prevent accidentally matching weird things if an incomplete set
of depth data is provided.
If x
is an AcousticEvent or AcousticStudy,
then depth
can be omitted and will be read from the databases contained
in the files
slot of x
.
the same data as x
, with depth data added. All AcousticEvents will
have depth data added to all detector dataframes as column hpDepth
Taiki Sakai [email protected]
data(exStudy) # need to update database file to local directory db <- system.file('extdata', 'Example.sqlite3', package='PAMpal') exStudy <- updateFiles(exStudy, db=db, bin=NA, verbose=FALSE) exStudy <- addHydrophoneDepth(exStudy) getClickData(exStudy[1])
data(exStudy) # need to update database file to local directory db <- system.file('extdata', 'Example.sqlite3', package='PAMpal') exStudy <- updateFiles(exStudy, db=db, bin=NA, verbose=FALSE) exStudy <- addHydrophoneDepth(exStudy) getClickData(exStudy[1])
Adds "measures" to an AcousticStudy or AcousticEvent. A "measure" is an event-level variable that will be exported alongside data from that event
addMeasures(x, measures, replace = TRUE) getMeasures(x)
addMeasures(x, measures, replace = TRUE) getMeasures(x)
x |
an AcousticStudy or AcousticEvent object |
measures |
the measures to add. Can either be a named list,
where names match event names of |
replace |
logical flag whether or not to replace |
object of same class as x
with measures added
Taiki Sakai [email protected]
data(exStudy) measList <- list('Example.OE1' = list(a=1, b=2), 'Example.OE2' = list(a=2, b=3) ) exMeasure <- addMeasures(exStudy, measList) print(getMeasures(exMeasure)) measDf <- data.frame(eventId = c('Example.OE1', 'Example.OE2'), a=4:5, b=6:7) exMeasure <- addMeasures(exMeasure, measDf, replace=TRUE) getMeasures(exMeasure)
data(exStudy) measList <- list('Example.OE1' = list(a=1, b=2), 'Example.OE2' = list(a=2, b=3) ) exMeasure <- addMeasures(exStudy, measList) print(getMeasures(exMeasure)) measDf <- data.frame(eventId = c('Example.OE1', 'Example.OE2'), a=4:5, b=6:7) exMeasure <- addMeasures(exMeasure, measDf, replace=TRUE) getMeasures(exMeasure)
Adds a note to an AcousticEvent or AcousticStudy. Notes can either be accessed with the "getNotes" function, or up to 6 notes will be printed when the object is printed
addNote(x, to = c("study", "event"), evNum = 1, label = NULL, note) getNotes(x)
addNote(x, to = c("study", "event"), evNum = 1, label = NULL, note) getNotes(x)
x |
An AcousticStudy or AcousticEvent object |
to |
One of "study" or "event", which object to add the note to |
evNum |
If |
label |
(optional) a short header or label for the note. Recommended to set this as a sumamry of the more detailed note |
note |
the full note message |
For addNote
, the same data as x
, with notes added.
For getNotes
, a list of all notes present in x
Taiki Sakai [email protected]
data(exStudy) exStudy <- addNote(exStudy, to='study', label='Note1', note='My first note for this study') exStudy <- addNote(exStudy, to='event', evNum=1:2, label='Note2', note='A note for the first two events') exStudy <- addNote(exStudy[[1]], to='event', label='Note3', note='A second note for the first event') exStudy
data(exStudy) exStudy <- addNote(exStudy, to='study', label='Note1', note='My first note for this study') exStudy <- addNote(exStudy, to='event', evNum=1:2, label='Note2', note='A note for the first two events') exStudy <- addNote(exStudy[[1]], to='event', label='Note3', note='A second note for the first event') exStudy
Adds recording files to an AcousticStudy object, runs interactively to allow users to select files if they are not provided. No actual recordings are stored, a dataframe containing information on the start and end times of the recording files is added to the object.
addRecordings(x, folder = NULL, log = FALSE, progress = TRUE) mapWavFolder(folder = NULL, log = NULL, progress = TRUE)
addRecordings(x, folder = NULL, log = FALSE, progress = TRUE) mapWavFolder(folder = NULL, log = NULL, progress = TRUE)
x |
a AcousticStudy object to add recordings to |
folder |
a folder of recordings to add. If |
log |
(optional) log files for SoundTrap recordings. These are used to
adjust apparent lengths of recordings for missing data. If |
progress |
logical flag to show progress bars |
mapWavFolder
returns a dataframe of start and end
times
the same object as x
with recording information added
to the files
slots. The information added is a dataframe containing
the start and end times of recording
Taiki Sakai [email protected]
data(exStudy) recs <- system.file('extdata', 'Recordings', package='PAMpal') exStudy <- addRecordings(exStudy, folder=recs, log=FALSE, progress=FALSE) files(exStudy)$recordings
data(exStudy) recs <- system.file('extdata', 'Recordings', package='PAMpal') exStudy <- addRecordings(exStudy, folder=recs, log=FALSE, progress=FALSE) files(exStudy)$recordings
Adds settings to a PAMpalSettings object, usually from an XML file created by Pamguard's "Export XML Configuration"
addSettings(pps, settings = NULL, type = c("xml", "list"), verbose = TRUE)
addSettings(pps, settings = NULL, type = c("xml", "list"), verbose = TRUE)
pps |
a PAMpalSettings object to add settings to |
settings |
settings to add, either an XML file or a |
type |
one of 'xml' or 'list' indicating type of settings to add |
verbose |
logical flag to show messages |
the same PAMpalSettings object as pps, with a new list of settings replacing what was previously in the "settings" slot
Taiki Sakai [email protected]
# not recommended to create PPS like this, for example only pps <- new('PAMpalSettings') xmlSettings <- system.file('extdata', 'Example.xml', package='PAMpal') pps <- addSettings(pps, xmlSettings, type='xml')
# not recommended to create PPS like this, for example only pps <- new('PAMpalSettings') xmlSettings <- system.file('extdata', 'Example.xml', package='PAMpal') pps <- addSettings(pps, xmlSettings, type='xml')
Add wave height to an AcousticStudy or AcousticEvent
addWaveHeight(x, height, thresh = 3600)
addWaveHeight(x, height, thresh = 3600)
x |
an AcousticStudy to add height data to |
height |
either a single numeric value, or a dataframe
with column |
thresh |
maximum time apart in seconds for matching height to
data, if the closest value is more than |
height values will be matched to the data
by using data.table's rolling join with roll='nearest'
. After the
join is done, the time difference between the matched rows is checked
and any that are greater than the set threshold are set to NA. This is
done to prevent accidentally matching weird things if an incomplete set
of height data is provided.
the same data as x
, with wave height data added. All AcousticEvents will
have height data added to all detector dataframes as column waveHeight
Taiki Sakai [email protected]
data(exStudy) # need to update database file to local directory exStudy <- addWaveHeight(exStudy, height=.5) getClickData(exStudy[1])
data(exStudy) # need to update database file to local directory exStudy <- addWaveHeight(exStudy, height=.5) getClickData(exStudy[1])
Combines multiple AcousticStudy objects (or lists of these) into a single object
bindStudies(...)
bindStudies(...)
... |
AcousticStudy objects, or a list of AcousticStudy objects |
All events will be combined into one large list of events. Files,
settings, effort, models, GPS, and ancillary fields will be combined
using the squishList function from the PAMmisc package
(dataframes are combined, vectors are appended). The id is changed by
pasting all IDs together along with a note that they have been combined.
Note that the PAMpalSettings object in the pps slot is just
left as the pps
in the first AcousticStudy to be combined, and thus
is not representative of the new combined AcousticStudy
A single AcousticStudy object
Taiki Sakai [email protected]
Calculates the average spectra of all the clicks present in an event
calculateAverageSpectra( x, evNum = 1, calibration = NULL, wl = 512, channel = 1:2, filterfrom_khz = 0, filterto_khz = NULL, sr = NULL, snr = 0, norm = TRUE, plot = TRUE, noise = FALSE, decimate = 1, sort = FALSE, mode = "spec", title = NULL, ylim = NULL, flim = NULL, cmap = hcl.colors(30, "YlOrRd", rev = TRUE), brightness = 0, contrast = 0, q = 0.01, showBreaks = TRUE, ... )
calculateAverageSpectra( x, evNum = 1, calibration = NULL, wl = 512, channel = 1:2, filterfrom_khz = 0, filterto_khz = NULL, sr = NULL, snr = 0, norm = TRUE, plot = TRUE, noise = FALSE, decimate = 1, sort = FALSE, mode = "spec", title = NULL, ylim = NULL, flim = NULL, cmap = hcl.colors(30, "YlOrRd", rev = TRUE), brightness = 0, contrast = 0, q = 0.01, showBreaks = TRUE, ... )
x |
an AcousticEvent or AcousticStudy object |
evNum |
if |
calibration |
a calibration function to apply, if desired |
wl |
the size of the click clips to use for calculating the spectrum. If greater than the clip present in the binary, clip will be zero padded |
channel |
channel(s) to include in calculations. Currently does not correspond to actual channel in instrument, just the order present in the binary file |
filterfrom_khz |
frequency in khz of highpass filter to apply, or the lower
bound of a bandpass filter if |
filterto_khz |
if a bandpass filter is desired, set this as the upper bound.
If only a highpass filter is desired, leave as the default |
sr |
a sample rate to use if the sample rate present in the database needs to be overridden (typically not needed) |
snr |
minimum signal-to-noise ratio to be included in the average, in dB. SNR is
calculated as difference between the signal and noise spectra at the peak frequency
of the signal. This can be inaccurate if noise is inaccurate (see |
norm |
logical flag to normalize dB magnitude to maximum of 0 |
plot |
logical flag whether or not to plot the result. This will create two plots, the first is a concatenated spectrogram where the y-axis is frequency and the x-axis is click number. The second plot is the average spectrogram of all clicks, the y-axis is dB, x-axis is frequency. Can be a vector of length two to create only one of the two plots |
noise |
logical flag to plot an average noise spectrum. This is estimated
by taking a window of length |
decimate |
integer factor to reduce sample rate by |
sort |
logical flag to sort concatenated spectrogram by peak frequency |
mode |
one of |
title |
replacement titles for plots, can be length vector of length two to provide separate titles |
ylim |
optional y limits for mean spectra plot |
flim |
optional frequency limits for both plots |
cmap |
colors to use for concatenated click spectrogram, either a palette function or vector of colors |
brightness |
value from -255 to 255, positive values increase brightness, negative values decrease brightness of concatenated spectrogram image |
contrast |
value from -255 to 255, positive values increase contrast, negative values decrease contrast of concatenated spectrogram image |
q |
lower and upper quantiles to remove for scaling concatenated spectrogram.
Or if a single value, then quantiles |
showBreaks |
logical flag to show lines separating events when plotting multiple events |
... |
optional args |
invisibly returns a list with six items: freq
- the frequency,
UID
- the UID of each click, avgSpec
- the average spectra of the event,
allSpec
- the individual spectrum of each click in the event as a matrix with
each spectrum in a separate column, avgNoise
- the average noise spectra,
allNoise
- the individual noise spectrum for each click
Taiki Sakai [email protected]
data(exStudy) # need to update binary file locations to users PAMpal installation binUpd <- system.file('extdata', 'Binaries', package='PAMpal') dbUpd <- system.file('extdata', package='PAMpal') exStudy <- updateFiles(exStudy, bin = binUpd, db=dbUpd) avSpec <- calculateAverageSpectra(exStudy) str(avSpec$avgSpec) range(avSpec$freq) str(avSpec$allSpec)
data(exStudy) # need to update binary file locations to users PAMpal installation binUpd <- system.file('extdata', 'Binaries', package='PAMpal') dbUpd <- system.file('extdata', package='PAMpal') exStudy <- updateFiles(exStudy, bin = binUpd, db=dbUpd) avSpec <- calculateAverageSpectra(exStudy) str(avSpec$avgSpec) range(avSpec$freq) str(avSpec$allSpec)
Calculate the estimated depth of echolocation clicks using surface reflected echoes. This uses the time delay between the received signal and its surface echo to estimate the depth of a calling animal. Requires that a set of waveform clips has been created using writeEventClips, and that events have been localized.
calculateEchoDepth( x, wav, clipLen = 0.03, spParams = NULL, soundSpeed = 1500, hpDepthError = 1, locType = "PGTargetMotion", plot = TRUE, nPlot = 400, nCol = 5, plotDir = NULL, plotIci = TRUE, maxIci = 2.5, sr = NULL, progress = TRUE, verbose = TRUE )
calculateEchoDepth( x, wav, clipLen = 0.03, spParams = NULL, soundSpeed = 1500, hpDepthError = 1, locType = "PGTargetMotion", plot = TRUE, nPlot = 400, nCol = 5, plotDir = NULL, plotIci = TRUE, maxIci = 2.5, sr = NULL, progress = TRUE, verbose = TRUE )
x |
AcousticStudy object |
wav |
either folder containing wave clips or list of wave clip files |
clipLen |
length (seconds) of clip to analyze |
spParams |
list of species-specific parameters, see details |
soundSpeed |
sound speed (meters/second) to use for calculations |
hpDepthError |
maximum error (meters) in hydrophone depth measurement |
locType |
name of localization, note that this function is not computing any localization, only using previously calculated |
plot |
logical flag to create summary plots |
nPlot |
number of waveform plots to create for summary |
nCol |
number of columns for waveform summary plot |
plotDir |
directory to store plot outputs, default |
plotIci |
logical flag to additionally create ICI plots |
maxIci |
maximum allowed ICI value (seconds) |
sr |
if not |
progress |
logical flag to show progress bar |
verbose |
logical flag to show messages |
spParams
allows for species-specific filtering and acceptable
echo time delays to be specified. These are provided as a list with elements
freqLow
and freqHigh
specifying the lower and upper ends of a
bandpass filter to apply to the signals (in Hz), which can aid in properly
detecting the echoes. Parameters minTime
and maxTime
can
also be supplied to define ranges on allowed time delay values. Alternatively
if maxTime
is NULL
or not present it will be calculated from the
hydrophone geometry, and minTime
can be calculated from geometry by
providing minDepth
and maxRange
as the minimum detectable depth
and maximum detectable range (in meters).
If the same values for these parameters should be used for all detections in
x
, then spParams
can be provided as a list with each parameter named,
e.g.
list(freqLow=10e3, freqHigh=50e3, minTime=.001, maxTime=NULL)
If different values should be used for different species, then spParams
must be a named list where the names match the species in x
, providing
a separate list of values for each species. e.g.
list(Zc=list(freqLow=10e3, freqHigh=50e3, minTime=.001, maxTime=NULL), Pm=list(freqLow=2e3, freqHigh=16e3, minTime=.001, maxTime=NULL))
the AcousticStudy object x
with estimated dive depth outputs
added for each detection that had a matching wav clip file in wav
.
Detections that either did not have matchinf wav files or did not have
localizations will have NA
for all dive depth outputs. The depth outputs
are
Delay time with maximum correlation value
Delay time with second highest correlation value
Delay time with third highest correlation value
Correlation magnitude for "maxTime"
Correlation magnitude for "pair2Time"
Correlation magnitude for "pair3Time"
Calculated depth for "maxTime"
Calculated depth for "pair2Time"
Calculated depth for "pair3Time"
Taiki Sakai [email protected]
# example not run because it requires access to large files not present # in the package testing material ## Not run: study <- addRecordings(study, folder='path/to/recordings') wavPath <- 'path/to/wavFiles' writeEventClips(study, outDir=wavPath, mode='detection') study <- calculateEchoDepth(study, wav=wavPath) ## End(Not run)
# example not run because it requires access to large files not present # in the package testing material ## Not run: study <- addRecordings(study, folder='path/to/recordings') wavPath <- 'path/to/wavFiles' writeEventClips(study, outDir=wavPath, mode='detection') study <- calculateEchoDepth(study, wav=wavPath) ## End(Not run)
Calculate inter-click interval for click data
calculateICI( x, time = c("UTC", "peakTime"), iciRange = c(0, Inf), callType = c("click", "whistle", "cepstrum", "gpl"), verbose = TRUE, ... ) ## S4 method for signature 'AcousticStudy' calculateICI( x, time = c("UTC", "peakTime"), iciRange = c(0, Inf), callType = c("click", "whistle", "cepstrum", "gpl"), verbose = TRUE, ... ) ## S4 method for signature 'AcousticEvent' calculateICI( x, time = c("UTC", "peakTime"), iciRange = c(0, Inf), callType = c("click", "whistle", "cepstrum", "gpl"), verbose = TRUE, ... ) getICI(x, type = c("value", "data"))
calculateICI( x, time = c("UTC", "peakTime"), iciRange = c(0, Inf), callType = c("click", "whistle", "cepstrum", "gpl"), verbose = TRUE, ... ) ## S4 method for signature 'AcousticStudy' calculateICI( x, time = c("UTC", "peakTime"), iciRange = c(0, Inf), callType = c("click", "whistle", "cepstrum", "gpl"), verbose = TRUE, ... ) ## S4 method for signature 'AcousticEvent' calculateICI( x, time = c("UTC", "peakTime"), iciRange = c(0, Inf), callType = c("click", "whistle", "cepstrum", "gpl"), verbose = TRUE, ... ) getICI(x, type = c("value", "data"))
x |
a AcousticStudy object, a list of AcousticEvent objects, or a single AcousticEvent object |
time |
the time measurement to use. |
iciRange |
optional range of allowed ICI (time to next detection) values. Values outside of this range will be removed before calculating the modal ICI. |
callType |
the call type to calculate ICI for, usually this is |
verbose |
logical flag to print messages |
... |
not currently used |
type |
the type of data to return, one of 'value' or 'data'. 'value' returns the single ICI value for each detector, 'data' returns all the individual ICI values used to calculate the number returned by 'value' |
Calculates the ICI for each individual detector and across all detectors. ICI calculation is done by ordering all individual detections by time, then taking the difference between consecutive detections and approximating the mode value.
the same object as x
, with ICI data added to the "ancillary" slot
of each AcousticEvent. Two items will be added. $ici contains all of the
individual inter-click intervals used to calculate the ICI, as well as an "All"
ICI using all the combined data. $measures will also have a ICI measurement added
for each detector, this will be the single modal value. Data in the $measures spot
can be exported easily to modeling algorithms. getICI
will just return either
the values stored in $measures for type = 'value'
or a dataframe of the
individual ICI values used to calculate these (with columns indicating separate Channels,
eventIds, and detectorNames) for type = 'data'
Taiki Sakai [email protected]
# setting up example data data(exStudy) exStudy <- calculateICI(exStudy) # each event has its ICI data stored separately, these are 0 # because there is only a single click in this event ancillary(exStudy[[1]])$ici # also saves it in measures that will get exported for modeling ancillary(exStudy[[1]])$measures
# setting up example data data(exStudy) exStudy <- calculateICI(exStudy) # each event has its ICI data stored separately, these are 0 # because there is only a single click in this event ancillary(exStudy[[1]])$ici # also saves it in measures that will get exported for modeling ancillary(exStudy[[1]])$measures
Run a list of custom calculations on a Pamguard binary file.
calculateModuleData( binData, binFuns = list(ClickDetector = list(standardClickCalcs)), settings = NULL )
calculateModuleData( binData, binFuns = list(ClickDetector = list(standardClickCalcs)), settings = NULL )
binData |
Pamguard binary data as read in by
|
binFuns |
A named list of functions to run on each Pamguard module. Currently supported modules are 'ClickDetector' and 'WhistlesMoans', a sample input for binFuns would be list('ClickDetector'=list(clickFun1, clickFun2), 'WhistlesMoans'=list(wmFun1)) |
settings |
a list of settings from a Pamguard XML file |
A data frame with one row for each channel of each detection. Each row will have the UID, channel number, and name of the detector. Clicks of different classifications are treated as different detectors for this purpose, with the classification label number appended to the detector name. The number of columns will depend on the results of the calculations from the supplied binFuns.
Taiki Sakai [email protected]
Checks for any possible issues in an AcousticStudy object, issuing warnings and saving the messages
checkStudy(x, maxLength = Inf, maxSep = 60 * 60 * 2)
checkStudy(x, maxLength = Inf, maxSep = 60 * 60 * 2)
x |
an AcousticStudy object |
maxLength |
events with length greater than this value in seconds will trigger a warning |
maxSep |
events containing consecutive detections greater than
|
This function is called at the end of processPgDetections with
default parameters, but can also be called later to investigate issues
specific to each user's data. For example, if you are expecting to process data
where all recordings were duty cycled to record 2 out of every 10 minutes, then
setting maxLength = 60*2
will alert you to any events that are longer than
the 2 minute duty cycle.
For continuously recorded data, the maxSep
argument can be used to
identify situations where there are large gaps between detections in a single
event, since this could mean that detections were accidentally added to the
incorrect event number during processing.
returns a list of warning messages
Taiki Sakai [email protected]
data(exStudy) # checks if any peak frequencies are 0, so we'll force this exStudy[[1]][[1]]$peak <- 0 checkStudy(exStudy) checkStudy(exStudy, maxLength = 1, maxSep = 1)
data(exStudy) # checks if any peak frequencies are 0, so we'll force this exStudy[[1]][[1]]$peak <- 0 checkStudy(exStudy) checkStudy(exStudy, maxLength = 1, maxSep = 1)
Exports data from an AcousticStudy into the format required to run a BANTER model from the "banter" package
export_banter( x, dropVars = NULL, dropSpecies = NULL, training = TRUE, verbose = TRUE )
export_banter( x, dropVars = NULL, dropSpecies = NULL, training = TRUE, verbose = TRUE )
x |
a AcousticStudy object or a list of AcousticEvent objects |
dropVars |
a vector of the names of any variables to remove |
dropSpecies |
a vector of the names of any species to exclude |
training |
logical flag whether or not this will be used as a
training data set, or a value between 0 and 1 specifying what percent
of the data should be used for training (with the rest set aside
for testing). If TRUE or greater than 0, must contain species ID.
NOTE: if value is not 0, 1, |
verbose |
logical flag to show summary and informational messages |
a list with three items, events
, detectors
, and
na
. If value of training
is not 0, 1, TRUE
, or
FALSE
, output will be split into training
and
test
lists that contain events
and detectors
.
events
is a dataframe with two columns. event.id
is a
unique identifier for each event, taken from the names of the event
list. species
is the species classification, taken from the
species
slot labelled id
. detectors
is a list
of data frames containing all the detections and measurements. There is
one list for each unique detector type found in the detectors
slots
of x
. The data frames will only have columns with class
numeric
, integer
, factor
, or logical
, and
will also have columns named UID
, Id
, parentID
,
sampleRate
, Channel
, angle
, and angleError
,
removed so that these are not treated as parameters for the banter random
forest model. The dataframes will also have columns event.id
and
call.id
added. na
contains the UIDs and Binary File names
for any detections that had NA values. These cannot be used in the
random forest model and are removed from the exported dataset.
Taiki Sakai [email protected]
# setting up example data data(exStudy) exStudy <- setSpecies(exStudy, method='pamguard') banterData <- export_banter(exStudy) # drop some variables banterLess <- export_banter(exStudy, dropVars = c('peak', 'duration'))
# setting up example data data(exStudy) exStudy <- setSpecies(exStudy, method='pamguard') banterData <- export_banter(exStudy) # drop some variables banterLess <- export_banter(exStudy, dropVars = c('peak', 'duration'))
An example AcousticStudy object created using the example PAMpalSettings object provided with the package. Processed with mode='db'
data(exStudy)
data(exStudy)
a AcousticStudy object containing two AcousticEvent objects
Apply dplyr-like filtering to the detecitons of an AcousticStudy or AcousticEvent object, with a special case for filtering by species for an AcousticStudy
## S3 method for class 'AcousticStudy' filter(.data, ..., .preserve = FALSE)
## S3 method for class 'AcousticStudy' filter(.data, ..., .preserve = FALSE)
.data |
AcousticStudy or AcousticEvent to filter |
... |
Logical expressions, syntax is identical to filter. There are special cases to filter by environmental variables, species ID, database, or detector name. See details. |
.preserve |
not used |
Most expression provided will be used to filter out detections based on calculated parameters.
If the name of an environmental variable added using matchEnvData,AcousticStudy-method is provided, will filter to only events with environmental variables matching those conditions.
If a provided logical expression uses
"species"
or "Species"
, then events will be filtered using the
species present in the $id
of the species
slot of each event.
If a provided logical expression uses "database"
or "Database"
,
then only events with databases matching the expression in files(.data)$db
will remain
If a provided logical expression uses "detector"
or "Detector"
, then
only detections from detectors with names matching the expression will remain in
events. Any events left with no detections will be removed.
The original .data
object, filtered by the given logical expressions
Taiki Sakai [email protected]
# create example data data(exStudy) exStudy <- setSpecies(exStudy, method='manual', value=letters[1:2]) filterData <- filter(exStudy, peak < 20) getDetectorData(filterData)$click filterData <- filter(exStudy, species == 'a') species(filterData[[1]])
# create example data data(exStudy) exStudy <- setSpecies(exStudy, method='manual', value=letters[1:2]) filterData <- filter(exStudy, peak < 20) getDetectorData(filterData)$click filterData <- filter(exStudy, species == 'a') species(filterData[[1]])
Filter out possible echo depths from calculateEchoDepth
based on maximum depth, autocorrelation magnitude, and maximum swim
speed criteria. Requires that calculateEchoDepth has been run
first. This function adds a keepClick
column to the data to
track which detections should be used for further depth analysis by
marking them as FALSE
to be excluded or TRUE
to be used
filterEchoDepths( x, time = 30, depth = NULL, speed = NULL, maxDepth = 4000, minCorr = 0.01 )
filterEchoDepths( x, time = 30, depth = NULL, speed = NULL, maxDepth = 4000, minCorr = 0.01 )
x |
an AcousticStudy object that has been processed with calculateEchoDepth |
time |
maximum time apart (seconds) for detections. Detections with no
no other detection within |
depth |
maximum depth difference (meters) between consecutive clicks, this value should be determined by maximum swim speed |
speed |
as an alternative to providing |
maxDepth |
calculated depth values greater than this will be marked
|
minCorr |
detections with autocorrelation magnitude less than this
will be marked as |
the AcousticStudy x
with detections marked with column
keepClick
as TRUE
or FALSE
depending if they
pass the filter parameters
Taiki Sakai [email protected]
# example not run because \link{calculateEchoDepth} must be run first, # and it requires a large amount of data not stored in the package ## Not run: study <- calculateEchoDepth(study, wav='path/to/wavFiles') study <- filterEchoDepths(study, time=30, speed=50/30, maxDepth=4000) ## End(Not run)
# example not run because \link{calculateEchoDepth} must be run first, # and it requires a large amount of data not stored in the package ## Not run: study <- calculateEchoDepth(study, wav='path/to/wavFiles') study <- filterEchoDepths(study, time=30, speed=50/30, maxDepth=4000) ## End(Not run)
Fetches matching binary data from a single or multiple detections in an AcousticEvent object
getBinaryData( x, UID, type = c("click", "whistle", "cepstrum", "gpl"), quiet = FALSE, ... )
getBinaryData( x, UID, type = c("click", "whistle", "cepstrum", "gpl"), quiet = FALSE, ... )
x |
a AcousticStudy object, a list of AcousticEvent objects, or a single AcousticEvent object |
UID |
the UID(s) of the individual detections to fetch the binary data for |
type |
detection type |
quiet |
logical flag to quiet some warnings, used internally and should generally
not be changed from default |
... |
additional arguments to pass to
|
a list of PamBinary
objects for each UID
Taiki Sakai [email protected]
data(exStudy) binData <- getBinaryData(exStudy, UID = 8000003) # works with multiple UIDs, if UIDs arent present they will be ignored binData <- getBinaryData(exStudy, UID = c(8000003, 529000024, 1))
data(exStudy) binData <- getBinaryData(exStudy, UID = 8000003) # works with multiple UIDs, if UIDs arent present they will be ignored binData <- getBinaryData(exStudy, UID = c(8000003, 529000024, 1))
Reads audio clips containing sounds from events or detections
getClipData( x, buffer = c(0, 0.1), mode = c("event", "detection"), channel = 1, useSample = FALSE, fixLength = FALSE, fillZeroes = TRUE, progress = TRUE, verbose = TRUE, FUN = NULL, ... )
getClipData( x, buffer = c(0, 0.1), mode = c("event", "detection"), channel = 1, useSample = FALSE, fixLength = FALSE, fillZeroes = TRUE, progress = TRUE, verbose = TRUE, FUN = NULL, ... )
x |
AcousticStudy object containing data to read wav clips for |
buffer |
amount before and after each event to also include in the clip, in seconds. Can either be a vector of length two specifying how much to buffer before and after (first number should be negative), or a single value if the buffer amount should be identical. |
mode |
either |
channel |
channel(s) of clips to write |
useSample |
logical flag to use startSample information in binaries instead of UTC time for start of detections. This can be slightly more accurate (~1ms) but will take longer |
fixLength |
logical flag to fix the output clip length to a constant value. If
|
fillZeroes |
logical flag to fill gaps in non-consecutive clips with zeroes. If
|
progress |
logical flag to show progress bar |
verbose |
logical flag to show summary messages |
FUN |
optional function to apply to wav clips. This function takes default inputs |
... |
optional arguments to pass to |
A named list of wav clips
Taiki Sakai [email protected]
data(exStudy) recs <- system.file('extdata', 'Recordings', package='PAMpal') exStudy <- addRecordings(exStudy, folder=recs, log=FALSE, progress=FALSE) ## Not run: # not running so that no wav clips are written to disk wavs <- getClipData(exStudy, mode='event') ## End(Not run)
data(exStudy) recs <- system.file('extdata', 'Recordings', package='PAMpal') exStudy <- addRecordings(exStudy, folder=recs, log=FALSE, progress=FALSE) ## Not run: # not running so that no wav clips are written to disk wavs <- getClipData(exStudy, mode='event') ## End(Not run)
Extracts just the detector data from all of x
, and will
combine all detections from each call type (currently whistle, click,
cepstrum, and gpl) into a single data frame.
getDetectorData(x, measures = TRUE) getClickData(x, measures = TRUE) getWhistleData(x, measures = TRUE) getCepstrumData(x, measures = TRUE) getGPLData(x, measures = TRUE) getFPODData(x, measures = TRUE) nDetections(x, distinct = FALSE) nClicks(x, distinct = FALSE) nWhistles(x) nCepstrum(x) nGPL(x)
getDetectorData(x, measures = TRUE) getClickData(x, measures = TRUE) getWhistleData(x, measures = TRUE) getCepstrumData(x, measures = TRUE) getGPLData(x, measures = TRUE) getFPODData(x, measures = TRUE) nDetections(x, distinct = FALSE) nClicks(x, distinct = FALSE) nWhistles(x) nCepstrum(x) nGPL(x)
x |
data to extract detector data from, either an |
measures |
logical flag whether or not to append measures to detector dataframes |
distinct |
logical flag to only return number of distinct click detections |
The purpose of this function is to extract your data out of
PAMpal
's S4 classes and put them into an easier format to work with.
The output will be a list of up to three data frames, one for each call type
found in your data. Each different call type will have had different processing
applied to it by processPgDetections
. Additionally, each detector will
have its associated event id, the name of the detector, and the species id
attached to it (species will be NA
if not set). All detections from each
call type will be combined into a single large data frame
A list of data frames containing all detection data from x
,
named by call type ('click', 'whistle', 'cepstrum', or 'gpl').
Taiki Sakai [email protected]
data(exStudy) dets <- getDetectorData(exStudy) names(dets) str(dets$click) # works on single events as well oneDets <- getDetectorData(exStudy[[1]]) str(oneDets$click)
data(exStudy) dets <- getDetectorData(exStudy) names(dets) str(dets$click) # works on single events as well oneDets <- getDetectorData(exStudy[[1]]) str(oneDets$click)
Accessor to easily get all warning messages for x
getWarnings(x)
getWarnings(x)
x |
an AcousticStudy or AcousticEvent object |
a list of warning messages, named by the function call that created the warning
Taiki Sakai [email protected]
## Not run: data(exStudy) # This will trigger a warning, then we can access it exStudy <- filter(exStudy, species == "test") getWarnings(exStudy) ## End(Not run)
## Not run: data(exStudy) # This will trigger a warning, then we can access it exStudy <- filter(exStudy, species == "test") getWarnings(exStudy) ## End(Not run)
Function to check if an object is an AcousticEvent
is.AcousticEvent(x)
is.AcousticEvent(x)
x |
object to check |
Function to check if an object is an AcousticStudy
is.AcousticStudy(x)
is.AcousticStudy(x)
x |
object to check |
Function to check if an object is a PAMpalSettings
is.PAMpalSettings(x)
is.PAMpalSettings(x)
x |
object to check |
Loads in relevant settings and formats for use in PAMpal
loadPamguardXML(x)
loadPamguardXML(x)
x |
an XML file created by Pamguard's "Export XML Configuration" |
A list with settings for audio sources
(sound acuisition, decimators,
FFT, and cepstrum) and detectors
(click detector and whistle and moan
detector). Also stores the entire XML file as raw
and the file name as
file
Taiki Sakai [email protected]
xmlFile <- system.file('extdata', 'Example.xml', package='PAMpal') xmlList <- loadPamguardXML(xmlFile) str(xmlList)
xmlFile <- system.file('extdata', 'Example.xml', package='PAMpal') xmlList <- loadPamguardXML(xmlFile) str(xmlList)
Marks detections within an AcousticStudy as being within the bounds of an annotation box. Annotations can either be read in from the "Spectrogram Annotation" module of PAMguard, or supplied as a separate dataframe. Detections must be entirely contained within the annotation bounds.
markAnnotated( x, anno = NULL, tBuffer = 0, fBuffer = 0, table = "Spectrogram_Annotation" )
markAnnotated( x, anno = NULL, tBuffer = 0, fBuffer = 0, table = "Spectrogram_Annotation" )
x |
an AcousticStudy object |
anno |
annotations to read from. If |
tBuffer |
additional buffer value to add on to annotation time bounds in seconds. If a single number, the number of seconds to extend the bounds by on the start and end of each annotation. Can also be a vector of two to extend different values on the start and end. This can be useful if original bounding boxes were drawn very close to the desired detections since any small portion of a signal outside the box will cause it to be excluded. |
fBuffer |
additional buffer value to add to annotation frequency bounds in Hz. If a single number, the number of Hz to extend bounds by on lower and upper end of boxes. Can also be a vector of two to extend different values on lower and upper bounds. This can be useful if original bounding boxes were drawn very close to the desired detections since any small portion of a signal outside the box will cause it to be excluded. |
table |
if |
This adds new columns inAnno
and annoId
to all detector
dataframes within the AcousticStudy. inAnno
is a logical flag whether or not
a given detection was fully contained in any annotation bounding box, and annoId
lists the IDs of the boxes it matched. A detection is considered within an annotation
only if it is entirely within the time and frequency bounds of the annotation. For
GPL and whistle detections, the min and max frequency values are used. For click detections,
only the peak frequency is used. For cesptrum detections, frequency bounds are ignored.
the same object as x
, but detectors have additional columns added
Taiki Sakai [email protected]
data(exStudy) annotation <- data.frame(start = min(getWhistleData(exStudy)$UTC), fmin = c(16000, 17000), fmax = c(17000, 18000)) annotation$end <- annotation$star + 1 exStudy <- markAnnotated(exStudy, annotation) getWhistleData(exStudy)[c('UTC', 'duration', 'freqMin', 'freqMax', 'inAnno', 'annoId')]
data(exStudy) annotation <- data.frame(start = min(getWhistleData(exStudy)$UTC), fmin = c(16000, 17000), fmax = c(17000, 18000)) annotation$end <- annotation$star + 1 exStudy <- markAnnotated(exStudy, annotation) getWhistleData(exStudy)[c('UTC', 'duration', 'freqMin', 'freqMax', 'inAnno', 'annoId')]
Extracts all variables from a netcdf file matching Longitude, Latitude, and UTC coordinates of the start of each AcousticEvent object. Matched values are stored in the "ancillary" slot of each event
## S4 method for signature 'AcousticEvent' matchEnvData( data, nc = NULL, var = NULL, buffer = c(0, 0, 0), FUN = c(mean), fileName = NULL, progress = TRUE, depth = 0, ... ) ## S4 method for signature 'AcousticStudy' matchEnvData( data, nc = NULL, var = NULL, buffer = c(0, 0, 0), FUN = c(mean), fileName = NULL, progress = TRUE, depth = 0, ... )
## S4 method for signature 'AcousticEvent' matchEnvData( data, nc = NULL, var = NULL, buffer = c(0, 0, 0), FUN = c(mean), fileName = NULL, progress = TRUE, depth = 0, ... ) ## S4 method for signature 'AcousticStudy' matchEnvData( data, nc = NULL, var = NULL, buffer = c(0, 0, 0), FUN = c(mean), fileName = NULL, progress = TRUE, depth = 0, ... )
data |
an AcousticStudy or AcousticEvent object that must have GPS data added to it using the addGps functions |
nc |
name of a netcdf file, ERDDAP dataset id, or an edinfo object |
var |
(optional) vector of variable names |
buffer |
vector of Longitude, Latitude, and Time (seconds) to buffer around each datapoint. All values within the buffer will be used to report the mean, median, and standard deviation |
FUN |
a vector or list of functions to apply to the data. Default is to apply mean, median, and standard deviation calculations |
fileName |
(optional) file name to save downloaded nc file to. If not provided,
then no nc files will be stored, instead small temporary files will be downloaded
and then deleted. This can be much faster, but means that the data will need to be
downloaded again in the future. If |
progress |
logical flag to show progress bar |
depth |
depth values (meters) to use for matching, overrides any |
... |
other parameters to pass to ncToData |
original data object with environmental data added to the ancillary
slot
of each event. Complete data will be stored in ancillary(data)$environmental
,
and the mean of each downloaded variable will be stored in ancillary(data)$measures
so that it can be exported for modeling. For each event the coordinates associated with
the earliest UTC value in that event are used to match
Taiki Sakai [email protected]
data(exStudy) nc <- system.file('extdata', 'sst.nc', package='PAMmisc') # suppressing warnings because nc coordinates dont align with this data, # function warns of possible coordinate mismatch exStudy <- suppressWarnings(matchEnvData(exStudy, nc=nc, progress=FALSE)) str(ancillary(exStudy[[1]])$environmental) ancillary(exStudy[[1]])$measures
data(exStudy) nc <- system.file('extdata', 'sst.nc', package='PAMmisc') # suppressing warnings because nc coordinates dont align with this data, # function warns of possible coordinate mismatch exStudy <- suppressWarnings(matchEnvData(exStudy, nc=nc, progress=FALSE)) str(ancillary(exStudy[[1]])$environmental) ancillary(exStudy[[1]])$measures
Match any time-based data (dataframe with a UTC
column)
to an AcousticStudy or AcousticEvent object
matchTimeData( x, data, mode = c("event", "detection"), thresh = Inf, interpolate = TRUE, replace = FALSE, keepDiff = FALSE ) timeJoin(x, y, thresh = Inf, interpolate = TRUE, replace = FALSE)
matchTimeData( x, data, mode = c("event", "detection"), thresh = Inf, interpolate = TRUE, replace = FALSE, keepDiff = FALSE ) timeJoin(x, y, thresh = Inf, interpolate = TRUE, replace = FALSE)
x |
AcousticStudy or AcousticEvent object
to match data to, or a dataframe for |
data |
a data frame to match to data to |
mode |
one of "event" or "detection". "event" will match one set of variables per event, stored in the "measures" for that event. "detection" will match variables to every detection. |
thresh |
maximum time apart in seconds for matching to
data, if the closest value is more than |
interpolate |
logical flag whether or not to interpolate between points
in |
replace |
one of |
keepDiff |
logical flag to keep time difference data |
y |
dataframe to join to |
This function lets you match any arbitrary data to a PAMpal object
as long as it has a time associated with it. Data will be attached to
detector dataframes for mode='detection'
or to the event "measures"
location for mode='event'
(this is where calculateICI and
matchEnvData,AcousticStudy-method store their event data). These can be accessed with the
getMeasures function and are also exported in the various "getXXX"
functions (getClickData etc.) if measures=TRUE
(default).
All columns in the provided data
object will be treated as variables
to add, with a few exceptions. There are a few reserved column names used by
PAMpal that cannot be overridden (e.g. UID, eventId, species). Also any columns
already existing in the PAMpal data will not be overridden unless replace
is not FALSE
. The column names in data
will be used as the names
for the added variables, so care should be taken to ensure these are informative
enough for future use.
the same data as x
, with data added from data
Taiki Sakai [email protected]
data(exStudy) addData <- data.frame(UTC = as.POSIXct('2018-03-20 15:25:10', tz='UTC'), newVariable = 26) data <- matchTimeData(exStudy, addData, mode='detection') getClickData(data) data <- matchTimeData(exStudy, addData, mode='event') getMeasures(data)
data(exStudy) addData <- data.frame(UTC = as.POSIXct('2018-03-20 15:25:10', tz='UTC'), newVariable = 26) data <- matchTimeData(exStudy, addData, mode='detection') getClickData(data) data <- matchTimeData(exStudy, addData, mode='event') getMeasures(data)
AcousticEvent
and AcousticStudy
accessorsAccessors for slots in AcousticEvent and AcousticStudy objects
settings(x, ...) ## S4 method for signature 'AcousticEvent' settings(x, ...) settings(x) <- value ## S4 replacement method for signature 'AcousticEvent' settings(x) <- value localizations(x, ...) ## S4 method for signature 'AcousticEvent' localizations(x, ...) localizations(x) <- value ## S4 replacement method for signature 'AcousticEvent' localizations(x) <- value id(x, ...) ## S4 method for signature 'AcousticEvent' id(x, ...) id(x) <- value ## S4 replacement method for signature 'AcousticEvent' id(x) <- value detectors(x, ...) ## S4 method for signature 'AcousticEvent' detectors(x, ...) detectors(x) <- value ## S4 replacement method for signature 'AcousticEvent' detectors(x) <- value species(x, ...) ## S4 method for signature 'AcousticEvent' species(x, ...) ## S4 method for signature 'AcousticStudy' species(x, type = "id", ...) species(x) <- value ## S4 replacement method for signature 'AcousticEvent' species(x) <- value files(x, ...) ## S4 method for signature 'AcousticEvent' files(x, ...) files(x) <- value ## S4 replacement method for signature 'AcousticEvent' files(x) <- value ancillary(x, ...) ## S4 method for signature 'AcousticEvent' ancillary(x, ...) ancillary(x) <- value ## S4 replacement method for signature 'AcousticEvent' ancillary(x) <- value ## S4 method for signature 'AcousticEvent,ANY,ANY,ANY' x[i] ## S4 replacement method for signature 'AcousticEvent,ANY,ANY,ANY' x[i] <- value ## S4 method for signature 'AcousticEvent' x$name ## S4 replacement method for signature 'AcousticEvent' x$name <- value ## S4 method for signature 'AcousticEvent,ANY,ANY' x[[i]] ## S4 replacement method for signature 'AcousticEvent,ANY,ANY,ANY' x[[i]] <- value ## S4 method for signature 'AcousticStudy' id(x, ...) ## S4 replacement method for signature 'AcousticStudy' id(x) <- value ## S4 method for signature 'AcousticStudy' files(x, ...) ## S4 replacement method for signature 'AcousticStudy' files(x) <- value gps(x, ...) ## S4 method for signature 'AcousticStudy' gps(x, ...) gps(x) <- value ## S4 replacement method for signature 'AcousticStudy' gps(x) <- value ## S4 method for signature 'AcousticStudy' detectors(x, ...) events(x, ...) ## S4 method for signature 'AcousticStudy' events(x, ...) events(x) <- value ## S4 replacement method for signature 'AcousticStudy' events(x) <- value ## S4 method for signature 'AcousticStudy' settings(x, ...) ## S4 replacement method for signature 'AcousticStudy' settings(x) <- value effort(x, ...) ## S4 method for signature 'AcousticStudy' effort(x, ...) effort(x) <- value ## S4 replacement method for signature 'AcousticStudy' effort(x) <- value pps(x, ...) ## S4 method for signature 'AcousticStudy' pps(x, ...) pps(x) <- value ## S4 replacement method for signature 'AcousticStudy' pps(x) <- value ## S4 method for signature 'AcousticStudy' ancillary(x, ...) ## S4 replacement method for signature 'AcousticStudy' ancillary(x) <- value models(x, ...) ## S4 method for signature 'AcousticStudy' models(x, ...) models(x) <- value ## S4 replacement method for signature 'AcousticStudy' models(x) <- value ## S4 method for signature 'AcousticStudy,ANY,ANY,ANY' x[i] ## S4 replacement method for signature 'AcousticStudy,ANY,ANY,ANY' x[i] <- value ## S4 method for signature 'AcousticStudy' x$name ## S4 replacement method for signature 'AcousticStudy' x$name <- value ## S4 method for signature 'AcousticStudy,ANY,ANY' x[[i]] ## S4 replacement method for signature 'AcousticStudy,ANY,ANY,ANY' x[[i]] <- value
settings(x, ...) ## S4 method for signature 'AcousticEvent' settings(x, ...) settings(x) <- value ## S4 replacement method for signature 'AcousticEvent' settings(x) <- value localizations(x, ...) ## S4 method for signature 'AcousticEvent' localizations(x, ...) localizations(x) <- value ## S4 replacement method for signature 'AcousticEvent' localizations(x) <- value id(x, ...) ## S4 method for signature 'AcousticEvent' id(x, ...) id(x) <- value ## S4 replacement method for signature 'AcousticEvent' id(x) <- value detectors(x, ...) ## S4 method for signature 'AcousticEvent' detectors(x, ...) detectors(x) <- value ## S4 replacement method for signature 'AcousticEvent' detectors(x) <- value species(x, ...) ## S4 method for signature 'AcousticEvent' species(x, ...) ## S4 method for signature 'AcousticStudy' species(x, type = "id", ...) species(x) <- value ## S4 replacement method for signature 'AcousticEvent' species(x) <- value files(x, ...) ## S4 method for signature 'AcousticEvent' files(x, ...) files(x) <- value ## S4 replacement method for signature 'AcousticEvent' files(x) <- value ancillary(x, ...) ## S4 method for signature 'AcousticEvent' ancillary(x, ...) ancillary(x) <- value ## S4 replacement method for signature 'AcousticEvent' ancillary(x) <- value ## S4 method for signature 'AcousticEvent,ANY,ANY,ANY' x[i] ## S4 replacement method for signature 'AcousticEvent,ANY,ANY,ANY' x[i] <- value ## S4 method for signature 'AcousticEvent' x$name ## S4 replacement method for signature 'AcousticEvent' x$name <- value ## S4 method for signature 'AcousticEvent,ANY,ANY' x[[i]] ## S4 replacement method for signature 'AcousticEvent,ANY,ANY,ANY' x[[i]] <- value ## S4 method for signature 'AcousticStudy' id(x, ...) ## S4 replacement method for signature 'AcousticStudy' id(x) <- value ## S4 method for signature 'AcousticStudy' files(x, ...) ## S4 replacement method for signature 'AcousticStudy' files(x) <- value gps(x, ...) ## S4 method for signature 'AcousticStudy' gps(x, ...) gps(x) <- value ## S4 replacement method for signature 'AcousticStudy' gps(x) <- value ## S4 method for signature 'AcousticStudy' detectors(x, ...) events(x, ...) ## S4 method for signature 'AcousticStudy' events(x, ...) events(x) <- value ## S4 replacement method for signature 'AcousticStudy' events(x) <- value ## S4 method for signature 'AcousticStudy' settings(x, ...) ## S4 replacement method for signature 'AcousticStudy' settings(x) <- value effort(x, ...) ## S4 method for signature 'AcousticStudy' effort(x, ...) effort(x) <- value ## S4 replacement method for signature 'AcousticStudy' effort(x) <- value pps(x, ...) ## S4 method for signature 'AcousticStudy' pps(x, ...) pps(x) <- value ## S4 replacement method for signature 'AcousticStudy' pps(x) <- value ## S4 method for signature 'AcousticStudy' ancillary(x, ...) ## S4 replacement method for signature 'AcousticStudy' ancillary(x) <- value models(x, ...) ## S4 method for signature 'AcousticStudy' models(x, ...) models(x) <- value ## S4 replacement method for signature 'AcousticStudy' models(x) <- value ## S4 method for signature 'AcousticStudy,ANY,ANY,ANY' x[i] ## S4 replacement method for signature 'AcousticStudy,ANY,ANY,ANY' x[i] <- value ## S4 method for signature 'AcousticStudy' x$name ## S4 replacement method for signature 'AcousticStudy' x$name <- value ## S4 method for signature 'AcousticStudy,ANY,ANY' x[[i]] ## S4 replacement method for signature 'AcousticStudy,ANY,ANY,ANY' x[[i]] <- value
x |
a AcousticEvent or AcousticStudy object |
... |
other arguments to pass to methods |
value |
value to assign with accessor |
type |
species type to select |
i |
index of the object to access |
name |
name of the object to access |
a unique id or name for this object
a named list of settings for each detector and localization or recorder
a list of detector data frames
list of localizations
list of species classifications
list of files used to create this object
a list of AcousticEvent objects
a dataframe containing gps data
the PAMpalSettings object used to create this
something about effort?
miscellaneous extra data
Taiki Sakai [email protected]
Create a PAMpalSettings object. Any values that are not supplied will be asked for interactively. Three processing functions will also be added by default: standardClickCalcs, roccaWhistleCalcs, and standardCepstrumCalcs
PAMpalSettings( db = NULL, binaries = NULL, settings = NULL, functions = NULL, verbose = TRUE, default = FALSE, ... )
PAMpalSettings( db = NULL, binaries = NULL, settings = NULL, functions = NULL, verbose = TRUE, default = FALSE, ... )
db |
the full path to a Pamguard database file or folder of databases |
binaries |
a folder containing Pamguard binary files, all subfolders will also be added |
settings |
an XML settings file from Pamguard |
functions |
a named list of additional functions to add |
verbose |
logical flag to show messages |
default |
logical flag to use default measurement function parameters |
... |
values to pass on to default standardClickCalcs function |
A PAMpalSettings object
Taiki Sakai [email protected]
# can be run with no arguments with popup menu selections if(interactive()) pps <- PAMpalSettings() db <- system.file('extdata', 'Example.sqlite3', package='PAMpal') bin <- system.file('extdata', 'Binaries', package='PAMpal') # or data folders can be supplied ahead of time if(interactive()) pps <- PAMpalSettings(db=db, binaries=bin)
# can be run with no arguments with popup menu selections if(interactive()) pps <- PAMpalSettings() db <- system.file('extdata', 'Example.sqlite3', package='PAMpal') bin <- system.file('extdata', 'Binaries', package='PAMpal') # or data folders can be supplied ahead of time if(interactive()) pps <- PAMpalSettings(db=db, binaries=bin)
PAMpalSettings
ClassAn S4 class that stores settings related to all processing and analysis steps done in PAMpal. A PAMpalSettings object will be the main input to any major function in the PAMpal package.
db
the full path to a PamGuard database file
binaries
a list with items "folder" containing the directory of the PamGuard binary files, and "list" containing the full path to each individual binary file.
functions
a named list of functions to apply to data read in by PAMpal. Should be named by the PamGuard module the function should be applied to. Currently supports "ClickDetector", "WhistlesMoans", and "Cepstrum".
calibration
a named list of calibration functions to apply while applying functions from the "functions" slot. Should named by the PamGuard module, same as the "functions"
settings
a named list of settings, usually imported from Pamguard's "Export XML Configuration"
Taiki Sakai [email protected]
Runs an interactive Shiny plot of detector data. Allows user to choose which numeric data to plot, and will allow user to both color and facet the plot by event number, detector name, or species
plotDataExplorer(x)
plotDataExplorer(x)
x |
data to plot, can be an |
nothing, just plots
Taiki Sakai [email protected]
data(exStudy) if(interactive()) plotDataExplorer(exStudy)
data(exStudy) if(interactive()) plotDataExplorer(exStudy)
Plots either a spectrogram or cepstrogram and also overlays whistle or cepstral contours from the binary files
plotGram( x, evNum = 1, start = NULL, end = NULL, channel = 1, wl = 512, hop = 0.25, mode = c("spec", "ceps"), detections = c("cepstrum", "click", "whistle"), detCol = c("red", "blue", "purple"), brightness = 0, contrast = 0, q = 0.01, cmap = gray.colors(64, start = 1, end = 0), size = 1, add = FALSE, title = NULL, sr = NULL, freqRange = NULL, ... )
plotGram( x, evNum = 1, start = NULL, end = NULL, channel = 1, wl = 512, hop = 0.25, mode = c("spec", "ceps"), detections = c("cepstrum", "click", "whistle"), detCol = c("red", "blue", "purple"), brightness = 0, contrast = 0, q = 0.01, cmap = gray.colors(64, start = 1, end = 0), size = 1, add = FALSE, title = NULL, sr = NULL, freqRange = NULL, ... )
x |
an AcousticStudy object |
evNum |
if |
start |
start time of the plot, either POSIXct or seconds from the start of the event |
end |
end time of the plot, either POSIXct or seconds from the start of the event. |
channel |
channel to plot |
wl |
window length of FFT to use for creating plot |
hop |
hop value of FFT to use for creating plot, either as a percentage
of |
mode |
one of |
detections |
vector containing any of |
detCol |
vector containing colors to use for plotting detections. Order matches order of detections (default alphabetical - cepstrum, click, whistle) |
brightness |
value from -255 to 255, positive values increase brightness, negative values decrease brightness of concatenated spectrogram image |
contrast |
value from -255 to 255, positive values increase contrast, negative values decrease contrast of concatenated spectrogram image |
q |
lower and upper quantiles to remove for scaling concatenated spectrogram.
Or if a single value, then quantiles |
cmap |
color map for the spectrogram, either a palette function or vector of colors |
size |
size scaling to apply to plotted points and lines, as a multiple
factor to the default values. Can be a vector of length equal to
|
add |
logical flag |
title |
optional title for plot, defaults to "Spectrogram" or "Cepstrogram" |
sr |
sample rate to decimate to |
freqRange |
frequency range to plot, in Hz for |
... |
nothing, just plots
Taiki Sakai [email protected]
data(exStudy) recs <- system.file('extdata', 'Recordings', package='PAMpal') exStudy <- updateFiles(exStudy, bin=system.file('extdata', 'Binaries', package='PAMpal'), db = system.file('extdata', 'Example.sqlite3', package='PAMpal')) exStudy <- addRecordings(exStudy, folder=recs, log=FALSE, progress=FALSE) # No detections will appear on plot because included recordings are heavily decimated plotGram(exStudy)
data(exStudy) recs <- system.file('extdata', 'Recordings', package='PAMpal') exStudy <- updateFiles(exStudy, bin=system.file('extdata', 'Binaries', package='PAMpal'), db = system.file('extdata', 'Example.sqlite3', package='PAMpal')) exStudy <- addRecordings(exStudy, folder=recs, log=FALSE, progress=FALSE) # No detections will appear on plot because included recordings are heavily decimated plotGram(exStudy)
Fetches matching binary data from a single or multiple detections in an AcousticStudy object, then plot the resulting data
plotWaveform(x, UID, length = NULL, sr = NULL) plotSpectrogram(x, UID, length = NULL, sr = NULL, ...) plotWigner(x, UID, length = NULL, sr = NULL, ...)
plotWaveform(x, UID, length = NULL, sr = NULL) plotSpectrogram(x, UID, length = NULL, sr = NULL, ...) plotWigner(x, UID, length = NULL, sr = NULL, ...)
x |
a AcousticStudy object, a list of AcousticEvent objects, or a single AcousticEvent object |
UID |
the UID(s) of the individual detections to fetch the binary data for |
length |
length of the waveform to use for plotting, in samples. The clip
used will be centered around the maximum value of the waveform, if |
sr |
if |
... |
other arguments to pass to the spectrogram or wigner functions |
The plotSpectrogram
function uses the function
specgram
to plot the spectrogram, see this function
for plotting options. The plotWigner
function uses the function
wignerTransform
to plot the Wigner-Ville transform,
see this function for options.
Nothing, just shows plots for every channel of the waveform for each UID provided
Taiki Sakai [email protected]
data(exStudy) plotWaveform(exStudy, 8000003) plotSpectrogram(exStudy, 8000003) plotWigner(exStudy, 8000003)
data(exStudy) plotWaveform(exStudy, 8000003) plotSpectrogram(exStudy, 8000003) plotWigner(exStudy, 8000003)
Loads and processes acoustic detection data that has been
run through Pamguard. Uses the binary files and database(s) contained
in pps
, and will group your data into events by the
grouping present in the 'OfflineEvents' and 'Detection Group Localiser'
tables (mode = 'db'
) or by the grouping specified by start and end
times in the supplied grouping
(mode = 'time'
), or by start and
end of recording files (mode = 'recording'
). Will apply
all processing functions in pps
to the appropriate modules
processPgDetections( pps, mode = c("db", "time", "recording", "fixed"), id = NULL, grouping = NULL, format = c("%m/%d/%Y %H:%M:%OS", "%m-%d-%Y %H:%M:%OS", "%Y/%m/%d %H:%M:%OS", "%Y-%m-%d %H:%M:%OS"), progress = TRUE, verbose = TRUE, ... )
processPgDetections( pps, mode = c("db", "time", "recording", "fixed"), id = NULL, grouping = NULL, format = c("%m/%d/%Y %H:%M:%OS", "%m-%d-%Y %H:%M:%OS", "%Y/%m/%d %H:%M:%OS", "%Y-%m-%d %H:%M:%OS"), progress = TRUE, verbose = TRUE, ... )
pps |
a PAMpalSettings object containing the databases,
binaries, and functions to use for processing data. See
|
mode |
selector for how to organize your data in to events. |
id |
an event name or id for this study, will default to today's date if not supplied (recommended to supply your own informative id) |
grouping |
For For
For |
format |
the date format for the |
progress |
logical flog to show progress bars |
verbose |
logical flag to show messages |
... |
additional arguments to pass onto to different methods |
If mode
is not specified, it will try to be automatically determined
in the following order. 1) if a grouping
data.frame or CSV is provided, then
mode='time'
will be used. 2) If there are labelled events present in the
database, mode='db'
will be used. 3) mode='recording'
will be used,
which should be equivalent to loading all possible data.
an AcousticStudy object with one AcousticEvent
for each event in the events
slot, and the PAMpalSettings object
used stored in the pps
slot.
Taiki Sakai [email protected]
exPps <- new('PAMpalSettings') exPps <- addDatabase(exPps, system.file('extdata', 'Example.sqlite3', package='PAMpal')) exPps <- addBinaries(exPps, system.file('extdata', 'Binaries', package='PAMpal')) exClick <- function(data) { standardClickCalcs(data, calibration=NULL, filterfrom_khz = 0) } exPps <- addFunction(exPps, exClick, module = 'ClickDetector') exPps <- addFunction(exPps, roccaWhistleCalcs, module='WhistlesMoans') exPps <- addFunction(exPps, standardCepstrumCalcs, module = 'Cepstrum') # process events labelled within the Pamguard database exStudyDb <- processPgDetections(exPps, mode='db', id='Example') # can also give an AcousticStudy as input and it will use same functions and data reprocess <- processPgDetections(exStudyDb, mode='db', id='Reprocess') # process events with manually set start/end times grp <- data.frame(start = as.POSIXct('2018-03-20 15:25:10', tz='UTC'), end = as.POSIXct('2018-03-20 15:25:11', tz='UTC'), id = 'GroupExample') exStudyTime <- processPgDetections(exPps, mode='time', grouping=grp, id='Time') # process events by recording event exStudyRecording <- processPgDetections(exPps, mode='recording', id='Recording') exFixed <- processPgDetections(exPps, mode='fixed', grouping='1min', id='1Minute')
exPps <- new('PAMpalSettings') exPps <- addDatabase(exPps, system.file('extdata', 'Example.sqlite3', package='PAMpal')) exPps <- addBinaries(exPps, system.file('extdata', 'Binaries', package='PAMpal')) exClick <- function(data) { standardClickCalcs(data, calibration=NULL, filterfrom_khz = 0) } exPps <- addFunction(exPps, exClick, module = 'ClickDetector') exPps <- addFunction(exPps, roccaWhistleCalcs, module='WhistlesMoans') exPps <- addFunction(exPps, standardCepstrumCalcs, module = 'Cepstrum') # process events labelled within the Pamguard database exStudyDb <- processPgDetections(exPps, mode='db', id='Example') # can also give an AcousticStudy as input and it will use same functions and data reprocess <- processPgDetections(exStudyDb, mode='db', id='Reprocess') # process events with manually set start/end times grp <- data.frame(start = as.POSIXct('2018-03-20 15:25:10', tz='UTC'), end = as.POSIXct('2018-03-20 15:25:11', tz='UTC'), id = 'GroupExample') exStudyTime <- processPgDetections(exPps, mode='time', grouping=grp, id='Time') # process events by recording event exStudyRecording <- processPgDetections(exPps, mode='recording', id='Recording') exFixed <- processPgDetections(exPps, mode='fixed', grouping='1min', id='1Minute')
Remove a binary folder and associated files from the "binaries" slot in a PAMpalSettings object.
removeBinaries(pps, index = NULL)
removeBinaries(pps, index = NULL)
pps |
a PAMpalSettings object to remove binaries from |
index |
index indicating which binary folders to remove. Can be a vector
if you want to remove multiple folders. If missing user is prompted to
select a folder from a list, will only show up to the first 20. You can
easily remove all of the folders with a large index like |
the same PAMpalSettings object as pps, with the binary folders and files associated with those folders removed from the "binaries" slot.
Taiki Sakai [email protected]
exPps <- new('PAMpalSettings') exPps <- addBinaries(exPps, system.file('extdata', 'Binaries', package='PAMpal')) removeBinaries(exPps,index = 1) if(interactive()) removeBinaries(exPps)
exPps <- new('PAMpalSettings') exPps <- addBinaries(exPps, system.file('extdata', 'Binaries', package='PAMpal')) removeBinaries(exPps,index = 1) if(interactive()) removeBinaries(exPps)
Remove a calibration function from the "calibration" slot of a PAMpalSettings object
removeCalibration(pps, index = NULL, module = "ClickDetector", verbose = TRUE)
removeCalibration(pps, index = NULL, module = "ClickDetector", verbose = TRUE)
pps |
a PAMpalSettings object to remove a calibration from |
index |
index of the calibration function to remove. If |
module |
the module of the calibration function to remove, currently not needed |
verbose |
logical flag to show messages |
the same PAMpalSettings object as pps, with the calibration function removed from the "calibration" slot
Taiki Sakai [email protected]
pps <- new('PAMpalSettings') calFile <- system.file('extdata', 'calibration.csv', package='PAMpal') pps <- addCalibration(pps, calFile, all = TRUE, units=3) calClick <- function(data, calibration=NULL) { standardClickCalcs(data, calibration=calibration, filterfrom_khz = 0) } pps <- addFunction(pps, calClick, module = 'ClickDetector') pps <- applyCalibration(pps, all=TRUE) pps removeCalibration(pps, index=1)
pps <- new('PAMpalSettings') calFile <- system.file('extdata', 'calibration.csv', package='PAMpal') pps <- addCalibration(pps, calFile, all = TRUE, units=3) calClick <- function(data, calibration=NULL) { standardClickCalcs(data, calibration=calibration, filterfrom_khz = 0) } pps <- addFunction(pps, calClick, module = 'ClickDetector') pps <- applyCalibration(pps, all=TRUE) pps removeCalibration(pps, index=1)
Remove a database from the "db" slot in a PAMpalSettings object.
removeDatabase(pps, index = NULL)
removeDatabase(pps, index = NULL)
pps |
a PAMpalSettings object to remove a database from |
index |
index indicating which database(s) to remove. Can be a vector
if you want to remove multiple databases. If missing user is prompted to
select a database from a list, will only show up to the first 20. You can
easily remove all of the databases with a large index like |
the same PAMpalSettings object as pps, with the database(s) removed from the "db" slot
Taiki Sakai [email protected]
exPps <- new('PAMpalSettings') exPps <- addDatabase(exPps, system.file('extdata', 'Example.sqlite3', package='PAMpal')) removeDatabase(exPps, 1) if(interactive()) removeDatabase(exPps)
exPps <- new('PAMpalSettings') exPps <- addDatabase(exPps, system.file('extdata', 'Example.sqlite3', package='PAMpal')) removeDatabase(exPps, 1) if(interactive()) removeDatabase(exPps)
Remove a function from the "function" slot in a PAMpalSettings object.
removeFunction(pps, index = NULL)
removeFunction(pps, index = NULL)
pps |
a PAMpalSettings object to remove a function from |
index |
index indicating which function to move, counting from
|
the same PAMpalSettings object as pps, with the function removed from the "functions" slot
Taiki Sakai [email protected]
exPps <- new('PAMpalSettings') exPps <- addFunction(exPps, roccaWhistleCalcs, module='WhistlesMoans') exPps <- addFunction(exPps, standardCepstrumCalcs, module = 'Cepstrum') removeFunction(exPps, 1) removeFunction(exPps, 1:2) # normally best to use interactively instead of specifying index if(interactive()) removeFunction(exPps)
exPps <- new('PAMpalSettings') exPps <- addFunction(exPps, roccaWhistleCalcs, module='WhistlesMoans') exPps <- addFunction(exPps, standardCepstrumCalcs, module = 'Cepstrum') removeFunction(exPps, 1) removeFunction(exPps, 1:2) # normally best to use interactively instead of specifying index if(interactive()) removeFunction(exPps)
Remove a note added with addNote
removeNote(x, index)
removeNote(x, index)
x |
An AcousticStudy or AcousticEvent object |
index |
The index of the note to remove, order matches the output of getNotes |
For addNote
, the same data as x
, with notes added.
For getNotes
, a list of all notes present in x
Taiki Sakai [email protected]
data(exStudy) exStudy <- addNote(exStudy, to='study', label='Note1', note='My first note for this study') exStudy <- addNote(exStudy, to='event', evNum=1:2, label='Note2', note='A note for the first two events') exStudy removeNote(exStudy, 1) removeNote(exStudy, 2) removeNote(exStudy, 3)
data(exStudy) exStudy <- addNote(exStudy, to='study', label='Note1', note='My first note for this study') exStudy <- addNote(exStudy, to='event', evNum=1:2, label='Note2', note='A note for the first two events') exStudy removeNote(exStudy, 1) removeNote(exStudy, 2) removeNote(exStudy, 3)
Remove all settings from the "settings" slot in a PAMpalSettings object.
removeSettings(pps)
removeSettings(pps)
pps |
a PAMpalSettings object to remove settings from |
the same PAMpalSettings object as pps, with all settings removed from the "settings" slot
Taiki Sakai [email protected]
exPps <- new('PAMpalSettings') exPps <- addSettings(exPps, system.file('extdata', 'Example.xml', package='PAMpal')) removeSettings(exPps)
exPps <- new('PAMpalSettings') exPps <- addSettings(exPps, system.file('extdata', 'Example.xml', package='PAMpal')) removeSettings(exPps)
Calculate a set of measurements from a whistle contour. All calculations following ROCCA method from Julie and Michael Oswald, as implemented in Pamguard and detailed in Oswald et al (2007) <doi:10.1121/1.2743157>
roccaWhistleCalcs(data)
roccaWhistleCalcs(data)
data |
a list that must have |
A list with 50 calculated ROCCA parameters, each item in the list will only have 1 entry so that this can easily be converted to a data frame.
Taiki Sakai [email protected]
data(testWhistle) roccaWhistleCalcs(testWhistle)
data(testWhistle) roccaWhistleCalcs(testWhistle)
Runs a Shiny app to review the slant delay and esimated depths
of an AcousticStudy object that has been processed with
calculateEchoDepth. App allows users to select detections that
should not be included in future analysis and marks them with the tag
keepClick=FALSE
, similar to filterEchoDepths.
runDepthReview(x)
runDepthReview(x)
x |
an AcousticStudy object that has been processed with calculateEchoDepth |
the object as x
, with updated keepClick
column
Taiki Sakai [email protected]
# example not run because \link{calculateEchoDepth} must be run first, # and it requires a large amount of data not stored in the package ## Not run: study <- calculateEchoDepth(study, wav='path/to/wavFiles') study <- runDepthReview(x) ## End(Not run)
# example not run because \link{calculateEchoDepth} must be run first, # and it requires a large amount of data not stored in the package ## Not run: study <- calculateEchoDepth(study, wav='path/to/wavFiles') study <- runDepthReview(x) ## End(Not run)
Runs a Shiny app that shows three plots - the ICI (time to
next detection) over time, histogram of ICI values, and the average
waveform of an event. Average waveform plot is only present if
calculateEchoDepth has been run first, otherwise IPI and
average waveform data will not be present. ICI plots have a red line
showing the modal ICI of the event, and average waveform plot has a
red line of the estimated IPI level. All plots can be interacted with
by clicking on a location to select a new ICI / IPI (called the "User
ICI/IPI") that will be shown in blue. "Save ICI/IPI" buttons can be
pressed to use save this "User" value as the new All_ici
or
ipiMax
value. "Remove ICI/IPI" buttons can be pressed to set
these values to NA
, which should be done in cases where no
apparent ICI/IPI exists from the plot. The "Reset" button can be used
to restore the original modal ICI and estimated IPI values.
runIciReview(x, maxIci = 2.5)
runIciReview(x, maxIci = 2.5)
x |
an AcousticStudy object that has been processed with calculateEchoDepth |
maxIci |
maximum ICI value (seconds) to display on plots |
the object as x
, with potentially updated All_ici
and ipiMax
measures for some events depending on user activity
Taiki Sakai [email protected]
# average waveform/IPI estimates not present because # calculateEchoDepth must be run first for those to exist if(interactive()) { data(exStudy) exStudy <- runIciReview(exStudy) }
# average waveform/IPI estimates not present because # calculateEchoDepth must be run first for those to exist if(interactive()) { data(exStudy) exStudy <- runIciReview(exStudy) }
samples either a fraction or fixed number from each detector in each event of an AcousticStudy
sampleDetector(x, n = 1)
sampleDetector(x, n = 1)
x |
AcousticStudy object |
n |
if less than 1, proportion of rows to sample from each detector. If 1 or more, the number of rows to sample from each detector. |
Uses slice_sample to do the sampling, n
is converted either to prop
or n
based on its size.
Negative values are treated the same as in slice_sample
subsampled AcousticStudy x
Taiki Sakai [email protected]
data(exStudy) nDetections(exStudy) halfData <- sampleDetector(exStudy, n=0.5) # there are odd numbers of rows in some detectors, so less than half nDetections(exStudy) oneDetPerDetector <- sampleDetector(exStudy, n=1) nDetections(exStudy)
data(exStudy) nDetections(exStudy) halfData <- sampleDetector(exStudy, n=0.5) # there are odd numbers of rows in some detectors, so less than half nDetections(exStudy) oneDetPerDetector <- sampleDetector(exStudy, n=1) nDetections(exStudy)
Sets the species
slot of AcousticEvent
objects within an AcousticStudy
setSpecies(x, method = c("pamguard", "manual", "reassign"), value, type = "id")
setSpecies(x, method = c("pamguard", "manual", "reassign"), value, type = "id")
x |
a AcousticStudy object, a list of AcousticEvent objects, or a single AcousticEvent object |
method |
the method for assigning species to an event. Currently supports
|
value |
required only if |
type |
the type of classification to set, this is just a label within
the |
the same object as x
, with species identifications assigned
as an item named type
in the species
slot
Taiki Sakai [email protected]
# setting up example data exPps <- new('PAMpalSettings') exPps <- addDatabase(exPps, system.file('extdata', 'Example.sqlite3', package='PAMpal')) exPps <- addBinaries(exPps, system.file('extdata', 'Binaries', package='PAMpal')) exClick <- function(data) { standardClickCalcs(data, calibration=NULL, filterfrom_khz = 0) } exPps <- addFunction(exPps, exClick, module = 'ClickDetector') exPps <- addFunction(exPps, roccaWhistleCalcs, module='WhistlesMoans') exPps <- addFunction(exPps, standardCepstrumCalcs, module = 'Cepstrum') exData <- processPgDetections(exPps, mode='db') exData <- setSpecies(exData, method='pamguard') species(exData) exData <- setSpecies(exData, method='manual', value = c('sp1', 'sp2')) species(exData) exData <- setSpecies(exData, method='reassign', value = data.frame(old='sp1', new='sp3')) species(exData)
# setting up example data exPps <- new('PAMpalSettings') exPps <- addDatabase(exPps, system.file('extdata', 'Example.sqlite3', package='PAMpal')) exPps <- addBinaries(exPps, system.file('extdata', 'Binaries', package='PAMpal')) exClick <- function(data) { standardClickCalcs(data, calibration=NULL, filterfrom_khz = 0) } exPps <- addFunction(exPps, exClick, module = 'ClickDetector') exPps <- addFunction(exPps, roccaWhistleCalcs, module='WhistlesMoans') exPps <- addFunction(exPps, standardCepstrumCalcs, module = 'Cepstrum') exData <- processPgDetections(exPps, mode='db') exData <- setSpecies(exData, method='pamguard') species(exData) exData <- setSpecies(exData, method='manual', value = c('sp1', 'sp2')) species(exData) exData <- setSpecies(exData, method='reassign', value = data.frame(old='sp1', new='sp3')) species(exData)
Calculate a set of measurements from a cepstrum contour. This is currently used to measure the inter-click interval of the burst pulse type calls
standardCepstrumCalcs(data)
standardCepstrumCalcs(data)
data |
a list that must have |
A list with inter-click interval (ici), duration (seconds), and slope of the ici
Taiki Sakai [email protected]
data(testCeps) standardCepstrumCalcs(testCeps)
data(testCeps) standardCepstrumCalcs(testCeps)
Calculate a set of "standard" measurements for odontocete clicks
standardClickCalcs( data, sr_hz = "auto", calibration = NULL, filterfrom_khz = 10, filterto_khz = NULL, winLen_sec = 0.0025 )
standardClickCalcs( data, sr_hz = "auto", calibration = NULL, filterfrom_khz = 10, filterto_khz = NULL, winLen_sec = 0.0025 )
data |
a list that must have 'wave' containing the wave form as a
matrix with a separate column for each channel, and 'sr' the
sample rate of the data. Data can also be a |
sr_hz |
either |
calibration |
a calibration function to apply to the spectrum, must be a gam. If NULL no calibration will be applied (not recommended). |
filterfrom_khz |
frequency in khz of highpass filter to apply, or the lower
bound of a bandpass filter if |
filterto_khz |
if a bandpass filter is desired, set this as the upper bound.
If only a highpass filter is desired, leave as the default |
winLen_sec |
length in seconds of fft window. The click wave is first shortened to this number of samples around the peak of the wave, removing a lot of the noise around the click. Following approach of JB/EG/MS. |
Calculations of parameters mostly follow the approach outlined in Griffiths et al (2020) <doi:10.1121/10.0001229> and Baumann-Pickering et al (2010) <doi:10.1121/1.3479549>. Additionally, up to 3 highest peak frequencies and the "troughs" between them are calculated (see peakTrough)
A data frame with one row for each channel of click waveform
Taiki Sakai [email protected]
data(testClick) standardClickCalcs(testClick)
data(testClick) standardClickCalcs(testClick)
Summarise results of dive depth estimation using calculateEchoDepth and related functions
summariseDiveDepth(x, hpDepthError = 1, locType = "PGTargetMotion")
summariseDiveDepth(x, hpDepthError = 1, locType = "PGTargetMotion")
x |
an AcousticStudy that has been processed with calculateEchoDepth |
hpDepthError |
hydrophone depth error to use for error estimation |
locType |
name of localization, note that this function is not computing any localization, only using previously calculated |
a dataframe with columns summarising the estimated dive depth
for each event in x
Taiki Sakai [email protected]
# example not run because \link{calculateEchoDepth} must be run first, # and it requires a large amount of data not stored in the package ## Not run: study <- calculateEchoDepth(study, wav='path/to/wavFiles') summariseDiveDepth(study) ## End(Not run)
# example not run because \link{calculateEchoDepth} must be run first, # and it requires a large amount of data not stored in the package ## Not run: study <- calculateEchoDepth(study, wav='path/to/wavFiles') summariseDiveDepth(study) ## End(Not run)
A manually created fake cepstrum contour, mimicing what the output would be from the Pamguard module and fed into the cepstrum calcs
data(testCeps)
data(testCeps)
A list with three items:
a vector of the cepstrum contour quefrency values
a vector of the time values of the cepsturm contour in seconds
the sample rate of the recording
An example delphinid click waveform. This is a two-channel recording of some kind of delphinid click, recorded at 500kHz There are 800 samples recorded on each channel.
data(testClick)
data(testClick)
A list with two items:
a matrix with two columns of 800 samples, each column is a separate recording channel
the sample rate of the recording
Southwest Fisheries Science Center / NMFS / NOAA
A manually created fake GPL contour, mimicing what the output would be from the Pamguard module and fed into the GPL calcs
data(testGPL)
data(testGPL)
A list with three items:
a vector of the frequency contour values in hertz
a vector of the time values of the contour in seconds
A manually created fake whistle contour reanging from 1kHz to 3.1kHz
data(testWhistle)
data(testWhistle)
A list with two items:
a vector of the frequency contour values in hertz
a vector of the time values of the contour in seconds
Updates the stored locations of binary, database, and/or recording
files in the files
slots of an AcousticStudy and all
AcousticEvent objects within. Runs interactively to prompt
users to select folders if missing files are found. Typically used after changing
computers, or if original data was on an external hard drive. If any
missing files are not able to be located, they will be kept in the files
slot so that this function can be run again
updateFiles( x, bin = NULL, db = NULL, recording = NULL, verbose = TRUE, check = TRUE )
updateFiles( x, bin = NULL, db = NULL, recording = NULL, verbose = TRUE, check = TRUE )
x |
an AcousticStudy or AcousticEvent object |
bin |
folder containing updated binary file locations. If
|
db |
single file or folder containing updated database file locations.
|
recording |
folder containing updated recording file locations. If
|
verbose |
logical flag to print messages about success of replacement |
check |
logical flag to do extra checking. You do not need to set this parameter, used internally for speed purposes so certain checks are not repeated |
the same AcousticStudy and
AcousticEvent object as x
with
updated file locations
Taiki Sakai [email protected]
data(exStudy) # files in exStudy will have paths local to package creator's computer files(exStudy)$db file.exists(files(exStudy)$db) files(exStudy)$binaries file.exists(files(exStudy)$binaries) # folder with example DB db <- system.file('extdata', package='PAMpal') # folder with example binaries bin <- system.file('extdata', 'Binaries', package='PAMpal') exStudy <- updateFiles(exStudy, db=db, bin=bin) files(exStudy)$db file.exists(files(exStudy)$db) files(exStudy)$binaries file.exists(files(exStudy)$binaries)
data(exStudy) # files in exStudy will have paths local to package creator's computer files(exStudy)$db file.exists(files(exStudy)$db) files(exStudy)$binaries file.exists(files(exStudy)$binaries) # folder with example DB db <- system.file('extdata', package='PAMpal') # folder with example binaries bin <- system.file('extdata', 'Binaries', package='PAMpal') exStudy <- updateFiles(exStudy, db=db, bin=bin) files(exStudy)$db file.exists(files(exStudy)$db) files(exStudy)$binaries file.exists(files(exStudy)$binaries)
Updates older versions of PAMpal's S4 objects to stop "validOjbect" warning messages
updatePamObject(x)
updatePamObject(x)
x |
an AcousticStudy, AcousticEvent, or PAMpalSettings object |
As of v0.12.0 this updates any previous version's PAMpalSettings objects to have the new "settings" slot, as well as updating any PAMpalSettings objects within an AcousticStudy
the same object as x
with any slot changes made
Taiki Sakai [email protected]
## Not run: pps <- new('PAMpalSettings') # manually breaking this S4 class, don't try this at home attr(pps, 'settings') <- NULL # This will now give an error pps pps <- updatePamObject(pps) # Fixed! pps ## End(Not run)
## Not run: pps <- new('PAMpalSettings') # manually breaking this S4 class, don't try this at home attr(pps, 'settings') <- NULL # This will now give an error pps pps <- updatePamObject(pps) # Fixed! pps ## End(Not run)
Creates audio clips containing sounds from events or detections
writeEventClips( x, buffer = c(0, 0.1), outDir = ".", mode = c("event", "detection"), channel = 1, filter = 0, useSample = FALSE, progress = TRUE, verbose = TRUE, fixLength = FALSE ) parseEventClipName(file, part = c("event", "time", "UID", "channel", "UTC"))
writeEventClips( x, buffer = c(0, 0.1), outDir = ".", mode = c("event", "detection"), channel = 1, filter = 0, useSample = FALSE, progress = TRUE, verbose = TRUE, fixLength = FALSE ) parseEventClipName(file, part = c("event", "time", "UID", "channel", "UTC"))
x |
AcousticStudy object containing data to make wav clips for |
buffer |
amount before and after each event to also include in the clip, in seconds. Can either be a vector of length two specifying how much to buffer before and after (first number should be negative), or a single value if the buffer amount should be identical. |
outDir |
directory to write clips to, defaults to current directory |
mode |
either |
channel |
channel(s) of clips to write |
filter |
filter to apply to wav clips before writing, values in kHz. A value of |
useSample |
logical flag to use startSample information in binaries instead of UTC time for start of detections. This can be slightly more accurate (~1ms) but will take longer |
progress |
logical flag to show progress bar |
verbose |
logical flag to show summary messages |
fixLength |
logical flag to fix the output clip length to a constant value. If
|
file |
file name to parse |
part |
part of file name to return |
parseEventClipName
parses the file names created to pull out
event names or file start times
A vector of file names for the wav clips that were successfully
created, any that were not able to be written will be NA
. Note
that currently this can only write clips with up to 2 channels. File names
will be formatted as
[Event or Detection]_[Id]CH[ChannelNumber(s)]_[YYYYMMDD]_[HHMMSS]_[mmm].wav
The last numbers are the start time of the file in UTC, accurate to milliseconds.
The Id is either the event ID or the detection UID.
Taiki Sakai [email protected]
data(exStudy) recs <- system.file('extdata', 'Recordings', package='PAMpal') exStudy <- addRecordings(exStudy, folder=recs, log=FALSE, progress=FALSE) ## Not run: # not running so that no wav clips are written to disk wavs <- writeEventClips(exStudy, outDir='WavFolder', mode='event') ## End(Not run)
data(exStudy) recs <- system.file('extdata', 'Recordings', package='PAMpal') exStudy <- addRecordings(exStudy, folder=recs, log=FALSE, progress=FALSE) ## Not run: # not running so that no wav clips are written to disk wavs <- writeEventClips(exStudy, outDir='WavFolder', mode='event') ## End(Not run)
Create Wigner-Ville transform data of click clips from all detections and save them to disk. A CSV file will also be written that lists all UIDs contained in the output
writeWignerData( x, n = 256, t = 300, outDir = ".", mode = "nparray", progress = TRUE, ... )
writeWignerData( x, n = 256, t = 300, outDir = ".", mode = "nparray", progress = TRUE, ... )
x |
AcousticStudy object containing data to make Wigner data for |
n |
number of frequency bins for Wigner transform (recommended power of 2) |
t |
number of samples to use for the click clip passed to the transform |
outDir |
directory to write data to |
mode |
specifies the kind of output that will be created, currently only
supports creating NumPy arrays using the |
progress |
logical flag to show progress bar |
... |
optional arguments to pass |
A list with two items: files
- a vector of file names
for the Wigner data that were successfully created, any that were not
able to be written will be NA
, and warnings
, a list with
items containing event IDs that triggered any warnings
Taiki Sakai [email protected]
data(exStudy) exStudy <- setSpecies(exStudy, method='pamguard') ## Not run: # not running because files are written to disk wigFiles <- writeWignerData(exStudy, outDir = 'WigFolder') ## End(Not run)
data(exStudy) exStudy <- setSpecies(exStudy, method='pamguard') ## Not run: # not running because files are written to disk wigFiles <- writeWignerData(exStudy, outDir = 'WigFolder') ## End(Not run)