Skip to content

Commit 987a6e8

Browse files
authored
Merge pull request #5 from Circuitscape/vl/dev
LightGraphs => Graphs, GeoData => Rasters, some changes to type names
2 parents b7457a4 + 8b96328 commit 987a6e8

17 files changed

+100
-98
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ authors = ["Vincent A. Landau <[email protected]>"]
44
version = "0.0.1"
55

66
[deps]
7-
GeoData = "9b6fcbb8-86d6-11e9-1ce7-23a6bb139a78"
8-
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
7+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
8+
Rasters = "a3a2b9e3-a471-40c9-b274-f788e487c689"
99
SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622"
1010
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1111
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1212

1313
[compat]
14+
Graphs = "1.4"
15+
Rasters = "0.1"
1416
julia = "1.6"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
[![docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://docs.circuitscape.org/SpatialGraphs.jl/latest) | [![Build Status](https://github.com/Circuitscape/SpatialGraphs.jl/workflows/CI/badge.svg)](https://github.com/Circuitscape/SpatialGraphs.jl/actions?query=workflow%3ACI) [![codecov](https://codecov.io/gh/Circuitscape/SpatialGraphs.jl/branch/main/graph/badge.svg?token=67OX4UPWOL)](https://codecov.io/gh/Circuitscape/SpatialGraphs.jl)
66

77
SpatialGraphs.jl introduces the `AbstractSpatialGraph`. `AbstractSpatialGraphs`
8-
are a subtype of `LightGraphs.AbstractGraph`, and can be weighted or directed.
9-
AbstractSpatialGraphs are AbstractGraphs, so methods from LightGraphs.jl work right
8+
are a subtype of `Graphs.AbstractGraph`, and can be weighted or directed.
9+
AbstractSpatialGraphs are AbstractGraphs, so methods from Graphs.jl work right
1010
out of the box.
1111

1212
`AbstractSpatialGraph`s themselves contain an `AbstractGraph` in addition to
1313
metadata that details the spatial location of each vertex in the
1414
graph. At this time, only raster-based graph types have been developed (and
15-
vertex locations are stored in a `GeoData.GeoArray`), but there are plans to
15+
vertex locations are stored in a `Rasters.Raster`), but there are plans to
1616
implement graph types for vector data as well.

docs/src/graphtypes.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# [Graph Types in SpatialGraphs.jl](@id graph_types)
22

33
At this time, only raster-based graph types have been developed (and
4-
vertex locations are stored in a `GeoData.GeoArray`), but there are plans to
4+
vertex locations are stored in a `Rasters.Raster`), but there are plans to
55
eventually implement graph types for vector data as well.
66

77
## Abstract Types
@@ -12,9 +12,9 @@ an `AbstractGraph`.
1212
AbstractSpatialGraph
1313
```
1414

15-
The `AbstractRasterGraph` type is as subtype of `AbstractSpatialGraph`. All
15+
The `AbstractRasterGraph` type is a subtype of `AbstractSpatialGraph`. All
1616
`AbstractRasterGraph` subtypes contain a field called `vertex_raster`, which is
17-
a `GeoData.GeoArray` that describes the spatial locations for the vertices in
17+
a `Rasters.Raster` that describes the spatial locations for the vertices in
1818
the graph. If your graph has 10 vertices, then the corresponding `vertex_raster`
1919
must have 10 unique values, starting at 1 (which corresponds to the first vertex
2020
in the graph) and going up to 10 (which corresponds to the tenth vertex in the
@@ -30,8 +30,8 @@ SpatialGraphs.jl has raster graph types for undirected, directed, unweighted,
3030
and weighted graphs, each detailed below.
3131

3232
```@docs
33-
SimpleRasterGraph
34-
SimpleRasterDiGraph
33+
RasterGraph
34+
RasterDiGraph
3535
WeightedRasterGraph
3636
WeightedRasterDiGraph
3737
```

docs/src/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# SpatialGraphs.jl
22

33
SpatialGraphs.jl introduces the `AbstractSpatialGraph`. `AbstractSpatialGraphs`
4-
are a subtype of `LightGraphs.AbstractGraph`, and can be weighted or directed.
4+
are a subtype of `Graphs.AbstractGraph`, and can be weighted or directed.
55
SpatialGraphs.jl is useful for turning spatial data into graphs. This can be
66
useful for landscape connectivity analysis, hydrology, and other spatial
77
network processes. AbstractSpatialGraphs are AbstractGraphs, so methods from
8-
LightGraphs.jl work right out of the box. Go to [Graph Types](@ref graph_types)
8+
Graphs.jl work right out of the box. Go to [Graph Types](@ref graph_types)
99
for more details on the graph types implemented in this package.
1010

docs/src/userguide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ data.
77

88
### Simple Graphs
99
```@docs
10-
simplerastergraph
10+
rastergraph
1111
make_simple_raster_graph
1212
```
1313

src/SpatialGraphs.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module SpatialGraphs
22

3-
using LightGraphs, SimpleWeightedGraphs, SparseArrays, GeoData
3+
using Graphs, SimpleWeightedGraphs, SparseArrays, Rasters
44

55
include("structs.jl")
66
include("graph_interface.jl")
@@ -9,12 +9,12 @@ include("utils.jl")
99
include("show.jl")
1010

1111
## Types and Structs
12-
export AbstractSpatialGraph, AbstractRasterGraph, SimpleRasterGraph,
13-
SimpleRasterDiGraph, WeightedRasterGraph, WeightedRasterDiGraph
12+
export AbstractSpatialGraph, AbstractRasterGraph, RasterGraph,
13+
RasterDiGraph, WeightedRasterGraph, WeightedRasterDiGraph
1414

1515
## Raster graph
1616
export make_weighted_raster_graph, weightedrastergraph,
17-
make_simple_raster_graph, simplerastergraph
17+
make_simple_raster_graph, rastergraph
1818

1919

2020
end # module

src/graph_interface.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## Methods for the LightGraphs ad SimpleWeightedGraphs interfaces
2-
## With these methods defined, functions from LightGraphs should "just work"
3-
import LightGraphs:
1+
## Methods for the Graphs ad SimpleWeightedGraphs interfaces
2+
## With these methods defined, functions from Graphs should "just work"
3+
import Graphs:
44
nv, ne, vertices, edges, eltype, edgetype, has_edge, has_vertex,
55
inneighbors, outneighbors, is_directed, add_edge!
66

@@ -9,7 +9,7 @@ import SimpleWeightedGraphs:
99

1010
import Base: zero
1111

12-
### LightGraphs interface
12+
### Graphs interface
1313
nv(g::AbstractSpatialGraph) = nv(g.graph)
1414
ne(g::AbstractSpatialGraph) = ne(g.graph)
1515
vertices(g::AbstractSpatialGraph) = vertices(g.graph)
@@ -22,13 +22,13 @@ inneighbors(g::AbstractSpatialGraph, v) = inneighbors(g.graph, v)
2222
outneighbors(g::AbstractSpatialGraph, v) = outneighbors(g.graph, v)
2323
is_directed(g::AbstractSpatialGraph) = is_directed(g.graph)
2424
function Base.zero(g::AbstractRasterGraph)
25-
if g.graph isa SimpleGraph
26-
SimpleRasterGraph(
25+
if g.graph isa Graph
26+
RasterGraph(
2727
zero(typeof(g.graph)),
2828
g.vertex_raster
2929
)
30-
elseif g.graph isa SimpleDiGraph
31-
SimpleRasterDiGraph(
30+
elseif g.graph isa DiGraph
31+
RasterDiGraph(
3232
zero(typeof(g.graph)),
3333
g.vertex_raster
3434
)

src/rastergraphs.jl

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
"""
2-
make_vertex_raster(A::GeoArray)
2+
make_vertex_raster(A::Raster)
33
44
Constuct a vertex raster (a raster where the value of each pixel corresponds
5-
to its ID in a graph, and 0s correspond to NoData). Returns a GeoArray. This
5+
to its ID in a graph, and 0s correspond to NoData). Returns a Raster. This
66
function is recommended for internal use only.
77
88
## Parameters
9-
`A`: The GeoArray from which a graph will be built, which is used as the
9+
`A`: The Raster from which a graph will be built, which is used as the
1010
reference for building the vertex raster. Pixels with NoData (`A.missingval`)
1111
are skipped (no vertex is assigned). Pixels with NoData will get a value of 0 in
1212
the vertex raster.
1313
"""
14-
function make_vertex_raster(A::GeoData.GeoArray)
14+
function make_vertex_raster(A::Raster)
1515
# Make an array of unique node identifiers
1616
nodemap = zeros(Int64, size(A.data))
1717
is_node = (A.data .!= A.missingval) .&
1818
((!).(isnan.(A.data)))
1919

2020
nodemap[is_node] = 1:sum(is_node)
2121

22-
nodemap = GeoData.GeoArray(nodemap, dims(A))
22+
nodemap = Raster(nodemap, dims(A))
2323

2424
nodemap
2525
end
2626

2727

2828
"""
2929
weightedrastergraph(
30-
weight_raster::GeoArray;
30+
weight_raster::Raster;
3131
directed::Bool = false,
32-
condition_raster::GeoArray = weight_raster,
32+
condition_raster::Raster = weight_raster,
3333
condition::Function = is_data,
3434
cardinal_neighbors_only::Bool = false,
3535
connect_using_avg_weights::Bool = true
@@ -42,7 +42,7 @@ on vertices, edge weights are calculated as the average of the weights for each
4242
vertex.
4343
4444
## Parameters
45-
`weight_raster`: A GeoData.GeoArray contained values that, where applicable
45+
`weight_raster`: A Rasters.Raster contained values that, where applicable
4646
based on other arguments, determines which pixels to connect and the edge
4747
weights between pixels. Any pixel in `weight_raster` with a value not equal to
4848
`weight_raster.missingval` will be assigned a vertex in the graph (corresponding
@@ -90,9 +90,9 @@ neighbors) of the weights in `weight_raster` is used.
9090
9191
"""
9292
function weightedrastergraph(
93-
weight_raster::GeoArray;
93+
weight_raster::Raster;
9494
directed::Bool = false,
95-
condition_raster::GeoArray = weight_raster,
95+
condition_raster::Raster = weight_raster,
9696
condition::Function = is_data,
9797
cardinal_neighbors_only::Bool = false,
9898
connect_using_avg_weights::Bool = true
@@ -119,18 +119,18 @@ function weightedrastergraph(
119119
end
120120

121121
"""
122-
simplerastergraph(
123-
raster::GeoArray;
122+
RasterGraph(
123+
raster::Raster;
124124
directed::Bool = true,
125125
condition::Function = is_data,
126126
cardinal_neighbors_only::Bool = false
127127
)
128128
129-
Construct a `SimpleRasterGraph` or `SimpleRasterDiGraph` (if
129+
Construct a `RasterGraph` or `RasterDiGraph` (if
130130
`directed = true`) from a raster dataset.
131131
132132
## Parameters
133-
`raster`: A GeoData.GeoArray on which to base the graph. Any pixel in `raster`
133+
`raster`: A Rasters.Raster on which to base the graph. Any pixel in `raster`
134134
with a value not equal to `raster.missingval` will be assigned a vertex
135135
in the graph (corresponding to its centroid). The values in the raster can also
136136
be used to determine which vertices to connect. See `condition` below for more
@@ -161,8 +161,8 @@ connected. Note that when determining weights between diagonal neighbors, the
161161
increased distance between them (as compared to the distance between cardinal
162162
neighbors) is accounted for.
163163
"""
164-
function simplerastergraph(
165-
raster::GeoArray;
164+
function rastergraph(
165+
raster::Raster;
166166
condition::Function = is_data,
167167
directed::Bool = true,
168168
cardinal_neighbors_only::Bool = false,
@@ -177,20 +177,20 @@ function simplerastergraph(
177177
)
178178

179179
if directed
180-
sg = SimpleRasterDiGraph(g, v)
180+
sg = RasterDiGraph(g, v)
181181
else
182-
sg = SimpleRasterGraph(g, v)
182+
sg = RasterGraph(g, v)
183183
end
184184

185185
return sg
186186
end
187187

188188
"""
189189
make_weighted_raster_graph(
190-
weight_raster::GeoArray,
191-
vertex_raster::GeoArray;
190+
weight_raster::Raster,
191+
vertex_raster::Raster;
192192
directed::Bool = false,
193-
condition_raster::GeoArray = weight_raster,
193+
condition_raster::Raster = weight_raster,
194194
condition::Function = is_data,
195195
cardinal_neighbors_only::Bool = false,
196196
connect_using_avg_weights::Bool = true,
@@ -206,13 +206,13 @@ vertex. Since edges are between rather than on vertices, edge weights are
206206
calculated as the average of the weights for each vertex being connected.
207207
208208
## Parameters
209-
`weight_raster`: A `GeoData.GeoArray` containing values that, where applicable
209+
`weight_raster`: A `Rasters.Raster` containing values that, where applicable
210210
based on other arguments, determine which pixels to connect and the edge
211211
weights between pixels. Any pixel in `weight_raster` with a value not equal to
212212
`weight_raster.missingval` will be assigned a vertex in the graph (corresponding
213213
to its centroid).
214214
215-
`vertex_raster`: A `GeoData.GeoArray` with integer values ranging from 1:n,
215+
`vertex_raster`: A `Rasters.Raster` with integer values ranging from 1:n,
216216
where n is the number of unique vertices in the graph.
217217
218218
## Arguments
@@ -256,10 +256,10 @@ of vertices, how should the weight be chosen? Defaults to `min`. See the docs
256256
for `SparseArrays.sparse()` for more information.
257257
"""
258258
function make_weighted_raster_graph(
259-
weight_raster::GeoArray,
260-
vertex_raster::GeoArray;
259+
weight_raster::Raster,
260+
vertex_raster::Raster;
261261
directed::Bool = false,
262-
condition_raster::GeoArray = weight_raster,
262+
condition_raster::Raster = weight_raster,
263263
condition::Function = is_data,
264264
cardinal_neighbors_only::Bool = false,
265265
connect_using_avg_weights::Bool = true,
@@ -289,8 +289,8 @@ end
289289

290290
"""
291291
make_simple_raster_graph(
292-
raster::GeoArray,
293-
vertex_raster::GeoArray;
292+
raster::Raster,
293+
vertex_raster::Raster;
294294
directed::Bool = false,
295295
condition::Function = is_data,
296296
cardinal_neighbors_only::Bool = false,
@@ -305,13 +305,13 @@ in the graph, and `raster` is used to construct the graph and determine which
305305
vertices to connect.
306306
307307
## Parameters
308-
`raster`: A GeoData.GeoArray on which to base the graph. Any pixel in `raster`
308+
`raster`: A Rasters.Raster on which to base the graph. Any pixel in `raster`
309309
with a value not equal to `raster.missingval` will be assigned a vertex
310310
in the graph (corresponding to its centroid). The values in the raster can also
311311
be used to determine which vertices to connect. See `condition` below for more
312312
information.
313313
314-
`vertex_raster`: A `GeoData.GeoArray` with integer values ranging from 1:n,
314+
`vertex_raster`: A `Rasters.Raster` with integer values ranging from 1:n,
315315
where n is the number of unique vertices in the graph.
316316
317317
## Arguments
@@ -355,8 +355,8 @@ of vertices, how should the weight be chosen? Defaults to `min`. See the docs
355355
for `SparseArrays.sparse()` for more information.
356356
"""
357357
function make_simple_raster_graph(
358-
raster::GeoArray,
359-
vertex_raster::GeoArray;
358+
raster::Raster,
359+
vertex_raster::Raster;
360360
directed::Bool = false,
361361
condition::Function = is_data,
362362
cardinal_neighbors_only::Bool = false,
@@ -378,11 +378,11 @@ end
378378

379379

380380
function make_raster_graph(
381-
raster::GeoArray,
382-
vertex_raster::GeoArray;
381+
raster::Raster,
382+
vertex_raster::Raster;
383383
directed::Bool = false,
384384
weighted::Bool = true,
385-
condition_raster::GeoArray = raster,
385+
condition_raster::Raster = raster,
386386
condition::Function = is_data,
387387
cardinal_neighbors_only::Bool = false,
388388
connect_using_avg_weights::Bool = true,
@@ -410,7 +410,7 @@ function make_raster_graph(
410410
# Add the edges
411411
# Only need to do neighbors down or to the right for undirected graphs
412412
# because edge additions will be redundant.
413-
# Cardinal directions are in quotes since sometimes GeoArray are permuted
413+
# Cardinal directions are in quotes since sometimes Raster are permuted
414414
# such that the top row doesn't necessarily correspond to the northern-most
415415
# pixels
416416
for row in 1:dims[1]
@@ -587,7 +587,7 @@ function make_raster_graph(
587587
)
588588
else
589589
n_nodes = max(maximum(sources), maximum(destinations))
590-
g = SimpleDiGraph(
590+
g = DiGraph(
591591
sparse(sources, destinations, 1, n_nodes, n_nodes, combine)
592592
)
593593
end
@@ -601,7 +601,7 @@ function make_raster_graph(
601601
)
602602
else
603603
n_nodes = max(maximum(sources), maximum(destinations))
604-
g = SimpleGraph(
604+
g = Graph(
605605
sparse(
606606
vcat(sources, destinations),
607607
vcat(destinations, sources),

src/show.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function show(io::IO, g::AbstractRasterGraph)
1212
)
1313
printstyled(" with dimensions:\n", color=:light_black)
1414

15-
x_dim = dims(g.vertex_raster, XDim)
16-
y_dim = dims(g.vertex_raster, YDim)
15+
x_dim = dims(g.vertex_raster, X)
16+
y_dim = dims(g.vertex_raster, Y)
1717
printstyled(" X", color=:cyan)
1818
print(
1919
": range($(minimum(x_dim)), $(maximum(x_dim)), step=$(x_dim.val[2] - x_dim.val[1]))\n"

0 commit comments

Comments
 (0)