-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathCalc_contours_snow.R
32 lines (25 loc) · 997 Bytes
/
Calc_contours_snow.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
30
31
32
# This is an spatial analysis example script for using R in CSC Puhti
# This scipt can be used for parallel jobs.
# Here countours are calculated and saved in GeoPackage format.
# The file given as input is a 10m DEM file from Finnish NLS.
# The input files are listed in the mapsheet.txt file
# For parallel tasks the snow package is used.
# Start the snow cluster
cl<-getMPIcluster()
# The function run on each core
# The R modules need to be loaded inside the functions.
# The variables from outside of this function are not visible.
funtorun<-function(mapsheet) {
DEM <- rast(mapsheet)
file <- gsub("tif", "gpkg", basename(mapsheet))
contours <- as.contour(DEM)
writeVector(contours, file, filetype="GPKG", overwrite=TRUE)
}
# load terra library
clusterEvalQ(cl, library(terra))
# Read the mapsheets from external file
mapsheets <- readLines('../mapsheets.txt')
# Give cluster the work to be done
system.time(a<-clusterApply(cl,mapsheets,funtorun))
#Stop cluster
stopCluster(cl)