2 The next_level_name_finder module contains the NextLevelNameFinder class, some
3 instrument specific subclasses, and miscellaneous functions for working with
20 __author__ =
'melliott'
22 __version__ =
'1.0.6-2018-05-08'
29 Returns an integer taken from the passed in string.
32 int_value =
int(short_str)
34 err_msg =
"Error! Unable to convert {0} to integer.".format(short_str)
40 Returns the extension from format_data_list that is indicated by
52 format_index = next((i
for i, t
in enumerate(format_data_list)
if format_data_list[i][tuple_index].lower() == search_term.lower()),
None)
53 if (format_index !=
None)
and (format_index < len(format_data_list)):
54 extension = format_data_list[format_index][2]
56 for ext_candidate
in format_data_list:
57 if search_term.lower() == ext_candidate[2].lower():
58 extension = ext_candidate[2]
62 def _get_days_diff(day1, day2):
64 Returns the number of days between two days, by subtracting day2 from day1.
66 return (day1 - day2).days
68 def _get_data_files_info(flf):
70 Returns a list of data files read from the specified input file.
73 with open(flf,
'rt')
as file_list_file:
74 inp_lines = file_list_file.readlines()
75 for line
in inp_lines:
76 filename = line.strip()
77 if os.path.exists(filename):
79 file_type, sensor = file_typer.get_file_type()
80 stime, etime = file_typer.get_file_times()
83 data_file_list.append(data_file)
89 A method to get the date/time stamp from L0 files.
92 if os.path.exists(l0_file_name +
'.const'):
93 with open(l0_file_name +
'.const')
as constructor_file:
94 constructor_data = constructor_file.readlines()
95 for line
in constructor_data:
96 if line.find(
'starttime=') != -1:
97 start_time = line[line.find(
'=') + 1].strip()
99 time_stamp = ProcUtils.date_convert(start_time,
't',
'j')
101 input_basename = os.path.basename(l0_file_name)
102 matched_name = re.match(
r"MOD00.?.[AP](\d\d\d\d\d\d\d).(\d\d\d\d)", input_basename)
103 if matched_name
is None:
104 matched_name = re.match(
r"[AP](\d\d\d\d\d\d\d)(\d\d\d\d)\d\d\.L0_.{3}", input_basename)
106 time_stamp = matched_name.group(1)+matched_name.group(2) +
'00'
108 err_msg =
"Unable to determine time stamp for input file {0}".\
117 Returns the end day and year for a file, determined from the contents of
120 if 'End Day' in metadata:
122 elif 'Period End Day' in metadata:
124 elif 'time_coverage_end' in metadata:
125 eday = time_utils.convert_month_day_to_doy(
126 metadata[
'time_coverage_end'][5:7],
127 metadata[
'time_coverage_end'][8:10],
128 metadata[
'time_coverage_end'][0:4])
130 err_msg =
'Error! Cannot determine end day.'
132 if 'End Year' in metadata:
134 elif 'Period End Year' in metadata:
136 elif 'time_coverage_end' in metadata:
139 err_msg =
'Error! Cannot determine end year.'
145 Returns the start day and year for a file, determined from the contents of
148 if 'Start Day' in metadata:
150 elif 'Period Start Day' in metadata:
152 elif 'time_coverage_start' in metadata:
153 sday = time_utils.convert_month_day_to_doy(
154 metadata[
'time_coverage_start'][5:7],
155 metadata[
'time_coverage_start'][8:10],
156 metadata[
'time_coverage_start'][0:4])
158 err_msg =
'Error! Cannot determine start day.'
160 if 'Start Year' in metadata:
162 elif 'Period Start Year' in metadata:
164 elif 'time_coverage_start' in metadata:
167 err_msg =
'Error! Cannot determine start year.'
173 Return the part of the file extension based on the time period within the
176 first_date = datetime.datetime.strptime(start_date_str,
'%Y%j%H%M%S')
177 last_date = datetime.datetime.strptime(end_date_str,
'%Y%j%H%M%S')
178 date_diff = last_date - first_date
179 if date_diff.days == 0:
181 elif date_diff.days == 7:
183 elif is_month(first_date, last_date):
185 elif is_year(first_date, last_date):
193 Returns True if the days are the endpoints of a month; False otherwise.
195 return day1.month == day2.month
and day1.day == 1
and\
196 day2.day == calendar.monthrange(day1.year, day1.month)[1]
200 Returns True if the days are the endpoints of a year; False otherwise.
202 return day1.year == day2.year
and day1.month == 1
and day1.day == 1
and\
203 day2.month == 12
and day2.day == 31
207 Returns a tuple containing the file formats.
210 format_file_path = os.path.join(os.getenv(
'OCDATAROOT'),
'common',
212 if os.path.exists(format_file_path):
214 format_file_hndl = open(format_file_path)
215 inp_lines = format_file_hndl.readlines()
216 format_file_hndl.close()
217 for line
in inp_lines:
218 cleaned_line = line.strip()
219 if cleaned_line[0] !=
'#':
221 file_format = tuple(cleaned_line.split(
':'))
223 file_formats.append(file_format)
227 err_msg =
'Error! Cannot find file {0}.'.format(format_file_path)
232 A class to determine what the standard OBPG filename would be when the
233 given input name is run through the next level of OBPG processing.
234 Note that some instruments are handled in subclasses.
236 PROCESSING_LEVELS = {
237 'l1agen':
'Level 1A',
238 'Level 1':
'Level 1B',
239 'Level 1A':
'Level 1A',
240 'level 1a':
'Level 1A',
241 'l1bgen':
'Level 1B',
242 'Level 1B':
'Level 1B',
243 'level 1b':
'Level 1B',
244 'l1brsgen':
'l1brsgen',
245 'l1mapgen':
'l1mapgen',
247 'l2gen_aquarius':
'Level 2',
248 'Level 2':
'Level 2',
249 'level 2':
'Level 2',
251 'l2bin_aquarius':
'l2bin_aquarius',
252 'l2brsgen':
'l2brsgen',
253 'l2extract':
'l2extract',
254 'l2mapgen':
'l2mapgen',
260 'Level 3 Binned':
'l3bin',
266 'general' : {
'L1A':
'L1B',
'L1B':
'L2',
'L2':
'L3b',
267 'L3b': [
'L3b',
'SMI',
'l3gen']},
272 def __init__(self, data_files_list, next_level, suite=None,
273 resolution=None, oformat=None):
274 if len(data_files_list) == 0:
275 err_msg =
"Error! No data file specified for {0}.".format(
276 self.__class__.__name__)
295 err_msg =
'Error! "{0}" is not a recognized target output type.'.\
304 if suite[0:1] ==
'.':
307 self.
suite =
'.' + suite
317 def _do_extension_substitution(self):
319 An internal method to do a simple substitution of the file's extension.
320 This is just a placeholder and will eventually be removed.
323 basename = os.path.split(self.
data_files[0].name)[1]
324 basename_parts = basename.rsplit(
'.', 2)
327 for key
in keys_list:
328 if basename_parts[1].find(key) != -1:
336 return basename_parts[0] +
'.' + suffix
338 def _extract_l1_time(self, date_str, time_str):
340 An internal method to extract the date/time stamp from L1 files.
348 dt_obj = datetime.datetime(year, mon, dom, hour, mins, secs)
349 return dt_obj.strftime(
'%Y%j%H%M%S')
351 def _get_data_type(self):
353 Returns the data type (usually GAC or LAC).
355 if 'Data Type' in self.
data_files[0].metadata:
356 return self.
data_files[0].metadata[
'Data Type']
360 def _get_end_doy_year(self):
362 Extract a day of year and year from an L0 file's metadata and return
363 them as integer values .
374 err_msg =
'Error! Cannot find end time for {0}'.format(
379 def _get_end_time_YMD(self):
381 Extract the start time in the format of YYYYMMDDTHHMMSS from a file's metadata and return
382 them as string value .
384 start_time = self.
data_files[-1].metadata[
'time_coverage_start'][0:4] +\
385 self.
data_files[0].metadata[
'time_coverage_start'][5:7] +\
386 self.
data_files[0].metadata[
'time_coverage_start'][8:10]
390 def _get_extra_extensions(self):
392 Return "extra" extensions, if any. Particularly meant for handling
393 input file names like "A2014009000000.L1A_LAC.x.hdf".
397 base_name = os.path.basename(self.
data_files[0].name)
398 if base_name.count(
'.') > 1:
400 name_parts = re.split(
r"\.L.*?\.", base_name)
401 if len(name_parts) > 1:
402 extra_ext = name_parts[1]
407 for file_format
in file_formats[:-1]:
408 if file_format[2] !=
'':
409 formats_re +=
''.join([
'(', file_format[2],
'$)|'])
410 formats_re +=
''.join([
'(', file_formats[-1][2],
'$)'])
411 extra_ext = re.sub(formats_re,
'', extra_ext)
417 extra_ext =
'' + format_ext
420 def _get_l1aextract_name(self):
422 Returns the output name from running one of the l1aextract_INST programs
423 (where INST = "modis" or "seawifs" or "viirs").
432 def _get_l1b_extension(self):
434 Returns the file extension for L1B files.
438 def _get_l1b_name(self):
440 An internal method to return the L1B name from an L1A file.
444 next_lvl_name =
'' + basename +
'.L1B'
447 def _get_l1brsgen_name(self):
449 An internal method to get the L1 browse file name.
463 def _get_l1mapgen_name(self):
465 An internal method to get the L1 mapped file name.
471 if self.
data_files[0].file_type ==
'Level 1A':
472 ext =
'.L1A.MAP.' + format_ext
473 elif self.
data_files[0].file_type ==
'Level 1B':
474 ext =
'.L1B.MAP.' + format_ext
476 ext =
'.L1.MAP.' + format_ext
479 def _get_l2_extension(self):
481 Return the appropriate extension for an L2 file.
485 if data_file.name.find(
'GAC') != -1:
490 def _get_l2extract_name(self):
492 Return the extension for an L2 extract file.
497 def _get_l2_name(self):
499 An internal method to return the L2 name from an L1 file.
503 if basename !=
'indeterminate':
504 if self.
suite is None:
505 next_lvl_name = basename +
".L2"
507 next_lvl_name = basename +
".L2" + self.
suite
509 err_msg =
'Error! Could not determine L2 name for {0}'.\
514 def _get_l2brsgen_name(self):
516 An internal method to get the L1 browse file name.
522 ext =
'.L2BRS.' + format_ext
525 def _get_l2mapgen_name(self):
527 An internal method to get the L1 mapped file name.
533 ext =
'.L2.MAP.' + format_ext
536 def _get_l3base_name(self):
538 An internal method to return the L3bin name from an L2 or
545 if sday
and syear
and sday > 0
and syear > 0:
546 sdate = datetime.datetime.strptime(
str(syear) +
'-' +
str(sday),
549 err_msg =
'Error! Cannot process start date data: year = {0}' \
550 ', doy = {1}'.format(syear, sday)
552 if eday
and eyear
and eday > 0
and eyear > 0:
553 edate = datetime.datetime.strptime(
str(eyear) +
'-' +
str(eday),
556 err_msg =
'Error! Cannot process end date data: year = {0},' \
557 'doy = {1}'.format(eyear, eday)
559 days_diff = _get_days_diff(edate, sdate)
561 basename =
'%s%d%02d%02d' % (first_char, syear, sdate.month, sdate.day)
564 basename =
'%s%d%02d%02d%d%02d%02d' % (first_char, syear, sdate.month, sdate.day, eyear, edate.month, edate.day)
568 def _get_l3bin_name(self):
570 An internal method to return the L3bin name from an L2 or L3bin file.
575 if sday
and syear
and sday > 0
and syear > 0:
576 sdate = datetime.datetime.strptime(
str(syear) +
'-' +
str(sday),
579 err_msg =
'Error! Cannot process start date data: year = ' \
580 '{0}, doy = {1}'.format(syear, sday)
582 if eday
and eyear
and eday > 0
and eyear > 0:
583 edate = datetime.datetime.strptime(
str(eyear) +
'-' +
str(eday),
586 err_msg =
'Error! Cannot process end date data: year = {0},' \
587 'doy = {1}'.format(eyear, eday)
589 days_diff = _get_days_diff(edate, sdate)
591 if self.
suite is None:
594 extension =
'.L3b.DAY.nc'
595 next_lvl_name =
'%s%d%02d%02d%s%s' % (first_char, syear, sdate.month, sdate.day, extension, self.
suite)
599 extension =
'.L3b.8D.nc'
601 extension =
'.L3b.CU.nc'
602 next_lvl_name =
'%s%d%02d%02d%d%02d%02d%s%s' % (first_char, syear, sdate.month, sdate.day,
603 eyear, edate.month, edate.day, extension, self.
suite)
608 def _get_l3gen_name(self):
610 Returns a name for an L3 bin file generated from an L3 bin file run
617 if sday
and syear
and sday > 0
and syear > 0:
618 sdate = datetime.datetime.strptime(
str(syear) +
'-' +
str(sday),
621 err_msg =
'Error! Cannot process start date data: year = {0}, doy = {1}'.format(syear, sday)
623 if eday
and eyear
and eday > 0
and eyear > 0:
624 edate = datetime.datetime.strptime(
str(eyear) +
'-' +
str(eday),
627 err_msg =
'Error! Cannot process end date data: year = {0}, doy = {1}'.format(eyear, eday)
629 days_diff = _get_days_diff(edate, sdate)
630 if self.
suite is None:
633 extension =
'.L3b.DAY' + self.
suite
635 extension =
'.L3b.8D' + self.
suite
637 extension =
'.L3b' + self.
suite
639 next_lvl_name =
''.join([basename, extension])
644 The API method to return the file name of the next level file(s) from
645 the file given when the object was instantiated. For example, if the
646 given filename is an L1B file, the next level file name will be an L2.
647 For some levels, if the filename already follows the OBPG convention,
648 the only change will be to the extension; e.g. A2000123010100.L1B_LAC ->
649 A2000123010100.L2_LAC. However, it is not assumed that the input file
650 follows this convention, so the output file name is derived from data
653 next_level_name =
'indeterminate'
664 err_msg =
'Error! Cannot transition {0} to {1}.'.format(
667 return next_level_name
669 def _get_next_suffixes(self):
671 An internal method to set up the dictionary which tells what the
672 suffix transitions should be. Separated from __init__() so that
673 it can be overridden.
675 return {
'L1A' :
'L1B',
'L1B' :
'L2',
'L2' :
'L3b'}
679 Returns the misson/instrument indicator according to the new OBPG file naming convention.
681 indicator_dict = {
'Aquarius':
'SACD_AQUARIUS.',
682 'CZCS':
'NIMBUS7_CZCS.',
683 'GOCI':
'COMS_GOCI.',
685 'MERIS':
'ENVISAT_MERIS_FRS.',
686 'MODIS Aqua':
'AQUA_MODIS.',
687 'MODIS Terra':
'TERRA_MODIS.',
688 'MOS':
'IRS-P3_MOS.',
689 'OCM2':
'OCEANSAT2_OCM2.',
690 'OCTS':
'ADEOS_OCTS_GAC.',
691 'OLI':
'LANDSAT8_OLI.',
692 'OSMI':
'KOMSAT1_OSMI.',
693 'SeaWiFS':
'SEASTAR_SEAWIFS.',
695 'VIIRSN':
'SNPP_VIIRS.'}
698 indicator = indicator_dict[self.
data_files[0].sensor]
700 base_file_name = os.path.basename(self.
data_files[0].name)
701 if base_file_name[0] ==
'A':
702 indicator =
'AQUA_MODIS'
703 elif base_file_name[0] ==
'T':
704 indicator =
'TERRA_MODIS'
705 elif base_file_name[0] ==
'X':
708 err_msg =
'Error! Could not determine platform indicator for MODIS file {0}.'.\
712 err_msg =
'Error! Platform indicator, {0}, for {1} is not known.'.\
716 if dfile.sensor
in list(indicator_dict.keys()):
717 if indicator != indicator_dict[dfile.sensor]:
725 def _get_single_file_basename(self):
727 Determine the base part of the output file for a single input file.
729 basename =
'indeterminate'
733 dt_obj = datetime.datetime.strptime(start_time,
"%Y%j%H%M%S")
734 basename =
"{}{}T{}".format(first_char, dt_obj.strftime(
"%Y%m%d"), start_time[7:])
737 self.
data_files[0].metadata[
'RANGEBEGINNINGDATE'],
738 self.
data_files[0].metadata[
'RANGEBEGINNINGTIME'])
741 def _get_l3mapgen_name(self):
743 Returns the output name from smigen for an L3 Binned file or group
755 if 'Input Parameters' in self.
data_files[0].metadata
and\
756 'SUITE' in self.
data_files[0].metadata[
'Input Parameters']
and\
757 self.
data_files[0].metadata[
'Input Parameters'][
'SUITE'].strip() !=
'':
758 suite =
'.' + self.
data_files[0].metadata[
'Input Parameters'][
'SUITE'].strip()
759 elif 'suite' in self.
data_files[0].metadata
and self.
data_files[0].metadata[
'suite'].strip() !=
'':
760 suite =
'.' + self.
data_files[0].metadata[
'suite'].strip()
768 sdate = datetime.datetime.strptime(
str(syear)+
'-'+
str(sday),
'%Y-%j')
769 edate = datetime.datetime.strptime(
str(eyear)+
'-'+
str(eday),
'%Y-%j')
771 days_diff = (edate - sdate).days
773 extension =
'.L3m.DAY'
774 smi_name =
'{0}{1:04d}{2:02d}{3:02d}{4}{5}'.format(first_char, syear, sdate.month, sdate.day,
779 extension =
'.L3m.8D'
781 extension =
'.L3m.CU'
782 smi_name =
'{0}{1:04d}{2:02d}{3:02d}{4:04d}{5:02d}{6:02d}{7}{8}'.format(
783 first_char, syear, sdate.month, sdate.day, eyear, edate.month, edate.day, extension, suite)
786 if self.
suite.startswith(
'_'):
787 smi_name += self.
suite
789 smi_name +=
'_' + self.
suite
799 smi_name += format_ext
802 def _get_start_doy_year(self):
804 Extract a day of year and year from a file's metadata and return
805 them as integer values .
811 day_str =
'Start Day'
812 yr_str =
'Start Year'
816 err_msg =
'Error! Cannot find end time for {0}'.format(
821 def _get_transition_functions(self):
823 An internal method to set up the "table" of functions to be
824 called for each level of processing. Separated from __init__() so it
847 def _get_transition_sequence(self):
849 An internal method to set up the sequence of transitions. Separated
850 from __init__() so it can be overridden.
852 return [
'L1A',
'L1B',
'L2',
'L3bin']
858 A class to determine what the standard OBPG filename would be for
859 HAWKEYE files when the given input name is run through the next
860 level of OBPG processing.
862 PROCESSING_LEVELS = {
863 'l1agen':
'Level 1A',
864 'Level 1A':
'Level 1A',
865 'geolocate_hawkeye':
'GEO',
866 'l1bgen':
'Level 1B',
867 'Level 1B':
'Level 1B',
868 'level 1b':
'Level 1B',
869 'l1brsgen':
'l1brsgen',
870 'l1mapgen':
'l1mapgen',
872 'Level 2':
'Level 2',
874 'l2brsgen':
'l2brsgen',
875 'l2extract':
'l2extract',
876 'l2mapgen':
'l2mapgen',
886 def __init__(self, data_files_list, next_level, suite=None,
887 resolution=None, oformat=None):
888 super(HawkeyeNextLevelNameFinder, self).
__init__(data_files_list,
892 def _get_geo_extension(self):
894 Returns the file extension for GEO files.
898 def _get_geo_name(self):
900 Returns the name of the GEO file.
904 dt_obj = datetime.datetime.strptime(start_time,
'%Y%j%H%M%S')
905 time_stamp =
"{}T{}".format(dt_obj.strftime(
"%Y%m%d"), start_time[7:])
908 self.
data_files[0].metadata[
'RANGEBEGINNINGDATE'],
909 self.
data_files[0].metadata[
'RANGEBEGINNINGTIME'])
916 Returns the misson/instrument indicator for hawkeye according to the new OBPG file naming convention.
918 return 'SEAHAWK1_HAWKEYE.'
920 def _get_transition_functions(self):
922 An internal method to set up the "table" of functions to be
923 called for each level of processing.
953 A class to determine what the standard OBPG filename would be
954 for MERIS files when the given input name is run through the next
955 level of OBPG processing.
958 def __init__(self, data_files_list, next_level, suite=None,
959 resolution=None, oformat=None):
960 super(MerisNextLevelNameFinder, self).
__init__(data_files_list,
964 def _get_l2_extension(self):
966 Return the appropriate extension for an L2 file.
968 ext =
'.BOGUS_MERIS_L2_EXTENSION'
969 if 'SPH_DESCRIPTOR' in self.
data_files[0].metadata:
970 ext =
''.join([
'.L2_',
971 self.
data_files[0].metadata[
'SPH_DESCRIPTOR'].\
983 A class to determine what the standard OBPG filename would be
984 for MODIS files when the given input name is run through the next
985 level of OBPG processing.
987 PROCESSING_LEVELS = {
988 'l1agen':
'Level 1A',
989 'modis_L1A':
'Level 1A',
990 'Level 1A':
'Level 1A',
991 'level 1a':
'Level 1A',
996 'l1aextract_modis':
'l1aextract_modis',
997 'l1bgen':
'Level 1B',
998 'level 1b':
'Level 1B',
999 'Level 1B':
'Level 1B',
1000 'modis_L1B':
'Level 1B',
1001 'l1brsgen':
'l1brsgen',
1002 'l1mapgen':
'l1mapgen',
1004 'Level 2':
'Level 2',
1005 'level 2':
'Level 2',
1007 'l2brsgen':
'l2brsgen',
1008 'l2extract':
'l2extract',
1009 'l2mapgen':
'l2mapgen',
1010 'Level 3 Binned':
'l3bin',
1020 def __init__(self, data_files_list, next_level, suite=None,
1021 resolution=None, oformat=None):
1022 super(ModisNextLevelNameFinder, self).
__init__(data_files_list,
1024 resolution, oformat)
1026 def _extract_l1_time(self, date_str, time_str):
1028 An internal method to extract the date/time stamp from L1 files.
1036 dt_obj = datetime.datetime(year, mon, dom, hour, mins, secs)
1037 return "{}T{}".format(dt_obj.strftime(
"%Y%m%d"), dt_obj.strftime(
"%H%M%S"))
1039 def _get_aqua_l0_to_l1a_name(self):
1041 An internal method to return the L1A name from an Aqua L0 file.
1044 time_stamp =
''.join([time_stamp[:-2],
'00'])
1048 def _get_geo_extension(self):
1050 Returns the file extension for GEO files.
1054 def _get_geo_name(self):
1056 Returns the name of the GEO file.
1060 dt_obj = datetime.datetime.strptime(start_time,
'%Y%j%H%M%S')
1061 time_stamp =
"{}T{}".format(dt_obj.strftime(
"%Y%m%d"), start_time[7:])
1064 self.
data_files[0].metadata[
'RANGEBEGINNINGDATE'],
1065 self.
data_files[0].metadata[
'RANGEBEGINNINGTIME'])
1070 def _get_l1a_extension(self):
1072 Returns the file extension for L1A files.
1076 def _get_l1a_name(self):
1078 An internal method to return the L1A name from an L0 file.
1080 if self.
data_files[0].sensor.find(
'Aqua') != -1:
1084 return next_level_name
1086 def _get_l1b_extension(self):
1088 Returns the file extension for L1B files.
1092 def _get_l1b_name(self):
1094 An internal method to return the L1B name from an L1A file.
1096 next_lvl_name =
'indeterminate'
1100 dt_obj = datetime.datetime.strptime(start_time,
"%Y%j%H%M%S")
1101 time_stamp =
"{}T{}".format(dt_obj.strftime(
"%Y%m%d"), start_time[7:])
1102 elif self.
data_files[0].metadata
is not None:
1104 self.
data_files[0].metadata[
'RANGEBEGINNINGDATE'],
1105 self.
data_files[0].metadata[
'RANGEBEGINNINGTIME'])
1106 next_lvl_name =
''.join([first_char, time_stamp,
1108 return next_lvl_name
1110 def _get_l2_extension(self):
1112 Returns the extension for an L2 file.
1116 def _get_l2_name(self):
1118 An internal method to return the L2 name from an L1B file.
1123 dt_obj = datetime.datetime.strptime(start_time,
"%Y%j%H%M%S")
1124 time_stamp =
"{}T{}".format(dt_obj.strftime(
"%Y%m%d"), start_time[7:])
1127 self.
data_files[0].metadata[
'RANGEBEGINNINGDATE'],
1128 self.
data_files[0].metadata[
'RANGEBEGINNINGTIME'])
1129 next_lvl_name =
''.join([first_char, time_stamp,
1131 if self.
suite is None:
1134 next_lvl_name += self.
suite
1140 return next_lvl_name
1144 The API method to return the file name of the next level file(s) from
1145 the file given when the object was instantiated. For example, if the
1146 given filename is an L1B file, the next level file name will be an L2.
1147 For some levels, if the filename already follows the OBPG convention,
1148 the only change will be to the extension; e.g. A2000123010100.L1B_LAC ->
1149 A2000123010100.L2_LAC. However, it is not assumed that the input file
1150 follows this convention, so the output file name is derived from data
1153 next_level_name =
None
1155 if (self.
data_files[0].file_type ==
'Level 0'):
1159 types.FunctionType)
or \
1170 return next_level_name
1172 err_msg =
'Error! Cannot transition {0} to {1}.'.format(
1178 Returns a character which indicates whether a file contains Aqua or
1179 Terra data, A = Aqua and T = Terra. This can be used as the first
1180 character of an output file.
1182 if self.
data_files[0].sensor.find(
'Aqua') != -1:
1183 indicator =
'AQUA_MODIS.'
1184 elif self.
data_files[0].sensor.find(
'Terra') != -1:
1185 indicator =
'TERRA_MODIS.'
1186 elif self.
data_files[0].sensor.find(
'MODIS') != -1:
1187 if 'platform' in self.
data_files[0].metadata:
1188 if self.
data_files[0].metadata[
'platform'].find(
'Aqua') != -1:
1189 indicator =
'AQUA_MODIS.'
1190 elif self.
data_files[0].metadata[
'platform'].find(
'Terra') != \
1192 indicator =
'TERRA_MODIS.'
1193 elif 'Mission' in self.
data_files[0].metadata:
1194 if self.
data_files[0].metadata[
'Mission'].find(
'Aqua') != -1:
1195 indicator =
'AQUA_MODIS.'
1196 elif self.
data_files[0].metadata[
'Mission'].find(
'Terra') != -1:
1197 indicator =
'TERRA_MODIS.'
1199 elif self.
data_files[0].metadata
is not None:
1201 if self.
data_files[0].metadata[
'LONGNAME'].find(
'Aqua') != -1:
1202 indicator =
'AQUA_MODIS.'
1203 elif self.
data_files[0].metadata[
'LONGNAME'].find(
'Terra') != \
1205 indicator =
'TERRA_MODIS.'
1207 err_msg =
'Error! Cannot find MODIS platform for {0}.'.\
1211 if self.
data_files[0].metadata[
'Title'].find(
'MODISA') != -1:
1212 indicator =
'AQUA_MODIS.'
1213 elif self.
data_files[0].metadata[
'Title'].find(
'MODIST') != -1:
1214 indicator =
'TERRA_MODIS.'
1216 err_msg =
'Error! Cannot find MODIS platform for {0}.'.\
1221 def _get_terra_l0_to_l1a_name(self):
1223 An internal method to return the L1A name from an Aqua L0 file.
1229 def _get_transition_sequence(self):
1231 Returns the sequence of transitions. Separated from __init__() so
1232 it can be overridden.
1234 return [
'L1A',
'L1B',
'L2',
'L3bin']
1236 def _get_next_suffixes(self):
1238 An internal method to set the dictionary which tells what the
1239 suffix transitions should be.
1241 return {
'L0':
'L1A',
'L1A' :
'L1B',
'L1B' :
'L2',
'L2' :
'L3b'}
1243 def _get_transition_functions(self):
1245 An internal method to set up the "table" of functions to be
1246 called for each level of processing.
1274 A class to determine what the standard OBPG filename would be for
1275 SeaWiFS files when the given input name is run through the next
1276 level of OBPG processing.
1278 PROCESSING_LEVELS = {
1279 'l1agen':
'Level 1A',
1280 'Level 1A':
'Level 1A',
1281 'l1aextract_seawifs' :
'l1aextract_seawifs',
1282 'l1bgen':
'Level 1B',
1283 'Level 1B':
'Level 1B',
1284 'level 1b':
'Level 1B',
1285 'l1brsgen':
'l1brsgen',
1286 'l1mapgen':
'l1mapgen',
1288 'Level 2':
'Level 2',
1290 'l2brsgen':
'l2brsgen',
1291 'l2extract':
'l2extract',
1292 'l2mapgen':
'l2mapgen',
1302 def __init__(self, data_files_list, next_level, suite=None,
1303 resolution=None, oformat=None):
1304 super(SeawifsNextLevelNameFinder, self).
__init__(data_files_list,
1306 resolution, oformat)
1308 def _get_data_type(self):
1310 Returns the data type (usually GAC or LAC).
1314 elif 'infile' in self.
data_files[0].metadata
and 'GAC' in self.
data_files[0].metadata[
'infile']:
1321 Returns the misson/instrument/data type indicator for SEAWIFS according to the new OBPG file naming convention.
1325 def _get_transition_functions(self):
1327 An internal method to set up the "table" of functions to be
1328 called for each level of processing.