Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak makie plots #485

Merged
merged 8 commits into from
Jul 30, 2023
Merged

Tweak makie plots #485

merged 8 commits into from
Jul 30, 2023

Conversation

rafaqz
Copy link
Owner

@rafaqz rafaqz commented Jul 29, 2023

This PR fixes pixel placement, adds methods for RasterSeries and automatically limits series or raster plotting to 16 tiles.

It also sets the color to :batlow to match the Plots.jl recipes.

@asinghvi17 maybe you want to review

Closes #428
Closes #431

@codecov-commenter
Copy link

codecov-commenter commented Jul 30, 2023

Codecov Report

Merging #485 (1a0df6d) into main (712570b) will decrease coverage by 0.06%.
The diff coverage is 38.46%.

@@            Coverage Diff             @@
##             main     #485      +/-   ##
==========================================
- Coverage   81.31%   81.25%   -0.06%     
==========================================
  Files          49       49              
  Lines        4116     4135      +19     
==========================================
+ Hits         3347     3360      +13     
- Misses        769      775       +6     
Files Changed Coverage Δ
ext/RastersMakieExt/plotrecipes.jl 0.00% <0.00%> (ø)
src/plotrecipes.jl 73.26% <62.06%> (+3.22%) ⬆️
...ersCoordinateTransformationsExt/affineprojected.jl 95.89% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@rafaqz rafaqz closed this Jul 30, 2023
@rafaqz rafaqz reopened this Jul 30, 2023
@rafaqz rafaqz merged commit 4de99aa into main Jul 30, 2023
14 checks passed
@rafaqz rafaqz deleted the tweak_makie_plots branch July 30, 2023 13:01
@tomchor
Copy link

tomchor commented Aug 4, 2023

I'm still working on a MWE, but I suspect this broke plotting for me. As an example, the code here is failing: https://tomchor.github.io/Oceanostics.jl/stable/generated/kelvin_helmholtz/

with the error:

ERROR: LoadError: MethodError: Cannot `convert` an object of type 
  DimArray{ColorTypes.RGBA{Float32}, 2, Tuple{Dim{:xC, DimensionalData.Dimensions.LookupArrays.Sampled{Float64, Vector{Float64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Points, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.NCDsource, Dict{String, Any}}}}, Dim{:zF, DimensionalData.Dimensions.LookupArrays.Sampled{Float64, Vector{Float64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Points, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.NCDsource, Dict{String, Any}}}}}, Tuple{}, Matrix{ColorTypes.RGBA{Float32}}, DimensionalData.NoName, DimensionalData.Dimensions.LookupArrays.NoMetadata} to an object of type 
  Union{ColorTypes.RGBA{Float32}, Matrix{ColorTypes.RGBA{Float32}}}

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:64

Stacktrace:
  [1] numbers_to_colors(numbers::DimArray{Float32, 2, Tuple{Dim{:xC, DimensionalData.Dimensions.LookupArrays.Sampled{Float64, Vector{Float64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Points, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.NCDsource, Dict{String, Any}}}}, Dim{:zF, DimensionalData.Dimensions.LookupArrays.Sampled{Float64, Vector{Float64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Points, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.NCDsource, Dict{String, Any}}}}}, Tuple{}, Matrix{Float32}, DimensionalData.NoName, DimensionalData.Dimensions.LookupArrays.NoMetadata}, colormap::Vector{ColorTypes.RGBA{Float32}}, colorscale::Function, colorrange::Vec{2, Float32}, lowclip::ColorTypes.RGBA{Float32}, highclip::ColorTypes.RGBA{Float32}, nan_color::ColorTypes.RGBA{Float32})
    @ Makie ~/.julia/packages/Makie/uAmck/src/colorsampler.jl:163
  [2] to_color(c::Makie.ColorMap{2, DimArray{Float32, 2, Tuple{Dim{:xC, DimensionalData.Dimensions.LookupArrays.Sampled{Float64, Vector{Float64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Points, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.NCDsource, Dict{String, Any}}}}, Dim{:zF, DimensionalData.Dimensions.LookupArrays.Sampled{Float64, Vector{Float64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Points, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.NCDsource, Dict{String, Any}}}}}, Tuple{}, Matrix{Float32}, DimensionalData.NoName, DimensionalData.Dimensions.LookupArrays.NoMetadata}, DimArray{Float32, 2, Tuple{Dim{:xC, DimensionalData.Dimensions.LookupArrays.Sampled{Float64, Vector{Float64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Points, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.NCDsource, Dict{String, Any}}}}, Dim{:zF, DimensionalData.Dimensions.LookupArrays.Sampled{Float64, Vector{Float64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Points, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.NCDsource, Dict{String, Any}}}}}, Tuple{}, Matrix{Float32}, DimensionalData.NoName, DimensionalData.Dimensions.LookupArrays.NoMetadata}})
    @ Makie ~/.julia/packages/Makie/uAmck/src/colorsampler.jl:258
  [3] draw_atomic(scene::Scene, screen::CairoMakie.Screen{CairoMakie.IMAGE}, primitive::Union{Image, Heatmap})
    @ CairoMakie ~/.julia/packages/CairoMakie/Ry75I/src/primitives.jl:643
  [4] draw_plot(scene::Scene, screen::CairoMakie.Screen{CairoMakie.IMAGE}, primitive::Heatmap{Tuple{Vector{Float32}, Vector{Float32}, DimArray{Float32, 2, Tuple{Dim{:xC, DimensionalData.Dimensions.LookupArrays.Sampled{Float64, Vector{Float64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Points, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.NCDsource, Dict{String, Any}}}}, Dim{:zF, DimensionalData.Dimensions.LookupArrays.Sampled{Float64, Vector{Float64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Points, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.NCDsource, Dict{String, Any}}}}}, Tuple{}, Matrix{Float32}, DimensionalData.NoName, DimensionalData.Dimensions.LookupArrays.NoMetadata}}})
    @ CairoMakie ~/.julia/packages/CairoMakie/Ry75I/src/infrastructure.jl:131
  [5] cairo_draw(screen::CairoMakie.Screen{CairoMakie.IMAGE}, scene::Scene)
    @ CairoMakie ~/.julia/packages/CairoMakie/Ry75I/src/infrastructure.jl:51
  [6] colorbuffer(screen::CairoMakie.Screen{CairoMakie.IMAGE})
    @ CairoMakie ~/.julia/packages/CairoMakie/Ry75I/src/screen.jl:307
  [7] colorbuffer(screen::CairoMakie.Screen{CairoMakie.IMAGE}, format::Makie.ImageStorageFormat)
    @ Makie ~/.julia/packages/Makie/uAmck/src/display.jl:363
  [8] recordframe!(io::VideoStream)
    @ Makie ~/.julia/packages/Makie/uAmck/src/ffmpeg-util.jl:242
  [9] Record(func::var"#49#50", figlike::Figure, iter::UnitRange{Int64}; kw_args::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:format, :framerate), Tuple{SubString{String}, Int64}}})
    @ Makie ~/.julia/packages/Makie/uAmck/src/recording.jl:168
 [10] record(func::Function, figlike::Figure, path::String, iter::UnitRange{Int64}; kw_args::Base.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:framerate,), Tuple{Int64}}})
    @ Makie ~/.julia/packages/Makie/uAmck/src/recording.jl:148
 [11] top-level scope
    @ ~/repos/Oceanostics.jl2/docs/examples/kelvin_helmholtz.jl:157
 [12] include(fname::String)
    @ Base.MainInclude ./client.jl:478
 [13] top-level scope
    @ REPL[24]:1
in expression starting at /home/tomas/repos/Oceanostics.jl2/docs/examples/kelvin_helmholtz.jl:157

This started a few days ago, coincidental with the release of version 0.8.1, which contains this PR, no?

@noahrhodes
Copy link

I am getting the same failure using the example from the Raster.jl docs

using CairoMakie, Makie
using Rasters, RasterDataSources, ArchGDAL
A = Raster(WorldClim{BioClim}, 5) # this is a 3D raster, so is not accepted.

fig = Figure()
plot(fig[1, 1], A)
contour(fig[1, 2], A)
ax = Axis(fig[2, 1]; aspect = DataAspect())
contourf!(ax, A)
surface(fig[2, 2], A) # even a 3D plot works!
fig

ERROR: MethodError: Cannot `convert` an object of type 
  DimArray{ColorTypes.RGBA{Float32}, 2, Tuple{X{Projected{Float64, LinRange{Float64, Int64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Intervals{DimensionalData.Dimensions.LookupArrays.Start}, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.GDALsource, Dict{String, Any}}, WellKnownText{GeoFormatTypes.CRS}, Nothing, X{Colon}}}, Y{Projected{Float64, LinRange{Float64, Int64}, DimensionalData.Dimensions.LookupArrays.ReverseOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Intervals{DimensionalData.Dimensions.LookupArrays.Start}, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.GDALsource, Dict{String, Any}}, WellKnownText{GeoFormatTypes.CRS}, Nothing, Y{Colon}}}}, Tuple{Rasters.Band{DimensionalData.Dimensions.LookupArrays.Categorical{Int64, UnitRange{Int64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.NoMetadata}}}, Matrix{ColorTypes.RGBA{Float32}}, Symbol, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.GDALsource, Dict{String, Any}}} to an object of type 
  Union{ColorTypes.RGBA{Float32}, Matrix{ColorTypes.RGBA{Float32}}}
Closest candidates are:
  convert(::Type{T}, ::T) where T at Base.jl:61
Stacktrace:
  [1] numbers_to_colors(numbers::DimArray{Float32, 2, Tuple{X{Projected{Float64, LinRange{Float64, Int64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Intervals{DimensionalData.Dimensions.LookupArrays.Start}, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.GDALsource, Dict{String, Any}}, WellKnownText{GeoFormatTypes.CRS}, Nothing, X{Colon}}}, Y{Projected{Float64, LinRange{Float64, Int64}, DimensionalData.Dimensions.LookupArrays.ReverseOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Intervals{DimensionalData.Dimensions.LookupArrays.Start}, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.GDALsource, Dict{String, Any}}, WellKnownText{GeoFormatTypes.CRS}, Nothing, Y{Colon}}}}, Tuple{Rasters.Band{DimensionalData.Dimensions.LookupArrays.Categorical{Int64, UnitRange{Int64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.NoMetadata}}}, Matrix{Float32}, Symbol, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.GDALsource, Dict{String, Any}}}, colormap::Vector{ColorTypes.RGBA{Float32}}, colorscale::Function, colorrange::Vec{2, Float32}, lowclip::ColorTypes.RGBA{Float32}, highclip::ColorTypes.RGBA{Float32}, nan_color::ColorTypes.RGBA{Float32})
    @ Makie C:\Users\noahx\.julia\packages\Makie\RgxaV\src\colorsampler.jl:163
  [2] to_color(c::Makie.ColorMapping{2, DimArray{Float32, 2, Tuple{X{Projected{Float64, LinRange{Float64, Int64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Intervals{DimensionalData.Dimensions.LookupArrays.Start}, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.GDALsource, Dict{String, Any}}, WellKnownText{GeoFormatTypes.CRS}, Nothing, X{Colon}}}, Y{Projected{Float64, LinRange{Float64, Int64}, DimensionalData.Dimensions.LookupArrays.ReverseOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Intervals{DimensionalData.Dimensions.LookupArrays.Start}, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.GDALsource, Dict{String, Any}}, WellKnownText{GeoFormatTypes.CRS}, Nothing, Y{Colon}}}}, Tuple{Rasters.Band{DimensionalData.Dimensions.LookupArrays.Categorical{Int64, UnitRange{Int64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.NoMetadata}}}, Matrix{Float32}, Symbol, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.GDALsource, Dict{String, Any}}}, DimArray{Float32, 2, Tuple{X{Projected{Float64, LinRange{Float64, Int64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Intervals{DimensionalData.Dimensions.LookupArrays.Start}, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.GDALsource, Dict{String, Any}}, WellKnownText{GeoFormatTypes.CRS}, Nothing, X{Colon}}}, Y{Projected{Float64, LinRange{Float64, Int64}, DimensionalData.Dimensions.LookupArrays.ReverseOrdered, DimensionalData.Dimensions.LookupArrays.Regular{Float64}, DimensionalData.Dimensions.LookupArrays.Intervals{DimensionalData.Dimensions.LookupArrays.Start}, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.GDALsource, Dict{String, Any}}, WellKnownText{GeoFormatTypes.CRS}, Nothing, Y{Colon}}}}, Tuple{Rasters.Band{DimensionalData.Dimensions.LookupArrays.Categorical{Int64, UnitRange{Int64}, DimensionalData.Dimensions.LookupArrays.ForwardOrdered, DimensionalData.Dimensions.LookupArrays.NoMetadata}}}, Matrix{Float32}, Symbol, DimensionalData.Dimensions.LookupArrays.Metadata{Rasters.GDALsource, Dict{String, Any}}}})
    @ Makie C:\Users\noahx\.julia\packages\Makie\RgxaV\src\colorsampler.jl:322

@rafaqz
Copy link
Owner Author

rafaqz commented Nov 13, 2023

Ok thanks. Can you put this in an issue instead, its hard to find comments in closed PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rplot fails for certain raster type Fix heatmap MAKIE recipe
4 participants