OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
modis_L1A_extract.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 
3 import seadasutils.anc_utils as anc_utils
4 import argparse
5 from shlex import quote
6 from modis.modis_utils import buildpcf, modis_env
8 import modis.modis_GEO_utils as ga
9 from seadasutils.setupenv import env
10 import sys
11 
12 if __name__ == "__main__":
13 
14  version = "1.1"
15 
16  # Read commandline options...
17 
18  parser = argparse.ArgumentParser(prog="modis_L1A_extract")
19  parser.add_argument('--version', action='version', version='%(prog)s ' + version)
20 
21  parser.add_argument("filename", nargs='?',
22  help="Input L1A file to extract", metavar="L1AFILE")
23  parser.add_argument("-p", "--parfile",
24  help="Parameter file containing program inputs", metavar="PARFILE")
25  parser.add_argument("-o", "--output",
26  help="Output L1A extract filename - defaults to L1AFILE.sub", metavar="EXTRACTFILE")
27  parser.add_argument("-g", "--geofile",
28  help="INPUT GEOFILE filename - defaults to basename of L1AFILE +'.GEO'", metavar="GEOFILE")
29  parser.add_argument("-n", "--north", type=float,
30  help="Northernmost desired latitude", metavar="NORTH")
31  parser.add_argument("-s", "--south", type=float,
32  help="Southernmost desired latitude", metavar="SOUTH")
33  parser.add_argument("-w", "--west", type=float,
34  help="Westernmost desired longitude", metavar="WEST")
35  parser.add_argument("-e", "--east", type=float,
36  help="Easternmost desired longitude", metavar="EAST")
37  parser.add_argument("--extract_geo",
38  help="extract geolocation filename", metavar="EXGEO")
39  parser.add_argument("--att1",
40  help="Input attitude filename 1 (chronological)", metavar="ATT1")
41  parser.add_argument("--att2",
42  help="Input attitude filename 2 (chronological)", metavar="ATT2")
43  parser.add_argument("--att3",
44  help="Input attitude filename 3 (chronological)", metavar="ATT3")
45  parser.add_argument("--eph1",
46  help="Input ephemeris filename 1 (chronological)", metavar="EPH1")
47  parser.add_argument("--eph2",
48  help="Input ephemeris filename 2 (chronological)", metavar="EPH2")
49  parser.add_argument("--eph3",
50  help="Input ephemeris filename 3 (chronological)", metavar="EPH3")
51  ancdb_help_text = "Use a custom filename for ancillary database. If " \
52  "full path not given, ANCDB is assumed to exist "\
53  "(or will be created) under " + \
54  anc_utils.DEFAULT_ANC_DIR_TEXT + "/log/. If " + \
55  anc_utils.DEFAULT_ANC_DIR_TEXT + "/log/ does not " \
56  "exist, ANCDB is assumed (or will be created) " \
57  "under the current working directory"
58  parser.add_argument("--ancdb", default='ancillary_data.db',help=ancdb_help_text, metavar="ANCDB")
59  parser.add_argument("--ancdir",
60  help="Use a custom directory tree for ancillary files", metavar="ANCDIR")
61  parser.add_argument("-v", "--verbose", action="store_true",
62  default=False, help="print status messages")
63  parser.add_argument("--log", action="store_true",
64  default=False, help="Save processing log file(s)")
65 
66  args = parser.parse_args()
67 
68  if args.parfile is None and args.filename is None:
69  parser.print_help()
70  sys.exit(1)
71 
72  parfile = None
73  if args.parfile:
74  parfile = quote(args.parfile)
75 
76  geofile = None
77  if args.geofile:
78  geofile = quote(args.geofile)
79 
80  ofile = "%s.sub" % args.filename
81  if args.output:
82  ofile = quote(args.output)
83 
84  m = ex.extract(filename=quote(args.filename),
85  parfile=parfile,
86  geofile=geofile,
87  outfile=ofile,
88  log=args.log,
89  north=args.north,
90  south=args.south,
91  west=args.west,
92  east=args.east,
93  verbose=args.verbose)
94 
95  env(m)
96  modis_env(m)
97  m.chk()
98  status = m.run()
99  if not status:
100  # Create geolocation file for extract
101  g = ga.modis_geo(filename=ofile,
102  geofile=args.extract_geo,
103  ancdb=args.ancdb,
104  ancdir=args.ancdir,
105  a1=args.att1,
106  a2=args.att2,
107  a3=args.att3,
108  e1=args.eph1,
109  e2=args.eph2,
110  e3=args.eph3,
111  log=args.log,
112  verbose=args.verbose)
113 
114  env(g)
115  modis_env(g)
116  g.atteph()
117  buildpcf(g)
118 
119  g.run()
120  sys.exit(0)
121  else:
122  sys.exit(status)
123 
def modis_env(self)
Definition: modis_utils.py:227
def buildpcf(self)
Definition: modis_utils.py:17
def env(self)
Definition: setupenv.py:7