2
2
make_vertex_raster(A::Raster)
3
3
4
4
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
6
6
function is recommended for internal use only.
7
7
8
8
## 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
10
10
reference for building the vertex raster. Pixels with NoData (`A.missingval`)
11
11
are skipped (no vertex is assigned). Pixels with NoData will get a value of 0 in
12
12
the vertex raster.
36
36
)
37
37
38
38
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
40
40
the edge weight correponding to each vertex. Since edges are between rather than
41
41
on vertices, edge weights are calculated as the average of the weights for each
42
42
vertex.
43
43
44
44
## 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
47
47
weights between pixels. Any pixel in `weight_raster` with a value not equal to
48
48
`weight_raster.missingval` will be assigned a vertex in the graph (corresponding
49
49
to its centroid).
@@ -53,23 +53,23 @@ to its centroid).
53
53
54
54
`condition_raster`: A raster with values that can be used to determine whether
55
55
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`.
57
57
58
58
`condition`: A function that compares the values in `condition_raster` for two
59
59
neighbors to determine if those neighbors should be connected. The function must
60
60
compare two values and return either `true` or `false`. Useful functions to use
61
61
here include `<`, `<=`, `==`, etc. The first argument to `condition` corresponds
62
62
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
68
68
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.
73
73
74
74
`cardinal_neighbors_only`: A `Bool` stating whether only cardinal neighbors
75
75
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:
86
86
`1 / ((1/R1 + 1/R2) / 2)`. `connect_using_avg_weights = false` corresponds to
87
87
the default settings in Circuitscape. Defaults to `true`, in which case the
88
88
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.
90
90
91
91
"""
92
92
function weightedrastergraph (
@@ -118,18 +118,18 @@ function weightedrastergraph(
118
118
end
119
119
120
120
"""
121
- RasterGraph (
121
+ rastergraph (
122
122
raster::Raster;
123
123
directed::Bool = true,
124
124
condition::Function = is_data,
125
125
cardinal_neighbors_only::Bool = false
126
126
)
127
127
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.
130
130
131
131
## 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`
133
133
with a value not equal to `raster.missingval` will be assigned a vertex
134
134
in the graph (corresponding to its centroid). The values in the raster can also
135
135
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.
156
156
157
157
`cardinal_neighbors_only`: A `Bool` stating whether only cardinal neighbors
158
158
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.
162
163
"""
163
164
function rastergraph (
164
165
raster:: Raster ;
@@ -217,21 +218,25 @@ where n is the number of unique vertices in the graph.
217
218
## Arguments
218
219
`directed`: A `Bool` determining whether the graph should be directed.
219
220
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
221
226
neighbors to determine if those neighbors should be connected. The function must
222
227
compare two values and return either `true` or `false`. Useful functions to use
223
228
here include `<`, `<=`, `==`, etc. The first argument to `condition` corresponds
224
229
to the source vertex, and the second argument corresponds to the destination
225
230
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.
235
240
236
241
`cardinal_neighbors_only`: A `Bool` stating whether only cardinal neighbors
237
242
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:
248
253
`1 / ((1/R1 + 1/R2) / 2)`. `connect_using_avg_weights = false` correspondes to
249
254
the default settings in Circuitscape. Defaults to `true`, in which case the
250
255
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.
252
257
253
258
`combine`: In the case that there are multiple edges defined for a single pair
254
259
of vertices, how should the weight be chosen? Defaults to `min`. See the docs
292
297
vertex_raster::Raster;
293
298
directed::Bool = false,
294
299
condition::Function = is_data,
295
- cardinal_neighbors_only::Bool = false,
296
- combine::Function = min
300
+ cardinal_neighbors_only::Bool = false
297
301
)
298
302
299
303
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
304
308
vertices to connect.
305
309
306
310
## 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`
308
312
with a value not equal to `raster.missingval` will be assigned a vertex
309
313
in the graph (corresponding to its centroid). The values in the raster can also
310
314
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.
316
320
## Arguments
317
321
`directed`: A `Bool` determining whether the graph should be directed.
318
322
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
320
324
neighbors to determine if those neighbors should be connected. The function must
321
325
compare two values and return either `true` or `false`. Useful functions to use
322
326
here include `<`, `<=`, `==`, etc. The first argument to `condition` corresponds
323
327
to the source vertex, and the second argument corresponds to the destination
324
328
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
326
330
graph based on elevation), then you would use `<` for `condition`. Defaults to
327
331
`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
329
333
an inequality function (or any function where the result depends on argument
330
334
position), the graph must be directed. For undirected graphs, you can use either
331
335
`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 `
333
337
are within a certain distance of each other.
334
338
335
339
`cardinal_neighbors_only`: A `Bool` stating whether only cardinal neighbors
336
340
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.
355
345
"""
356
346
function make_simple_raster_graph (
357
347
raster:: Raster ,
358
348
vertex_raster:: Raster ;
359
349
directed:: Bool = false ,
360
350
condition:: Function = is_data,
361
- cardinal_neighbors_only:: Bool = false ,
362
- combine:: Function = min
351
+ cardinal_neighbors_only:: Bool = false
363
352
)
353
+
354
+ # combine and connect_using_avg_weights don't matter for simple graphs,
355
+ # so use defaults
364
356
g = make_raster_graph (
365
357
raster,
366
358
vertex_raster,
367
359
directed = directed,
368
360
weighted = false ,
369
361
condition_raster = raster,
370
362
condition = condition,
371
- cardinal_neighbors_only = cardinal_neighbors_only,
372
- combine = combine
363
+ cardinal_neighbors_only = cardinal_neighbors_only
373
364
)
374
365
375
366
return g
0 commit comments