update apply_oe envi headers to handle extensions
@@ -200,7 +200,7 @@ def main(rawargs=None):
if args.wavelength_path:
chn, wl, fwhm = np.loadtxt(args.wavelength_path).T
else:
- radiance_dataset = envi.open(paths.radiance_working_path + '.hdr')
+ radiance_dataset = envi.open(envi_header(paths.radiance_working_path))
wl = np.array([float(w) for w in radiance_dataset.metadata['wavelength']])
if 'fwhm' in radiance_dataset.metadata:
fwhm = np.array([float(f) for f in radiance_dataset.metadata['fwhm']])
@@ -286,7 +286,7 @@ def main(rawargs=None):
max_water = 6
# run H2O grid as necessary
- if not exists(paths.h2o_subs_path + '.hdr') or not exists(paths.h2o_subs_path):
+ if not exists(envi_header(paths.h2o_subs_path)) or not exists(paths.h2o_subs_path):
# Write the presolve connfiguration file
h2o_grid = np.linspace(0.01, max_water - 0.01, 10).round(2)
logging.info(f'Pre-solve H2O grid: {h2o_grid}')
@@ -309,7 +309,7 @@ def main(rawargs=None):
else:
logging.info('Existing h2o-presolve solutions found, using those.')
- h2o = envi.open(paths.h2o_subs_path + '.hdr')
+ h2o = envi.open(envi_header(paths.h2o_subs_path))
h2o_est = h2o.read_band(-1)[:].flatten()
p05 = np.percentile(h2o_est[h2o_est > lut_params.h2o_min], 5)
@@ -538,7 +538,7 @@ class Pathnames():
logging.info('Staging %s to %s' % (src, dst))
copyfile(src, dst)
if hasheader:
- copyfile(src + '.hdr', dst + '.hdr')
+ copyfile(envi_header(src), envi_header(dst))
class SerialEncoder(json.JSONEncoder):
@@ -1401,6 +1401,22 @@ def write_modtran_template(atmosphere_type: str, fid: str, altitude_km: float, d
with open(output_file, 'w') as fout:
fout.write(json.dumps(h2o_template, cls=SerialEncoder, indent=4, sort_keys=True))
+def envi_header(inputpath):
+ """
+ Convert a envi binary/header path to a header, handling extensions
+ Args:
+ inputpath: path to envi binary file
+ Returns:
+ str
+
+ """
+ if os.path.splitext()[-1] == '.img' or os.path.splitext()[-1] == '.dat':
+ return os.path.splitext()[-1] + '.hdr'
+ elif os.path.splitext()[-1] == '.hdr':
+ return inputpath
+ else:
+ return inputpath + '.hdr'
+
if __name__ == "__main__":
main()
