Skip to content
Browse files

Changed command line arguments for glue scripts so you need '-d' to

specify a directory to search for and '-f' to a series of files.
'-d' and '-D' were changed to '--fornav-d' and '--fornav-D' for clarity.
Made 2 new test scripts (run/verify) for the viirs2geotiff glue script.
Changed the polar2grid_env.sh script to unset PYTHONPATH so the user's
settings don't affect us.
  • Loading branch information...
1 parent aa4ff11 commit 6594985edd4da5db59399f41c2a3ff2278af3212 @davidh-ssec committed
View
31 py/polar2grid/polar2grid/viirs2awips.py
@@ -444,12 +444,14 @@ def main():
parser.add_argument('-v', '--verbose', dest='verbosity', action="count", default=0,
help='each occurrence increases verbosity 1 level through ERROR-WARNING-INFO-DEBUG (default INFO)')
- parser.add_argument('-D', dest='fornav_D', default=40,
+ parser.add_argument('--fornav-D', dest='fornav_D', default=40,
help="Specify the -D option for fornav")
- parser.add_argument('-d', dest='fornav_d', default=2,
+ parser.add_argument('--fornav-d', dest='fornav_d', default=2,
help="Specify the -d option for fornav")
- parser.add_argument('-f', dest='get_files', default=False, action="store_true",
- help="Specify that hdf files are listed, not a directory")
+ parser.add_argument('-f', dest='data_files', nargs="+",
+ help="List of one or more hdf files")
+ parser.add_argument('-d', dest='data_dir', nargs="?",
+ help="Data directory to look for input data files")
parser.add_argument('--sp', dest='single_process', default=False, action='store_true',
help="Processing is sequential instead of one process per kind of band")
parser.add_argument('--num-procs', dest="num_procs", default=1,
@@ -460,6 +462,8 @@ def main():
help="Don't create pseudo bands")
parser.add_argument('--rescale-config', dest='rescale_config', default=None,
help="specify alternate rescale configuration file")
+ parser.add_argument('--new-dnb', dest='new_dnb', default=False, action='store_true',
+ help="run new DNB scaling if provided DNB data (temporary)") # XXX
# Remapping/Grids
parser.add_argument('-g', '--grids', dest='forced_grids', nargs="+", default="all",
@@ -472,11 +476,6 @@ def main():
help="Specify a different ncml file to use")
parser.add_argument('--backend-config', dest='backend_config', default=None,
help="specify alternate backend configuration file")
- parser.add_argument('--new-dnb', dest='new_dnb', default=False, action='store_true',
- help="run new DNB scaling if provided DNB data (temporary)") # XXX
-
- parser.add_argument('data_files', nargs="+",
- help="Data directory where satellite data is stored or list of data filenames if '-f' is specified")
args = parser.parse_args()
@@ -502,18 +501,10 @@ def main():
log.error("Specified nc file does not exist '%s'" % args.forced_nc)
return -1
- if "help" in args.data_files:
- parser.print_help()
- sys.exit(0)
- elif "remove" in args.data_files:
- log.debug("Removing previous products")
- remove_products()
- sys.exit(0)
-
- if args.get_files:
+ if args.data_files:
hdf_files = args.data_files[:]
- elif len(args.data_files) == 1:
- base_dir = os.path.abspath(os.path.expanduser(args.data_files[0]))
+ elif args.data_dir:
+ base_dir = os.path.abspath(os.path.expanduser(args.data_dir))
hdf_files = [ os.path.join(base_dir,x) for x in os.listdir(base_dir) if x.startswith("SV") and x.endswith(".h5") ]
else:
log.error("Wrong number of arguments")
View
31 py/polar2grid/polar2grid/viirs2binary.py
@@ -343,8 +343,14 @@ def main():
parser.add_argument('-v', '--verbose', dest='verbosity', action="count", default=0,
help='each occurrence increases verbosity 1 level through ERROR-WARNING-INFO-DEBUG (default INFO)')
- parser.add_argument('-f', dest='get_files', default=False, action="store_true",
- help="Specify that hdf files are listed, not a directory")
+ parser.add_argument('--fornav-D', dest='fornav_D', default=40,
+ help="Specify the -D option for fornav")
+ parser.add_argument('--fornav-d', dest='fornav_d', default=2,
+ help="Specify the -d option for fornav")
+ parser.add_argument('-f', dest='data_files', nargs="+",
+ help="List of one or more hdf files")
+ parser.add_argument('-d', dest='data_dir', nargs="?",
+ help="Data directory to look for input data files")
parser.add_argument('--sp', dest='single_process', default=False, action='store_true',
help="Processing is sequential instead of one process per kind of band")
parser.add_argument('--num-procs', dest="num_procs", default=1,
@@ -361,13 +367,6 @@ def main():
# Remapping/Grids
parser.add_argument('-g', '--grids', dest='forced_grids', nargs="+", default="wgs84_fit",
help="Force remapping to only some grids, defaults to 'wgs84_fit', use 'all' for determination")
- parser.add_argument('-D', dest='fornav_D', default=40,
- help="Specify the -D option for fornav")
- parser.add_argument('-d', dest='fornav_d', default=2,
- help="Specify the -d option for fornav")
-
- parser.add_argument('data_files', nargs="+",
- help="Data directory where satellite data is stored or list of data filenames if '-f' is specified")
args = parser.parse_args()
@@ -383,18 +382,10 @@ def main():
forced_grids = args.forced_grids
if forced_grids == 'all': forced_grids = None
- if "help" in args.data_files:
- parser.print_help()
- sys.exit(0)
- elif "remove" in args.data_files:
- log.debug("Removing previous products")
- remove_products()
- sys.exit(0)
-
- if args.get_files:
+ if args.data_files:
hdf_files = args.data_files[:]
- elif len(args.data_files) == 1:
- base_dir = os.path.abspath(os.path.expanduser(args.data_files[0]))
+ elif args.data_dir:
+ base_dir = os.path.abspath(os.path.expanduser(args.data_dir))
hdf_files = [ os.path.join(base_dir,x) for x in os.listdir(base_dir) if x.startswith("SV") and x.endswith(".h5") ]
else:
log.error("Wrong number of arguments")
View
29 py/polar2grid/polar2grid/viirs2gtiff.py
@@ -135,7 +135,7 @@ def process_data_sets(filepaths,
filepaths,
scale_dnb=True,
new_dnb=new_dnb,
- create_fog=True,
+ create_fog=create_pseudo,
cut_bad=True
)
@@ -353,12 +353,14 @@ def main():
parser.add_argument('-v', '--verbose', dest='verbosity', action="count", default=0,
help='each occurrence increases verbosity 1 level through ERROR-WARNING-INFO-DEBUG (default INFO)')
- parser.add_argument('-D', dest='fornav_D', default=40,
+ parser.add_argument('--fornav-D', dest='fornav_D', default=40,
help="Specify the -D option for fornav")
- parser.add_argument('-d', dest='fornav_d', default=2,
+ parser.add_argument('--fornav-d', dest='fornav_d', default=2,
help="Specify the -d option for fornav")
- parser.add_argument('-f', dest='get_files', default=False, action="store_true",
- help="Specify that hdf files are listed, not a directory")
+ parser.add_argument('-f', dest='data_files', nargs="+",
+ help="List of one or more hdf files")
+ parser.add_argument('-d', dest='data_dir', nargs="?",
+ help="Data directory to look for input data files")
parser.add_argument('--sp', dest='single_process', default=False, action='store_true',
help="Processing is sequential instead of one process per kind of band")
parser.add_argument('--num-procs', dest="num_procs", default=1,
@@ -382,9 +384,6 @@ def main():
parser.add_argument('--dont_inc', dest="inc_by_one", default=True, action="store_false",
help="tell rescaler to not increment by one to scaled data can have a 0 fill value (ex. 0-254 -> 1-255 with 0 being fill)")
- parser.add_argument('data_files', nargs="+",
- help="Data directory where satellite data is stored or list of data filenames if '-f' is specified")
-
args = parser.parse_args()
levels = [logging.ERROR, logging.WARN, logging.INFO, logging.DEBUG]
@@ -399,18 +398,10 @@ def main():
forced_grids = args.forced_grids
if forced_grids == 'all': forced_grids = None
- if "help" in args.data_files:
- parser.print_help()
- sys.exit(0)
- elif "remove" in args.data_files:
- log.debug("Removing previous products")
- remove_products()
- sys.exit(0)
-
- if args.get_files:
+ if args.data_files:
hdf_files = args.data_files[:]
- elif len(args.data_files) == 1:
- base_dir = os.path.abspath(os.path.expanduser(args.data_files[0]))
+ elif args.data_dir:
+ base_dir = os.path.abspath(os.path.expanduser(args.data_dir))
hdf_files = [ os.path.join(base_dir,x) for x in os.listdir(base_dir) if x.startswith("SV") and x.endswith(".h5") ]
else:
log.error("Wrong number of arguments")
View
3 py/polar2grid_core/MANIFEST.in
@@ -0,0 +1,3 @@
+include polar2grid/core/rescale_configs/*.conf
+include polar2grid/core/*.conf
+
View
2 swbundle/polar2grid_env.sh
@@ -11,6 +11,8 @@ if [ -z "$POLAR2GRID_REV" ]; then
export PATH=$POLAR2GRID_HOME/bin:$PATH
# Add ShellB3 to PATH
export PATH=$POLAR2GRID_HOME/ShellB3/bin:$PATH
+ # Don't let someone else's PYTHONPATH mess us up
+ unset PYTHONPATH
export POLAR2GRID_REV="$Id$"
fi
View
71 swbundle_tests/v2g_ak_run.sh
@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+### Run simple tests to verify viirs2geotiff will run properly ###
+# Should be renamed run.sh in the corresponding test tarball
+
+
+oops() {
+ echo "OOPS: $*"
+ echo "FAILURE"
+ exit 1
+}
+
+run_test() {
+ echo "Running test for data in $2..."
+ set -x
+ viirs2gtiff.sh -g $1 -d $2
+ set +x
+ if [ $? -ne 0 ]; then
+ echo "ERROR: viirs2awips.sh did not complete test $2 successfully"
+ echo "ERROR: Won't remove test directory, check it for more information"
+ echo "FAILURE"
+ exit 2
+ fi
+}
+
+# Setup viirs2awips environment
+if [ -z "$POLAR2GRID_HOME" ]; then
+ oops "POLAR2GRID_HOME needs to be defined"
+fi
+source $POLAR2GRID_HOME/bin/polar2grid_env.sh
+
+# Find out where the tests are relative to this script
+TEST_BASE="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+echo "Base directory for all test cases is $TEST_BASE"
+
+# Make sure we can call viirs2awips.sh before making any test directories
+which viirs2gtiff.sh || oops "viirs2gtiff.sh is not in PATH"
+
+# Check if they specified a different working directory
+if [ $# -ne 1 ]; then
+ WORK_DIR=./p2g-v2g-ak-tests-$$
+else
+ echo "Will use $1 directory, but won't delete it"
+ WORK_DIR=$1
+fi
+
+echo "Making temporary test directory $WORK_DIR"
+mkdir -p $WORK_DIR || oops "Could not create test directory '$WORK_DIR'"
+cd $WORK_DIR
+
+# Run tests for each test data directory in the base directory
+for DDIR in $TEST_BASE/*; do
+ if [ -d $DDIR ] && [ `basename $DDIR` != "verify" ]; then
+ # Make a unique working test directory
+ TDIR=`basename $DDIR`-$$
+ echo "Making temporary working directory $TDIR"
+ mkdir -p $TDIR || oops "Couldn't make $TDIR test directory"
+ pushd $TDIR
+
+ run_test wgs84_fit $DDIR
+ # Move all NetCDF files here
+ mv npp_viirs_*.tif ../ || oops "No geotiff files created for $DDIR in $TDIR"
+
+ popd
+ echo "Removing test dir $TDIR"
+ rm -r $TDIR || oops "Couldn't remove $TDIR test directory"
+ fi
+done
+
+# End of all tests
+echo "SUCCESS"
+
View
46 swbundle_tests/v2g_ak_verify.sh
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+### Verify simple test products with known products ###
+# Should be renamed verify.sh in the corresponding test tarball
+
+oops() {
+ echo "OOPS: $*"
+ echo "FAILURE"
+ exit 1
+}
+
+# Setup viirs2gtiff environment
+if [ -z "$POLAR2GRID_HOME" ]; then
+ oops "POLAR2GRID_HOME needs to be defined"
+fi
+source $POLAR2GRID_HOME/bin/polar2grid_env.sh
+
+# Find out where the tests are relative to this script
+TEST_BASE="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+echo "Base directory for all test cases is $TEST_BASE"
+VERIFY_BASE=$TEST_BASE/verify
+
+# Check if they specified a different working directory
+if [ $# -ne 1 ]; then
+ WORK_DIR=./p2g-v2g-ak-tests
+else
+ echo "Will use $1 directory"
+ WORK_DIR=$1
+fi
+
+if [ ! -d $WORK_DIR ]; then
+ oops "Working directory $WORK_DIR does not exist"
+fi
+
+# Run tests for each test data directory in the base directory
+for VFILE in $VERIFY_BASE/*; do
+ WFILE=$WORK_DIR/`basename $VFILE`
+ if [ ! -f $WFILE ]; then
+ oops "Could not find output file $WFILE"
+ fi
+ echo "Comparing $WFILE to known valid file"
+ diff $WFILE $VFILE || oops "$WFILE was different than expected"
+done
+
+# End of all tests
+echo "SUCCESS"
+
View
71 swbundle_tests/v2g_econus_run.sh
@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+### Run simple tests to verify viirs2geotiff will run properly ###
+# Should be renamed run.sh in the corresponding test tarball
+
+
+oops() {
+ echo "OOPS: $*"
+ echo "FAILURE"
+ exit 1
+}
+
+run_test() {
+ echo "Running test for data in $2..."
+ set -x
+ viirs2gtiff.sh -g $1 -d $2
+ set +x
+ if [ $? -ne 0 ]; then
+ echo "ERROR: viirs2awips.sh did not complete test $2 successfully"
+ echo "ERROR: Won't remove test directory, check it for more information"
+ echo "FAILURE"
+ exit 2
+ fi
+}
+
+# Setup viirs2awips environment
+if [ -z "$POLAR2GRID_HOME" ]; then
+ oops "POLAR2GRID_HOME needs to be defined"
+fi
+source $POLAR2GRID_HOME/bin/polar2grid_env.sh
+
+# Find out where the tests are relative to this script
+TEST_BASE="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+echo "Base directory for all test cases is $TEST_BASE"
+
+# Make sure we can call viirs2awips.sh before making any test directories
+which viirs2gtiff.sh || oops "viirs2gtiff.sh is not in PATH"
+
+# Check if they specified a different working directory
+if [ $# -ne 1 ]; then
+ WORK_DIR=./p2g-v2g-econus-tests-$$
+else
+ echo "Will use $1 directory, but won't delete it"
+ WORK_DIR=$1
+fi
+
+echo "Making temporary test directory $WORK_DIR"
+mkdir -p $WORK_DIR || oops "Could not create test directory '$WORK_DIR'"
+cd $WORK_DIR
+
+# Run tests for each test data directory in the base directory
+for DDIR in $TEST_BASE/*; do
+ if [ -d $DDIR ] && [ `basename $DDIR` != "verify" ]; then
+ # Make a unique working test directory
+ TDIR=`basename $DDIR`-$$
+ echo "Making temporary working directory $TDIR"
+ mkdir -p $TDIR || oops "Couldn't make $TDIR test directory"
+ pushd $TDIR
+
+ run_test wgs84_fit $DDIR
+ # Move all NetCDF files here
+ mv npp_viirs_*.tif ../ || oops "No geotiff files created for $DDIR in $TDIR"
+
+ popd
+ echo "Removing test dir $TDIR"
+ rm -r $TDIR || oops "Couldn't remove $TDIR test directory"
+ fi
+done
+
+# End of all tests
+echo "SUCCESS"
+
View
46 swbundle_tests/v2g_econus_verify.sh
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+### Verify simple test products with known products ###
+# Should be renamed verify.sh in the corresponding test tarball
+
+oops() {
+ echo "OOPS: $*"
+ echo "FAILURE"
+ exit 1
+}
+
+# Setup viirs2gtiff environment
+if [ -z "$POLAR2GRID_HOME" ]; then
+ oops "POLAR2GRID_HOME needs to be defined"
+fi
+source $POLAR2GRID_HOME/bin/polar2grid_env.sh
+
+# Find out where the tests are relative to this script
+TEST_BASE="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+echo "Base directory for all test cases is $TEST_BASE"
+VERIFY_BASE=$TEST_BASE/verify
+
+# Check if they specified a different working directory
+if [ $# -ne 1 ]; then
+ WORK_DIR=./p2g-v2g-ak-tests
+else
+ echo "Will use $1 directory"
+ WORK_DIR=$1
+fi
+
+if [ ! -d $WORK_DIR ]; then
+ oops "Working directory $WORK_DIR does not exist"
+fi
+
+# Run tests for each test data directory in the base directory
+for VFILE in $VERIFY_BASE/*; do
+ WFILE=$WORK_DIR/`basename $VFILE`
+ if [ ! -f $WFILE ]; then
+ oops "Could not find output file $WFILE"
+ fi
+ echo "Comparing $WFILE to known valid file"
+ diff $WFILE $VFILE || oops "$WFILE was different than expected"
+done
+
+# End of all tests
+echo "SUCCESS"
+

0 comments on commit 6594985

Please sign in to comment.
Something went wrong with that request. Please try again.