Skip to content

Commit 3aaa850

Browse files
author
tungli
committed
added a test and corrections to docs
1 parent f6ded5b commit 3aaa850

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/findpeaks.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ end
3535
x::Array{S}=collect(1:length(y))
3636
;min_height::T=minimum(y), min_prom::T=minimum(y),
3737
min_dist::S=0, threshold::T=0 ) where {T<:Real,S}`\n
38-
Returns indices of local maxima (sorted from highest peaks to lowest)
39-
in 1D array of real numbers. Similar to MATLAB's findpeaks().\n
38+
39+
Finds peaks in 1D array. Similar to MATLAB's findpeaks().\n
40+
Returns:\n
41+
* tuple of peak positions found
42+
* a tuple of `PeakInfo` structures with additional information about peaks.
43+
4044
*Arguments*:\n
4145
`y` -- data\n
4246
*Optional*:\n
@@ -97,7 +101,6 @@ function findpeaks(
97101

98102
peak_info = [PeakInfo{T}(heights[i], ldiffs[i], rdiffs[i], proms[i], 1:1) for i in 1:length(inds2keep)]
99103

100-
101104
grouped = group_plateaus(peaks, peak_info, min_plateau_points, max_plateau_points)
102105
@on_empty_return(grouped, x)
103106

test/findpeaks.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ end
3939
expected_peak_1 = argmin(abs.(x .- positions[2])) # global highest peak
4040
expected_peak_2 = argmin(abs.(x .- positions[4])) # lowest peak
4141

42-
# check peaks are around expected - may be shifted because of background
42+
# check peaks are around expected -> they may be shifted because of background
4343
@test abs(peaks[1] - expected_peak_1) < 20
4444
@test abs(peaks[2] - expected_peak_2) < 20
4545
end
@@ -93,6 +93,12 @@ end
9393
@test Set(findpeaks(y)[1]) == Set([4])
9494
end
9595

96+
@testset "$NAME Threshold with height" begin
97+
y = [0., 1., 3., 2., 4., 2., 1., 0.]
98+
@test Set(findpeaks(y, min_height=2.9)[1]) == Set([3, 5])
99+
@test Set(findpeaks(y, min_height=2.9, threshold=2.)[1]) == Set([5])
100+
end
101+
96102
@testset "$NAME Empty inputs" begin
97103
y1 = Float64[]
98104
x1 = Int64[]

0 commit comments

Comments
 (0)