5 from pathlib
import Path
10 from shlex
import quote
12 logger = logging.getLogger(
'viirs_l1_benchmark')
14 'SNPP':
'viirs-snpp-sample',
15 'NOAA20':
'viirs-noaa20-sample'
23 Returns the path to the program named in prog_name.
24 None is returned if the program is not found.
29 if Path.exists(packageroot /
'bin' / prog_name):
30 prog_path = packageroot /
'bin' / prog_name
32 err_msg =
"Cannot find program %s" % prog_name
33 logging.error(err_msg)
40 Execute a process on the system
42 logging.info(
"Running: " +
' '.join(command))
44 result = subprocess.run(command, shell=
False, capture_output=
True, text=
True)
45 std_out = result.stdout
46 err_out = result.stderr
49 logging.debug(std_out)
51 logging.error(err_out)
53 print(
"Exiting: {command} returned a status {status}".
format(command=
' '.join(command),status=result.returncode), result.returncode)
57 logging.debug(std_out)
59 logging.debug(err_out)
63 Set up and run a program that accepts keyword=value command line arguemnts ala CLO
66 logging.info(
'###### %s ######\n' % program)
69 params = [
"%s=%s" % (k,v)
for k, v
in artifacts[platform][program].items()]
76 Set up and run a program that accepts positional command line arguemnts
79 logging.info(
'###### %s ######\n' % program)
82 cmd.extend(artifacts[platform][program])
87 Verify the generated products against a standard set
90 logging.info(
'###### Verifying outputs ######\n')
95 nccmp_tolerance =
"-T %f" % tolerance
97 skipthese = [
'cmn_lut_file',
'geo_lut_file',
'polar_wander_file',
'leapsec_file',
98 'static_lut_file',
'rsb_dynamic_lut_file',
'dnb_dynamic_lut_file',
'straylight_lut_file']
100 for program
in (
'calibrate_viirs',
'geolocate_viirs'):
101 pdict = artifacts[platform][program]
103 for k,v
in pdict.items():
108 logging.info(
"Comparing %s output %s ..." % (k,v))
109 cmd = [
str(prog),
'-m',
'-g',
'-d',
'-f',
'-C',
'10',
'-G',
'date_created,ProductionTime,software_version', nccmp_tolerance,
''.join([
'../baseline/',v]), v]
112 if __name__ ==
"__main__":
114 parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description=
'''\
115 This program runs a benchmark the VIIRS L1 code suite including:
116 l1agen_viirs, calibrate_viirs and geolocate_viirs
117 SNPP and NOAA-20 are supported
119 This script requires that the benchmark data files have previously been downloaded
120 The working directory for this script should be the directory in which the benchmark data have been untar'd
121 (yeah, lazy programmers)
123 parser.add_argument(
'--mission', type=str, help=
'Mission to test. If not set, both SNPP and NOAA20 are run',
124 choices=[
'SNPP',
'NOAA20'], default=
None)
125 parser.add_argument(
'--packageroot',type=str, help=
'''Base directory for package install
126 This can also be set with the OCSSWROOT or VIIRSL1ROOT environment variables
127 If both are set, OCSSWROOT is used''')
128 parser.add_argument(
'--logfile',
'-l', type=str, default=
'viirs_l1_benchmark.log', help=
"output log filename")
129 parser.add_argument(
'--check',
'-c', action=
"store_true", default=
False,
130 help=
'verify the generated products against the standard artifacts')
131 parser.add_argument(
'--tolerance',
'-t',type=float, default=
None, help=
"Tolerance (in percentage) to allow when running artifact verification")
132 parser.add_argument(
'--artifacts',
'-a', type=str, default=
"viirs_l1_benchmark.json", help=
"JSON file containing the test artifacts to generate")
133 parser.add_argument(
'--verbose',
'-v', action=
"count", default=0,
134 help=
'each occurrence increases verbosity (default is ERROR): -v=WARNING -vv=INFO -vvv=DEBUG')
137 args = parser.parse_args()
139 sanitize = [
'packageroot',
'logfile',
'artifacts']
140 for arg
in vars(args):
142 value = getattr(args,arg)
144 setattr(args,arg,quote(value))
146 with open(args.artifacts)
as f:
147 artifacts = json.load(f)
150 levels = [logging.ERROR, logging.WARN, logging.INFO, logging.DEBUG]
151 logging.basicConfig(filename=args.logfile,
152 format=
'-%(levelname)s- %(asctime)s - %(message)s',
153 level=levels[args.verbose])
154 logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
158 rootvar = args.packageroot
160 rootvar = os.environ.get(
'OCSSWROOT')
162 rootvar = os.environ.get(
'VIIRSL1ROOT')
164 packageroot = Path(rootvar)
165 if (
not packageroot.exists())
or (
not packageroot.is_dir()):
166 errormsg =
"package root variable does not exist or is not a directory path!"
167 logging.error(errormsg)
170 errormsg =
"package root variable is not defined!"
171 logging.error(errormsg)
174 missions = [
'SNPP',
'NOAA20']
176 missions = [args.mission]
179 for mission
in missions:
180 logging.info(
"Processing platform: %s",mission)
181 os.chdir(os.path.join(cwd,workingDir[mission]))