-
Notifications
You must be signed in to change notification settings - Fork 0
/
runCS.R
30 lines (26 loc) · 1.15 KB
/
runCS.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## To run this function you need to install the circuitscape python library:
## https://pypi.python.org/pypi/Circuitscape/
## Define runCS function
runCS <- function(coordinates, raster){
name <- as.character(strsplit(raster, ".asc"))
out <- paste0(name, ".out")
ini <- paste0(name, ".ini")
CS_ini <- c("[circuitscape options]",
"data_type = raster",
"scenario = pairwise",
paste(c("point_file =",
"habitat_file =",
"output_file ="),
paste(getwd(),c(coordinates, raster, out), sep="/")))
writeLines(CS_ini, ini)
CS_run <- paste("csrun.py", paste(getwd(), ini, sep="/"))
system(CS_run)
}
#### Create tab-separated file containing coordinates:
# Coords <- read.csv("Coords.csv", head=T) ## read csv file containing coordinates
# Coords$ID <- 1:nrow(Coords) ## append row ID
# Coords <- Coords [ , c(3,1,2)] ## Select IDs and coordinates
# write.table(Coords, file="coordinates.txt", sep="\t", row.names=F, col.names=F) ## write tab-separated file
### Example use:
## > source("runCS.R")
## > runCS(coordinates="coordinates.txt", raster="GD.asc")