| Title: | 'Circuitscape' and 'Omniscape' Connectivity Analysis via 'Julia' |
| Version: | 0.1.0 |
| Author: | Matthew Kling [aut, cre, cph] |
| Maintainer: | Matthew Kling <mattkling@berkeley.edu> |
| Description: | Provides an R-native interface to the 'Circuitscape.jl' and 'Omniscape.jl' 'Julia' packages for landscape connectivity modeling using circuit theory. Users work entirely in R with familiar objects (SpatRaster, file paths) while 'Julia' handles computation invisibly. Supports all four 'Circuitscape' modes (pairwise, one-to-all, all-to-one, advanced) and 'Omniscape' moving-window analysis. Methods are described in McRae (2006) <doi:10.1111/j.0014-3820.2006.tb00500.x> and Landau et al. (2021) <doi:10.21105/joss.02829>. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/matthewkling/circuitscaper, https://matthewkling.github.io/circuitscaper/ |
| BugReports: | https://github.com/matthewkling/circuitscaper/issues |
| Depends: | R (≥ 4.0) |
| Imports: | terra, JuliaCall, utils |
| Suggests: | testthat (≥ 3.0.0), knitr, rmarkdown |
| VignetteBuilder: | knitr |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.2 |
| Config/testthat/edition: | 3 |
| SystemRequirements: | Julia (>= 1.9), Circuitscape.jl, Omniscape.jl |
| NeedsCompilation: | no |
| Packaged: | 2026-04-04 13:27:15 UTC; matthewkling |
| Repository: | CRAN |
| Date/Publication: | 2026-04-09 09:20:02 UTC |
circuitscaper: 'Circuitscape' and 'Omniscape' Connectivity Analysis via 'Julia'
Description
Provides an R-native interface to the 'Circuitscape.jl' and 'Omniscape.jl' 'Julia' packages for landscape connectivity modeling using circuit theory. Users work entirely in R with familiar objects (SpatRaster, file paths) while 'Julia' handles computation invisibly. Supports all four 'Circuitscape' modes (pairwise, one-to-all, all-to-one, advanced) and 'Omniscape' moving-window analysis. Methods are described in McRae (2006) doi:10.1111/j.0014-3820.2006.tb00500.x and Landau et al. (2021) doi:10.21105/joss.02829.
Author(s)
Maintainer: Matthew Kling mattkling@berkeley.edu [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/matthewkling/circuitscaper/issues
Advanced Circuitscape Analysis
Description
Solve a single circuit with user-specified source and ground layers.
Usage
cs_advanced(
resistance,
source,
ground,
resistance_is = "resistances",
ground_is = "resistances",
use_unit_currents = FALSE,
use_direct_grounds = FALSE,
short_circuit = NULL,
source_ground_conflict = "keepall",
four_neighbors = FALSE,
avg_resistances = FALSE,
solver = "cg+amg",
output_dir = NULL,
verbose = FALSE
)
Arguments
resistance |
A terra::SpatRaster or file path. The resistance (or conductance) surface. Higher values represent greater resistance to movement. |
source |
A terra::SpatRaster or file path. Source current strengths (amps per cell). Cells with value 0 or NA are not sources. |
ground |
A terra::SpatRaster or file path. Ground node values.
Interpretation depends on |
resistance_is |
Character. Whether the resistance surface represents
|
ground_is |
Character. Whether the ground raster values represent
|
use_unit_currents |
Logical. If |
use_direct_grounds |
Logical. If |
short_circuit |
Optional terra::SpatRaster or file path. Raster
identifying short-circuit regions (aka polygons). Cells sharing the same
positive integer value are treated as short-circuit regions with zero
resistance between them. Default |
source_ground_conflict |
Character. How to resolve cells that appear in
both the source and ground rasters: |
four_neighbors |
Logical. Use 4-neighbor (rook) connectivity instead of
8-neighbor (queen). Default |
avg_resistances |
Logical. When using 8-neighbor connectivity, compute
the resistance of diagonal connections as the average of the two cells
rather than their sum. Default |
solver |
Character. Solver to use: |
output_dir |
Optional character path. If provided, output files persist
there. Default |
verbose |
Logical. Print Circuitscape solver output. Default |
Details
Unlike the other Circuitscape modes, advanced mode does not iterate over focal nodes. Instead, the user provides explicit source current and ground conductance rasters, and a single circuit is solved. This gives full control over the current injection pattern and is useful for modeling specific scenarios such as directional movement between a defined source area and destination.
Value
A terra::SpatRaster with the following layers:
- current
Current density at each cell.
- voltage
Voltage at each cell. Voltage is analogous to movement probability and decreases with distance from sources.
References
McRae, B.H. (2006). Isolation by resistance. Evolution, 60(8), 1551–1561. doi:10.1111/j.0014-3820.2006.tb00500.x
Circuitscape.jl: https://docs.circuitscape.org/Circuitscape.jl/latest/
See Also
cs_pairwise(), cs_one_to_all(), cs_all_to_one(), cs_setup()
Examples
library(terra)
res <- rast(system.file("extdata/resistance.tif", package = "circuitscaper"))
origin <- rast(system.file("extdata/source.tif", package = "circuitscaper"))
dest <- rast(system.file("extdata/ground.tif", package = "circuitscaper"))
result <- cs_advanced(res, origin, dest, ground_is = "conductances")
plot(result)
All-to-One Circuitscape Analysis
Description
For each focal node in turn, inject current at all other focal nodes and ground that single node.
Usage
cs_all_to_one(
resistance,
locations,
resistance_is = "resistances",
four_neighbors = FALSE,
avg_resistances = FALSE,
short_circuit = NULL,
included_pairs = NULL,
write_voltage = FALSE,
cumulative_only = TRUE,
source_strengths = NULL,
solver = "cg+amg",
output_dir = NULL,
verbose = FALSE
)
Arguments
resistance |
A terra::SpatRaster or file path. The resistance (or
conductance) surface. Higher values represent greater resistance to
movement. Use the |
locations |
Focal node locations, provided as any of:
|
resistance_is |
Character. Whether the resistance surface represents
|
four_neighbors |
Logical. Use 4-neighbor (rook) connectivity instead of
8-neighbor (queen). Default |
avg_resistances |
Logical. When using 8-neighbor connectivity, compute
the resistance of diagonal connections as the average of the two cells
rather than their sum. Default |
short_circuit |
Optional terra::SpatRaster or file path. Raster
identifying short-circuit regions (aka polygons). Cells sharing the same
positive integer value are treated as short-circuit regions with zero
resistance between them. Default |
included_pairs |
Optional character file path. A text file specifying
which pairs of focal nodes to include or exclude from analysis. See the
Circuitscape documentation for the file format. Default |
write_voltage |
Logical. Write voltage maps. Default |
cumulative_only |
Logical. If |
source_strengths |
Optional. Variable current injection strengths for each focal node. Can be:
|
solver |
Character. Solver to use: |
output_dir |
Optional character path. If provided, output files persist
there. Default |
verbose |
Logical. Print Circuitscape solver output. Default |
Details
All-to-one mode iterates over each focal node. In each iteration, all other focal nodes are injected with 1 amp of current each, and the focal node is connected to ground. This produces a current map showing how current converges on that node from across the landscape.
This mode is useful for identifying the most accessible or reachable sites in the network, emphasizing current flow toward each ground node. The cumulative map sums across all iterations and highlights cells that are important for connectivity across the full set of nodes.
Value
A terra::SpatRaster with the following layers:
- cumulative_current
Current flow summed across all iterations.
- current_N
Per-node current map for focal node N, where N is the integer node ID from the
locationsraster. One layer per focal node.
References
McRae, B.H. (2006). Isolation by resistance. Evolution, 60(8), 1551–1561. doi:10.1111/j.0014-3820.2006.tb00500.x
Circuitscape.jl: https://docs.circuitscape.org/Circuitscape.jl/latest/
See Also
cs_pairwise(), cs_one_to_all(), cs_advanced(), cs_setup()
Examples
library(terra)
res <- rast(system.file("extdata/resistance.tif", package = "circuitscaper"))
coords <- matrix(c(10, 40, 40, 40, 10, 10, 40, 10), ncol = 2, byrow = TRUE)
result <- cs_all_to_one(res, coords)
plot(result)
Install Julia and Required Packages
Description
Downloads and installs Julia, Circuitscape.jl, and Omniscape.jl. This is the recommended first step after installing the circuitscaper R package.
Usage
cs_install_julia(force = FALSE, version = "latest")
Arguments
force |
Logical. If |
version |
Character. Julia version to install. Default |
Details
In interactive sessions, prompts for confirmation before downloading. In non-interactive sessions (e.g., CI), proceeds without prompting.
Value
Invisibly returns TRUE on success, FALSE if cancelled.
Examples
cs_install_julia()
cs_install_julia(force = TRUE)
Check if Julia and Required Packages Are Available
Description
Tests whether Julia is installed and the Circuitscape Julia package can be loaded. This is a lightweight check that does not initialize a full Julia session. It is used internally by example code and can be called by users to verify their setup before running analyses.
Usage
cs_julia_available()
Value
TRUE if Julia is found on the system PATH and the
'Circuitscape' Julia package loads successfully, FALSE otherwise.
Examples
cs_julia_available()
One-to-All Circuitscape Analysis
Description
For each focal node in turn, inject current at that node and ground all other focal nodes simultaneously.
Usage
cs_one_to_all(
resistance,
locations,
resistance_is = "resistances",
four_neighbors = FALSE,
avg_resistances = FALSE,
short_circuit = NULL,
included_pairs = NULL,
write_voltage = FALSE,
cumulative_only = TRUE,
source_strengths = NULL,
solver = "cg+amg",
output_dir = NULL,
verbose = FALSE
)
Arguments
resistance |
A terra::SpatRaster or file path. The resistance (or
conductance) surface. Higher values represent greater resistance to
movement. Use the |
locations |
Focal node locations, provided as any of:
|
resistance_is |
Character. Whether the resistance surface represents
|
four_neighbors |
Logical. Use 4-neighbor (rook) connectivity instead of
8-neighbor (queen). Default |
avg_resistances |
Logical. When using 8-neighbor connectivity, compute
the resistance of diagonal connections as the average of the two cells
rather than their sum. Default |
short_circuit |
Optional terra::SpatRaster or file path. Raster
identifying short-circuit regions (aka polygons). Cells sharing the same
positive integer value are treated as short-circuit regions with zero
resistance between them. Default |
included_pairs |
Optional character file path. A text file specifying
which pairs of focal nodes to include or exclude from analysis. See the
Circuitscape documentation for the file format. Default |
write_voltage |
Logical. Write voltage maps. Default |
cumulative_only |
Logical. If |
source_strengths |
Optional. Variable current injection strengths for each focal node. Can be:
|
solver |
Character. Solver to use: |
output_dir |
Optional character path. If provided, output files persist
there. Default |
verbose |
Logical. Print Circuitscape solver output. Default |
Details
One-to-all mode iterates over each focal node. In each iteration, the focal node is injected with 1 amp of current and all remaining focal nodes are simultaneously connected to ground. This produces a current map showing how current spreads from that node through the landscape to reach the others.
This mode is useful for mapping how well each site is connected to the rest of the focal node network, emphasizing current dispersal from each source. The cumulative map sums across all iterations and highlights cells that are important for connectivity across the full set of nodes.
Value
A terra::SpatRaster with the following layers:
- cumulative_current
Current flow summed across all iterations.
- current_N
Per-node current map for focal node N, where N is the integer node ID from the
locationsraster. One layer per focal node.
References
McRae, B.H. (2006). Isolation by resistance. Evolution, 60(8), 1551–1561. doi:10.1111/j.0014-3820.2006.tb00500.x
Circuitscape.jl: https://docs.circuitscape.org/Circuitscape.jl/latest/
See Also
cs_pairwise(), cs_all_to_one(), cs_advanced(), cs_setup()
Examples
library(terra)
res <- rast(system.file("extdata/resistance.tif", package = "circuitscaper"))
coords <- matrix(c(10, 40, 40, 40, 10, 10, 40, 10), ncol = 2, byrow = TRUE)
result <- cs_one_to_all(res, coords)
plot(result)
Pairwise Circuitscape Analysis
Description
Compute pairwise effective resistances and cumulative current flow between all pairs of focal nodes.
Usage
cs_pairwise(
resistance,
locations,
resistance_is = "resistances",
four_neighbors = FALSE,
avg_resistances = FALSE,
short_circuit = NULL,
included_pairs = NULL,
write_voltage = FALSE,
cumulative_only = TRUE,
source_strengths = NULL,
solver = "cg+amg",
output_dir = NULL,
verbose = FALSE
)
Arguments
resistance |
A terra::SpatRaster or file path. The resistance (or
conductance) surface. Higher values represent greater resistance to
movement. Use the |
locations |
Focal node locations, provided as any of:
|
resistance_is |
Character. Whether the resistance surface represents
|
four_neighbors |
Logical. Use 4-neighbor (rook) connectivity instead of
8-neighbor (queen). Default |
avg_resistances |
Logical. When using 8-neighbor connectivity, compute
the resistance of diagonal connections as the average of the two cells
rather than their sum. Default |
short_circuit |
Optional terra::SpatRaster or file path. Raster
identifying short-circuit regions (aka polygons). Cells sharing the same
positive integer value are treated as short-circuit regions with zero
resistance between them. Default |
included_pairs |
Optional character file path. A text file specifying
which pairs of focal nodes to include or exclude from analysis. See the
Circuitscape documentation for the file format. Default |
write_voltage |
Logical. Write voltage maps. Default |
cumulative_only |
Logical. If |
source_strengths |
Optional. Variable current injection strengths for each focal node. Can be:
|
solver |
Character. Solver to use: |
output_dir |
Optional character path. If provided, output files persist
there. Default |
verbose |
Logical. Print Circuitscape solver output. Default |
Details
Pairwise mode iterates over every unique pair of focal nodes. For each pair, one node is injected with 1 amp of current and the other is connected to ground. The effective resistance between the pair is recorded, and the resulting current flow is accumulated across all pairs into a cumulative current map that highlights important movement corridors.
This is the most common Circuitscape mode and is typically used to quantify connectivity between discrete habitat patches or populations. The resistance matrix can be used as a distance metric in analyses such as isolation by resistance.
Value
A named list with:
- current_map
A terra::SpatRaster. By default contains a single
cumulative_currentlayer (current flow summed across all pairs). Whencumulative_only = FALSE, additional per-pair layers are included (e.g.,current_1_2,current_1_3). Whenwrite_voltage = TRUE, per-pair voltage layers are included (e.g.,voltage_1_2,voltage_1_3).- resistance_matrix
A symmetric numeric matrix of pairwise effective resistances between focal nodes, with node IDs as row and column names.
References
McRae, B.H. (2006). Isolation by resistance. Evolution, 60(8), 1551–1561. doi:10.1111/j.0014-3820.2006.tb00500.x
Circuitscape.jl: https://docs.circuitscape.org/Circuitscape.jl/latest/
See Also
cs_one_to_all(), cs_all_to_one(), cs_advanced(), cs_setup()
Examples
library(terra)
res <- rast(system.file("extdata/resistance.tif", package = "circuitscaper"))
coords <- matrix(c(10, 40, 40, 40, 10, 10, 40, 10), ncol = 2, byrow = TRUE)
result <- cs_pairwise(res, coords, cumulative_only = FALSE)
plot(result$current_map)
result$resistance_matrix
Set Up Julia and Load Circuitscape/Omniscape
Description
Initialize the Julia session and load the Circuitscape and Omniscape Julia
packages. This is called automatically on first use of any cs_* or os_*
function. Call explicitly to control the Julia path, number of threads, or
pre-warm the session.
Usage
cs_setup(julia_home = NULL, threads = 1L, quiet = TRUE, ...)
Arguments
julia_home |
Character. Path to the Julia |
threads |
Integer. Number of Julia threads to start. Default |
quiet |
Logical. Suppress Julia startup messages. Default |
... |
Additional arguments passed to |
Details
cs_setup() does not install Julia or Julia packages. If Julia is not
found or the required packages are missing, it throws an informative error
directing you to cs_install_julia().
cs_setup() will:
Verify that Julia is installed and accessible.
Verify that the Circuitscape and Omniscape Julia packages are installed.
Load both packages and warm up the JIT compiler.
Once Julia is initialized, it stays warm for the R session. Subsequent calls
to cs_setup() return immediately.
Threading
Julia's thread count is fixed at startup and cannot be changed mid-session.
Multi-threading is used by os_run() when parallelize = TRUE.
Circuitscape functions (cs_pairwise, cs_one_to_all, etc.) do not
benefit from multiple threads.
cs_setup(threads = 4) os_run(resistance, radius = 50, parallelize = TRUE)
Value
Invisibly returns TRUE on success.
References
McRae, B.H. (2006). Isolation by resistance. Evolution, 60(8), 1551–1561. doi:10.1111/j.0014-3820.2006.tb00500.x
Landau, V.A., Shah, V.B., Anantharaman, R. & Hall, K.R. (2021). Omniscape.jl: Software to compute omnidirectional landscape connectivity. Journal of Open Source Software, 6(57), 2829. doi:10.21105/joss.02829
Circuitscape.jl: https://docs.circuitscape.org/Circuitscape.jl/latest/
Omniscape.jl: https://docs.circuitscape.org/Omniscape.jl/latest/
See Also
cs_install_julia(), cs_pairwise(), os_run()
Examples
cs_setup()
cs_setup(threads = 4)
cs_setup(julia_home = "/usr/local/julia/bin")
Run Omniscape Moving-Window Connectivity Analysis
Description
Performs an Omniscape analysis, computing omnidirectional landscape connectivity using a moving window approach based on circuit theory.
Usage
os_run(
resistance,
radius,
source_strength = NULL,
block_size = 1L,
source_threshold = 0,
r_cutoff = Inf,
resistance_is = "resistances",
calc_normalized_current = TRUE,
calc_flow_potential = TRUE,
condition = NULL,
condition_type = NULL,
parallelize = FALSE,
julia_threads = 2L,
solver = "cg+amg",
output_dir = NULL,
verbose = FALSE
)
Arguments
resistance |
A terra::SpatRaster or file path. The resistance (or conductance) surface. Higher values represent greater resistance to movement. |
radius |
Numeric. Moving window radius in pixels. This determines the maximum distance over which connectivity is evaluated from each source pixel. |
source_strength |
Optional terra::SpatRaster or file path. Source
strength weights, often derived from habitat quality or suitability, where
higher values indicate stronger sources of movement. If |
block_size |
Integer. Aggregation block size for source points. Default
|
source_threshold |
Numeric. Minimum source strength to include a pixel.
Default |
r_cutoff |
Numeric. Maximum resistance value for a cell to be included
as a source when |
resistance_is |
Character. Whether the resistance surface represents
|
calc_normalized_current |
Logical. Compute normalized current flow.
Default |
calc_flow_potential |
Logical. Compute flow potential. Default |
condition |
Optional terra::SpatRaster or file path. Conditional layer for targeted connectivity analysis. |
condition_type |
Character. How the condition layer filters connectivity:
|
parallelize |
Logical. Use Julia multithreading. Default |
julia_threads |
Integer. Number of Julia threads if |
solver |
Character. Solver to use: |
output_dir |
Optional character path. If provided, output files persist
there. Default |
verbose |
Logical. Print Omniscape output. Default |
Value
A terra::SpatRaster with the following layers (depending on options):
- cumulative_current
Raw cumulative current flow. Always present. Higher values indicate cells that carry more current across all moving-window iterations.
- flow_potential
Expected current under homogeneous resistance (if
calc_flow_potential = TRUE). Reflects the spatial configuration of sources independently of landscape resistance.- normalized_current
Cumulative current divided by flow potential (if
calc_normalized_current = TRUE). Values greater than 1 indicate cells where connectivity is higher than expected given the source geometry; values less than 1 indicate relative barriers. This is typically the most informative layer for identifying corridors and pinch points.
References
Landau, V.A., Shah, V.B., Anantharaman, R. & Hall, K.R. (2021). Omniscape.jl: Software to compute omnidirectional landscape connectivity. Journal of Open Source Software, 6(57), 2829. doi:10.21105/joss.02829
Omniscape.jl: https://docs.circuitscape.org/Omniscape.jl/latest/
See Also
Examples
library(terra)
res <- rast(system.file("extdata/resistance.tif", package = "circuitscaper"))
result <- os_run(res, radius = 20)
plot(result)