org-arl / SignalAnalysis.jl

Signal analysis toolbox for Julia
MIT License
41 stars 10 forks source link

MethodError when trying to show created Signal in Pluto #25

Closed notthetup closed 2 years ago

notthetup commented 2 years ago

Running a simple Pluto notebook with

using SignalAnalysis, SignalAnalysis.Units
---------
chirp(5kHz, 7kHz, 100ms, 44.1kHz; shape=:hyperbolic, window=(tukey,0.05))

gives this...

Failed to show value:

MethodError: no method matching keys(::SignalAnalysis.SamplingInfo)

Closest candidates are:

keys(!Matched::Missings.EachFailMissing) at /Users/chinmay/.julia/packages/Missings/sx5js/src/Missings.jl:154

keys(!Matched::DataStructures.Trie) at /Users/chinmay/.julia/packages/DataStructures/ixwFs/src/trie.jl:82

keys(!Matched::DataStructures.Trie, !Matched::AbstractString) at /Users/chinmay/.julia/packages/DataStructures/ixwFs/src/trie.jl:82

...

showarg(::IOBuffer, ::MetaArrays.MetaArray{Vector{ComplexF64}, SignalAnalysis.SamplingInfo, ComplexF64, 1}, ::Bool)@MetaArrays.jl:118
var"#sprint#385"(::Nothing, ::Int64, ::typeof(sprint), ::Function, ::MetaArrays.MetaArray{Vector{ComplexF64}, SignalAnalysis.SamplingInfo, ComplexF64, 1}, ::Vararg{Any, N} where N)@io.jl:105
sprint(::Function, ::MetaArrays.MetaArray{Vector{ComplexF64}, SignalAnalysis.SamplingInfo, ComplexF64, 1}, ::Vararg{Any, N} where N)@io.jl:101
array_prefix(::Any)@PlutoRunner.jl:703
tree_data(::AbstractVector{var"#s84"} where var"#s84", ::IOContext{IOBuffer})@PlutoRunner.jl:785
show_richest(::IOContext{IOBuffer}, ::Any)@PlutoRunner.jl:639
var"#sprint_withreturned#28"(::IOContext{Base.DevNull}, ::Int64, ::typeof(Main.PlutoRunner.sprint_withreturned), ::Function, ::MetaArrays.MetaArray{Vector{ComplexF64}, SignalAnalysis.SamplingInfo, ComplexF64, 1})@PlutoRunner.jl:591
format_output_default(::Any, ::Any)@PlutoRunner.jl:515
#format_output#17@PlutoRunner.jl:532[inlined]
formatted_result_of(::Base.UUID, ::Bool, ::Nothing, ::Module)@PlutoRunner.jl:448
top-level scope@none:1
mchitre commented 2 years ago

No problem on REPL:

julia> using SignalAnalysis, SignalAnalysis.Units

julia> chirp(5kHz, 7kHz, 100ms, 44.1kHz; shape=:hyperbolic, window=(tukey,0.05))
SampledSignal @ 44100.0 Hz, 4410-element Vector{ComplexF64}:
                    0.0 - 0.0im
 0.00015368365272524137 + 0.0001327388027281813im
 0.00011810536015839258 + 0.0008034894213194122im
  -0.000980410986611016 + 0.0015412581539023496im
  -0.003108732228055483 + 0.0009334648998984505im
              :
mchitre commented 2 years ago

Confirmed error occurs as reported with Pluto. The reason is that Pluto calls Base.showarg(), which the MetaArrays package defines and calls Base.keys() on the meta data object, implicitly assuming that the object stored in meta data is a dictionary! The SignalAnalysis' metadata is stored in a struct SignalInfo, for which Base.keys() is not defined.

Simple fix: Base.keys(x::SignalAnalysis.SamplingInfo) = fieldnames(typeof(x))

mchitre commented 2 years ago

Works!

image