findPeaks: Find Score Peaks and Detections in a 'templateScores' Object

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/findPeaks.R

Description

This function accepts templateScores objects and returns information on all score peaks and those peaks that are considered detections.

Usage

1
2
findPeaks(score.obj, fd.rat = 1, frame, parallel = FALSE)
  

Arguments

score.obj

A templateScores object, produced by corMatch or binMatch.

fd.rat

A ratio of frame width (twice minimum peak separation) to template duration.

frame

If you want the same frame width for templates with varying duration, specify a value directly. fd.rate will be ignored if frame is specified.

parallel

Set to TRUE for parallel processing using mclapply. This option is not available for Windows operating systems.

Details

The findPeaks function translates raw scores from template matching to detection information, by finding peaks in the score data, and determining which peaks, if any, exceed the score cutoffs specified in the templates (see the two functions for making templates, makeBinTemplate and makeCorTemplate and templateCutoff for more details on cutoffs).

Value

An S4 object of class templateScores, with the following slots:

survey.name

The file path to the survey that the scores apply to.

survey

The actual survey as a Wave object.

survey.data

A named list with one element per template. Each element is a named list with time-domain results for the survey.

templates

The templates (an S4 object of class corTemplateList or binTemplateList) used to calculate the scores.

scores

A named list with an element for each template. Each element contains the scores for an individual template.

peaks

A named list with peak information (as a data frame) for each template.

detections

A named list with detection information (as a data frame) for each template.

Author(s)

Sasha D. Hafner and Jon Katz

See Also

makeCorTemplate, makeBinTemplate, corMatch, binMatch, getDetections, getPeaks

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Load data
data(btnw)
data(oven)
data(survey)

# Write Wave objects to file (temporary directory used here)
btnw.fp <- file.path(tempdir(), "btnw.wav")
oven.fp <- file.path(tempdir(), "oven.wav")
survey.fp <- file.path(tempdir(), "survey2010-12-31_120000_EST.wav")
writeWave(btnw, btnw.fp)
writeWave(oven, oven.fp)
writeWave(survey, survey.fp)

# Correlation example
# Create two correlation templates
wct <- makeCorTemplate(btnw.fp, t.lim = c(1.5, 2.1), frq.lim = c(4.2, 5.6), name = "w")

oct <- makeCorTemplate(oven.fp, t.lim = c(1, 4), frq.lim = c(1, 11), dens = 0.1, name = "o")

# Combine them
ctemps <- combineCorTemplates(wct, oct)

# Calculate scores
cscores <- corMatch(survey.fp, ctemps)

# Finally, find peaks and detections
cdetects <- findPeaks(cscores)

cdetects

plot(cdetects)

# plotting help:
method?plot('detectionList')

# Binary example
## Not run: 
# Not run because of the time required (maybe 2-5 seconds) Create two templates
wbt <- makeBinTemplate(btnw.fp, amp.cutoff = -30, t.lim = c(1.5, 2.1), frq.lim = c(4.2, 5.6),
                       buffer = 2, name = "w")

obt <- makeBinTemplate(oven.fp, amp.cutoff = -20, t.lim = c(1, 4), frq.lim = c(1, 11), 
                       name = "o")

# Combine them
btemps <- combineBinTemplates(wbt, obt)

# Calculate scores
bscores <- binMatch(survey.fp, btemps)

# Finally, find peaks and detections
bdetects <- findPeaks(bscores)

bdetects

plot(bdetects)

## End(Not run)

# Clean up (only because these files were created in these examples)
file.remove(btnw.fp)
file.remove(oven.fp)
file.remove(survey.fp)

Example output

Loading required package: tuneR

Attaching package: 'monitoR'

The following object is masked from 'package:tuneR':

    readMP3


Automatic point selection.

Done.

Automatic point selection.

Done.

Starting  w . . .
	Fourier transform on survey . . .
	Continuing. . .

	Done.

Starting  o . . .
	Done.

Done with  w
Done with  o
Done

A "detectionList" object

Based on survey file:  /work/tmp/tmp/RtmpJaoGTT/survey2010-12-31_120000_EST.wav 

and  2  templates

Detection information
  n.peaks n.detections min.peak.score max.peak.score min.detection.score
w      38            3    0.009121254      0.7291718           0.4057619
o       5            3    0.168144533      0.6221447           0.4572363
  max.detection.score
w           0.7291718
o           0.6221447
0 to 23.5 seconds
plot-methods              package:monitoR              R Documentation

_M_e_t_h_o_d_s _f_o_r _t_h_e '_p_l_o_t' _F_u_n_c_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     Plotting acoustic templates and template scores

_U_s_a_g_e:

     ## S4 method for signature 'TemplateList,ANY'
     plot(x, which.one = names(x@templates), click = FALSE, 
     ask = if(length(which.one)>1) TRUE else FALSE, spec.col = gray.3(), on.col = '#FFA50075', 
     off.col = '#0000FF75', pt.col = '#FFA50075', line.col = 'black')
     
     ## S4 method for signature 'detectionList,ANY'
     plot(x, flim = c(0, 12), scorelim, 
     which.one = names(x@templates), box = TRUE, spec.col = gray.2(), t.each = 30, 
     hit.marker = 'lines', 
     color = c('red', 'blue', 'green', 'orange', 'purple', 'pink', 'darkgreen', 'turquoise', 
     'royalblue', 'orchid4', 'brown', 'salmon2'), legend = TRUE, all.peaks = FALSE, 
     ask = if(dev.list() == 2) TRUE else FALSE)
     
_A_r_g_u_m_e_n_t_s:

       x: A template list ('TemplateList' object) or detection list
          ('detectionList' object).

which.one: Names of templates to be plotted.

   click: Set to 'TRUE' to see values of locations on plot by mouse
          clicks.

     ask: Set to 'FALSE' to eliminate pause between plots.

spec.col: Color ramp for spectrogram.

  on.col: Color for ``on'' points (binary templates only).

 off.col: Color for ``off'' points (binary templates only).

  pt.col: Color for template points (correlation templates only).

line.col: Color for lines if 'click = TRUE'.

    flim: Frequency limits for plot.

scorelim: Score limits for plot.

     box: If 'TRUE' boxes are plotted in spectrogram for each
          detection.

  t.each: Duration shown in each individual plot (s).

hit.marker: Type of marker used to show detections in score plot. Can
          be '"lines"' or '"points"'.

   color: Colors used for individual templates.

  legend: Show legend?

all.peaks: Indicate location of all peaks?

_A_u_t_h_o_r(_s):

     Sasha D. Hafner

_S_e_e _A_l_s_o:

     'makeCorTemplate', 'makeBinTemplate'

_E_x_a_m_p_l_e_s:

     ## Not run:
     
     # Not run because of the time required (maybe 5-10 seconds)
     # Also some plot calls require user input by default
     # Load data
     data(btnw)
     data(survey)
     
     # Write Wave objects to file (temporary directory used here)
     btnw.fp <- file.path(tempdir(), "btnw.wav")
     oven.fp <- file.path(tempdir(), "oven.wav")
     survey.fp <- file.path(tempdir(), "survey2010-12-31_120000_EST.wav")
     writeWave(btnw, btnw.fp)
     writeWave(survey, survey.fp)
     
     # Create a template list
     ctemp1 <- makeCorTemplate(btnw.fp, name = "w1")
     ctemp2 <- makeCorTemplate(btnw.fp, t.lim = c(0.5, 2.5), frq.lim = c(1, 10), dens = 0.1, name = "w2")
     ctemps <- combineCorTemplates(ctemp1, ctemp2)
     
     # Then it can be plotted like this
     plot(ctemps)
     
     # Next call is not useful for template w1 but good for w2:
     plot(ctemps, pt.col = "red")
     
     # Can plot just one template
     plot(ctemps, which.one = 2, pt.col = "red")
     plot(ctemps, which.one = "w2", pt.col = "red")
     
     # And to check values
     plot(ctemps, which.one = 1, click = TRUE)
     
     # To plot detections, let's create some
     cscores <- corMatch(survey.fp, ctemps)
     cdetects <- findPeaks(cscores)
     
     # And to plot them:
     plot(cdetects)
     
     # Clean up (only because these files were created in these examples)
     file.remove(btnw.fp)
     file.remove(survey.fp)
     ## End(Not run)
     


Automatic point selection.

Done.

Automatic point selection.

Done.

Starting  w . . .

	Fourier transform on survey . . .
	Continuing. . .

	Done.

Starting  o . . .

	Done.

Done with  w
Done with  o
Done

A "detectionList" object

Based on survey file:  /work/tmp/tmp/RtmpJaoGTT/survey2010-12-31_120000_EST.wav 

and  2  templates

Detection information
  n.peaks n.detections min.peak.score max.peak.score min.detection.score
w      31            1     -0.4115253       17.58376            17.58376
o       5            1      3.1192727       18.75724            18.75724
  max.detection.score
w            17.58376
o            18.75724
0 to 23.5 seconds
[1] TRUE
[1] TRUE
[1] TRUE

monitoR documentation built on May 1, 2019, 6:28 p.m.