From f9ffacf58adbd6df850868f6c94a6bf8d1775422 Mon Sep 17 00:00:00 2001
From: Francesco Sabatini <francesco.sabatini@idiv.de>
Date: Fri, 14 Feb 2020 13:03:11 +0100
Subject: [PATCH] Fixed minor bugs for submitting array jobs

---
 code/A98_PredictorsExtract.R |  7 ++++++-
 code/cli_A98.r               |  2 +-
 code/submit-A98.sh           | 10 +++++-----
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/code/A98_PredictorsExtract.R b/code/A98_PredictorsExtract.R
index fd9e1b3..7b8aad7 100644
--- a/code/A98_PredictorsExtract.R
+++ b/code/A98_PredictorsExtract.R
@@ -7,11 +7,14 @@ PredExtr <- function(x.shp, myfunction=NA, output,
   require(doParallel)
   require(raster)
   require(rgeos)
-  
+  require(rgdal) 
+ 
   print(paste("Loading", typp, "data :", toextract))
   if(typp=="raster"){ mypredictor <- raster(toextract)} else
     mypredictor <- readOGR(toextract)
   header.shp <-readOGR(x.shp)
+  crs(mypredictor) <- crs(header.shp) #should be verified beforehand!
+
   ## Divide in chunks if requested
   if(chunkn>1 & !is.na(chunk.i)){
     print(paste("divide in chunks and run on chunk n.", chunk.i))
@@ -41,6 +44,8 @@ PredExtr <- function(x.shp, myfunction=NA, output,
   } else {
     out <- sp::over(x=header.shp, y=mypredictor) 
     toassign <- header.shp[which(is.na(out[,1])),]
+    print(paste(length(toassign), "plots not matched directely - seek for NN"))
+
     
     nearest <- foreach(i=1:length(toassign), .packages=c('raster'), .combine=rbind) %dopar% { 
       nearest.tmp <- geosphere::dist2Line(toassign[i,], mypredictor)
diff --git a/code/cli_A98.r b/code/cli_A98.r
index 5e0e49e..178e1c1 100644
--- a/code/cli_A98.r
+++ b/code/cli_A98.r
@@ -30,7 +30,7 @@ options <- list (
 	  metavar = "4"
 	), 
 	make_option(
-	  opt_str = c("-c", "--chunkn"),
+	  opt_str = c("-n", "--chunkn"),
 	  dest    = "chunkn",
 	  type    = "integer",
 	  default = 1,
diff --git a/code/submit-A98.sh b/code/submit-A98.sh
index 0a54ff1..28b7664 100644
--- a/code/submit-A98.sh
+++ b/code/submit-A98.sh
@@ -7,9 +7,9 @@
 #$ -j y
 
 #$ -l h_rt=00:30:00:00
-#$ -l h_vmem=3G
+#$ -l h_vmem=1G
 
-#$ -pe smp 4-32
+#$ -pe smp 8-32
 
 #$ -cwd
 
@@ -26,10 +26,10 @@ output=/work/$USER/output_pred/$(basename $filename .shp).csv
 Rscript \
     cli_A98.r \
     --cores ${NSLOTS:-1} \
-    --typp \
+    --typp "shp" \
     --chunk.i $SGE_TASK_ID \
     --chunkn 99 \
-    /data/splot/_data/header.shp.RData \
+    /data/splot/_data_splot3/header.shp.shp \
     robust.mean \
     "$output" \
-    "$filename"
\ No newline at end of file
+    "$filename"
-- 
GitLab