def getSystemT(newLambda, bg3fn: Path, windfn: Path, qefn: Path, obsalt_km, zenang_deg, verbose: bool = False) -> xarray.Dataset: bg3fn = Path(bg3fn).expanduser() windfn = Path(windfn).expanduser() qefn = Path(qefn).expanduser() newLambda = np.asarray(newLambda) # %% atmospheric absorption if lowtran is not None: c1 = {'model': 5, 'h1': obsalt_km, 'angle': zenang_deg, 'wlshort': newLambda[0], 'wllong': newLambda[-1]} if verbose: print('loading LOWTRAN7 atmosphere model...') atmT = lowtran.transmittance(c1)['transmission'].squeeze() try: atmTcleaned = atmT.values.squeeze() atmTcleaned[atmTcleaned == 0] = np.spacing(1) # to avoid log10(0) fwl = interp1d(atmT.wavelength_nm, np.log(atmTcleaned), axis=0) except AttributeError: # problem with lowtran fwl = interp1d(newLambda, np.log(np.ones_like(newLambda)), kind='linear') else: fwl = interp1d(newLambda, np.log(np.ones_like(newLambda)), kind='linear') atmTinterp = np.exp(fwl(newLambda)) if not np.isfinite(atmTinterp).all(): logging.error('problem in computing LOWTRAN atmospheric attenuation, results are suspect!') # %% BG3 filter with h5py.File(bg3fn, 'r') as f: try: assert isinstance(f['/T'], h5py.Dataset), 'we only allow one transmission curve per file' # simple legacy behavior fbg3 = interp1d(f['/wavelength'], np.log(f['/T']), kind='linear', bounds_error=False) except KeyError: raise KeyError('could not find /wavelength in {}'.format(f.filename)) try: fname = f['T'].attrs['name'].item() if isinstance(fname, bytes): fname = fname.decode('utf8') except KeyError: fname = '' # %% camera window with h5py.File(windfn, 'r') as f: fwind = interp1d(f['/lamb'], np.log(f['/T']), kind='linear') # %% quantum efficiency with h5py.File(qefn, 'r') as f: fqe = interp1d(f['/lamb'], np.log(f['/QE']), kind='linear') # %% collect results into DataArray T = xarray.Dataset({'filter': ('wavelength_nm', np.exp(fbg3(newLambda))), 'window': ('wavelength_nm', np.exp(fwind(newLambda))), 'qe': ('wavelength_nm', np.exp(fqe(newLambda))), 'atm': ('wavelength_nm', atmTinterp), }, coords={'wavelength_nm': newLambda}, attrs={'filename': fname}) T['sysNObg3'] = T['window'] * T['qe'] * T['atm'] T['sys'] = T['sysNObg3'] * T['filter'] return T
def test_transmittance(): angles = 60 c1 = {'model': 5, 'h1': 0, # of observer 'angle': angles, # of observer 'wlshort': 200, 'wllong': 30000, 'wlstep': 20, } # %% TR = lowtran.transmittance(c1) assert TR.wavelength_nm[[0, -1]].values == approx((30303.03, 200), rel=0.001) assert TR['transmission'][0, [1000, 1200], 0].values == approx([0.726516, 0.527192], rel=0.001)
def test_transmittance(): vlim = (200, 30000) angles = 60 c1 = {'model': 5, 'h1': 0, # of observer 'angle': angles, # of observer 'wlnmlim': vlim, } # %% TR = lowtran.transmittance(c1) assert_allclose(TR.wavelength_nm[[0, -1]], (30303.03, 200), rtol=1e-6) assert_allclose(TR['transmission'][0, [1000, 1200], 0], [0.002074, 0.924557], rtol=0.001)
def main(): p = ArgumentParser(description='Lowtran 7 interface') p.add_argument('-z', '--obsalt', help='altitude of observer [km]', type=float, default=0.) p.add_argument('-a', '--zenang', help='observer zenith angle [deg]', type=float, nargs='+', default=[0, 60, 80]) p.add_argument('-s', '--short', help='shortest wavelength nm ', type=float, default=200) p.add_argument('-l', '--long', help='longest wavelength cm^-1 ', type=float, default=30000) p.add_argument('-step', help='wavelength step size cm^-1', type=float, default=20) p.add_argument('--model', help='0-6, see Card1 "model" reference. 5=subarctic winter', type=int, default=5) P = p.parse_args() c1 = { 'model': P.model, 'h1': P.obsalt, 'angle': P.zenang, 'wlshort': P.short, 'wllong': P.long, 'wlstep': P.step, } TR = lowtran.transmittance(c1) plottrans(TR, c1) show()
def main(): p = ArgumentParser(description='Lowtran 7 interface') p.add_argument('-z', '--obsalt', help='altitude of observer [km]', type=float, default=0.) p.add_argument('-a', '--zenang', help='observer zenith angle [deg]', type=float, nargs='+', default=[0, 60, 80]) p.add_argument('-w', '--wavelen', help='wavelength range nm (start,stop)', type=float, nargs=2, default=(200, 30000)) p.add_argument('--model', help='0-6, see Card1 "model" reference. 5=subarctic winter', type=int, default=5) P = p.parse_args() c1 = {'model': P.model, 'h1': P.obsalt, 'angle': P.zenang, 'wlnmlim': P.wavelen, } TR = lowtran.transmittance(c1) plottrans(TR, c1) show()
# absorbing gases correction #################################### import lowtran import lowtran.plots as lp lowtran.nm2lt7(200, 2500, 20) c1 = { 'model': 6, 'h1': 0, 'angle': [0, 30, 60], 'wlshort': 300, 'wllong': 2600, 'wlstep': 5, } TR = lowtran.transmittance(c1) lp.plottrans(TR, c1) TR = lowtran.radiance(c1) lp.plotradiance(TR, c1) TR = lowtran.irradiance(c1) lp.plotirrad(TR, c1) s = SixS() s.geometry.solar_z = sza s.geometry.solar_a = 0 s.geometry.view_z = vza s.geometry.view_a = azi s.aero_profile = AeroProfile.PredefinedType(AeroProfile.Maritime) parameter = 'apparent_radiance' parameter = 'direct_solar_irradiance' params = [