4 Program to return the name of the next level file that would be created from
22 __version__ =
'1.0.5-2018-05-08'
23 __author__ =
'melliott'
29 FILE_TYPES_CONVERTER = {
'Level 0':
'Level 0',
30 'Level 1A':
'Level 1A',
31 'l1agen' :
'Level 1A',
32 'Level 1B':
'Level 1B',
35 'Level 3 Binned':
'L3bin'}
41 Return the next level name for a single file.
46 next_level_name = level_finder.get_next_level_name()
47 return next_level_name
51 Returns the extension appropriate for the program.
53 extensions = {
'l2bin':
'.L3b',
'l3bin':
'.L3b',
'smigen':
'.L3m'}
54 return extensions[file_type]
58 Return the next level name for a set of files.
60 for file_info
in data_files_list_info:
61 if file_info.file_type ==
'unknown':
62 err_msg =
'Error! File {0} is of unknown type.'.format(
66 target_program, clopts)
67 return next_level_name
71 Returns the file name derived from a group of files names.
73 list_file_type = data_files_list_info[0].file_type
74 for data_file
in data_files_list_info[1:]:
75 if data_file.file_type != list_file_type:
76 err_msg =
'Error! File types do not match for {0} and {1}'.\
77 format(data_files_list_info[0].name, data_file.name)
82 output_name = level_finder.get_next_level_name()
89 Returns the options and arguments from a command line call.
91 ver_msg =
' '.join([
'%prog', __version__])
92 use_msg =
'usage: %prog INPUT_FILE TARGET_PROGRAM'
93 cl_parser = optparse.OptionParser(usage=use_msg, version=ver_msg)
94 cl_parser.add_option(
'--oformat', dest=
'oformat', action=
'store',
95 type=
'string', help=
'output format')
96 cl_parser.add_option(
'--resolution', dest=
'resolution', action=
'store',
98 help=
'resolution for smigen/l3mapgen')
99 cl_parser.add_option(
'--suite', dest=
'suite', action=
'store',
100 type=
'string', help=
'data type suite')
103 (clopts, clargs) = cl_parser.parse_args()
105 print (
"\nError! No input file or target program specified.\n")
106 cl_parser.print_help()
108 elif len(clargs) == 1:
109 print (
"\nError! No target program specified.\n")
110 cl_parser.print_help()
112 elif len(clargs) > 2:
113 print (
'\nError! Too many arguments specified on the command line.')
114 cl_parser.print_help()
117 return clopts, clargs[0], clargs[1]
121 Returns a list of of data files.
124 with open(file_list_file,
'rt')
as file_list_file:
125 inp_lines = file_list_file.readlines()
126 for line
in inp_lines:
127 filename = line.strip()
128 if os.path.exists(filename):
130 file_type, sensor = file_typer.get_file_type()
131 if file_type !=
'unknown':
132 stime, etime = file_typer.get_file_times()
134 sensor, stime, etime)
135 file_info.append(data_file)
137 err_msg =
'Error! {0} is not an OBPG file.'.\
141 err_msg =
'Error! File {0} could not be found.'.format(filename)
143 file_info.sort(key=myfunc)
151 Builds and prints an error message from the exception information,
155 err_type =
str(exc_parts[0]).split(
'.')[1][0:-2]
156 err_msg =
'Error! Encountered {0}:'.format(
str(err_type))
159 traceback.print_exc()
164 Main function for when this module is called as a program.
170 if not targ_prog
in PROCESSABLE_PROGRAMS:
171 err_msg =
'Error! The target program, "{0}", is not known.'.\
174 if os.path.exists(inp_name):
177 ftype, sensor = file_typer.get_file_type()
178 if ftype ==
'unknown':
182 if len(data_files_info) > 0:
184 data_files_info, targ_prog, clopts)
186 err_msg =
"Error! No OBPG files found in {0}".\
191 err_msg =
"File {0} is not an OBPG file.".format(inp_name)
195 stime, etime = file_typer.get_file_times()
196 file_metadata = file_typer.attributes
201 print (
'Output Name: ' + next_level_name)
202 except SystemExit
as sys_ex:
210 err_msg =
"Error! File {0} was not found.".format(inp_name)
219 PROCESSABLE_PROGRAMS = \
220 set(
list(mlp.next_level_name_finder.NextLevelNameFinder.PROCESSING_LEVELS.keys()) +\
221 list(mlp.next_level_name_finder.HawkeyeNextLevelNameFinder.PROCESSING_LEVELS.keys()) +\
222 list(mlp.next_level_name_finder.ModisNextLevelNameFinder.PROCESSING_LEVELS.keys()) +\
223 list(mlp.next_level_name_finder.SeawifsNextLevelNameFinder.PROCESSING_LEVELS.keys()) +\
224 list(mlp.viirs_next_level_name_finder.ViirsNextLevelNameFinder.PROCESSING_LEVELS.keys()))
226 if __name__ ==
'__main__':