OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
name_finder_utils.py
Go to the documentation of this file.
1 """
2 Utility functions for the next_name_finder program and associated modules.
3 
4 These functions were placed in a separate module to prevent "circular imports".
5 Take care making modifications.
6 """
7 
8 __author__ = 'melliott'
9 
10 __version__ = '1.0.3-2015-08-10'
11 
13 #import modules.viirs_next_level_name_finder as viirs_next_level_name_finder
14 
15 def convert_opts_to_dict(options):
16  """
17  Converts optparse options into a dictionary
18  """
19  ret_dict = {}
20  if options.resolution:
21  ret_dict['resolution'] = options.resolution
22  if options.suite:
23  ret_dict['suite'] = options.suite
24  if options.oformat:
25  ret_dict['oformat'] = options.oformat
26  return ret_dict
27 
28 def create_level_finder(finder_class, clopts, data_file_list, target_program):
29  """
30  Instantiates an instance of finder_class and returns it.
31  """
32  level_finder = None
33  if 'resolution' in clopts:
34  resolution = clopts['resolution']
35  else:
36  resolution = None
37  if 'suite' in clopts:
38  suite = clopts['suite']
39  else:
40  suite = None
41  if 'oformat' in clopts:
42  oformat = clopts['oformat']
43  else:
44  oformat = None
45  level_finder = finder_class(data_file_list, target_program, suite,
46  resolution, oformat)
47  return level_finder
48 
49 def get_level_finder(data_file_list, target_program, clopts=None):
50  """
51  Returns an appropriate level finder object for the data file passed in.
52  """
53  if not isinstance(clopts, dict):
54  # Assuming the clopts passed in is a group of options from optparse.
55  clopts = vars(clopts)
56 
57  if data_file_list[0].sensor.find('MODIS') != -1:
58  level_finder = create_level_finder(
60  data_file_list, target_program)
61  elif data_file_list[0].sensor.find('HAWKEYE') != -1:
62  level_finder = create_level_finder(
64  data_file_list, target_program)
65  elif data_file_list[0].sensor.find('SeaWiFS') != -1:
66  level_finder = create_level_finder(
68  data_file_list, target_program)
69  elif data_file_list[0].sensor.find('Aquarius') != -1:
70  level_finder = create_level_finder(
72  data_file_list, target_program)
73  elif data_file_list[0].sensor.find('MERIS') != -1:
74  level_finder = create_level_finder(
76  data_file_list, target_program)
77  elif data_file_list[0].sensor.find('VIIRS') != -1:
78  level_finder = create_level_finder(
80  data_file_list, target_program)
81  else:
82  level_finder = create_level_finder(
84  data_file_list, target_program)
85  return level_finder
def convert_opts_to_dict(options)
def get_level_finder(data_file_list, target_program, clopts=None)
def create_level_finder(finder_class, clopts, data_file_list, target_program)