Skip to content

Commit 9b4a288

Browse files
author
Vincent Landau
committed
add test for simplerasterdigraph
1 parent e050f28 commit 9b4a288

File tree

5 files changed

+69
-11
lines changed

5 files changed

+69
-11
lines changed

src/rastergraphs.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ increased distance between them (as compared to the distance between cardinal
162162
neighbors) is accounted for.
163163
"""
164164
function simplerastergraph(
165-
raster::GeoArray;
166-
condition::Function = is_data,
167-
directed::Bool = true,
168-
cardinal_neighbors_only::Bool = false,
169-
)
170-
v = make_vertex_raster(weight_raster)
165+
raster::GeoArray;
166+
condition::Function = is_data,
167+
directed::Bool = true,
168+
cardinal_neighbors_only::Bool = false,
169+
)
170+
v = make_vertex_raster(raster)
171171
g = make_simple_raster_graph(
172172
raster,
173-
vertex_raster,
173+
v,
174174
directed = directed,
175175
condition = condition,
176176
cardinal_neighbors_only = cardinal_neighbors_only

test/runtests.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using Test, SpatialGraphs
22

3-
@testset "Raster Graph Construction" begin
4-
include("rastergraphs.jl")
3+
@testset "Weighted Raster Graph Construction" begin
4+
include("weightedrastergraphs.jl")
55
end
66

7-
@testset "Raster DiGraph Construction" begin
8-
include("rasterdigraphs.jl")
7+
@testset "Simple Raster DiGraph Construction" begin
8+
include("simplerasterdigraphs.jl")
9+
end
10+
11+
@testset "Weighted Raster DiGraph Construction" begin
12+
include("weightedrasterdigraphs.jl")
913
end

test/simplerasterdigraphs.jl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using GeoData, LightGraphs, SimpleWeightedGraphs, SpatialGraphs, Test
2+
3+
condition_array = Array{Float64}(undef, (3, 4, 1))
4+
condition_array[:,:,:] = [1, 3, 5, 2, 4, 8, 5, -9999, 2, 3, 6, 7]
5+
6+
x = X(1:4)
7+
y = Y(1:3)
8+
band = Band(1:1)
9+
10+
condition_raster = GeoArray(condition_array, (y, x, band), missingval = -9999)
11+
12+
compare = <
13+
rasgraph = simplerastergraph(
14+
condition_raster,
15+
directed = true,
16+
condition = compare
17+
)
18+
19+
# no vertices in NoData pixels?
20+
@test (rasgraph.vertex_raster .== 0) ==
21+
((condition_raster .== condition_raster.missingval) .|
22+
isnan.(condition_raster))
23+
24+
# Is the number of of vertices correct, and is the range of values correct?
25+
@test sort(collect(rasgraph.vertex_raster[rasgraph.vertex_raster .!= 0])) ==
26+
collect(1:sum(
27+
(condition_raster .!= condition_raster.missingval) .&
28+
(!).(isnan.(condition_raster))
29+
))
30+
31+
graph_edges = collect(edges(rasgraph))
32+
33+
# Test that the edges are correct and have proper weights
34+
for i in 1:length(graph_edges)
35+
source_i = src(graph_edges[i])
36+
dest_i = dst(graph_edges[i])
37+
38+
source_coords = findall(rasgraph.vertex_raster .== source_i)[1]
39+
dest_coords = findall(rasgraph.vertex_raster .== dest_i)[1]
40+
41+
# Check that condition is met
42+
@test compare(
43+
condition_raster[source_coords],
44+
condition_raster[dest_coords]
45+
)
46+
47+
# Test that source row is within 1 step of dest row
48+
row_diff = abs(source_coords[1] - dest_coords[1])
49+
@test row_diff <= 1
50+
51+
# Test that source column is within 1 step of dest row
52+
col_diff = abs(source_coords[2] - dest_coords[2])
53+
@test col_diff <= 1
54+
end
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)