From f9818c66bb2e116000dba32f72a1f229263f8556 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Sat, 28 Oct 2023 21:31:14 +0200 Subject: [PATCH] fix makie for RGB rasters (#553) --- Project.toml | 3 +-- ext/RastersMakieExt/plotrecipes.jl | 9 ++++----- test/plotrecipes.jl | 7 ++++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Project.toml b/Project.toml index 20b8bf781..2ddbc0b0c 100644 --- a/Project.toml +++ b/Project.toml @@ -66,7 +66,6 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" -MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b" NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" RasterDataSources = "3cb90ccd-e1b6-4867-9617-4276c8b2ca36" @@ -76,7 +75,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Aqua", "ArchGDAL", "CFTime", "CoordinateTransformations", "DataFrames", "GeometryBasics", "HDF5", "MakieCore", "NCDatasets", "Plots", "RasterDataSources", "SafeTestsets", "Shapefile", "Statistics", "Test"] +test = ["Aqua", "ArchGDAL", "CFTime", "CoordinateTransformations", "DataFrames", "GeometryBasics", "HDF5", "NCDatasets", "Plots", "RasterDataSources", "SafeTestsets", "Shapefile", "Statistics", "Test"] [weakdeps] ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3" diff --git a/ext/RastersMakieExt/plotrecipes.jl b/ext/RastersMakieExt/plotrecipes.jl index c851da237..299701d4c 100644 --- a/ext/RastersMakieExt/plotrecipes.jl +++ b/ext/RastersMakieExt/plotrecipes.jl @@ -345,8 +345,7 @@ function _series_dim(A) last((dims(A, spatialdims)..., otherdims(A, spatialdims)...)) end -function _prepare_dimarray(A) - map(A) do x - isequal(x, missingval(A)) || ismissing(x) ? NaN32 : Float32(x) - end |> DimArray -end +_prepare_dimarray(A) = DimArray(map(x -> _convert_with_missing(x, missingval(A)), A)) + +_convert_with_missing(x::Real, missingval) = isequal(x, missingval) || ismissing(x) ? NaN32 : Float32(x) +_convert_with_missing(x, missingval) = isequal(x, missingval) ? missing : x diff --git a/test/plotrecipes.jl b/test/plotrecipes.jl index 319b98dd6..b236bca82 100644 --- a/test/plotrecipes.jl +++ b/test/plotrecipes.jl @@ -56,7 +56,7 @@ if !haskey(ENV, "CI") ys = -20.0:1.0:20.0 rast = Raster(rand(X(xs), Y(ys))) - using Makie + using GLMakie # Some small diversions from the DimensionalData.jl recipes @test Makie.convert_arguments(Makie.DiscreteSurface(), rast) == (lookup(rast, X), lookup(rast, Y), Float32.(rast.data)) @@ -74,4 +74,9 @@ if !haskey(ENV, "CI") Makie.heatmap(ga3) Rasters.rplot(ga2) Rasters.rplot(ga3) + + using Colors + c = Raster(rand(RGB, X(10), Y(10))) + Makie.image(c) + # Makie.heatmap(c) # Doesn't work because of the auto Colorbar end