36
36
# Help functions
37
37
# ==============
38
38
usage () {
39
- echo " GISTOOL: Geospatial Dataset Processing Script
39
+ echo " GISTOOL: Geospatial Data Processing Script
40
40
41
41
Usage:
42
42
extract-gis [options...]
43
43
44
44
Script options:
45
45
-d, --dataset Geospatial dataset of interest, currently
46
46
available options are: 'MODIS';
47
- 'MERIT-Hydro';'SoilGridsV1'
47
+ 'MERIT-Hydro';'SoilGridsV1';'Landsat';
48
+ 'gsde';'depth-to-bedrock';
48
49
-i, --dataset-dir=DIR The source path of the dataset file(s)
49
50
-r, --crs=INT The EPSG code of interest; optional
50
51
[defaults to 4326]
@@ -66,26 +67,28 @@ Script options:
66
67
'min';'max';'mean';'majority';'minority';
67
68
'median';'quantile';'variety';'variance';
68
69
'stdev';'coefficient_of_variation';'frac';
69
- 'coords'; optional
70
+ 'coords'; 'count'; optional
71
+ -u, --include-na Include NA values in generated statistics;
72
+ optional
70
73
-q, --quantile=q1[,q2[...]] Quantiles of interest to be produced if 'quantile'
71
74
is included in the '--stat' argument. The values
72
75
must be comma delimited float numbers between
73
76
0 and 1; optional [defaults to every 5th quantile]
74
77
-p, --prefix=STR Prefix prepended to the output files
75
78
-c, --cache=DIR Path of the cache directory; optional
76
79
-E, --email=STR E-mail when job starts, ends, and
77
- finishes ; optional
80
+ fails ; optional
78
81
-V, --version Show version
79
82
-h, --help Show this screen and exit
80
83
81
- For bug reports, questions, discussions open an issue
84
+ For bug reports, questions, and discussions open an issue
82
85
at https://github.com/kasra-keshavarz/gistool/issues" >&1 ;
83
86
84
87
exit 0;
85
88
}
86
89
87
90
short_usage () {
88
- echo " usage: $( basename $0 ) -d DATASET -io DIR -v var1[,var2,[...]] [-jVhE ] [-t BOOL] [-c DIR] [-se DATE] [-r INT] [-ln REAL,REAL] [-f PATH} [-p STR] [-a stat1[,stat2,[...]] [-q q1[,q2[...]]]] " >&1 ;
91
+ echo " usage: $( basename $0 ) -d DATASET -io DIR -v var1[,var2,[...]] [-jVhEu ] [-t BOOL] [-c DIR] [-se DATE] [-r INT] [-ln REAL,REAL] [-f PATH] [-p STR] [-a stat1[,stat2,[...]] [-q q1[,q2[...]]]] " >&1 ;
89
92
}
90
93
91
94
version () {
@@ -107,8 +110,11 @@ shopt -s expand_aliases
107
110
# =======================
108
111
# Parsing input arguments
109
112
# =======================
110
- # argument parsing using getopt - WORKS ONLY ON LINUX BY DEFAULT
111
- parsedArguments=$( getopt -a -n extract-geotiff -o d:i:r:v:o:s:e:l:n:f:jt:a:q:p:c:EVh --long dataset:,dataset-dir:,crs:,variable:,output-dir:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,submit-job,print-geotiff:,stat:,quantile:,prefix:,cache:,email:,version,help -- " $@ " )
113
+ # argument parsing using getopt -
114
+ # ATTENTION: `getopt` is available by default on most GNU/Linux
115
+ # distributions, however, it may not work out of the
116
+ # box on MacOS or BSD
117
+ parsedArguments=$( getopt -a -n extract-geotiff -o d:i:r:v:o:s:e:l:n:f:jt:a:uq:p:c:EVh --long dataset:,dataset-dir:,crs:,variable:,output-dir:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,submit-job,print-geotiff:,stat:,include-na,quantile:,prefix:,cache:,email:,version,help -- " $@ " )
112
118
validArguments=$?
113
119
# check if there is no valid options
114
120
if [ " $validArguments " != " 0" ]; then
140
146
-j | --submit-job) jobSubmission=true ; shift ;; # optional
141
147
-t | --print-geotiff) printGeotiff=" $2 " ; shift 2 ;; # optional
142
148
-a | --stat) stats=" $2 " ; shift 2 ;; # optional
149
+ -u | --include-na) includeNA=true ; shift ;; # optional
143
150
-q | --quantile) quantiles=" $2 " ; shift 2 ;; # optional
144
151
-p | --prefix) prefixStr=" $2 " ; shift 2 ;; # required
145
152
-c | --cache) cache=" $2 " ; shift 2 ;; # optional
@@ -174,6 +181,11 @@ if [[ -z $printGeotiff ]]; then
174
181
printGeotiff=true
175
182
fi
176
183
184
+ # if $includeNA is not triggered
185
+ if [[ -z $includeNA ]]; then
186
+ includeNA=false
187
+ fi
188
+
177
189
# check the value of $printGeotiff
178
190
if [[ -n $printGeotiff ]]; then
179
191
case " ${printGeotiff,,} " in
@@ -254,6 +266,7 @@ declare -A funcArgs=([geotiffDir]="$geotiffDir" \
254
266
[jobSubmission]=" $jobSubmission " \
255
267
[printGeotiff]=" $printGeotiff " \
256
268
[stats]=" $stats " \
269
+ [includeNA]=" $includeNA " \
257
270
[quantiles]=" $quantiles " \
258
271
[prefixStr]=" $prefixStr " \
259
272
[cache]=" $cache " \
@@ -274,13 +287,14 @@ call_processing_func () {
274
287
# all processing script files must follow same input argument standard
275
288
local scriptRun
276
289
read -rd ' ' scriptRun << - EOF
277
- bash ${script} --dataset-dir="${funcArgs[geotiffDir]} " --crs="${funcArgs[crs]} " --variable="${funcArgs[variables]} " --output-dir="${funcArgs[outputDir]} " --start-date="${funcArgs[startDate]} " --end-date="${funcArgs[endDate]} " --lat-lims="${funcArgs[latLims]} " --lon-lims="${funcArgs[lonLims]} " --shape-file="${funcArgs[shapefile]} " --print-geotiff="${funcArgs[printGeotiff]} " --stat="${funcArgs[stats]} " --quantile="${funcArgs[quantiles]} " --prefix="${funcArgs[prefixStr]} " --cache="${funcArgs[cache]} "
290
+ bash ${script} --dataset-dir="${funcArgs[geotiffDir]} " --crs="${funcArgs[crs]} " --variable="${funcArgs[variables]} " --output-dir="${funcArgs[outputDir]} " --start-date="${funcArgs[startDate]} " --end-date="${funcArgs[endDate]} " --lat-lims="${funcArgs[latLims]} " --lon-lims="${funcArgs[lonLims]} " --shape-file="${funcArgs[shapefile]} " --print-geotiff="${funcArgs[printGeotiff]} " --stat="${funcArgs[stats]} " --include-na=" ${funcArgs[includeNA]} " -- quantile="${funcArgs[quantiles]} " --prefix="${funcArgs[prefixStr]} " --cache="${funcArgs[cache]} "
278
291
EOF
279
292
280
293
# evaluate the script file using the arguments provided
281
294
if [[ " ${funcArgs[jobSubmission]} " == true ]]; then
282
295
# Create a temporary directory for keeping job logs
283
- mkdir -p " $HOME /scratch/.gdt_logs"
296
+ logDir=" $HOME /scratch/.gistool_logs/"
297
+ mkdir -p " $logDir "
284
298
# SLURM batch file
285
299
sbatch << - EOF
286
300
#!/bin/bash
@@ -290,15 +304,15 @@ call_processing_func () {
290
304
#SBATCH --time=04:00:00
291
305
#SBATCH --mem=16GB
292
306
#SBATCH --job-name=GIS_${scriptName}
293
- #SBATCH --error=$HOME /scratch/.gdt_logs /GIS_%j_err.txt
294
- #SBATCH --output=$HOME /scratch/.gdt_logs /GIS_%j.txt
307
+ #SBATCH --error=$logDir /GIS_%j_err.txt
308
+ #SBATCH --output=$logDir /GIS_%j.txt
295
309
#SBATCH --mail-user=$email
296
310
#SBATCH --mail-type=BEGIN,END,FAIL
297
311
298
312
srun ${scriptRun} --cache="${cache} -\$ {SLURM_JOB_ID}"
299
313
EOF
300
314
# echo message
301
- echo " $( basename $0 ) : job submission details are printed under ${HOME} /scratch/.gdt_logs "
315
+ echo " $( basename $0 ) : job submission details are printed under ${logDir} "
302
316
303
317
else
304
318
eval " $scriptRun "
0 commit comments