4 Program to return the name of the next level file that would be created from
25 __version__ =
'1.0.6-2021-08-01'
32 FILE_TYPES_CONVERTER = {
'Level 0':
'Level 0',
33 'Level 1A':
'Level 1A',
34 'l1agen' :
'Level 1A',
35 'Level 1B':
'Level 1B',
38 'Level 3 Binned':
'L3bin'}
89 Return the next level name for a set of files.
91 for file_info
in data_files_list_info:
92 if file_info.file_type ==
'unknown':
93 err_msg =
'Error! File {0} is of unknown type.'.format(
97 target_program, clopts)
98 return next_level_name
102 Returns the file name derived from a group of files names.
104 list_file_type = data_files_list_info[0].file_type
105 for data_file
in data_files_list_info[1:]:
106 if data_file.file_type != list_file_type:
107 err_msg =
'Error! File types do not match for {0} and {1}'.\
108 format(data_files_list_info[0].name, data_file.name)
142 Returns the options and arguments from a command line call.
144 ver_msg =
' '.join([
'%prog', __version__])
145 use_msg =
'usage: %prog INPUT_FILE TARGET_PROGRAM'
146 cl_parser = optparse.OptionParser(usage=use_msg, version=ver_msg)
147 cl_parser.add_option(
'--oformat', dest=
'oformat', action=
'store',
148 type=
'string', help=
'output format')
149 cl_parser.add_option(
'--odir', dest=
'odir', action=
'store',
150 type=
'string', help=
'output directory')
151 cl_parser.add_option(
'--resolution', dest=
'resolution', action=
'store',
153 help=
'resolution for l3mapgen')
154 cl_parser.add_option(
'--suite', dest=
'suite', action=
'store',
155 type=
'string', help=
'data type suite')
158 (clopts, clargs) = cl_parser.parse_args()
160 print (
"\nError! No input file or target program specified.\n")
161 cl_parser.print_help()
163 elif len(clargs) == 1:
164 print (
"\nError! No target program specified.\n")
165 cl_parser.print_help()
167 elif len(clargs) > 2:
168 print (
'\nError! Too many arguments specified on the command line.')
169 cl_parser.print_help()
172 return clopts, clargs[0], clargs[1]
176 Returns a list of of data files.
179 with open(file_list_file,
'rt')
as file_list_file:
180 inp_lines = file_list_file.readlines()
181 for line
in inp_lines:
182 filename = line.strip()
183 if os.path.exists(filename):
185 file_type, sensor = file_typer.get_file_type()
186 if file_type !=
'unknown':
187 stime, etime = file_typer.get_file_times()
188 file_metadata = file_typer.attributes
190 sensor, stime, etime, file_metadata)
191 file_info.append(data_file)
193 err_msg =
'Error! {0} is not an OBPG file.'.\
197 err_msg =
'Error! File {0} could not be found.'.format(filename)
199 file_info.sort(key=myfunc)
207 Builds and prints an error message from the exception information,
211 err_type =
str(exc_parts[0]).split(
'.')[1][0:-2]
212 err_msg =
'Error! Encountered {0}:'.format(
str(err_type))
215 traceback.print_exc()
220 Main function for when this module is called as a program.
226 if not targ_prog
in PROCESSABLE_PROGRAMS:
227 err_msg =
'Error! The target program, "{0}", is not known.'.\
230 if os.path.exists(inp_name):
233 ftype, sensor = file_typer.get_file_type()
234 if ftype ==
'unknown':
238 if len(data_files_info) > 0:
240 data_files_info, targ_prog, clopts)
242 err_msg =
"Error! No OBPG files found in {0}".\
247 err_msg =
"File {0} is not an OBPG file.".format(inp_name)
251 stime, etime = file_typer.get_file_times()
252 file_metadata = file_typer.attributes
257 print (
'Output Name: ' + next_level_name)
258 except SystemExit
as sys_ex:
266 err_msg =
"Error! File {0} was not found.".format(inp_name)
275 PROCESSABLE_PROGRAMS = \
276 set(
list(mlp.next_level_name_finder.NextLevelNameFinder.PROCESSING_LEVELS.keys()) +\
277 list(mlp.next_level_name_finder.HawkeyeNextLevelNameFinder.PROCESSING_LEVELS.keys()) +\
278 list(mlp.next_level_name_finder.ModisNextLevelNameFinder.PROCESSING_LEVELS.keys()) +\
279 list(mlp.next_level_name_finder.SeawifsNextLevelNameFinder.PROCESSING_LEVELS.keys()) +\
280 list(mlp.viirs_next_level_name_finder.ViirsNextLevelNameFinder.PROCESSING_LEVELS.keys()))
282 if __name__ ==
'__main__':