OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1aqc_oci.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 import sys
4 import argparse
5 from netCDF4 import Dataset
6 
7 __version__ = '0.1.0_2020-12-04'
8 
9 def get_ncdf_object(file,group,object):
10  # read data object from NetCDF file
11 
12  from netCDF4 import Dataset
13 
14  nc_fid = Dataset(file,'r')
15  ngid = nc_fid.groups[group]
16  data = ngid.variables[object][:].data
17  nc_fid.close()
18 
19  return data
20 
21 
22 def l1aqc_oci(args):
23 # procedure to get start, end times and more from Level-1a files for OCI
24 
25  try:
26  nc_fid = Dataset(args.input_file,'r')
27  except:
28  print("Problem reading L1A file.")
29  return 1
30 
31  status = 0
32 
33 # Generate output file if user desired it
34  output = None
35  if args.output:
36  if args.verbose:
37  print("Writing output file: %s" % args.output)
38  output = open(args.output,'w')
39  output.write("# Info for %s\n" % args.input_file)
40 
41  try:
42  stime = getattr(nc_fid, 'time_coverage_start')
43  print("start_time=%sZ" % stime)
44  if output:
45  output.write("start_time=%sZ\n" % stime)
46  except:
47  return 120
48 
49  try:
50  etime = getattr(nc_fid, 'time_coverage_end')
51  print("stop_time=%sZ" % etime)
52 
53  if output:
54  output.write("\nstop_time=%sZ\n" % etime)
55  output.close()
56  except:
57  return 120
58 
59  try:
60  nRec = getattr(nc_fid, 'number_of_filled_scans')
61  print("number_of_records=%s" % nRec)
62 
63  if output:
64  output.write("\number_of_records=%s\n" % nRec)
65  output.close()
66  except:
67  return 120
68 
69  # quality flag will be an evolving development
70  quality_flag = 0
71  print("quality_flag=%d" % quality_flag)
72  if output:
73  output.write("\quality_flag=%d\n" % quality_flag)
74  output.close()
75 
76  nc_fid.close()
77  return status
78 
79 def main():
80  parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,description=\
81  'Reads OCI L1A science data and reports related info',epilog="""
82 EXIT Status:
83 0 : All is well in the world
84 1 : File not accessible
85 120 : Problem reading info from metadata
86 """)
87  parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)
88  parser.add_argument('input_file', type=str, help='path to the input L1a file')
89  parser.add_argument('--output', type=str, help='path to the optional output text file')
90  parser.add_argument('--verbose', '-v', action='store_true')
91 
92  args = parser.parse_args()
93 
94  status = l1aqc_oci(args)
95  if status:
96  sys.exit(status)
97 
98 if __name__ == '__main__':
99  sys.exit(main())
def main()
Definition: l1aqc_oci.py:79
def l1aqc_oci(args)
Definition: l1aqc_oci.py:22
def get_ncdf_object(file, group, object)
Definition: l1aqc_oci.py:9