def __init__(self, engine_config: RadiativeTransferEngineConfig, full_config: Config): self.angular_lut_keys_degrees = [ 'OBSZEN', 'TRUEAZ', 'viewzen', 'viewaz', 'solzen', 'solaz' ] self.angular_lut_keys_radians = [] super().__init__(engine_config, full_config) self.treat_as_emissive = False self.sixs_dir = self.find_basedir(engine_config) self.sixs_grid_init = s.arange(self.wl[0], self.wl[-1] + 2.5, 2.5) self.sixs_ngrid_init = len(self.sixs_grid_init) self.params = { 'aermodel': 1, 'AOT550': 0.01, 'H2OSTR': 0, 'O3': 0.40, 'day': engine_config.day, 'month': engine_config.month, 'elev': engine_config.elev, 'alt': engine_config.alt, 'atm_file': None, 'abscf_data_directory': None, 'wlinf': self.sixs_grid_init[0] / 1000.0, # convert to nm 'wlsup': self.sixs_grid_init[-1] / 1000.0 } if engine_config.obs_file is not None: # A special case where we load the observation geometry # from a custom-crafted text file g = Geometry(obs=engine_config.obs_file) self.params['solzen'] = g.solar_zenith self.params['solaz'] = g.solar_azimuth self.params['viewzen'] = g.observer_zenith self.params['viewaz'] = g.observer_azimuth else: # We have to get geometry from somewhere, so we presume it is # in the configuration file. self.params['solzen'] = engine_config.solzen self.params['viewzen'] = engine_config.viewzen self.params['solaz'] = engine_config.solaz self.params['viewaz'] = engine_config.viewaz self.esd = s.loadtxt(engine_config.earth_sun_distance_file) dt = datetime(2000, self.params['month'], self.params['day']) self.day_of_year = dt.timetuple().tm_yday self.irr_factor = self.esd[self.day_of_year - 1, 1] irr = s.loadtxt(engine_config.irradiance_file, comments='#') iwl, irr = irr.T irr = irr / 10.0 # convert, uW/nm/cm2 irr = irr / self.irr_factor**2 # consider solar distance self.solar_irr = resample_spectrum(irr, iwl, self.wl, self.fwhm) self.lut_quantities = ['rhoatm', 'transm', 'sphalb', 'transup'] self.build_lut()
def test_Geometry(): geom = Geometry() assert geom.earth_sun_file == None assert geom.observer_zenith == 0 assert geom.observer_azimuth == 0 assert geom.observer_altitude_km == None assert geom.surface_elevation_km == None assert geom.datetime == None assert geom.day_of_year == None assert geom.latitude == None assert geom.longitude == None assert geom.longitudeE == None assert geom.gmtime == None assert geom.earth_sun_distance == None assert geom.OBSZEN == 180.0 assert geom.RELAZ == 0.0 assert geom.TRUEAZ == 0.0 assert geom.umu == 1.0
def generate_noise(config): """Add noise to a radiance spectrum or image.""" config = json_load_ascii(config, shell_replace=True) configdir, configfile = split(abspath(config)) infile = expand_path(configdir, config['input_radiance_file']) outfile = expand_path(configdir, config['output_radiance_file']) instrument = Instrument(config['instrument_model']) geom = Geometry() if infile.endswith('txt'): rdn, wl = load_spectrum(infile) Sy = instrument.Sy(rdn, geom) rdn_noise = rdn + np.random.multivariate_normal( np.zeros(rdn.shape), Sy) with open(outfile, 'w') as fout: for w, r in zip(wl, rdn_noise): fout.write('%8.5f %8.5f' % (w, r)) else: raise ValueError("Image cubes not yet implemented.")
"windows": windows}}} inverse_config = Config(inversion_settings) iv = Inversion(inverse_config, fm) # Refine water vapor LUT water = [] window =5 for line in range(10,990,100): print(line) obs_mean = observables.get_chunk(2,990, line-window,line+window).mean(axis =(0,1)) loc_mean = location.get_chunk(2,990, line-window,line+window).mean(axis =(0,1)) rad_mean = radiance.get_chunk(2,990, line-window,line+window).mean(axis =(0,1)) geom = Geometry(obs = obs_mean,loc = loc_mean) state_trajectory = iv.invert(rad_mean, geom) water.append(state_trajectory[-1][-1]) #Create new water table water_min = np.min(water)*.9 water_max = np.max(water)*1.1 water_vals = np.linspace(water_min,water_max,5).tolist() # Recreate configs with refined water vapor for file in glob.glob(cal_dir+"/lut_full/*"): os.remove(file) rtm_config,surface_config,instrument_config =fw_configs(iso_base, cal_dir, template_file,
def __init__(self, config, statevector_names): TabularRT.__init__(self, config) self.sixs_dir = self.find_basedir(config) self.wl, self.fwhm = load_wavelen(config['wavelength_file']) self.sixs_grid_init = s.arange(self.wl[0], self.wl[-1]+2.5, 2.5) self.sixs_ngrid_init = len(self.sixs_grid_init) self.sixs_dir = self.find_basedir(config) self.params = {'aermodel': 1, 'AOT550': 0.01, 'H2OSTR': 0, 'O3': 0.40, 'day': config['day'], 'month': config['month'], 'elev': config['elev'], 'alt': config['alt'], 'atm_file': None, 'abscf_data_directory': None, 'wlinf': self.sixs_grid_init[0]/1000.0, # convert to nm 'wlsup': self.sixs_grid_init[-1]/1000.0} if 'obs_file' in config: # A special case where we load the observation geometry # from a custom-crafted text file g = Geometry(obs=config['obs_file']) self.params['solzen'] = g.solar_zenith self.params['solaz'] = g.solar_azimuth self.params['viewzen'] = g.observer_zenith self.params['viewaz'] = g.observer_azimuth else: # We have to get geometry from somewhere, so we presume it is # in the configuration file. for f in ['solzen', 'viewzen', 'solaz', 'viewaz']: self.params[f] = config[f] self.esd = s.loadtxt(config['earth_sun_distance_file']) dt = datetime(2000, self.params['month'], self.params['day']) self.day_of_year = dt.timetuple().tm_yday self.irr_factor = self.esd[self.day_of_year-1, 1] irr = s.loadtxt(config['irradiance_file'], comments='#') iwl, irr = irr.T irr = irr / 10.0 # convert, uW/nm/cm2 irr = irr / self.irr_factor**2 # consider solar distance self.solar_irr = resample_spectrum(irr, iwl, self.wl, self.fwhm) self.angular_lut_keys_degrees = ['OBSZEN','TRUEAZ','viewzen','viewaz', 'solzen','solaz'] self.lut_quantities = ['rhoatm', 'transm', 'sphalb', 'transup'] self.build_lut() # This array is used to handle the potential indexing mismatch between # the 'global statevector' (which may couple multiple radiative # transform models) and this statevector. It should never be modified full_to_local_statevector_position_mapping = [] for sn in self.statevec: ix = statevector_names.index(sn) full_to_local_statevector_position_mapping.append(ix) self._full_to_local_statevector_position_mapping = \ s.array(full_to_local_statevector_position_mapping)