OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l0info_pace.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 import sys
4 import os
5 import argparse
6 from l0info_utils import read_cfe_header, print_utils_version
7 from l0info_hkt import l0info_hkt
8 from l0info_oci import l0info_oci
9 from l0info_harp import l0info_harp
10 from l0info_spex import l0info_spex
11 
12 
13 __version__ = '1.6.2_2023-01-23'
14 
15 __instids__ = ['hkt','oci','harp','spex']
16 
17 def l0info_pace(args):
18 
19  try:
20  fh = open(args.input_file, mode='rb')
21  except:
22  print("%s not found." % args.input_file)
23  return 101
24 
25  rcode = 0
26 
28 
29  if args.verbose:
30  print("Opened PACE data file: %s" % args.input_file)
31 
32  bDSB = False if args.noCFEheader else True
33 
34  # Get data type from CFE file header
35  if bDSB:
36  ctime, dtype = read_cfe_header(fh)
37 
38  # Check for EOF
39  if fh.tell() == os.fstat(fh.fileno()).st_size:
40  print('No packets in file.')
41  fh.close()
42  return 110
43 
44  fh.seek(0)
45  try:
46  strInst = __instids__[dtype]
47  except:
48  strInst = ''
49  else:
50  try:
51  strInst = args.instrument.lower()
52  except:
53  strInst = ''
54 
55  output = None
56  if args.output:
57  if args.verbose:
58  print("Writing output file: %s" % args.output)
59  output = open(args.output,'w')
60  # output.write("# Info for %s\n" % args.input_file)
61 
62  print("datatype=%s\n"%strInst.upper())
63 
64  # Call appropriate function depending on data type
65  if strInst == 'hkt': # PACE HKT data
66  if output: output.write("datatype=HKT\n")
67  rcode = l0info_hkt(args,fh,output)
68 
69  elif strInst == 'oci': # OCI science data
70  # if output: output.write("datatype=OCI\n")
71  rcode = l0info_oci(args,fh,output,bDSB)
72 
73  elif strInst == 'harp': # HARP science data
74  if output: output.write("datatype=HARP\n")
75  rcode = l0info_harp(args,fh,output)
76 
77  elif strInst == 'spex': # SPEXone science data
78  # if output: output.write("datatype=SPEX\n")
79  rcode = l0info_spex(args,fh,output)
80 
81  else:
82  print('Invalid file or data type from CFE header. Or specify from [hkt,oci,harp,spex].')
83  rcode = 102
84 
85  fh.close()
86  if output:
87  output.close()
88 
89  return rcode
90 
91 
92 def main():
93  print("Running l0info_pace (version: %s) \n" % __version__)
94  parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,description=\
95  'Reads OCI L0 HKT/science data and reports start/stop times',epilog="""
96 EXIT Status:
97 0 : All is well in the world
98 1 : Dunno, something horrible occurred
99 101 : File open error
100 102 : Invalid file or instrument from CFE header
101 103 : Problem reading packet information
102 104 : Invalid packet [header/datatype/length]
103 110 : No [Science] packets found
104 111 : Bad image data
105 120 : Problem reading time from ancillary packet
106 13X : OCI science data error
107 """)
108  parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)
109  parser.add_argument('input_file', type=str, help='path to the input L0 file')
110  parser.add_argument('--output', type=str, help='path to the optional output text file')
111  parser.add_argument('--verbose', '-v', action='store_true')
112  parser.add_argument('--noCFEheader', action='store_true', help="data without CFE header")
113  parser.add_argument('--instrument', type=str, help='hkt,oci,harp or spex')
114 
115  args = parser.parse_args()
116 
117  status = l0info_pace(args)
118  if status:
119  sys.exit(status)
120 
121 if __name__ == '__main__':
122  sys.exit(main())
def read_cfe_header(filehandle, bVerbose=False)
Definition: l0info_utils.py:13
def main()
Definition: l0info_pace.py:92
def print_utils_version()
Definition: l0info_utils.py:10
def l0info_pace(args)
Definition: l0info_pace.py:17