Code Monkey home page Code Monkey logo

peaks.jl's Issues

plotpeaks doesn't exist?

(@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

Add `findpeaks` as alias for `findmaxima`

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`
  • Other frameworks such as scipy and MATLAB use 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).

Add number of peaks to look for

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.

How to set width in `findmaxima`

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.

peaks for periodic data

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 😀

Wrong local maximum

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:

maxPeakfalse

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)

WrongPeak.csv

Am I doing something wrong here?

TagBot trigger issue

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!

Add absolute lower value

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.

Performance

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.

Bibliography

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

Functions are not importing

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.

Better discoverability of functions and keyword arguments

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"

Unusual behavior of peakprom?

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[]).

peakprom can't find a peak within the minimum distance `w` of the boundary

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.

peakheights and other not working with array of floats

Hello,

I'm trying to use this code to find peak position from an array of floats. However I'm getting this error:
image

If I run the example code with this array x = [0,5,2,3,3,1,4,0]; I do get a result, any idea of what is the problem?

Thanks in advance!

The API is not great

EDIT: See later comments, as the proposed API has changed significantly during this thread.

I find the current implementation of

  1. finding peaks
  2. redefining pks with the return values from peakproms and peakwidths
    to be rather weird and un-ergonomic. Something like what is implemented in https://github.com/tungli/Findpeaks.jl seems way more inntuitive for me, where there is only one function, and the peaks can be filtered by prominence and width directly by keyword arguments.

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)`

findpeaks from pracma

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).

add 4 to compat?

from a cursory glance there shouldn't be any issues with that

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.