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.7.3 (2023-08-10)'
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,args.verbose)
37 
38  if dtype==-1:
39  fh.close()
40  return 110
41 
42  # Check for EOF
43  if fh.tell() == os.fstat(fh.fileno()).st_size:
44  print('No packets in file.')
45  fh.close()
46  return 110
47 
48  fh.seek(0)
49  try:
50  strInst = __instids__[dtype]
51  except:
52  strInst = ''
53  else:
54  try:
55  strInst = args.instrument.lower()
56  except:
57  strInst = ''
58 
59  output = None
60  if args.output:
61  if args.verbose:
62  print("Writing output file: %s" % args.output)
63  output = open(args.output,'w')
64  # output.write("# Info for %s\n" % args.input_file)
65 
66  print("datatype=%s\n"%strInst.upper())
67  # Check if the CRC check requested
68  crc_check = args.crc_check
69  if strInst!='oci' and crc_check:
70  print("Warning: CRC check is only availible for OCI Science data")
71  # Call appropriate function depending on data type
72  if strInst == 'hkt': # PACE HKT data
73  if output: output.write("datatype=HKT\n")
74  rcode = l0info_hkt(args,fh,output)
75 
76  elif strInst == 'oci': # OCI science data
77  # if output: output.write("datatype=OCI\n")
78  rcode = l0info_oci(args,fh,output,bDSB,crc_check)
79 
80  elif strInst == 'harp': # HARP science data
81  if output: output.write("datatype=HARP\n")
82  rcode = l0info_harp(args,fh,output)
83 
84  elif strInst == 'spex': # SPEXone science data
85  # if output: output.write("datatype=SPEX\n")
86  rcode = l0info_spex(args,fh,output)
87 
88  else:
89  print('Invalid file or data type from CFE header. Or specify from [hkt,oci,harp,spex].')
90  rcode = 102
91 
92  fh.close()
93  if output:
94  output.close()
95 
96  return rcode
97 
98 
99 def main():
100  print("l0info_pace", __version__)
101  parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,description=\
102  'Reads OCI L0 HKT/science data and reports start/stop times',epilog="""
103 EXIT Status:
104 0 : All is well in the world
105 1 : Dunno, something horrible occurred
106 101 : File open error
107 102 : Invalid file or instrument from CFE header
108 103 : Problem reading packet information
109 104 : Invalid packet [header/datatype/length]
110 110 : No [Science] packets found
111 111 : Bad image data
112 120 : Problem reading time from ancillary packet
113 131 : OCI Checksum failure
114 13X : OCI science data error
115 """)
116  parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)
117  parser.add_argument('input_file', type=str, help='path to the input L0 file')
118  parser.add_argument('--output', type=str, help='path to the optional output text file')
119  parser.add_argument('--verbose', '-v', action='store_true')
120  parser.add_argument('--noCFEheader', action='store_true', help="data without CFE header")
121  parser.add_argument('--instrument', type=str, help='hkt,oci,harp or spex')
122  parser.add_argument('--crc_check', nargs='?', const=1, type=bool,default=False, help='validate crc checksum')
123  args = parser.parse_args()
124 
125  status = l0info_pace(args)
126  if status:
127  sys.exit(status)
128 
129 if __name__ == '__main__':
130  sys.exit(main())
def read_cfe_header(filehandle, bVerbose=False)
Definition: l0info_utils.py:13
def main()
Definition: l0info_pace.py:99
void print(std::ostream &stream, const char *format)
Definition: PrintDebug.hpp:38
def print_utils_version()
Definition: l0info_utils.py:10
def l0info_pace(args)
Definition: l0info_pace.py:17