Skip to content

Commit

Permalink
Iss23 (#24)
Browse files Browse the repository at this point in the history
* Bumping version to v0.1.1 to add a minor feature of including NA values in printed stats

* Adding feature to consider or not consider NA values in stats

* adding NA values consideration feature

* Updating long usage notice/message
  • Loading branch information
kasra-keshavarz authored Feb 18, 2023
1 parent d0995ce commit f131743
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 34 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Usage:
Script options:
-d, --dataset Geospatial dataset of interest, currently
available options are: 'MODIS';
'MERIT-Hydro';'SoilGridsV1'
'MERIT-Hydro';'SoilGridsV1';'Landsat';
'gsde';'depth-to-bedrock';
-i, --dataset-dir=DIR The source path of the dataset file(s)
-r, --crs=INT The EPSG code of interest; optional
[defaults to 4326]
Expand All @@ -30,15 +31,17 @@ Script options:
'min';'max';'mean';'majority';'minority';
'median';'quantile';'variety';'variance';
'stdev';'coefficient_of_variation';'frac';
'coords'; optional
'coords'; 'count'; optional
-u, --include-na Include NA values in generated statistics;
optional
-q, --quantile=q1[,q2[...]] Quantiles of interest to be produced if 'quantile'
is included in the '--stat' argument. The values
must be comma delimited float numbers between
0 and 1; optional [defaults to every 5th quantile]
-p, --prefix=STR Prefix prepended to the output files
-c, --cache=DIR Path of the cache directory; optional
-E, --email=STR E-mail when job starts, ends, and
finishes; optional
fails; optional
-V, --version Show version
-h, --help Show this screen and exit
```
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.1.1
15 changes: 13 additions & 2 deletions assets/stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ vrt_path <- args[12];
shapefile_path <- args[13];
output_path <- args[14];
stats <- args[15];
quantiles <- args[16];
include_na <- args[16];
quantiles <- args[17];

# set the working directory path
setwd(working_dir_path)
Expand Down Expand Up @@ -75,11 +76,21 @@ if (coord_var %in% s) {
} else {
include_coords = FALSE
}

# extract ID column name
id_col <- names(p[1])[1]

# check `na_values`
if (include_na == 'true') {
na_values = 9999
print('Including NA values');
} else {
na_values = NA_real_
print('NOT including NA values');
}

# run exactextractr and calculate necessary stats
df <- exactextractr::exact_extract(r, p, s, quantiles=q, append_cols=id_col); # assuming first column indicates ID
df <- exactextractr::exact_extract(r, p, s, default_value=na_values, quantiles=q, append_cols=id_col); # assuming first column indicates ID

# extract centroid coordinates and prepend to `df`
if (include_coords == TRUE) {
Expand Down
6 changes: 4 additions & 2 deletions depth_to_bedrock/depth_to_bedrock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
# Usage Functions
# ===============
short_usage() {
echo "usage: $(basename $0) -cio DIR -v var1[,var2[...]] [-r INT] [-se DATE] [-ln REAL,REAL] [-f PATH] [-t BOOL] [-a stat1[,stat2,[...]] [-q q1[,q2[...]]]] [-p STR] "
echo "usage: $(basename $0) -cio DIR -v var1[,var2[...]] [-r INT] [-se DATE] [-ln REAL,REAL] [-f PATH] [-t BOOL] [-a stat1[,stat2,[...]] [-u BOOL] [-q q1[,q2[...]]]] [-p STR] "
}


# argument parsing using getopt - WORKS ONLY ON LINUX BY DEFAULT
parsedArguments=$(getopt -a -n depth-to-bedrock -o i:o:v:r:s:e:l:n:f:t:a:q:p:c: --long dataset-dir:,output-dir:,variable:,crs:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,print-geotiff:,stat:,quantile:,prefix:,cache: -- "$@")
parsedArguments=$(getopt -a -n depth-to-bedrock -o i:o:v:r:s:e:l:n:f:t:a:u:q:p:c: --long dataset-dir:,output-dir:,variable:,crs:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,print-geotiff:,stat:,include-na:,quantile:,prefix:,cache: -- "$@")
validArguments=$?
if [ "$validArguments" != "0" ]; then
short_usage;
Expand Down Expand Up @@ -75,6 +75,7 @@ do
-f | --shape-file) shapefile="$2" ; shift 2 ;; # required - could be redundant
-t | --print-geotiff) printGeotiff="$2" ; shift 2 ;; # required
-a | --stat) stats="$2" ; shift 2 ;; # optional
-u | --include-na) includeNA="$2" ; shift 2 ;; # required
-q | --quantile) quantiles="$2" ; shift 2 ;; # optional
-p | --prefix) prefix="$2" ; shift 2 ;; # optional
-c | --cache) cache="$2" ; shift 2 ;; # required
Expand Down Expand Up @@ -273,6 +274,7 @@ if [[ -n "$shapefile" ]] && [[ -n $stats ]]; then
"$shapefile" \
"$outputDir/${prefix}stats_${var}.csv" \
"$stats" \
"$includeNA" \
"$quantiles" >> "${outputDir}/${prefix}stats_${var}.log" 2>&1;
done
fi
Expand Down
40 changes: 27 additions & 13 deletions extract-gis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@
# Help functions
# ==============
usage () {
echo "GISTOOL: Geospatial Dataset Processing Script
echo "GISTOOL: Geospatial Data Processing Script
Usage:
extract-gis [options...]
Script options:
-d, --dataset Geospatial dataset of interest, currently
available options are: 'MODIS';
'MERIT-Hydro';'SoilGridsV1'
'MERIT-Hydro';'SoilGridsV1';'Landsat';
'gsde';'depth-to-bedrock';
-i, --dataset-dir=DIR The source path of the dataset file(s)
-r, --crs=INT The EPSG code of interest; optional
[defaults to 4326]
Expand All @@ -66,26 +67,28 @@ Script options:
'min';'max';'mean';'majority';'minority';
'median';'quantile';'variety';'variance';
'stdev';'coefficient_of_variation';'frac';
'coords'; optional
'coords'; 'count'; optional
-u, --include-na Include NA values in generated statistics;
optional
-q, --quantile=q1[,q2[...]] Quantiles of interest to be produced if 'quantile'
is included in the '--stat' argument. The values
must be comma delimited float numbers between
0 and 1; optional [defaults to every 5th quantile]
-p, --prefix=STR Prefix prepended to the output files
-c, --cache=DIR Path of the cache directory; optional
-E, --email=STR E-mail when job starts, ends, and
finishes; optional
fails; optional
-V, --version Show version
-h, --help Show this screen and exit
For bug reports, questions, discussions open an issue
For bug reports, questions, and discussions open an issue
at https://github.com/kasra-keshavarz/gistool/issues" >&1;

exit 0;
}

short_usage () {
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;
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;
}

version () {
Expand All @@ -107,8 +110,11 @@ shopt -s expand_aliases
# =======================
# Parsing input arguments
# =======================
# argument parsing using getopt - WORKS ONLY ON LINUX BY DEFAULT
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 -- "$@")
# argument parsing using getopt -
# ATTENTION: `getopt` is available by default on most GNU/Linux
# distributions, however, it may not work out of the
# box on MacOS or BSD
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 -- "$@")
validArguments=$?
# check if there is no valid options
if [ "$validArguments" != "0" ]; then
Expand Down Expand Up @@ -140,6 +146,7 @@ do
-j | --submit-job) jobSubmission=true ; shift ;; # optional
-t | --print-geotiff) printGeotiff="$2" ; shift 2 ;; # optional
-a | --stat) stats="$2" ; shift 2 ;; # optional
-u | --include-na) includeNA=true ; shift ;; # optional
-q | --quantile) quantiles="$2" ; shift 2 ;; # optional
-p | --prefix) prefixStr="$2" ; shift 2 ;; # required
-c | --cache) cache="$2" ; shift 2 ;; # optional
Expand Down Expand Up @@ -174,6 +181,11 @@ if [[ -z $printGeotiff ]]; then
printGeotiff=true
fi

# if $includeNA is not triggered
if [[ -z $includeNA ]]; then
includeNA=false
fi

# check the value of $printGeotiff
if [[ -n $printGeotiff ]]; then
case "${printGeotiff,,}" in
Expand Down Expand Up @@ -254,6 +266,7 @@ declare -A funcArgs=([geotiffDir]="$geotiffDir" \
[jobSubmission]="$jobSubmission" \
[printGeotiff]="$printGeotiff" \
[stats]="$stats" \
[includeNA]="$includeNA" \
[quantiles]="$quantiles" \
[prefixStr]="$prefixStr" \
[cache]="$cache" \
Expand All @@ -274,13 +287,14 @@ call_processing_func () {
# all processing script files must follow same input argument standard
local scriptRun
read -rd '' scriptRun <<- EOF
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]}"
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]}"
EOF

# evaluate the script file using the arguments provided
if [[ "${funcArgs[jobSubmission]}" == true ]]; then
# Create a temporary directory for keeping job logs
mkdir -p "$HOME/scratch/.gdt_logs"
logDir="$HOME/scratch/.gistool_logs/"
mkdir -p "$logDir"
# SLURM batch file
sbatch <<- EOF
#!/bin/bash
Expand All @@ -290,15 +304,15 @@ call_processing_func () {
#SBATCH --time=04:00:00
#SBATCH --mem=16GB
#SBATCH --job-name=GIS_${scriptName}
#SBATCH --error=$HOME/scratch/.gdt_logs/GIS_%j_err.txt
#SBATCH --output=$HOME/scratch/.gdt_logs/GIS_%j.txt
#SBATCH --error=$logDir/GIS_%j_err.txt
#SBATCH --output=$logDir/GIS_%j.txt
#SBATCH --mail-user=$email
#SBATCH --mail-type=BEGIN,END,FAIL
srun ${scriptRun} --cache="${cache}-\${SLURM_JOB_ID}"
EOF
# echo message
echo "$(basename $0): job submission details are printed under ${HOME}/scratch/.gdt_logs"
echo "$(basename $0): job submission details are printed under ${logDir}"

else
eval "$scriptRun"
Expand Down
9 changes: 6 additions & 3 deletions gsde/gsde.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
# GIS Data Processing Workflow
# Copyright (C) 2022, University of Saskatchewan
# Copyright (C) 2022-2023, University of Saskatchewan
# Copyright (C) 2023, University of Calgary
# Copyright (C) 2021, Wouter Knoben
#
# This file is part of GIS Data Processing Workflow
Expand Down Expand Up @@ -40,12 +41,12 @@
# Usage Functions
# ===============
short_usage() {
echo "usage: $(basename $0) -cio DIR -v var1[,var2[...]] [-r INT] [-se DATE] [-ln REAL,REAL] [-f PATH] [-t BOOL] [-a stat1[,stat2,[...]] [-q q1[,q2[...]]]] [-p STR] "
echo "usage: $(basename $0) -cio DIR -v var1[,var2[...]] [-r INT] [-se DATE] [-ln REAL,REAL] [-f PATH] [-t BOOL] [-a stat1[,stat2,[...]] [-u BOOL] [-q q1[,q2[...]]]] [-p STR] "
}


# argument parsing using getopt - WORKS ONLY ON LINUX BY DEFAULT
parsedArguments=$(getopt -a -n gsde -o i:o:v:r:s:e:l:n:f:t:a:q:p:c: --long dataset-dir:,output-dir:,variable:,crs:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,print-geotiff:,stat:,quantile:,prefix:,cache: -- "$@")
parsedArguments=$(getopt -a -n gsde -o i:o:v:r:s:e:l:n:f:t:a:u:q:p:c: --long dataset-dir:,output-dir:,variable:,crs:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,print-geotiff:,stat:,include-na:,quantile:,prefix:,cache: -- "$@")
validArguments=$?
if [ "$validArguments" != "0" ]; then
short_usage;
Expand Down Expand Up @@ -74,6 +75,7 @@ do
-f | --shape-file) shapefile="$2" ; shift 2 ;; # required - could be redundant
-t | --print-geotiff) printGeotiff="$2" ; shift 2 ;; # required
-a | --stat) stats="$2" ; shift 2 ;; # optional
-u | --include-na) includeNA="$2" ; shift 2 ;; # required
-q | --quantile) quantiles="$2" ; shift 2 ;; # optional
-p | --prefix) prefix="$2" ; shift 2 ;; # optional
-c | --cache) cache="$2" ; shift 2 ;; # required
Expand Down Expand Up @@ -284,6 +286,7 @@ if [[ -n "$shapefile" ]] && [[ -n $stats ]]; then
"$shapefile" \
"$outputDir/${prefix}stats_${var}.csv" \
"$stats" \
"$includeNA" \
"$quantiles" >> "${outputDir}/${prefix}stats_${var}.log" 2>&1;
done
fi
Expand Down
8 changes: 5 additions & 3 deletions landsat/landsat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
# Usage Functions
# ===============
short_usage() {
echo "usage: $(basename $0) -cio DIR -v var1[,var2[...]] [-r INT] [-se DATE] [-ln REAL,REAL] [-f PATH] [-t BOOL] [-a stat1[,stat2,[...]] [-q q1[,q2[...]]]] [-p STR] "
echo "usage: $(basename $0) -cio DIR -v var1[,var2[...]] [-r INT] [-se DATE] [-ln REAL,REAL] [-f PATH] [-t BOOL] [-a stat1[,stat2,[...]] [-u BOOL] [-q q1[,q2[...]]]] [-p STR] "
}


# argument parsing using getopt - WORKS ONLY ON LINUX BY DEFAULT
parsedArguments=$(getopt -a -n landsat -o i:o:v:r:s:e:l:n:f:t:a:q:p:c: --long dataset-dir:,output-dir:,variable:,crs:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,print-geotiff:,stat:,quantile:,prefix:,cache: -- "$@")
parsedArguments=$(getopt -a -n landsat -o i:o:v:r:s:e:l:n:f:t:a:u:q:p:c: --long dataset-dir:,output-dir:,variable:,crs:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,print-geotiff:,stat:,include-na:,quantile:,prefix:,cache: -- "$@")
validArguments=$?
if [ "$validArguments" != "0" ]; then
short_usage;
Expand Down Expand Up @@ -75,6 +75,7 @@ do
-f | --shape-file) shapefile="$2" ; shift 2 ;; # required - could be redundant
-t | --print-geotiff) printGeotiff="$2" ; shift 2 ;; # required
-a | --stat) stats="$2" ; shift 2 ;; # optional
-u | --include-na) includeNA="$2" ; shift 2 ;; # required
-q | --quantile) quantiles="$2" ; shift 2 ;; # optional
-p | --prefix) prefix="$2" ; shift 2 ;; # optional
-c | --cache) cache="$2" ; shift 2 ;; # required
Expand Down Expand Up @@ -385,7 +386,8 @@ if [[ -n "$shapefile" ]] && [[ -n $stats ]]; then
"$shapefile" \
"$outputDir/${prefix}stats_${fileName[0]}.csv" \
"$stats" \
"$quantiles" >> "${outputDir}/${prefix}stats_${fileName[0]}.log" 2>&1;
"$includeNA" \
"$quantiles" >> "${outputDir}/${prefix}stats_${fileName[0]}.log" 2>&1;
wait;
done
fi
Expand Down
5 changes: 3 additions & 2 deletions merit_hydro/merit_hydro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
# Usage Functions
# ===============
short_usage() {
echo "usage: $(basename $0) -cio DIR -v var1[,var2[...]] [-r INT] [-se DATE] [-ln REAL,REAL] [-f PATH] [-t BOOL] [-a stat1[,stat2,[...]] [-q q1[,q2[...]]]] [-p STR] "
echo "usage: $(basename $0) -cio DIR -v var1[,var2[...]] [-r INT] [-se DATE] [-ln REAL,REAL] [-f PATH] [-t BOOL] [-a stat1[,stat2,[...]] [-u BOOL] [-q q1[,q2[...]]]] [-p STR] "
}


# argument parsing using getopt - WORKS ONLY ON LINUX BY DEFAULT
parsedArguments=$(getopt -a -n merit_hydro -o i:o:v:r:s:e:l:n:f:t:a:q:p:c: --long dataset-dir:,output-dir:,variable:,crs:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,print-geotiff:,stat:,quantile:,prefix:,cache: -- "$@")
parsedArguments=$(getopt -a -n merit_hydro -o i:o:v:r:s:e:l:n:f:t:a:u:q:p:c: --long dataset-dir:,output-dir:,variable:,crs:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,print-geotiff:,stat:,include-na:,quantile:,prefix:,cache: -- "$@")
validArguments=$?
if [ "$validArguments" != "0" ]; then
short_usage;
Expand Down Expand Up @@ -376,6 +376,7 @@ if [[ -n "$shapefile" ]] && [[ -n $stats ]]; then
"$shapefile" \
"$outputDir/${prefix}stats_${var}.csv" \
"$stats" \
"$includeNA" \
"$quantiles" >> "${outputDir}/${prefix}stats_${var}.log" 2>&1;
done
fi
Expand Down
6 changes: 4 additions & 2 deletions modis/modis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
# Usage Functions
# ===============
short_usage() {
echo "usage: $(basename $0) -cio DIR -v var1[,var2[...]] [-r INT] [-se DATE] [-ln REAL,REAL] [-f PATH] [-t BOOL] [-a stat1[,stat2,[...]] [-q q1[,q2[...]]]] [-p STR] "
echo "usage: $(basename $0) -cio DIR -v var1[,var2[...]] [-r INT] [-se DATE] [-ln REAL,REAL] [-f PATH] [-t BOOL] [-a stat1[,stat2,[...]] [-u BOOL] [-q q1[,q2[...]]]] [-p STR] "
}


# argument parsing using getopt - WORKS ONLY ON LINUX BY DEFAULT
parsedArguments=$(getopt -a -n modis -o i:o:v:r:s:e:l:n:f:t:a:q:p:c: --long dataset-dir:,output-dir:,variable:,crs:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,print-geotiff:,stat:,quantile:,prefix:,cache: -- "$@")
parsedArguments=$(getopt -a -n modis -o i:o:v:r:s:e:l:n:f:t:a:u:q:p:c: --long dataset-dir:,output-dir:,variable:,crs:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,print-geotiff:,stat:,include-na:,quantile:,prefix:,cache: -- "$@")
validArguments=$?
if [ "$validArguments" != "0" ]; then
short_usage;
Expand Down Expand Up @@ -75,6 +75,7 @@ do
-f | --shape-file) shapefile="$2" ; shift 2 ;; # required - could be redundant
-t | --print-geotiff) printGeotiff="$2" ; shift 2 ;; # required
-a | --stat) stats="$2" ; shift 2 ;; # optional
-u | --include-na) includeNA="$2" ; shift 2 ;; # required
-q | --quantile) quantiles="$2" ; shift 2 ;; # optional
-p | --prefix) prefix="$2" ; shift 2 ;; # optional
-c | --cache) cache="$2" ; shift 2 ;; # required
Expand Down Expand Up @@ -314,6 +315,7 @@ if [[ -n "$shapefile" ]] && [[ -n $stats ]]; then
"$shapefile" \
"$outputDir/${var}/${prefix}stats_${var}_${yr}.csv" \
"$stats" \
"$includeNA" \
"$quantiles" >> "${outputDir}/${var}/${prefix}stats_${var}_${yr}.log" 2>&1;
done
done
Expand Down
8 changes: 5 additions & 3 deletions soil_grids/soil_grids_v1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright (C) 2022-2023, University of Saskatchewan
# Copyright (C) 2023, University of Calgary
#
# This file is part of GIS Data Processing Workflow
# This file is part of Geospatial Data Processing Workflow
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -41,12 +41,12 @@
# Usage Functions
# ===============
short_usage() {
echo "usage: $(basename $0) -cio DIR -v var1[,var2[...]] [-r INT] [-se DATE] [-ln REAL,REAL] [-f PATH] [-t BOOL] [-a stat1[,stat2,[...]] [-q q1[,q2[...]]]] [-p STR] "
echo "usage: $(basename $0) -cio DIR -v var1[,var2[...]] [-r INT] [-se DATE] [-ln REAL,REAL] [-f PATH] [-t BOOL] [-a stat1[,stat2,[...]] [-u BOOL] [-q q1[,q2[...]]]] [-p STR] "
}


# argument parsing using getopt - WORKS ONLY ON LINUX BY DEFAULT
parsedArguments=$(getopt -a -n soil-grids-v1 -o i:o:v:r:s:e:l:n:f:t:a:q:p:c: --long dataset-dir:,output-dir:,variable:,crs:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,print-geotiff:,stat:,quantile:,prefix:,cache: -- "$@")
parsedArguments=$(getopt -a -n soil-grids-v1 -o i:o:v:r:s:e:l:n:f:t:a:u:q:p:c: --long dataset-dir:,output-dir:,variable:,crs:,start-date:,end-date:,lat-lims:,lon-lims:,shape-file:,print-geotiff:,stat:,include-na:,quantile:,prefix:,cache: -- "$@")
validArguments=$?
if [ "$validArguments" != "0" ]; then
short_usage;
Expand Down Expand Up @@ -75,6 +75,7 @@ do
-f | --shape-file) shapefile="$2" ; shift 2 ;; # required - could be redundant
-t | --print-geotiff) printGeotiff="$2" ; shift 2 ;; # required
-a | --stat) stats="$2" ; shift 2 ;; # optional
-u | --include-na) includeNA="$2" ; shift 2 ;; # required
-q | --quantile) quantiles="$2" ; shift 2 ;; # optional
-p | --prefix) prefix="$2" ; shift 2 ;; # optional
-c | --cache) cache="$2" ; shift 2 ;; # required
Expand Down Expand Up @@ -272,6 +273,7 @@ if [[ -n "$shapefile" ]] && [[ -n $stats ]]; then
"$shapefile" \
"$outputDir/${prefix}stats_${var}.csv" \
"$stats" \
"$includeNA" \
"$quantiles" >> "${outputDir}/${prefix}stats_${var}.log" 2>&1;
done
fi
Expand Down

0 comments on commit f131743

Please sign in to comment.