OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
getanc.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 
3 """
4 Program to check for updated ancillary data files and download them
5 as appropriate.
6 """
7 
8 import argparse
9 import sys
10 import seadasutils.anc_utils as ga
11 from seadasutils.setupenv import env
12 
13 def main():
14  """
15  The main function for the program. Gets and checks command line options, instantiates
16  a getanc object (from the class defined in anc_utils) and then calls the methods to
17  get the ancillary data.
18  """
19 
20  version = "2.2"
21 
22  # Read commandline options...
23  usage = """
24  %(prog)s [OPTIONS] FILE
25  or
26  -s,--start YYYYDDDHHMMSS [-e,--end YYYDDDHHMMSS] [OPTIONS]
27 
28  FILE Input L1A or L1B file
29 
30  NOTE: Currently NO2 climatological data is used for OBPG operational
31  processing, so to match OBPG distributed data products, the default
32  behaviour disables NO2 searching.
33 
34  This program queries an OBPG server and optionally downloads the optimal
35  ancillary data files for Level-1 to Level-2 processing. If an input file
36  is specified the start and end times are determined automatically, otherwise
37  a start time must be provided by the user.
38 
39  A text file (with the extension '.anc') is created containing parameters
40  that can be directly used as input to the l2gen program for optimal Level-1
41  to Level-2 processing, e.g.:
42 
43  l2gen ifile=<infile> ofile=<outfile> par=<the *.anc text file>
44 
45  EXIT STATUS:
46  0 : all optimal ancillary files exist and are present on the locally
47  99 : an error was encountered; no .anc parameter text file was created
48  31 : no ancillary files currently exist corresponding to the start
49  time and therefore no .anc parameter text file was created
50  1-30 : bitwise value indicating one or more files are not optimal:
51 
52  bit 0 set = missing one or more MET files
53  bit 1 set = missing one or more OZONE files
54  bit 2 set = no SST file found
55  bit 3 set = no NO2 file found
56  bit 4 set = no ICE file found
57 
58  e.g. STATUS=11 indicates there are missing optimal MET, OZONE, and NO2 files
59 
60  """
61 
62  parser = argparse.ArgumentParser(prog="getanc",usage=usage)
63  parser.add_argument('--version', action='version', version='%(prog)s ' + version)
64  parser.add_argument("filename", nargs='?',
65  help="Input L1 file", metavar="L1FILE")
66  parser.add_argument("-s", "--start",
67  help="Time of the first scanline (if used, no input file is required)",
68  metavar="START")
69  parser.add_argument("-e", "--stop",
70  help="Time of last scanline", metavar="STOP")
71 
72  ancdb_help_text = "Use a custom filename for ancillary database. If " \
73  "full path not given, ANCDB is assumed to exist "\
74  "(or will be created) under " + \
75  ga.DEFAULT_ANC_DIR_TEXT + "/log/. If " + \
76  ga.DEFAULT_ANC_DIR_TEXT + "/log/ does not " \
77  "exist, ANCDB is assumed (or will be created) " \
78  "under the current working directory"
79  parser.add_argument("--ancdb", default='ancillary_data.db',help=ancdb_help_text, metavar="ANCDB")
80  parser.add_argument("-o", "--ofile", help="output ancillary par file", metavar="ANC_FILE")
81  parser.add_argument("--ancdir",
82  help="Use a custom directory tree for ancillary files", metavar="ANCDIR")
83  parser.add_argument("-c", "--curdir", action="store_true",
84  default=False, help="Download ancillary files directly into current working directory")
85  parser.add_argument("-r", "--refreshDB", action="store_true", default=False,
86  help="Remove existing database records and re-query for ancillary files")
87  parser.add_argument("--disable-download", action="store_false", dest="download",default=True,
88  help="Disable download of ancillary files not found on hard disk")
89  parser.add_argument("--timeout", type=float, default=10.0, metavar="TIMEOUT",
90  help="set the network timeout in seconds")
91  parser.add_argument("-m", "--mission", help="Mission name", metavar="MISSION")
92 
93  parser.add_argument("-i", "--ice", action="store_false", default=True,
94  help="Do not search for sea-ice ancillary data")
95  parser.add_argument("-n", "--no2", action="store_true", default=False,
96  help="Search for NO2 ancillary data")
97  parser.add_argument("-t", "--sst", action="store_false", default=True,
98  help="Do not search for SST ancillary data")
99  parser.add_argument("-v", "--verbose", action="count",
100  default=0, help="print status messages")
101  parser.add_argument("--noprint", action="store_false", default=True,
102  help="Suppress printing the resulting list of files to the screen")
103  parser.add_argument("-f", "--force-download", action="store_true", dest='force', default=False,
104  help="Force download of ancillary files, even if found on hard disk")
105  parser.add_argument("-u", "--use_filename", action="store_true", default=False,
106  help="Use filename to call API instead of deriving start time")
107 
108  args = parser.parse_args()
109  if args.filename is None and args.start is None:
110  parser.print_help()
111  sys.exit(32)
112 
113  g = ga.getanc(filename=args.filename,
114  start=args.start,
115  stop=args.stop,
116  ancdir=args.ancdir,
117  ancdb=args.ancdb,
118  anc_file=args.ofile,
119  curdir=args.curdir,
120  sensor=args.mission,
121  opt_flag=5, # defaults to retrieving met, ozone, sst, and ice data
122  verbose=args.verbose,
123  printlist=args.noprint,
124  download=args.download,
125  timeout=args.timeout,
126  refreshDB=args.refreshDB,
127  use_filename=args.use_filename)
128 
129  if args.sst is False:
130  g.set_opt_flag('sst', off=True)
131  if args.no2:
132  g.set_opt_flag('no2')
133  if args.ice is False:
134  g.set_opt_flag('ice', off=True)
135 
136  env(g)
137  g.chk()
138  if (args.filename and g.finddb()) or (args.start and g.finddb()):
139  g.setup()
140  else:
141  g.setup()
142  g.findweb()
143  g.locate(forcedl=args.force)
144  g.write_anc_par()
145  g.cleanup()
146  return(g.db_status)
147 
148 if __name__ == "__main__":
149  exit(main())
def env(self)
Definition: setupenv.py:7
def main()
Definition: getanc.py:13