Skip to content

Commit 5d45d14

Browse files
committed
Add eltype keyword to Pyramid construction and make plotting handle Float16 types
1 parent ce0d278 commit 5d45d14

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

ext/PyramidSchemeMakieExt.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using PyramidScheme: Pyramid, switchkeys, levels, selectlevel, xkey, ykey
88
using DimensionalData: DimensionalData as DD
99
using DimensionalData.Dimensions: XDim, YDim
1010
using Extents: Extent, extent, intersects
11-
miss2nan(x) = ismissing(x) ? NaN : x
11+
miss2nan(T::Type) = x -> ismissing(x) ? T(NaN) : x
1212

1313
# hacks to get around DD hacks that get around Makie issues
1414
for p in (Heatmap, Image, Contour, Contourf, Contour3d, Spy, Surface)
@@ -77,8 +77,8 @@ function Makie.plot!(plot::Heatmap{<: Tuple{<: Pyramid}})
7777
datalimit = switchkeys(data_limits_ext, pyramid_ext)
7878

7979
if intersects(pyramid_data_ext, data_limits_ext)
80-
data[] = miss2nan.(
81-
selectlevel(pyramid, datalimit, target_imsize = pixel_widths)
80+
data[] = miss2nan(nonmissingtype(eltype(data[]))).(
81+
selectlevel(pyramid, datalimit, target_imsize = pixel_widths),
8282
)
8383
end
8484
nothing

src/PyramidScheme.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct Pyramid{T,N,D,A,B<:DD.AbstractDimArray{T,N,D,A},L, Me} <: DD.AbstractDimA
3939
metadata::Me
4040
end
4141

42-
function Pyramid(data::DD.AbstractDimArray; resampling_method= mean skipmissing, kwargs...)
43-
pyrdata, pyraxs = getpyramids(resampling_method, data; kwargs...)
42+
function Pyramid(data::DD.AbstractDimArray; resampling_method= mean skipmissing, eltype=nothing, kwargs...)
43+
pyrdata, pyraxs = getpyramids(resampling_method, data; eltype, kwargs...)
4444
levels = DD.DimArray.(pyrdata, pyraxs)
4545
meta = Dict(deepcopy(DD.metadata(data)))
4646
push!(meta, "resampling_method" => "mean_skipmissing")
@@ -352,7 +352,8 @@ function buildpyramids(path::AbstractString; resampling_method=mean, recursive=t
352352
#tfunc = typeof(resampling_method(zeros(eltype(org), 2,2)))
353353
#t = Missing <: eltype(org) ? Union{Missing, tfunc} : tfunc
354354

355-
t = Base.infer_return_type(resampling_method, (Matrix{nonmissingtype(eltype(org))},))
355+
t = Base.infer_return_type(resampling_method, (Matrix{eltype(org)},))
356+
356357
n_level = compute_nlevels(org)
357358
input_axes = DD.dims(org, spatial_dims)
358359
outarrs = [output_zarr(n, DD.dims(org), t, joinpath(path, string(n)),input_axes) for n in 1:n_level]
@@ -414,7 +415,7 @@ end
414415
Compute the data of the pyramids of a given data cube `ras`.
415416
This returns the data of the pyramids and the dimension values of the aggregated axes.
416417
"""
417-
function getpyramids(reducefunc, ras;recursive=true, tilesize=256, spatial_dims=SpatialDim)
418+
function getpyramids(reducefunc, ras;recursive=true, tilesize=256, spatial_dims=SpatialDim, eltype=nothing)
418419
input_axes = DD.dims(ras)
419420
n_level = compute_nlevels(ras, tilesize)
420421
if iszero(n_level)
@@ -423,7 +424,11 @@ function getpyramids(reducefunc, ras;recursive=true, tilesize=256, spatial_dims=
423424
end
424425
pyramid_sizes = [ceil.(Int, size(ras) ./ 2^i) for i in 1:n_level]
425426
pyramid_axes = [agg_axis.(input_axes,2^i) for i in 1:n_level]
426-
outtype = Base.infer_return_type(reducefunc, (Matrix{eltype(ras)},))
427+
if isnothing(eltype)
428+
outtype = Base.infer_return_type(reducefunc, (Matrix{eltype(ras)},))
429+
else
430+
outtype = eltype
431+
end
427432
#outtype = Missing <: eltype(ras) ? Union{Missing, outtypefunc} : outtypefunc
428433
outmin = output_arrays(pyramid_sizes, outtype)
429434
ispatial_dims = DD.dimnum(DD.dims(ras),spatial_dims)

0 commit comments

Comments
 (0)