rafaqz / DimensionalData.jl

Named dimensions and indexing for julia arrays and other data
https://rafaqz.github.io/DimensionalData.jl/stable/
MIT License
274 stars 39 forks source link

Cannot plot Raster based from Geotiff #625

Closed felixcremer closed 7 months ago

felixcremer commented 7 months ago

I am trying to plot a band from a geotiff that I opened with Rasters. The plot command works but when I try to show the Figure it fails with the error below. This seems to have nothing to do with the actual data but is somewhere in the font handling code. I am opening the issue here, because it is not happening when I plot a normal Array. The underlying data is the testdata from ArchGDAL.

@SimonDanisch maybe you have some idea?

julia> ras = Raster("dev/ArchGDAL/test/gdalworkshop/world.tif")
2048×1024×3 Raster{UInt8,3} with dimensions: 
  X Projected{Float64} LinRange{Float64}(-180.0, 179.824, 2048) ForwardOrdered Regular Intervals{Start} crs: WellKnownText,
  Y Projected{Float64} LinRange{Float64}(89.8242, -90.0, 1024) ReverseOrdered Regular Intervals{Start} crs: WellKnownText,
  Band Categorical{Int64} 1:3 ForwardOrdered
extent: Extent(X = (-180.0, 180.0), Y = (-90.0, 90.0), Band = (1, 3))
crs: GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
parent:
[:, :, 1]
             89.8242    89.6484    89.4727    89.2969    89.1211    88.9453    88.7695    88.5938  …   -88.7695   -88.9453   -89.1211   -89.2969   -89.4727   -89.6484   -89.8242   -90.0
 -180.0    0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd0       0xcf       0xd0       0xd0       0xd5       0xd9       0xd6       0xd0
 -179.824  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd2       0xd1       0xd2       0xd3       0xd8       0xdb       0xd8       0xd2
 -179.648  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd4       0xd3       0xd4       0xd5       0xda       0xde       0xda       0xd4
 -179.473  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd4       0xd4       0xd4       0xd5       0xda       0xde       0xdb       0xd4
 -179.297  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       …  0xd3       0xd2       0xd3       0xd4       0xd9       0xdd       0xd9       0xd3
 -179.121  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd2       0xd2       0xd2       0xd3       0xd8       0xdc       0xd9       0xd2
 -178.945  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd3       0xd2       0xd3       0xd4       0xd9       0xdd       0xd9       0xd3
 -178.77   0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd4       0xd4       0xd4       0xd5       0xda       0xde       0xdb       0xd4
 -178.594  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd3       0xd3       0xd5       0xd5       0xd9       0xdc       0xda       0xd5
 -178.418  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       …  0xd3       0xd3       0xd5       0xd5       0xd9       0xdc       0xda       0xd5
 -178.242  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd3       0xd3       0xd5       0xd5       0xd9       0xdc       0xda       0xd5
    ⋮                                                     ⋮                                        ⋱     ⋮                                                      ⋮                  
  177.891  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd0       0xd2       0xd4       0xd4       0xd6       0xd8       0xd6       0xd2
  178.066  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd0       0xd2       0xd4       0xd4       0xd6       0xd8       0xd6       0xd2
  178.242  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       …  0xd0       0xd2       0xd4       0xd4       0xd6       0xd8       0xd6       0xd2
  178.418  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd0       0xd2       0xd4       0xd4       0xd6       0xd8       0xd6       0xd2
  178.594  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd4       0xd5       0xd4       0xd5       0xd8       0xdc       0xd9       0xd4
  178.77   0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd0       0xd1       0xd0       0xd0       0xd4       0xd7       0xd5       0xd0
  178.945  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd3       0xd4       0xd4       0xd4       0xd7       0xdb       0xd9       0xd3
  179.121  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       …  0xd4       0xd5       0xd5       0xd5       0xd9       0xdc       0xda       0xd4
  179.297  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd1       0xd2       0xd1       0xd1       0xd5       0xd8       0xd6       0xd1
  179.473  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd5       0xd6       0xd5       0xd6       0xd9       0xdd       0xda       0xd5
  179.648  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xd4       0xd5       0xd5       0xd5       0xd9       0xdc       0xda       0xd4
  179.824  0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c       0x0c          0xc7       0xc8       0xc8       0xc8       0xcb       0xcf       0xcd       0xc7
[and 2 more slices...]

julia> heatmap(ras[Band=1])
Error showing value of type Makie.FigureAxisPlot:
ERROR: MethodError: no method matching mean(::SubArray{Float64, 2, Matrix{Float64}, Tuple{UnitRange{Int64}, UnitRange{Int64}}, false})

Closest candidates are:
  mean(::AbstractArray, ::StatsBase.UnitWeights; dims)
   @ StatsBase ~/.julia/packages/StatsBase/WLz8A/src/weights.jl:687
  mean(::AbstractArray, ::StatsBase.AbstractWeights; dims)
   @ StatsBase ~/.julia/packages/StatsBase/WLz8A/src/weights.jl:680
  mean(::AbstractArray{T}, ::StatsBase.AbstractWeights{W, T} where T<:Real, ::Int64) where {T<:Number, W<:Real}
   @ StatsBase deprecated.jl:103
  ...

Stacktrace:
  [1] downsample(img::Matrix{Float64}, xsize::Int64, ysize::Int64)
    @ SignedDistanceFields ~/.julia/packages/SignedDistanceFields/RNoSO/src/SignedDistanceFields.jl:78
  [2] sdf
    @ ~/.julia/packages/SignedDistanceFields/RNoSO/src/SignedDistanceFields.jl:64 [inlined]
  [3] sdistancefield(img::Matrix{UInt8}, downsample::Int32, pad::Int32)
    @ Makie ~/.julia/packages/Makie/QGPt0/src/utilities/texture_atlas.jl:355
  [4] render(atlas::Makie.TextureAtlas, ::Tuple{UInt64, FreeTypeAbstraction.FTFont})
    @ Makie ~/.julia/packages/Makie/QGPt0/src/utilities/texture_atlas.jl:383
  [5] (::Makie.var"#58#59"{Makie.TextureAtlas, Tuple{UInt64, FreeTypeAbstraction.FTFont}})()
    @ Makie ~/.julia/packages/Makie/QGPt0/src/utilities/texture_atlas.jl:313
  [6] get!(default::Makie.var"#58#59"{Makie.TextureAtlas, Tuple{UInt64, FreeTypeAbstraction.FTFont}}, h::Dict{UInt32, Int64}, key::UInt32)
    @ Base ./dict.jl:479
  [7] insert_glyph!
    @ ~/.julia/packages/Makie/QGPt0/src/utilities/texture_atlas.jl:312 [inlined]
  [8] insert_glyph!
    @ ~/.julia/packages/Makie/QGPt0/src/utilities/texture_atlas.jl:304 [inlined]
  [9] glyph_index!(atlas::Makie.TextureAtlas, glyph::UInt64, font::FreeTypeAbstraction.FTFont)
    @ Makie ~/.julia/packages/Makie/QGPt0/src/utilities/texture_atlas.jl:276
 [10] glyph_uv_width!
    @ ~/.julia/packages/Makie/QGPt0/src/utilities/texture_atlas.jl:284 [inlined]
 [11] text_quads(atlas::Makie.TextureAtlas, position::Vector{Point{3, Float32}}, gcs::Vector{Makie.GlyphCollection}, offset::Tuple{Float64, Float64}, transfunc::Function, space::Symbol)
    @ Makie ~/.julia/packages/Makie/QGPt0/src/layouting/layouting.jl:329
 [12] (::GLMakie.var"#252#263"{Makie.TextureAtlas})(pos::Vector{Point{3, Float32}}, gc::Vector{Makie.GlyphCollection}, offset::Tuple{Float64, Float64}, transfunc::Function, space::Symbol)
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/drawing_primitives.jl:524
 [13] map(::GLMakie.var"#252#263"{Makie.TextureAtlas}, ::Union{Scene, Plot}, ::Observable{Vector{…}}, ::Observable{Vector{…}}, ::Vararg{Any}; ignore_equal_values::Bool, priority::Int64)
    @ Makie ~/.julia/packages/Makie/QGPt0/src/scenes.jl:160
 [14] map(::GLMakie.var"#252#263"{Makie.TextureAtlas}, ::Union{Scene, Plot}, ::Observable{Vector{Point{3, Float32}}}, ::Observable{Vector{Makie.GlyphCollection}}, ::Vararg{Any})
    @ Makie ~/.julia/packages/Makie/QGPt0/src/scenes.jl:157
 [15] (::GLMakie.var"#251#262"{GLMakie.Screen{GLFW.Window}, Scene, MakieCore.Text{Tuple{Vector{Makie.GlyphCollection}}}})(gl_attributes::Dict{Symbol, Any})
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/drawing_primitives.jl:523
 [16] (::GLMakie.var"#209#216"{GLMakie.var"#251#262"{GLMakie.Screen{GLFW.Window}, Scene, MakieCore.Text{Tuple{…}}}, GLMakie.Screen{GLFW.Window}, Scene, MakieCore.Text{Tuple{Vector{…}}}})()
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/drawing_primitives.jl:305
 [17] get!(default::GLMakie.var"#209#216"{GLMakie.var"#251#262"{…}, GLMakie.Screen{…}, Scene, MakieCore.Text{…}}, h::Dict{UInt64, GLMakie.GLAbstraction.RenderObject}, key::UInt64)
    @ Base ./dict.jl:479
 [18] cached_robj!(robj_func::GLMakie.var"#251#262"{GLMakie.Screen{…}, Scene, MakieCore.Text{…}}, screen::GLMakie.Screen{GLFW.Window}, scene::Scene, plot::MakieCore.Text{Tuple{…}})
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/drawing_primitives.jl:234
 [19] draw_atomic(screen::GLMakie.Screen{GLFW.Window}, scene::Scene, plot::MakieCore.Text{Tuple{Vector{Makie.GlyphCollection}}})
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/drawing_primitives.jl:512
 [20] insert!(screen::GLMakie.Screen{GLFW.Window}, scene::Scene, x::Plot)
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/drawing_primitives.jl:322
 [21] (::GLMakie.var"#223#224"{GLMakie.Screen{GLFW.Window}, Scene})(x::MakieCore.Text{Tuple{Vector{Makie.GlyphCollection}}})
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/drawing_primitives.jl:327
 [22] foreach(f::GLMakie.var"#223#224"{GLMakie.Screen{GLFW.Window}, Scene}, itr::Vector{Plot})
    @ Base ./abstractarray.jl:3097
 [23] insert!
    @ ~/.julia/packages/GLMakie/UPCfE/src/drawing_primitives.jl:324 [inlined]
 [24] (::GLMakie.var"#223#224"{GLMakie.Screen{GLFW.Window}, Scene})(x::MakieCore.Text{Tuple{Vector{Point{3, Float32}}}})
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/drawing_primitives.jl:327
 [25] foreach(f::GLMakie.var"#223#224"{GLMakie.Screen{GLFW.Window}, Scene}, itr::Vector{Plot})
    @ Base ./abstractarray.jl:3097
 [26] insert!(screen::GLMakie.Screen{GLFW.Window}, scene::Scene, x::Plot)
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/drawing_primitives.jl:324
 [27] insertplots!(screen::GLMakie.Screen{GLFW.Window}, scene::Scene)
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/screen.jl:477
 [28] insertplots!(screen::GLMakie.Screen{GLFW.Window}, scene::Scene)
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/screen.jl:480
 [29] display_scene!(screen::GLMakie.Screen{GLFW.Window}, scene::Scene)
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/screen.jl:408
 [30] GLMakie.Screen(scene::Scene, config::GLMakie.ScreenConfig; visible::Nothing, start_renderloop::Bool)
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/screen.jl:425
 [31] GLMakie.Screen(scene::Scene, config::GLMakie.ScreenConfig)
    @ GLMakie ~/.julia/packages/GLMakie/UPCfE/src/screen.jl:421
 [32] getscreen(::Module, ::Scene, ::Dict{Symbol, Any})
    @ Makie ~/.julia/packages/Makie/QGPt0/src/display.jl:427
 [33] display(figlike::Makie.FigureAxisPlot; backend::Module, inline::Bool, update::Bool, screen_config::@Kwargs{})
    @ Makie ~/.julia/packages/Makie/QGPt0/src/display.jl:165
 [34] display(figlike::Makie.FigureAxisPlot)
    @ Makie ~/.julia/packages/Makie/QGPt0/src/display.jl:130
 [35] #invokelatest#2
    @ ./essentials.jl:892 [inlined]
 [36] invokelatest
    @ ./essentials.jl:889 [inlined]
 [37] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL ~/.julia/juliaup/julia-1.10.1+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:315
 [38] (::REPL.var"#57#58"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/.julia/juliaup/julia-1.10.1+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:284
 [39] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-1.10.1+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:569
 [40] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/.julia/juliaup/julia-1.10.1+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:282
 [41] (::REPL.var"#do_respond#80"{Bool, Bool, REPL.var"#93#103"{…}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/.julia/juliaup/julia-1.10.1+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:911
 [42] (::VSCodeServer.var"#101#104"{REPL.var"#do_respond#80"{Bool, Bool, REPL.var"#93#103"{…}, REPL.LineEditREPL, REPL.LineEdit.Prompt}})(mi::REPL.LineEdit.MIState, buf::IOBuffer, ok::Bool)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.66.2/scripts/packages/VSCodeServer/src/repl.jl:122
 [43] #invokelatest#2
    @ ./essentials.jl:892 [inlined]
 [44] invokelatest
    @ ./essentials.jl:889 [inlined]
 [45] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/.julia/juliaup/julia-1.10.1+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/LineEdit.jl:2656
 [46] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/.julia/juliaup/julia-1.10.1+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:1312
 [47] (::REPL.var"#62#68"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ~/.julia/juliaup/julia-1.10.1+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:386
Some type information was truncated. Use `show(err)` to see complete types.
SimonDanisch commented 7 months ago

That's a really weird error.... I can't explain it unless some package incorrectly overloaded base array methods... Note the stack trace:

ERROR: MethodError: no method matching mean(::SubArray{Float64, 2, Matrix{Float64}, Tuple{UnitRange{Int64}, UnitRange{Int64}}, false})

  ...

Stacktrace:
  [1] downsample(img::Matrix{Float64}, xsize::Int64, ysize::Int64)

So there is an error in downsample which gets called with a completely normal array. This function gets called in font rendering code, which only gets called if a font + glyph hasn't been added to the texture atlas already (most glyphs + default fonts are already in there).

So I suspect, the recipe renders a new glyph, and somewhere some incorrectly overloaded array methods break the font rendering. It could be a Makie problem, but the function that errors hasn't been changed in ages and most dependencies for it neither.

rafaqz commented 7 months ago

How can there be no mean method for SubArray ?

Where is the AbstractArray method??

felixcremer commented 7 months ago

I restarted my computer and now I can't reproduce the issue anymore. I am going to close this for now until I get a proper reproducer.

felixcremer commented 7 months ago

This was a Revise bug which deleted the fallback. This is fixed in Revise 3.5.14.

rafaqz commented 7 months ago

Ahh yes I've been getting that with other things too