Skip to content

Commit 7f8743b

Browse files
author
Vincent Landau
committed
clean up dockstrings
1 parent b9b1f06 commit 7f8743b

File tree

2 files changed

+61
-64
lines changed

2 files changed

+61
-64
lines changed

docs/src/userguide.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
## Building Graphs from Rasters
44

55
SpatialGraphs.jl offers several functions for constructing graphs from raster
6-
data.
6+
data, which are detailed below. Once you have converted your data to an
7+
[`AbstractSpatialGraph`](@ref AbstractSpatialGraph), you can analyze the graph
8+
using funtions from Graphs.jl. Following you analysis, you can then use the
9+
spatial information stored in the `AbstractSpatialGraph` to map values
10+
(such as betweenness or cost distance, for example) back to the appropriate
11+
points in space. See the [Examples](@ref Examples) section for a detailed
12+
demonstration of how this can be done.
713

814
### Simple Graphs
915
```@docs

src/rastergraphs.jl

Lines changed: 54 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
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 Raster. 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 Raster 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.
@@ -36,14 +36,14 @@ end
3636
)
3737
3838
Construct a `WeightedRasterGraph` or `WeightedRasterDiGraph` (if
39-
`directed = true`) from a raster dataset. The weight raster, denotes
39+
`directed = true`) from a raster dataset. The weight raster denotes
4040
the edge weight correponding to each vertex. Since edges are between rather than
4141
on vertices, edge weights are calculated as the average of the weights for each
4242
vertex.
4343
4444
## Parameters
45-
`weight_raster`: A Rasters.Raster contained values that, where applicable
46-
based on other arguments, determines which pixels to connect and the edge
45+
`weight_raster`: A `Rasters.Raster` containing values that, where applicable
46+
based on other arguments, determine 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
4949
to its centroid).
@@ -53,23 +53,23 @@ to its centroid).
5353
5454
`condition_raster`: A raster with values that can be used to determine whether
5555
two neighboring pixels should be connected. For example, an elevation raster
56-
can be used to create a hydologic flow graph.
56+
can be used to create a hydologic flow graph. Defaults to the `weight_raster`.
5757
5858
`condition`: A function that compares the values in `condition_raster` for two
5959
neighbors to determine if those neighbors should be connected. The function must
6060
compare two values and return either `true` or `false`. Useful functions to use
6161
here include `<`, `<=`, `==`, etc. The first argument to `condition` corresponds
6262
to the source vertex, and the second argument corresponds to the destination
63-
vertex. So, if you only want to connect sources to destinations with a lower
64-
value in `condition_raster` (e.g. in the case of developing a hydrologic flow
65-
graph based on elevation), then you would use `<` for `condition`. Defaults to
66-
`is_data`, which results in neighbors being connected as long as they are not
67-
NoData (`condition_raster.missingval`) in `condition_raster`. Note that if using
63+
vertex. So, if you only want to connect sources to destinations that have a
64+
lower value in `condition_raster` (e.g. in the case of developing a hydrologic
65+
flow graph based on elevation), then you would use `>` for `condition`. Defaults
66+
to `is_data`, which results in neighbors being connected as long as they are not
67+
NoData in `condition_raster` (`condition_raster.missingval`). Note that if using
6868
an inequality function (or any function where the result depends on argument
69-
position), the graph must be directed. For undirected graphs, you can use either
70-
`is_data` or `==`, or any other custom function where argument position doesn't
71-
matter, e.g. a function that determines whether the values in `condition_raster`
72-
are within a certain distance of each other.
69+
position), `directed` should be set to `true`. For undirected graphs, you can
70+
use either `is_data` or `==`, or any other custom function where argument
71+
position doesn't matter, e.g. a function that determines whether the values in
72+
`condition_raster` are within a certain distance of each other.
7373
7474
`cardinal_neighbors_only`: A `Bool` stating whether only cardinal neighbors
7575
should be connected. By default, both cardinal _and_ diagonal neighbors are
@@ -86,7 +86,7 @@ taking the inverse of the result to convert back to resistance:
8686
`1 / ((1/R1 + 1/R2) / 2)`. `connect_using_avg_weights = false` corresponds to
8787
the default settings in Circuitscape. Defaults to `true`, in which case the
8888
simple average (adjusted for distance in the case of diagonal
89-
neighbors) of the weights in `weight_raster` is used.
89+
neighbors) of the weights in `weight_raster` is used.
9090
9191
"""
9292
function weightedrastergraph(
@@ -118,18 +118,18 @@ function weightedrastergraph(
118118
end
119119

120120
"""
121-
RasterGraph(
121+
rastergraph(
122122
raster::Raster;
123123
directed::Bool = true,
124124
condition::Function = is_data,
125125
cardinal_neighbors_only::Bool = false
126126
)
127127
128-
Construct a `RasterGraph` or `RasterDiGraph` (if
129-
`directed = true`) from a raster dataset.
128+
Construct a `RasterGraph` or `RasterDiGraph` (if `directed = true`) from a
129+
raster dataset.
130130
131131
## Parameters
132-
`raster`: A Rasters.Raster on which to base the graph. Any pixel in `raster`
132+
`raster`: A `Rasters.Raster` on which to base the graph. Any pixel in `raster`
133133
with a value not equal to `raster.missingval` will be assigned a vertex
134134
in the graph (corresponding to its centroid). The values in the raster can also
135135
be used to determine which vertices to connect. See `condition` below for more
@@ -156,9 +156,10 @@ are within a certain distance of each other.
156156
157157
`cardinal_neighbors_only`: A `Bool` stating whether only cardinal neighbors
158158
should be connected. By default, both cardinal _and_ diagonal neighbors are
159-
connected. Note that when determining weights between diagonal neighbors, the
160-
increased distance between them (as compared to the distance between cardinal
161-
neighbors) is accounted for.
159+
connected. Note that this particular function does **NOT** account for the
160+
increased distance between diagonal neighbors (as compared to the distance
161+
between cardinal neighbors), since for a `SimpleGraph` or `SimpleDiGraph`, all
162+
weights are effectively set to 1.
162163
"""
163164
function rastergraph(
164165
raster::Raster;
@@ -217,21 +218,25 @@ where n is the number of unique vertices in the graph.
217218
## Arguments
218219
`directed`: A `Bool` determining whether the graph should be directed.
219220
220-
`condition`: A function that compares the values in `raster` for two
221+
`condition_raster`: A raster with values that can be used to determine whether
222+
two neighboring pixels should be connected. For example, an elevation raster
223+
can be used to create a hydologic flow graph. Defaults to the `weight_raster`.
224+
225+
`condition`: A function that compares the values in `condition_raster` for two
221226
neighbors to determine if those neighbors should be connected. The function must
222227
compare two values and return either `true` or `false`. Useful functions to use
223228
here include `<`, `<=`, `==`, etc. The first argument to `condition` corresponds
224229
to the source vertex, and the second argument corresponds to the destination
225230
vertex. So, if you only want to connect sources to destinations that have a
226-
lower value in `raster` (e.g. in the case of developing a hydrologic flow
227-
graph based on elevation), then you would use `>` for `condition`. Defaults to
228-
`is_data`, which results in neighbors being connected as long as they are not
229-
NoData (`raster.missingval`). Note that if using an inequality function (or
230-
any function where the result depends on argument position), `directed`
231-
should be set to `true`. For undirected graphs, you can use either
232-
`is_data` or `==`, or any other custom function where argument position doesn't
233-
matter, e.g. a function that determines whether the values in `raster`
234-
are within a certain distance of each other.
231+
lower value in `condition_raster` (e.g. in the case of developing a hydrologic
232+
flow graph based on elevation), then you would use `>` for `condition`. Defaults
233+
to `is_data`, which results in neighbors being connected as long as they are not
234+
NoData in `condition_raster` (`condition_raster.missingval`). Note that if using
235+
an inequality function (or any function where the result depends on argument
236+
position), `directed` should be set to `true`. For undirected graphs, you can
237+
use either `is_data` or `==`, or any other custom function where argument
238+
position doesn't matter, e.g. a function that determines whether the values in
239+
`condition_raster` are within a certain distance of each other.
235240
236241
`cardinal_neighbors_only`: A `Bool` stating whether only cardinal neighbors
237242
should be connected. By default, both cardinal _and_ diagonal neighbors are
@@ -248,7 +253,7 @@ taking the inverse of the result to convert back to resistance:
248253
`1 / ((1/R1 + 1/R2) / 2)`. `connect_using_avg_weights = false` correspondes to
249254
the default settings in Circuitscape. Defaults to `true`, in which case the
250255
simple average (adjusted for distance in the case of diagonal
251-
neighbors) of the weights in `weight_raster` is used.
256+
neighbors) of the weights in `weight_raster` is used.
252257
253258
`combine`: In the case that there are multiple edges defined for a single pair
254259
of vertices, how should the weight be chosen? Defaults to `min`. See the docs
@@ -292,8 +297,7 @@ end
292297
vertex_raster::Raster;
293298
directed::Bool = false,
294299
condition::Function = is_data,
295-
cardinal_neighbors_only::Bool = false,
296-
combine::Function = min
300+
cardinal_neighbors_only::Bool = false
297301
)
298302
299303
Construct a `SimpleGraph` or `SimpleDiGraph` (if `directed = true`) based on
@@ -304,7 +308,7 @@ in the graph, and `raster` is used to construct the graph and determine which
304308
vertices to connect.
305309
306310
## Parameters
307-
`raster`: A Rasters.Raster on which to base the graph. Any pixel in `raster`
311+
`raster`: A `Rasters.Raster` on which to base the graph. Any pixel in `raster`
308312
with a value not equal to `raster.missingval` will be assigned a vertex
309313
in the graph (corresponding to its centroid). The values in the raster can also
310314
be used to determine which vertices to connect. See `condition` below for more
@@ -316,60 +320,47 @@ where n is the number of unique vertices in the graph.
316320
## Arguments
317321
`directed`: A `Bool` determining whether the graph should be directed.
318322
319-
`condition`: A function that compares the values in `condition_raster` for two
323+
`condition`: A function that compares the values in `raster` for two
320324
neighbors to determine if those neighbors should be connected. The function must
321325
compare two values and return either `true` or `false`. Useful functions to use
322326
here include `<`, `<=`, `==`, etc. The first argument to `condition` corresponds
323327
to the source vertex, and the second argument corresponds to the destination
324328
vertex. So, if you only want to connect sources to destinations with a lower
325-
value in `condition_raster` (e.g. in the case of developing a hydrologic flow
329+
value in `raster` (e.g. in the case of developing a hydrologic flow
326330
graph based on elevation), then you would use `<` for `condition`. Defaults to
327331
`is_data`, which results in neighbors being connected as long as they are not
328-
NoData (`condition_raster.missingval`) in `condition_raster`. Note that if using
332+
NoData in `raster` (`raster.missingval`). Note that if using
329333
an inequality function (or any function where the result depends on argument
330334
position), the graph must be directed. For undirected graphs, you can use either
331335
`is_data` or `==`, or any other custom function where argument position doesn't
332-
matter, e.g. a function that determines whether the values in `condition_raster`
336+
matter, e.g. a function that determines whether the values in `raster`
333337
are within a certain distance of each other.
334338
335339
`cardinal_neighbors_only`: A `Bool` stating whether only cardinal neighbors
336340
should be connected. By default, both cardinal _and_ diagonal neighbors are
337-
connected. Note that when determining weights between diagonal neighbors, the
338-
increased distance between them (as compared to the distance between cardinal
339-
neighbors) is accounted for.
340-
341-
`connect_using_avg_raster_val`: `Bool`. This is intended to offer methods that
342-
complement those used in Circuitscape.jl and Omniscape.jl. In this context,
343-
weights (the values in `weight_raster`) are in units of electrical resistance.
344-
If `false`, the weight between two nodes with resistances R1 and R2 is
345-
calculated by converting resistance to conductances, taking the average, then
346-
taking the inverse of the result to convert back to resistance:
347-
`1 / ((1/R1 + 1/R2) / 2)`. `connect_using_avg_weights = false` correspondes to
348-
the default settings in Circuitscape. Defaults to `true', in which case the
349-
simple average of the weights (adjusted for distance in the case of diagonal
350-
neighbors) in `weight_raster` are used.
351-
352-
`combine`: In the case that there are multiple edges defined for a single pair
353-
of vertices, how should the weight be chosen? Defaults to `min`. See the docs
354-
for `SparseArrays.sparse()` for more information.
341+
connected. Note that this particular function does **NOT** account for the
342+
increased distance between diagonal neighbors (as compared to the distance
343+
between cardinal neighbors), since for a `SimpleGraph` or `SimpleDiGraph`, all
344+
weights are effectively set to 1.
355345
"""
356346
function make_simple_raster_graph(
357347
raster::Raster,
358348
vertex_raster::Raster;
359349
directed::Bool = false,
360350
condition::Function = is_data,
361-
cardinal_neighbors_only::Bool = false,
362-
combine::Function = min
351+
cardinal_neighbors_only::Bool = false
363352
)
353+
354+
# combine and connect_using_avg_weights don't matter for simple graphs,
355+
# so use defaults
364356
g = make_raster_graph(
365357
raster,
366358
vertex_raster,
367359
directed = directed,
368360
weighted = false,
369361
condition_raster = raster,
370362
condition = condition,
371-
cardinal_neighbors_only = cardinal_neighbors_only,
372-
combine = combine
363+
cardinal_neighbors_only = cardinal_neighbors_only
373364
)
374365

375366
return g

0 commit comments

Comments
 (0)