Skip to content

Commit be4c984

Browse files
authored
Add isequal dispatch on Pyramid (#91)
* Add isequal dispatch on Pyramid This tests isequal on all levels separately this should be faster and also more correct. This will also catch if two pyramids are from the same data but with different aggregation functions. * Add test for different base but same levels and for different number of levels * Make Makie imports explicit
1 parent b5ff435 commit be4c984

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

ext/PyramidSchemeMakieExt.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module PyramidSchemeMakieExt
2-
using Makie: Axis, Colorbar, DataAspect, Figure, FigureAxisPlot, Observable, Relative
2+
using Makie: Makie, Axis, Colorbar, DataAspect, Figure, FigureAxisPlot, Observable, Relative, Point2f, Rect3f
33
using Makie: on, heatmap!, map!
44
using Makie.ComputePipeline: add_input!
5-
using Makie
5+
using Makie: Heatmap, Image, Contour, Contourf, Contour3d, Spy, Surface
66

77
using PyramidScheme: Pyramid, switchkeys, levels, selectlevel, xkey, ykey
88
using DimensionalData: DimensionalData as DD

src/PyramidScheme.jl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and the `buildpyramids` function to generate the aggregation layers for an exist
77
"""
88
module PyramidScheme
99

10-
using DiskArrayEngine: DiskArrayEngine, GMDWop, InputArray, LocalRunner, MovingWindow, RegularWindows
10+
using DiskArrayEngine: DiskArrayEngine, GMDWop, InputArray, LocalRunner, RegularWindows
1111
using DiskArrayEngine: create_outwindows, engine
1212
using DiskArrays: DiskArrays
1313
#using YAXArrays: savecube
@@ -18,8 +18,8 @@ using DimensionalData: DimensionalData as DD
1818
using DimensionalData.Dimensions: XDim, YDim
1919
using Extents: Extent, extent, intersects
2020
using FillArrays: Zeros
21-
using Proj
22-
using OffsetArrays
21+
using Proj: Proj
22+
using OffsetArrays: OffsetArray
2323

2424
using Statistics: mean
2525

@@ -89,6 +89,17 @@ Return the number of levels of the `pyramid`
8989
nlevels(pyramid::Pyramid) = length(levels(pyramid)) - 1
9090
Base.parent(pyramid::Pyramid) = pyramid.base
9191
Base.size(pyramid::Pyramid) = size(parent(pyramid))
92+
function Base.isequal(pyrA::Pyramid, pyrB::Pyramid)
93+
nlevela = nlevels(pyrA)
94+
nlevelb = nlevels(pyrB)
95+
nlevela != nlevelb && return false
96+
for i in nlevela:-1:1
97+
isequal(pyrA.levels[i], pyrB.levels[i]) || return false
98+
end
99+
return isequal(pyrA.base, pyrB.base)
100+
end
101+
102+
# all(isequal.(reverse(PyramidScheme.levels(pyrA)), reverse(PyramidScheme.levels(pyrB))))
92103

93104
DD.name(pyramid::Pyramid) = DD.name(parent(pyramid))
94105
DD.refdims(pyramid::Pyramid) = DD.refdims(parent(pyramid))

test/runtests.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ end
168168
using DimensionalData
169169
pyr1 = Pyramid(fill(1,X(1:128),Y(1:128)), tilesize=16)
170170
pyr2 = Pyramid(fill(1, X(1:128),Y(1:128)), tilesize=16, resampling_method=sum)
171+
171172
pyr1_neg = map(x-> x-1, pyr1)
172173
@test all(all.(iszero, pyr1_neg.levels))
173174
@test iszero(pyr1_neg.base)
@@ -196,6 +197,27 @@ end
196197
limits!(ax, 200,300, 200, 300)
197198
@test cb.limits[] == [-0.5, 0.5]
198199
end
200+
201+
@testitem "isequal of two pyramids" begin
202+
using DimensionalData
203+
pyr1 = Pyramid(fill(1, X(1:128),Y(1:128)), tilesize=16)
204+
pyr2 = Pyramid(fill(1, X(1:128),Y(1:128)), tilesize=16, resampling_method=sum)
205+
@test !isequal(pyr1, pyr2)
206+
207+
a = fill(1, 100,100)
208+
a[1:2:end, 1:2:end] .= 2
209+
a[2:2:end, 2:2:end] .= 2
210+
dda = DimArray(a, (X(1:100), Y(1:100)))
211+
pyra = Pyramid(dda, tilesize=25)
212+
213+
b = fill(2, 100,100)
214+
b[1:2:end, 1:2:end] .= 1
215+
b[2:2:end, 2:2:end] .= 1
216+
ddb = DimArray(b, (X(1:100), Y(1:100)))
217+
pyrb = Pyramid(ddb, tilesize=25)
218+
@test !isequal(pyra, pyrb)
219+
@test !isequal(pyra, pyr1)
220+
end
199221
#=
200222
@testitem "Comparing zarr pyramid with tif pyramid" begin
201223
using PyramidScheme: PyramidScheme as PS

0 commit comments

Comments
 (0)