halleysfifthinc / peaks.jl Goto Github PK
View Code? Open in Web Editor NEWFind peaks (local extrema) of signals
Home Page: https://halleysfifthinc.github.io/Peaks.jl/
License: MIT License
Find peaks (local extrema) of signals
Home Page: https://halleysfifthinc.github.io/Peaks.jl/
License: MIT License
(@v1.8) pkg> activate --temp
(jl_H5YLNr) pkg> add Peaks Plots
--- snip ---
Precompiling project...
41 dependencies successfully precompiled in 70 seconds. 94 already precompiled.
(jl_H5YLNr) pkg> st
Status `/tmp/jl_H5YLNr/Project.toml`
[18e31ff7] Peaks v0.4.1
[91a5bcdd] Plots v1.36.2
julia> using Peaks, Plots
julia> plotpeaks
ERROR: UndefVarError: plotpeaks not defined
As previously discussed, some users are likely to find findpeaks
to be a more natural name than findmaxima
. There are likely two potential reasons:
findpeaks
aligns better with the package name "Peaks.jl`findpeaks
for this functionality.In my opinion, the second point weighs the most. But the first also makes obvious to me that this is a good idea.
Because findmaxima
is already exported, and provides a more explicit distinction between minima (findminima
) and maxima, it is useful to keep around. But it would not hurt to export const findpeaks = findmaxima
(I think const is good here...?), which would not increase the "surface area" of the source code (no extra docstring, the underlying function is the only function to compile, etc).
It is currently not hard to do manually, but it would be very convenient to have a keyword argument to some function see #24
that set the maximal and/or minimal number of peaks to look for, defaulting to 0
and Inf
. I am using this in the context of calibrating a spectrogram, where I know the number of peaks I am looking for in advance, and in reality I just want the 4 most prominent peaks.
If I have a vector v
, and want to find all peaks so that it is the highest value in the interval [i-w:i+w]
, how do I do it? The docs says
findmaxima(x[, w=1; strict=true]) -> (idxs, vals)
but I really do not understand what syntax to use, e.g.
findmaxima(x[, w=1; strict=true])
does not work. I can do
findmaxima(x)
but then I have w=1
, which I not necessarily want.
Hi,
I was wondering if it was possible to include an option to detect peaks in periodic data?
E.g. if I'm having a simple cos(x)
curve over an x
range of 0 to 2π, then it would be nice if findmaxima()
would detect x=0
(or x=2π
) as a maxima.
As a workaround I assume one can just shift the data and search for maxima in there?!
( MWE:findmaxima([cos(ϕ) for ϕ in 0:2π])
gives no peaks. )
Cheers 😀
I tried to to find the local maxima of my data with this package. It worked very well except for two points where the results seem wrong. An example with reduced data:
Here is the code to reproduce this with the attached data (with CSV.jl):
w = 327
CSVData = CSV.File("WrongPeak.csv")
x = CSVData.Column1
y = CSVData.Column2
pks, vals = findmaxima(y, w)
plotpeaks(x, y, peaks=pks, scale=:log10)
Am I doing something wrong here?
It would be very nice to get an option to get a minimal peak separation, such as that found in https://github.com/tungli/Findpeaks.jl.
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
Again, this is not hard to implement manually. But it would be very nice to be able to specify a lower bound for not only the peak prominence, but also the absolute value.
I am a little bit surprised about the performance of argmaxima
compared with a direct implementation:
using Test, BenchmarkTools
using Peaks
function localmaxmin!(y, maxs::Vector{Int}, mins::Vector{Int})
empty!(maxs)
empty!(mins)
for i in 2:length(y)-1
if y[i+1] < y[i] > y[i-1]
push!(maxs, i)
elseif y[i+1] > y[i] < y[i-1]
push!(mins, i)
end
end
end
function localmaxmin2!(x, maxs, mins)
append!(maxs2, argmaxima(x))
append!(mins2, argminima(x))
maxs2, mins2
end
function localmax(y)
maxs = Int[]
for i in 2:length(y)-1
if y[i+1] < y[i] > y[i-1]
push!(maxs, i)
end
end
maxs
end
function localmax2(x)
maxs2 = argmaxima(x)
end
maxs = Int[]
mins = Int[]
maxs2= Int[]
mins2 = Int[]
x = zeros(100000)
x_max = 2:100:100000
x[x_max] .= 1
x_min = 5:100:100000
x[x_min] .= -1
localmaxmin!(x, maxs, mins)
localmaxmin2!(x, maxs2, mins2)
@test maxs == maxs2
@test mins == mins2
@btime localmax(x)
@btime localmax2(x)
@test localmax(x) == localmax2(x)
On my laptop, this returns
102.428 μs (10 allocations: 16.39 KiB)
380.387 μs (6 allocations: 398.92 KiB)
Test Passed
which is 3 times slower.
!(-0. < 0.) && !(-0. > 0.)
# BUT:
-0. !== 0.
# BUT:
argmaxima([-1., -0., 0., -1.]) != [2]
Arguably the last line should be considered a plateau. (Egal is also overly strict for arrays of non-isbits types for which == and === are even more likely to disagree.)
HI,
Do you have some bibliography explaining the implemented code?
I would like to understand how the algorithm of finding peaks (and the prominences) works
Thank you!
Ignacio
On Julia v1.0 I installed the package Pkg.add("Peaks")
and then using Peaks
and none of the functions are usable. My interpreter doesn't recognize the commands.
thanks for this package!
i'd suggest providing links to these alternatives in your README and differentiating your features from them. or join forces to provide the ultimate peak finder!
https://github.com/JuliaImages/Images.jl/blob/master/src/algorithms.jl#L464
Currently, the readme and plot therein look to me like they demo the package. However, they do not show examples of setting the minimum window width w
, nor do they demo the peakheights
function.
I suggest:
a) All functions are shown in the readme, perhaps in a complete list, or that
b) the readme is made more barebones, and that users are referred to the documentation for fuller examples, which should include examples using peakheight
and w
?
Or some combination of the two:
"The filtering functions are seen in the table below, and full examples can be found in the docs"
Maxima of an array of all zeros is
julia> peakprom(zeros(10), Maxima())
([2, 4, 6, 8], [0.0, 0.0, 0.0, 0.0])
instead of (Int64[], Float64[])
.
Calculating the extrema of an array with peakprom
it would be nice to be able to switch off the strictbounds
imposed by the maxima
/minima
.
Maybe something like
...
@eval begin
function peakprom(x::AbstractVector{T}, ::$Extrema, w=1, minprom::T=zero(T), strictbounds::Bool=true) where T
if ($Extrema) === Maxima
m = maxima(x, w, strictbounds)
else
m = minima(x, w, strictbounds)
end
...
would already be enough.
EDIT: See later comments, as the proposed API has changed significantly during this thread.
I find the current implementation of
pks
with the return values from peakproms
and peakwidths
If a redo is on the table, I just want to mention an idea I have had:
With the package called "Peaks", I was expecting "findpeaks" to be the main function. It could return a FoundPeaks
object (Can not be same as package, perhaps other names for the type is better) that contains the peaks, the indices, the prominence, and the widths. It would also be nice to be able to provide the x-values, and get the corresponding x-values for the peaks and widths in terms of x-values, rather than having to work with indices always. Ofc the indices should also be part of the returned object.
Then, the API could be something like
xs = 0:0.1:10
ys = rand(length(xs))
pks = findpeaks(ys) # Only have indices as x-units
pks = findpeaks(xs, ys) # Return x-coordinate of peaks, and width in units of the x-coordinate
# Access fields, reads almost like english words.
# Internal implementation could be pks.fieldname, allowing
# internal changes to be non-breaking in the future to remain flexible
index(pks)
location(pks) # for getting x-vals
width(pks)
width(pks, ind=false) # kwarg to select indices or x-vals as unit
prominence(pks)
seperation(pks) # Or just exemplify with `diff(index(pks))` or `diff(location(pks)`
hi,
I've implemented findpeaks
as found in the pracma R package (https://github.com/cran/pracma). The original author gave his OK for a transcription into Julia, now the question is, if you are open to accept this function as a PR. (I don't want to create/register/maintain a package just for a single function, and your package Peaks.jl
looks like a good candidate to include such a function).
from a cursory glance there shouldn't be any issues with that
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.