19 a1=None, a2=None, a3=None,
20 e1=None, e2=None, e3=None,
29 ancdb='ancillary_data.db',
79 p.parseParFile(prog=
'geogen')
81 phash = p.params[
'geogen']
82 for param
in (
list(phash.keys())):
85 self[param] = phash[param]
88 self.__dict__[index] = item
91 return self.__dict__[index]
99 print(
"ERROR: No MODIS_L1A_file was specified in either the parameter file or in the argument list. Exiting")
101 if not os.path.exists(self.
filename):
102 print(
"ERROR: File '" + self.
filename +
"' does not exist. Exiting.")
104 if self.
a1 is not None and not os.path.exists(self.
a1):
105 print(
"ERROR: Attitude file '" + self.
a1 +
"' does not exist. Exiting.")
107 if self.
a2 is not None and not os.path.exists(self.
a2):
108 print(
"ERROR: Attitude file '" + self.
a2 +
"' does not exist. Exiting.")
110 if self.
a3 is not None and not os.path.exists(self.
a3):
111 print(
"ERROR: Attitude file '" + self.
a3 +
"' does not exist. Exiting.")
113 if self.
e1 is not None and not os.path.exists(self.
e1):
114 print(
"ERROR: Ephemeris file '" + self.
e1 +
"' does not exist. Exiting.")
116 if self.
e2 is not None and not os.path.exists(self.
e2):
117 print(
"ERROR: Ephemeris file '" + self.
e2 +
"' does not exist. Exiting.")
119 if self.
e3 is not None and not os.path.exists(self.
e3):
120 print(
"ERROR: Ephemeris file '" + self.
e3 +
"' does not exist. Exiting.")
122 if self.
a1 is None and self.
e1 is not None or self.
a1 is not None and self.
e1 is None:
123 print(
"ERROR: User must specify attitude AND ephemeris files.")
124 print(
" Attitude/ephemeris files must ALL be specified or NONE specified. Exiting.")
126 if self.
terrain is True and not os.path.exists(self.
dirs[
'dem']):
127 print(
"WARNING: Could not locate MODIS digital elevation maps directory:")
128 print(
" '" + self.
dirs[
'dem'] +
"/'.")
130 print(
"*TERRAIN CORRECTION DISABLED*")
135 Check date of utcpole.dat and leapsec.dat.
136 Download if older than 14 days.
139 lut = Lut.LutUtils(verbose=self.
verbose,
142 utcpole = os.path.join(self.
dirs[
'var'],
'modis',
'utcpole.dat')
143 leapsec = os.path.join(self.
dirs[
'var'],
'modis',
'leapsec.dat')
145 if not (os.path.exists(utcpole)
and os.path.exists(leapsec)):
147 print(
"** Files utcpole.dat/leapsec.dat are not present on hard disk.")
148 print(
"** Running update_luts.py to download the missing files...")
151 elif (ProcUtils.mtime(utcpole) > 14)
or (ProcUtils.mtime(leapsec) > 14):
153 print(
"** Files utcpole.dat/leapsec.dat are more than 2 weeks old.")
154 print(
"** Running update_luts.py to update files...")
159 Determine and retrieve required ATTEPH files
168 if self.
a1 is not None:
172 self.
attdir1 = os.path.abspath(os.path.dirname(self.
a1))
174 self.
ephdir1 = os.path.abspath(os.path.dirname(self.
e1))
176 if self.
a2 is not None:
178 self.
attdir2 = os.path.abspath(os.path.dirname(self.
a2))
179 if self.
a3 is not None:
181 self.
attdir3 = os.path.abspath(os.path.dirname(self.
a3))
183 if self.
e2 is not None:
185 self.
ephdir2 = os.path.abspath(os.path.dirname(self.
e2))
186 if self.
e3 is not None:
188 self.
ephdir3 = os.path.abspath(os.path.dirname(self.
e3))
191 print(
"Using specified attitude and ephemeris files.")
195 print(
"att_file2: NULL")
199 print(
"att_file3: NULL")
204 print(
"eph_file2: NULL")
208 print(
"eph_file3: NULL")
213 print(
"Determining required attitude and ephemeris files...")
214 get = ga.getanc(filename=self.
filename,
243 get.locate(forcedl=self.
forcedl)
258 print(
"Missing attitude files!")
260 print(
"Missing ephemeris files!")
264 if 'att1' in get.files:
265 self.
attfile1 = os.path.basename(get.files[
'att1'])
266 self.
attdir1 = os.path.dirname(get.files[
'att1'])
268 print(
"Missing attitude files!")
270 if 'eph1' in get.files:
271 self.
ephfile1 = os.path.basename(get.files[
'eph1'])
272 self.
ephdir1 = os.path.dirname(get.files[
'eph1'])
274 print(
"Missing ephemeris files!")
276 if 'att2' in get.files:
277 self.
attfile2 = os.path.basename(get.files[
'att2'])
278 self.
attdir2 = os.path.dirname(get.files[
'att2'])
279 if 'att3' in get.files:
280 self.
attfile3 = os.path.basename(get.files[
'att3'])
281 self.
attdir3 = os.path.dirname(get.files[
'att3'])
282 if 'eph2' in get.files:
283 self.
ephfile2 = os.path.basename(get.files[
'eph2'])
284 self.
ephdir2 = os.path.dirname(get.files[
'eph2'])
285 if 'eph3' in get.files:
286 self.
ephfile3 = os.path.basename(get.files[
'eph3'])
287 self.
ephdir3 = os.path.dirname(get.files[
'eph3'])
290 """Examine a MODIS geolocation file for percent missing data
291 Returns an error if percent is greater than a threshold"""
294 if not os.path.exists(self.
geofile):
295 print(
"*** ERROR: geogen_modis failed to produce a geolocation file.")
296 print(
"*** Validation test failed for geolocation file:", os.path.basename(self.
geofile))
301 if 'QAPERCENTMISSINGDATA' in metadata:
302 pctmissing = metadata[
'QAPERCENTMISSINGDATA']
303 if pctmissing
is not None:
304 pctvalid = 100 - pctmissing
305 if pctvalid < thresh:
306 print(
"Percent valid data (%.2f) is less than threshold (%.2f)" % (pctvalid, thresh))
311 print(
"Percentage of pixels with missing geolocation: %.2f" % pctmissing)
312 print(
"Validation test passed for geolocation file %s" % self.
geofile)
314 print(
"Problem reading geolocation file: %s" % self.
geofile)
317 print(
"Problem reading geolocation file: %s" % self.
geofile)
322 Run geogen_modis (MOD_PR03)
327 print(
"Creating MODIS geolocation file...")
328 geogen = os.path.join(self.
dirs[
'bin'],
'geogen_modis')
329 status = subprocess.run(geogen, shell=
False).returncode
331 print(
"geogen_modis returned with exit status: " +
str(status))
335 except SystemExit
as e:
337 print(
"Validation test returned with error code: ", e)
338 print(
"ERROR: MODIS geolocation processing failed.")
343 print(
"geogen_modis created %s successfully!" % self.
geofile)
344 print(
"MODIS geolocation processing complete.")
350 ProcUtils.remove(os.path.join(self.
dirs[
'run'],
"GetAttr.temp"))
351 ProcUtils.remove(os.path.join(self.
dirs[
'run'],
"ShmMem"))
352 ProcUtils.remove(
'.'.join([self.
filename,
'met']))
353 ProcUtils.remove(
'.'.join([self.
geofile,
'met']))
354 if self.
log is False:
356 base = os.path.basename(self.
geofile)
357 ProcUtils.remove(os.path.join(self.
dirs[
'run'], (
'.'.join([
'LogReport', base]))))
358 ProcUtils.remove(os.path.join(self.
dirs[
'run'], (
'.'.join([
'LogStatus', base]))))
359 ProcUtils.remove(os.path.join(self.
dirs[
'run'], (
'.'.join([
'LogUser', base]))))