OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
viirs_next_level_name_finder.py
Go to the documentation of this file.
1 """
2 The viirs_next_level_name_finder module contains the ViirsNextLevelNameFinder
3 class for finding standard output file names for VIIRS files when run through
4 OBPG software.
5 """
6 
7 # import os
8 import re
9 import datetime
11 
12 
13 __author__ = 'melliott'
14 
15 __version__ = '1.0.4-2016-04-29'
16 
18  """
19  A class to determine the standard OBPG filename for VIIRS files when the
20  given input name is run through the next level of OBPG processing.
21  """
22 
23  PROCESSING_LEVELS = {
24  'l1agen': 'Level 1A',
25  'Level 1A': 'Level 1A',
26  'l1aextract_viirs' : 'l1aextract_viirs',
27  'geolocate_viirs' : 'geo',
28  'geo' : 'geo',
29  'calibrate_viirs': 'Level 1B',
30  'Level 1B': 'Level 1B',
31  'level 1b': 'Level 1B',
32  'l1brsgen': 'l1brsgen',
33  'l1mapgen': 'l1mapgen',
34  'l2gen': 'Level 2',
35  'Level 2': 'Level 2',
36  'l2bin': 'l2bin',
37  'l2brsgen': 'l2brsgen',
38  'l2extract': 'l2extract',
39  'l2mapgen': 'l2mapgen',
40  'l3bin': 'l3bin',
41  'L3b': 'l3bin',
42  'l3gen': 'l3gen',
43  'l3mapgen': 'SMI', # Temporary(?)
44  'mapgen': 'mapgen',
45  'SDR': 'Level 1B',
46  'SMI': 'SMI',
47  'smigen': 'SMI'
48  }
49 
50 
51  def __init__(self, data_files_list, next_level, suite=None,
52  resolution=None, oformat=None):
53  super(ViirsNextLevelNameFinder, self).__init__(data_files_list,
54  next_level, suite,
55  resolution, oformat)
56 
57  def _get_geo_extension(self):
58  """
59  Returns the file extension for GEO MOD files.
60  """
61  if 'J1' in self.data_files[0].sensor:
62  return '.GEO-M_JPSS1'
63  return '.GEO-M_SNPP'
64 
65  # def _get_l1b_extension(self):
66  # """
67  # Returns the file extension for L1B MOD files.
68  # """
69  # if 'J1' in self.data_files[0].sensor:
70  # return '.L1B-M_JPSS1'
71  # return '.L1B-M_SNPP'
72 
73  def _get_geo_name(self):
74  """
75  Returns the name of the GEO file.
76  """
77  if self.data_files[0].start_time:
78  start_time = self.data_files[0].start_time
79  dt_obj = datetime.datetime.strptime(start_time, "%Y%j%H%M%S")
80  time_stamp = "{}T{}".format(dt_obj.strftime("%Y%m%d"), start_time[7:])
81  elif self.data_files[0].metadata:
82  time_stamp = self._extract_l1_time(
83  self.data_files[0].metadata['RANGEBEGINNINGDATE'],
84  self.data_files[0].metadata['RANGEBEGINNINGTIME'])
85  geo_name = self.get_platform_indicator() + time_stamp +\
86  ".GEO-M"
87  return geo_name
88 
89  def _get_extra_extensions(self):
90  """
91  Make sure ".tar" is stripped out before determining what ."extra"
92  extensions may be needed.
93  """
94  orig_name = self.data_files[0].name
95  self.data_files[0].name = re.sub(r"\.tar", "", self.data_files[0].name)
96 
97  extra_ext = super(ViirsNextLevelNameFinder, self)._get_extra_extensions()
98  self.data_files[0].name = orig_name
99  return extra_ext
100 
101  # def _get_l2_extension(self):
102  # """
103  # Return the appropriate extension for an L2 file.
104  # """
105  # if 'J1' in self.data_files[0].sensor:
106  # return '.L2_JPSS1'
107  # return '.L2_SNPP'
108 
110  """
111  Returns a character which indicates what platform (instrument) the
112  data in the file is from. This is usually used as the first character
113  of an output file.
114  """
115  if self.data_files[0].metadata['platform'].find('JPSS-1') != -1:
116  head_name = 'NOAA20'
117  elif self.data_files[0].metadata['platform'].find('Suomi-NPP') != -1:
118  head_name = 'SNPP'
119  head_name += '_VIIRS.'
120  return head_name
121 
122  def _get_transition_functions(self):
123  """
124  An internal method to set up the "table" of functions to be
125  called for each level of processing.
126  """
127  return {'Level 1A': {'Level 1B': self._get_l1b_name,
128  'geo': self._get_geo_name,
129  'l1aextract_viirs' : self._get_l1aextract_name,
130  'l1bgen' : self._get_l1b_name,
131  'l1brsgen': self._get_l1brsgen_name,
132  'l1mapgen': self._get_l1mapgen_name,
133  'Level 2' : self._get_l2_name,
134  'mapgen': self._get_l1mapgen_name,
135  },
136  'SDR': {'Level 1B': self._get_l1b_name,
137  'l1aextract_seawifs' : self._get_l1aextract_name,
138  'l1bgen' : self._get_l1b_name,
139  'l1brsgen': self._get_l1brsgen_name,
140  'l1mapgen': self._get_l1mapgen_name,
141  'Level 2' : self._get_l2_name
142  },
143  'Level 1B': {'Level 2': self._get_l2_name,
144  'l1brsgen': self._get_l1brsgen_name,
145  'l1mapgen': self._get_l1mapgen_name,
146  'mapgen': self._get_l1mapgen_name,
147  },
148  'Level 2': {'l2bin': self._get_l3bin_name,
149  'l2extract': self._get_l2extract_name,
150  'l3bin': self._get_l3bin_name,
151  'l2brsgen': self._get_l2brsgen_name,
152  'l2mapgen': self._get_l2mapgen_name,
153  'mapgen': self._get_l2mapgen_name,
154  },
155  'Level 3 Binned': {'l3bin' : self._get_l3bin_name,
156  'l3gen': self._get_l3gen_name,
157  'l3mapgen' : self._get_l3mapgen_name,
158  'SMI' : self._get_l3mapgen_name,
159  'mapgen': self._get_l3mapgen_name,
160  }
161  }
def __init__(self, data_files_list, next_level, suite=None, resolution=None, oformat=None)