UCD4IDS / ContinuousWavelets.jl

wide array of continuous wavelet transforms using Julia
https://dsweber2.github.io/ContinuousWavelets.jl/dev/
Other
21 stars 7 forks source link

Error calling `range` when running basic example from readme #35

Closed ThomasChaffey closed 2 years ago

ThomasChaffey commented 2 years ago

Running the basic example from the readme file:

    function CWT_example()
            n = 2047;
            t = range(0, n/1000, length = n); # 1kHz sampling rate
            f = testfunction(n, "Doppler");
            p1 = plot(t, f, legend = false, title="Doppler", xticks=false)
            c = wavelet(Morlet(π), β = 2);
            res = ContinuousWavelets.cwt(f, c)
            freqs = getMeanFreq(ContinuousWavelets.computeWavelets(n, c)[1])
            freqs[1] = 0
            p2 = heatmap(t,freqs, abs.(res)', xlabel= "time (s)", ylabel="frequency (Hz)",colorbar=false)
            l = @layout [a{.3h};b{.7h}]
            plot(p1,p2,layout=l)
    end

gives the following error:

  ┌ Warning: the lowest frequency wavelet has more than 1% its max at zero, so it may not be analytic. Think carefully
  │   lowAprxAnalyt = 0.06186323501016359
  └ @ ContinuousWavelets ~/.julia/packages/ContinuousWavelets/rDi28/src/sanityChecks.jl:6
  ┌ Warning: the lowest frequency wavelet has more than 1% its max at zero, so it may not be analytic. Think carefully
  │   lowAprxAnalyt = 0.06186323501016359
  └ @ ContinuousWavelets ~/.julia/packages/ContinuousWavelets/rDi28/src/sanityChecks.jl:6
  ERROR: LoadError: ArgumentError: range(0.0, stop=1000.0, length=1): endpoints differ
  Stacktrace:
    [1] _linspace1(#unused#::Type{Float64}, start::Float64, stop::Float64, len::Int64)
      @ Base ./twiceprecision.jl:678
    [2] _range(start::Float64, #unused#::Nothing, stop::Float64, len::Int64)
      @ Base ./twiceprecision.jl:595
    [3] _range
      @ ./range.jl:437 [inlined]
    [4] _range2
      @ ./range.jl:100 [inlined]
    [5] #range#58
      @ ./range.jl:94 [inlined]
    [6] getMeanFreq(Ŵ::Matrix{Float64}, fsample::Int64)
      @ ContinuousWavelets ~/.julia/packages/ContinuousWavelets/rDi28/src/utils.jl:248
    [7] getMeanFreq(Ŵ::Matrix{Float64})
      @ ContinuousWavelets ~/.julia/packages/ContinuousWavelets/rDi28/src/utils.jl:247
    [8] CWT_example()
ThomasChaffey commented 2 years ago

I guess line 248 of utils.jl should be either

  freqs = range(0, fsample / 2, length=size(Ŵ, 1))

or

  freqs = range(0, fsample / 2, length=size(Ŵ, 2))

Both give an answer (but neither looks that sensible. Apologies, I'm an absolute beginner at wavelets).

There are other issues in the Readme: the calls to heatmap break with the error

  MethodError: no method matching heatmap_edges(::Surface{Matrix{Float64}}, ::Symbol)

And NaiveDual() and PenroseDual() should be replaced with NaiveDelta() and PenroseDelta().

dsweber2 commented 2 years ago

I suppose this is why they tell you to put the documentation in a doctest. Its fixed.