3636# Help functions
3737# ==============
3838usage () {
39- echo " GISTOOL: Geospatial Dataset Processing Script
39+ echo " GISTOOL: Geospatial Data Processing Script
4040
4141Usage:
4242 extract-gis [options...]
4343
4444Script options:
4545 -d, --dataset Geospatial dataset of interest, currently
4646 available options are: 'MODIS';
47- 'MERIT-Hydro';'SoilGridsV1'
47+ 'MERIT-Hydro';'SoilGridsV1';'Landsat';
48+ 'gsde';'depth-to-bedrock';
4849 -i, --dataset-dir=DIR The source path of the dataset file(s)
4950 -r, --crs=INT The EPSG code of interest; optional
5051 [defaults to 4326]
@@ -66,26 +67,28 @@ Script options:
6667 'min';'max';'mean';'majority';'minority';
6768 'median';'quantile';'variety';'variance';
6869 'stdev';'coefficient_of_variation';'frac';
69- 'coords'; optional
70+ 'coords'; 'count'; optional
71+ -u, --include-na Include NA values in generated statistics;
72+ optional
7073 -q, --quantile=q1[,q2[...]] Quantiles of interest to be produced if 'quantile'
7174 is included in the '--stat' argument. The values
7275 must be comma delimited float numbers between
7376 0 and 1; optional [defaults to every 5th quantile]
7477 -p, --prefix=STR Prefix prepended to the output files
7578 -c, --cache=DIR Path of the cache directory; optional
7679 -E, --email=STR E-mail when job starts, ends, and
77- finishes ; optional
80+ fails ; optional
7881 -V, --version Show version
7982 -h, --help Show this screen and exit
8083
81- For bug reports, questions, discussions open an issue
84+ For bug reports, questions, and discussions open an issue
8285at https://github.com/kasra-keshavarz/gistool/issues" >&1 ;
8386
8487 exit 0;
8588}
8689
8790short_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 ;
8992}
9093
9194version () {
@@ -107,8 +110,11 @@ shopt -s expand_aliases
107110# =======================
108111# Parsing input arguments
109112# =======================
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 -- " $@ " )
112118validArguments=$?
113119# check if there is no valid options
114120if [ " $validArguments " != " 0" ]; then
140146 -j | --submit-job) jobSubmission=true ; shift ;; # optional
141147 -t | --print-geotiff) printGeotiff=" $2 " ; shift 2 ;; # optional
142148 -a | --stat) stats=" $2 " ; shift 2 ;; # optional
149+ -u | --include-na) includeNA=true ; shift ;; # optional
143150 -q | --quantile) quantiles=" $2 " ; shift 2 ;; # optional
144151 -p | --prefix) prefixStr=" $2 " ; shift 2 ;; # required
145152 -c | --cache) cache=" $2 " ; shift 2 ;; # optional
@@ -174,6 +181,11 @@ if [[ -z $printGeotiff ]]; then
174181 printGeotiff=true
175182fi
176183
184+ # if $includeNA is not triggered
185+ if [[ -z $includeNA ]]; then
186+ includeNA=false
187+ fi
188+
177189# check the value of $printGeotiff
178190if [[ -n $printGeotiff ]]; then
179191 case " ${printGeotiff,,} " in
@@ -254,6 +266,7 @@ declare -A funcArgs=([geotiffDir]="$geotiffDir" \
254266 [jobSubmission]=" $jobSubmission " \
255267 [printGeotiff]=" $printGeotiff " \
256268 [stats]=" $stats " \
269+ [includeNA]=" $includeNA " \
257270 [quantiles]=" $quantiles " \
258271 [prefixStr]=" $prefixStr " \
259272 [cache]=" $cache " \
@@ -274,13 +287,14 @@ call_processing_func () {
274287 # all processing script files must follow same input argument standard
275288 local scriptRun
276289 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]} "
278291 EOF
279292
280293 # evaluate the script file using the arguments provided
281294 if [[ " ${funcArgs[jobSubmission]} " == true ]]; then
282295 # 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 "
284298 # SLURM batch file
285299 sbatch << - EOF
286300 #!/bin/bash
@@ -290,15 +304,15 @@ call_processing_func () {
290304 #SBATCH --time=04:00:00
291305 #SBATCH --mem=16GB
292306 #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
295309 #SBATCH --mail-user=$email
296310 #SBATCH --mail-type=BEGIN,END,FAIL
297311
298312 srun ${scriptRun} --cache="${cache} -\$ {SLURM_JOB_ID}"
299313 EOF
300314 # 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} "
302316
303317 else
304318 eval " $scriptRun "
0 commit comments