OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
modis_processor.py
Go to the documentation of this file.
1 
2 """
3 Class for handling the processing of MODIS data files.
4 """
5 
8 import os
9 import subprocess
10 import sys
11 
12 __author__ = 'melliott'
13 
15  """
16  A class for doing MODIS Processing
17  """
18  def __init__(self, l0_name, l1a=None, geo=None):
19  self.ocssw_root = os.getenv('OCSSWROOT')
20  self.l0_file = l0_name
21  if l1a is not None:
22  self.l1a = l1a
23  else:
24  self.l1a = self.derive_l1a_basename() + '.L1A_LAC'
25  if geo is not None:
26  self.geo = l1a
27  else:
28  self.geo = self.derive_l1a_basename() + '.GEO'
29 
31  """
32  Determine what the default basename for the L1A file (and GEO file) should be.
33  """
34  starttime = None
35  create_constructor_cmd = ['l0cnst_write_modis ', self.l0_file]
36  print('Running: ', create_constructor_cmd)
37  try:
38  l0cnst_write_output = subprocess.run(create_constructor_cmd, capture_output=True, text=True, shell=False)
39  if l0cnst_write_output.returncode:
40  print('Error! Could not run l0const')
41  sys.exit(41)
42  else:
43  print('l0cnst_write_modis run complete')
44  for line in l0cnst_write_output.stdout.splitlines():
45  try:
46  key, val = line.split('=')
47  except ValueError:
48  continue # line doesn't contain '='
49  if 'starttime' in key:
50  self.start = val.strip()
51  break
52  except OSError as ose:
53  print(ose.errno, ose.strerror)
54 
55  if starttime is None:
56  print('Error! Could not determine start time.')
57  sys.exit(42)
58  granule_time = seadasutils.ProcUtils.date_convert(starttime, 't', 'j')
59  return ''.join(['A', granule_time])
60 
61  def run_modis_geo(self, out_file=None):
62  """
63  Do the MODIS Geonavigation processing.
64  """
65  geo_cmd = [os.path.join(self.ocssw_root, 'bin', 'modis_GEO'), self.l1a]
66  if out_file:
67  geo_cmd.append(['-o',out_file])
68  ret_val = subprocess.run(geo_cmd, shell=False).returncode
69  return ret_val
70 
71  def run_modis_l1a(self, out_file=None):
72  """
73  Do the MODIS L1A processing.
74  """
75  l1a_cmd = [os.path.join(self.ocssw_root, 'bin', 'modis_L1A'), '-v', self.l0_file]
76  if out_file:
77  l1a_cmd.append(['-o',out_file])
78  ret_val = subprocess.run(l1a_cmd, shell=False).returncode
79  return ret_val
80 
81  def run_modis_l1b(self):
82  """
83  Do the MODIS L1B processing.
84  """
85  l1b_cmd = [os.path.join(self.ocssw_root, 'bin', 'modis_L1B'), self.l1a]
86  ret_val = subprocess.run(l1b_cmd, shell=False).returncode
87  return ret_val
def run_modis_l1a(self, out_file=None)
def run_modis_geo(self, out_file=None)
def __init__(self, l0_name, l1a=None, geo=None)
def date_convert(datetime_i, in_datetype=None, out_datetype=None)
Definition: ProcUtils.py:232