OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
processor.py
Go to the documentation of this file.
1 """
2 Defines the Processor class, which defines how to create targets from their
3 sources.
4 """
5 
6 import os
7 #import processing_rules
8 #import subprocess
9 import sys
10 
11 __author__ = 'melliott'
12 
13 class Processor(object):
14  """
15  Processor contains the data and methods needed to create a single target.
16  """
17  __name__ = "Processor"
18  #def __init__(self, instr, src, ruleset, target_type, targt=''):
19  def __init__(self, sensor, ruleset, program, par_data, out_dir):
20 
21  self.input_file = None
22  self.geo_file = None
23  self.par_data = par_data
24  self.sensor = sensor
25  self.target_type = program
26  self.ocssw_root = os.environ['OCSSWROOT']
27  self.ocssw_bin = os.environ['OCSSW_BIN']
28  self.rule_set = ruleset
30  if 'odir' in par_data:
31  self.out_directory = par_data['odir']
32  else:
33  self.out_directory = out_dir
34  if 'ofile' in par_data:
35  self.output_file = par_data['ofile']
36  else:
37  self.output_file = ''
38  # if 'deletefiles' in par_data:
39  # self.deletefiles = par_data['deletefiles']
40  # else:
41  # self.deletefiles = False
42 
44 
45  def __cmp__(self, other):
46  """
47  Custom comparator to determine which Processor should come before another.
48  This is based on the order in which they should be processed.
49  """
50  self_ndx = self.rule_set.order.index(self.target_type)
51  if self_ndx < 0:
52  print('Error! Could not locate {0} target type in {1} rule set.'.format(self.target_type, str(self)))
53  sys.exit(99)
54 # other_ndx = other.rule_set.find_target_type(other.target_type)
55  other_ndx = other.rule_set.order.index(other.target_type)
56  if other_ndx < 0:
57  print('Error! Could not locate {0} target type in {1} rule set.'.format(other.target_type, str(other)))
58  sys.exit(98)
59  if self_ndx < other_ndx:
60  return -1
61  elif self_ndx > other_ndx:
62  return 1
63  else:
64  return 0
65 
66  def __eq__(self, other):
67  return self.__cmp__(other) == 0
68 
69  def __lt__(self, other):
70  return self.__cmp__(other) < 0
71 
72  def __le__(self, other):
73  return self.__cmp__(other) <= 0
74 
75  def __ne__(self, other):
76  return self.__cmp__(other) != 0
77 
78  def __gt__(self, other):
79  return self.__cmp__(other) > 0
80 
81  def __ge__(self, other):
82  return self.__cmp__(other) >= 0
83 
84  def _find_required_types(self):
85  req_types = self.rule_set.rules[self.target_type][1]
86  return req_types
87 
88  def _get_applicable_rules(self, ruleset):
89  applicable_rules = []
90  ndx = 0
91  # end_fnd = False
92 # while (ndx < len(ruleset.rules)) and (not end_fnd):
93  for targ in ruleset.order:
94  if (self.target_type == targ):
95  break
96  else:
97  applicable_rules.append(ruleset.rules[targ])
98  ndx += 1
99 # print "applicable_rules for %s: %s" % (str(self), str([str(r) for r in applicable_rules]))
100  return applicable_rules
101 
102  def inputs_exist(self):
103  """
104  Return True if the inputs needed for the target output exist,
105  otherwise return False.
106  """
107  input_file = ''
108  if 'ifile' in self.par_data:
109  input_file = self.par_data['ifile']
110  return os.path.exists(input_file)
111 
112  def __repr__(self):
113  return "Processor for target_type = {0}".format(self.target_type)
114 
115  def __str__(self):
116  return "{0} processor".format(self.target_type)
117 
118  def execute(self):
119  """
120  Call the function to run the command for this Processor.
121  """
122  status = self.rule_set.rules[self.target_type].action(self)
123  return status
124 
126  return self.rule_set.rules[self.target_type].requires_batch
def __init__(self, sensor, ruleset, program, par_data, out_dir)
Definition: processor.py:19
def __le__(self, other)
Definition: processor.py:72
def __lt__(self, other)
Definition: processor.py:69
def __cmp__(self, other)
Definition: processor.py:45
def requires_batch_processing(self)
Definition: processor.py:125
action
Definition: __init__.py:2
def _find_required_types(self)
Definition: processor.py:84
const char * str
Definition: l1c_msi.cpp:35
def __eq__(self, other)
Definition: processor.py:66
def _get_applicable_rules(self, ruleset)
Definition: processor.py:88
def __ge__(self, other)
Definition: processor.py:81
def __ne__(self, other)
Definition: processor.py:75
def __gt__(self, other)
Definition: processor.py:78