Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Jul 29, 2023
1 parent 7b89002 commit f35ded9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
10 changes: 6 additions & 4 deletions ext/RastersMakieExt/plotrecipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ function Rasters.rplot(
end

function Rasters.rplot(
gp::GridPosition, series::Union{<:AbstractRasterSeries,Observable{<:AbstractRasterSeries}};
gp::GridPosition,
series::Union{<:AbstractRasterSeries{<:Any,1},Observable{<:AbstractRasterSeries{<:Any,1}}};
ncols=Makie.automatic,
nrows=Makie.automatic,
kw...
Expand All @@ -160,7 +161,8 @@ function Rasters.rplot(

nrows, ncols, plotinds = if ncols isa Makie.Automatic && nrows isa Makie.Automatic
_, plotinds, nplots = Rasters._maybe_thin_plots(val_series)
Rasters._balance_grid(nplots)..., plotinds
nrows, ncols = Rasters._balance_grid(nplots)
nrows, ncols, plotinds
elseif ncols isa Int && nrows isa Int
nrows, ncols, eachindex(series)
else
Expand All @@ -169,8 +171,8 @@ function Rasters.rplot(

layout = GridLayout(gp, nrows, ncols)

for i in plotinds
ax, plt = Rasters.rplot(layout[fldmod1(i, ncols)...], lift_layer(series, i); kw...)
for (i, ip) in enumerate(plotinds)
ax, plt = Rasters.rplot(layout[fldmod1(i, ncols)...], lift_layer(series, ip); kw...)
if fldmod1(i, ncols)[1] != nrows
hidexdecorations!(ax; HIDE_DEC...)
end
Expand Down
12 changes: 6 additions & 6 deletions src/plotrecipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ struct RasterZPlot end
DD.DimensionalPlot(), ddplot(A)
elseif all(hasdim(A, (SpatialDim, SpatialDim)))
# Heatmap or multiple heatmaps. Use Rasters recipes.
A = _prepare(_subsample(A, max_res))
A = _prepare_plots(_subsample(A, max_res))
RasterPlot(), A
elseif hasdim(A, ZDim) && ndims(A) == 1
# Z dim plot, but for spatial data we want Z on the Y axis
RasterZPlot(), _prepare(A)
RasterZPlot(), _prepare_plots(A)
else
# Otherwise use DD recipes
DD.DimensionalPlot(), ddplot(A)
Expand Down Expand Up @@ -96,7 +96,7 @@ end
:xguide --> xguide
:yguide --> yguide
:label --> ""
z = map(_prepare, dims(A))
z = map(_prepare_plots, dims(A))
parent(A), index(z)
end

Expand Down Expand Up @@ -262,7 +262,6 @@ end
function MakieCore.convert_arguments(
::MakieCore.VolumeLike, raster::AbstractRaster{<:Union{Real,Missing},3,<:Tuple{D1,D2,D3}}
) where {D1<:SpatialDim,D2<:SpatialDim,D3<:SpatialDim}
@show "here"
A = _prepare_makie(raster)
xs, ys, zs = lookup(A)
return (xs, ys, zs, parent(A))
Expand Down Expand Up @@ -332,7 +331,8 @@ function _makie_not_implemented_error(t, r::AbstractRaster{T,N}) where {T,N}
"""
end

_prepare_makie(A) = replace_missing(read(_missing_or_float32.(_prepare(A))); missingval=NaN32)
_prepare_makie(A) =
replace_missing(read(_missing_or_float32.(_reorder(A))); missingval=NaN32)

# initial definitions of `rplot`, to get around the extension package availability question

Expand Down Expand Up @@ -387,7 +387,7 @@ end
# So we should center the index, and use the projected value.
_prepare(d::Dimension) = d |> _maybe_shift |> _maybe_mapped
# Convert arrays to a consistent missing value and Forward array order
_prepare(A::AbstractRaster) = A |> _reorder |> _permute
_prepare_plots(A::AbstractRaster) = A |> _reorder |> _permute
_reorder(A) = reorder(A, DD.ForwardOrdered)
_permute(A) = permutedims(A, DD.commondims(>:, (ZDim, YDim, XDim, TimeDim, Dimension), dims(A)))

Expand Down
1 change: 1 addition & 0 deletions test/sources/ncdatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ end

@testset "Raster" begin
@time ncarray = Raster(ncsingle)
plot(ncarray)

@time lazyarray = Raster(ncsingle; lazy=true);
@time eagerarray = Raster(ncsingle; lazy=false);
Expand Down

0 comments on commit f35ded9

Please sign in to comment.