# David R Thompson, Adam Erickson, Jay Fahlen from isofit.core.isofit import Isofit from isofit.utils import surface_model # Build the surface model surface_model("configs/surface.json") # Run retrievals model1 = Isofit("configs/joint_isofit_with_prof_WATER_nogrid.json").run( debug=True)
wave_fit = pd.DataFrame(index = [x for x in range(radiance.bands)]) wave_fit[0] =np.round(radiance.wavelengths/1000,5) wave_fit[1] = np.round(radiance.fwhm/1000,5) wave_fit.to_csv(wavelength_file, sep = '\t',header=False) # Create decorrelated surface model windows= [[380.0, 1300.0], [1500, 1780.0], [1975.0, 2450.0]] surface_data_path = "%s/isotest/data/surface/surface_20210215_emit" % home surface_file = "%s/data/surface_emit.mat" % cal_dir surface_config = "%s/configs/surface.json" % cal_dir surface_config_gen_decorr(surface_data_path, windows, wavelength_file, surface_file, surface_config) surface_model(surface_config) # Create modtran template file engine = 'sRTMnet' template_file = '%s/configs/radtran_template.json' % cal_dir modtran_template_create(obs_mean.astype(np.float64), loc_mean.astype(np.float64), doy, template_file) # Create forward model configs rtm_config,surface_config,instrument_config =fw_configs(iso_base, cal_dir, template_file, wavelength_file, surface_file,
def main(): parser = argparse.ArgumentParser() parser.add_argument('rdn_file', type=str, help='Radiance') parser.add_argument('obs_file', type=str, help='Observables') parser.add_argument('loc_file', type=str, help='Location') parser.add_argument('output_dir', type=str, help='Output directory') parser.add_argument('temp_dir', type=str, help='Temp directory') parser.add_argument('config', type=str, help='ISOFIT config files') args = parser.parse_args() base_name = os.path.basename(args.rdn_file)[:38] date = base_name[4:12] # Load ISOFIT config file with open(args.config,'r') as file: configs = yaml.load(file, Loader=yaml.FullLoader) for key in configs['surface']: get_surface_spectra(args.temp_dir + key, configs['surface'][key]) surface_config = "%s/surface_config.json" % args.temp_dir surface_file = '%s/surface.mat'% args.temp_dir wavelength_file = gen_wavelength_file(args.rdn_file, args.temp_dir) surface_config_gen(configs['windows'], surface_config, configs['prior']) surface_model(surface_config) apply_oe = ['python'] apply_oe.append('%s/isofit/utils/apply_oe.py' % configs['base']) apply_oe.append(args.rdn_file) apply_oe.append(args.loc_file) apply_oe.append(args.obs_file) apply_oe.append(args.output_dir) apply_oe.append('NA-%s' % date) apply_oe += ['--surface_path', surface_file] apply_oe += ['--n_cores',str(configs['n_cores'])] apply_oe += ['--empirical_line',str(configs['empirical_line'])] apply_oe += ['--presolve',str(configs['presolve'])] apply_oe += ['--ray_temp_dir',args.temp_dir] apply_oe += ['--log_file','%s/%s_logfile' % (args.temp_dir,base_name)] apply_oe += ['--emulator_base',configs['emulator']] if configs['radiance_factors']: rad_factors = "%s/radiance_factors.txt" % args.temp_dir download_file(rad_factors,configs['radiance_factors']) apply_oe += ['--rdn_factors_path',rad_factors] apply = subprocess.Popen(apply_oe) apply.wait()
# David R Thompson, Adam Erickson from isofit.core.isofit import Isofit from isofit.utils import surface_model # Build the surface model surface_model("configs/ang20171108t184227_surface.json") # Run retrievals model1 = Isofit("configs/ang20171108t173546_darklot.json") model1.run() model2 = Isofit("configs/ang20171108t173546_horse.json") model2.run() model3 = Isofit("configs/ang20171108t184227_astrored.json") model3.run() model4 = Isofit("configs/ang20171108t184227_astrogreen.json") model4.run() model5 = Isofit("configs/ang20171108t184227_beckmanlawn.json") model5.run() model6 = Isofit("configs/ang20171108t184227_beckmanlawn-oversmoothed.json") model6.run() model7 = Isofit("configs/ang20171108t184227_beckmanlawn-undersmoothed.json") model7.run()
# David R Thompson, Adam Erickson from isofit.core.isofit import Isofit from isofit.utils import surface_model # Build the surface model surface_model("configs/prm20151026t173213_surface_coastal.json") # Run retrievals model1 = Isofit("configs/prm20151026t173213_D8W_6s.json") model1.run() model2 = Isofit("configs/prm20151026t173213_D8p5W_6s.json") model2.run() model3 = Isofit("configs/prm20151026t173213_D9W_6s.json") model3.run() model4 = Isofit("configs/prm20151026t173213_D9p5W_6s.json") model4.run()
def reflectance(self): '''Run ISOFIT reflectance inversion ''' # Check for input files if not (self.exists(self.rdn_file) & self.exists(self.loc_file) & self.exists(self.obs_file)): print('Radiance data not found, generating radiance datasets') self.radiance() rfl_tmp = self.tmp_dir + '%s_isofit/' % self.base_name if not os.path.isdir(rfl_tmp): os.mkdir(rfl_tmp) else: shutil.rmtree(rfl_tmp) os.mkdir(rfl_tmp) for key in self.isofit['surface']: get_surface_spectra(rfl_tmp + key, self.isofit['surface'][key]) surface_config = "%s/surface_config.json" % rfl_tmp surface_file = '%s/surface_filtered.mat'% rfl_tmp wavelength_file = gen_wavelength_file(self.rdn_file, rfl_tmp) surface_config_gen(rfl_tmp, self.isofit['surface_type'], self.isofit['windows'], wavelength_file, surface_file, surface_config) surface_model(surface_config) apply_oe = ['python'] apply_oe.append('%s/isofit/utils/apply_oe.py' % self.isofit['base']) apply_oe.append(self.rdn_file) apply_oe.append(self.loc_file) apply_oe.append(self.obs_file) apply_oe.append(rfl_tmp) if self.sensor in ['prisma','desis']: apply_oe.append('NA-%s' % self.date) apply_oe += ['--surface_path', surface_file] apply_oe += ['--n_cores',str(cpu_count())] apply_oe += ['--empirical_line',str(self.isofit['empirical_line'])] apply_oe += ['--presolve',str(self.isofit['presolve'])] apply_oe += ['--ray_temp_dir',rfl_tmp] apply_oe += ['--log_file','%s/%s_logfile' % (rfl_tmp,self.base_name)] apply_oe += ['--emulator_base',self.isofit['emulator']] if self.rdn_cfg['radiance_factors']: rad_factors = "%s/radiance_factors.txt" % rfl_tmp download_file(rad_factors,self.rdn_cfg['radiance_factors']) apply_oe += ['--rdn_factors_path',rad_factors] apply = subprocess.Popen(apply_oe) apply.wait() if not os.path.isdir(os.path.dirname(self.rfl_file)): os.mkdir(os.path.dirname(self.rfl_file)) # Mask windows and rename ISOFIT output files rfl = glob.glob('%s/output/*_rfl_prj_rfl' % rfl_tmp)[0] uncert = glob.glob('%s/output/*_uncert_prj_uncert'% rfl_tmp)[0] for new,old in [(self.rfl_file,rfl),(self.unc_file,uncert)]: hy_obj = ht.HyTools() hy_obj.read_file(old,'envi') mask = [] for wave in hy_obj.wavelengths: window = False for start,end in self.isofit['windows']: if (wave>start) and (wave<end): window |= True mask.append(window) header_dict = hy_obj.get_header() writer = ht.io.WriteENVI(new, header_dict) for band_num in range(hy_obj.bands): band = hy_obj.get_band(band_num) if not mask[band_num]: band = np.zeros(band.shape) writer.write_band(band,band_num) shutil.rmtree(rfl_tmp)