OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
obpg_file_type.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 """
4 A class for determining the OBPG type of a file.
5 """
6 __version__ = '2.0'
7 
8 __author__ = 'melliott'
9 
10 import optparse
11 import os
12 import sys
14 
16  usage_text = \
17  """usage: %prog [options] FILE_NAME [FILE_NAME ...]
18 
19  The following file types are recognized:
20  Instruments: CZCS, GOCI, HICO, Landsat OLI, MODIS Aqua,
21  MODIS Terra, OCM2, OCTS, SeaWiFS, VIIRSN, VIIRSJ1
22  Processing Levels: L0 (MODIS only), L1A, L1B, L2, L3 binned,
23  L3 mapped """
24  return usage_text
25 
26 def process_command_line(cl_parser):
27  """
28  Uses optparse to get the command line options & arguments.
29  """
30  cl_parser.add_option('-t', '--times', action='store_true',
31  dest='times', default=False,
32  help='output start and end times for the file(s)')
33  (opts, args) = cl_parser.parse_args()
34  return opts, args
35 
36 def main():
37  """
38  Main function to drive the program when invoked as a program.
39  """
40  use_msg = get_usage_text()
41  ver_msg = ' '.join(['%prog', __version__])
42  cl_parser = optparse.OptionParser(usage=use_msg, version=ver_msg)
43  (opts, args) = process_command_line(cl_parser)
44 
45  if len(args) > 0:
46  for arg in args:
47  fname = arg
48  file_typer = mlp.get_obpg_file_type.ObpgFileTyper(fname)
49  (obpg_file_type, instrument) = file_typer.get_file_type()
50  output = ''
51  if obpg_file_type == 'unknown':
52  if instrument != 'unknown':
53  output = '{0}: {1}: unknown'.format(
54  os.path.basename(fname), instrument)
55  else:
56  output = '{0}: unknown: unknown'.format(
57  os.path.basename(fname))
58  else:
59  if instrument != 'unknown':
60  output = '{0}: {1}: {2}'.format(os.path.basename(fname),
61  instrument, obpg_file_type)
62  else:
63  output = '{0}: unknown: {1}'.format(
64  os.path.basename(fname), obpg_file_type)
65  if opts.times:
66  if obpg_file_type != 'unknown' and instrument != 'unknown':
67  start_time, end_time = file_typer.get_file_times()
68  output += ': {0} : {1}'.format(start_time, end_time)
69  else:
70  output += ': unable to determine file start and end times'
71  print(output)
72  else:
73  print('\nError! No file specified for type identification.\n')
74  cl_parser.print_help()
75  return 0
76 
77 if __name__ == '__main__':
78  sys.exit(main())
def process_command_line(cl_parser)