class TestSolarflux(unittest.TestCase): """Unit testing the solar flux calculations.""" def setUp(self): """Set up.""" self.solar_irr = SolarIrradianceSpectrum( TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.005) self.rsr = TEST_RSR def test_read(self): """Test that solar irradiance spctrum.""" self.assertTrue(os.path.exists(self.solar_irr.filename)) self.assertEqual(self.solar_irr.wavelength.shape[0], 1697) self.assertEqual(self.solar_irr.irradiance.shape[0], 1697) def test_solar_flux(self): """Calculate the solar-flux.""" # rsr function (se above) is given in micronsm therefore the scale # factor is 1.0 and not 1e+6 (default)! sflux = self.solar_irr.inband_solarflux(self.rsr, scale=1.0) self.assertAlmostEqual(sflux, 2.002927627) # self.assertAlmostEqual(sflux, 2.5) def test_interpolate(self): """Test the interpolate method.""" self.solar_irr.interpolate(dlambda=0.001, ival_wavelength=(0.200, 0.240)) self.assertTrue( np.allclose(RESULT_IPOL_WVLS, self.solar_irr.ipol_wavelength))
def _get_solarflux(self): """Derive the in-band solar flux from rsr over the Near IR band (3.7 or 3.9 microns).""" solar_spectrum = \ SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.0005, wavespace=self.wavespace) self.solar_flux = solar_spectrum.inband_solarflux(self.rsr[self.bandname])
def main(): """Main""" handler = logging.StreamHandler(sys.stderr) handler.setLevel(logging.DEBUG) formatter = logging.Formatter(fmt=_DEFAULT_LOG_FORMAT, datefmt=_DEFAULT_TIME_FORMAT) handler.setFormatter(formatter) logging.getLogger('').addHandler(handler) logging.getLogger('').setLevel(logging.DEBUG) modis = RelativeSpectralResponse('EOS-Aqua', 'modis') modis.read(channel='20', scale=0.001) solar_irr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.005) solar_irr.read() # Calculate the solar-flux: sflux = solar_irr.solar_flux_over_band(modis.rsr) print("Solar flux over Band: ", sflux) from pyspectral.nir_reflectance import Calculator #refl37 = Calculator(modis.rsr, solar_flux=sflux) refl37 = Calculator(modis.rsr) sunz = 80. tb3 = 290 tb4 = 282 refl = refl37.reflectance_from_tbs(sunz, tb3, tb4) print refl refl37.make_tb2rad_lut('./modis_EOS-Aqua_band20_tb2rad_lut.npz')
def main(): """Main""" handler = logging.StreamHandler(sys.stderr) handler.setLevel(logging.DEBUG) formatter = logging.Formatter(fmt=_DEFAULT_LOG_FORMAT, datefmt=_DEFAULT_TIME_FORMAT) handler.setFormatter(formatter) logging.getLogger("").addHandler(handler) logging.getLogger("").setLevel(logging.DEBUG) modis = RelativeSpectralResponse("EOS-Aqua", "modis") modis.read(channel="20", scale=0.001) solar_irr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.005) solar_irr.read() # Calculate the solar-flux: sflux = solar_irr.solar_flux_over_band(modis.rsr) print ("Solar flux over Band: ", sflux) from pyspectral.nir_reflectance import Calculator # refl37 = Calculator(modis.rsr, solar_flux=sflux) refl37 = Calculator(modis.rsr) sunz = 80.0 tb3 = 290 tb4 = 282 refl = refl37.reflectance_from_tbs(sunz, tb3, tb4) print refl refl37.make_tb2rad_lut("./modis_EOS-Aqua_band20_tb2rad_lut.npz")
def test_solar_flux(self): """Calculate the solar-flux""" self.solar_irr = SolarIrradianceSpectrum( TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.005) # rsr function (se above) is given in micronsm therefore the scale # factor is 1.0 and not 1e+6 (default)! sflux = self.solar_irr.inband_solarflux(self.rsr, scale=1.0) self.assertAlmostEqual(sflux, 2.0029277645144234)
def _get_solarflux(self): """Derive the in-band solar flux from rsr over the Near IR band (3.7 or 3.9 microns)""" solar_spectrum = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.0005, wavespace=self.wavespace) self.solar_flux = solar_spectrum.inband_solarflux( self.rsr[self.bandname])
def test_read(self): """Test that solar irradiance spctrum""" self.solar_irr = \ SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.005) self.assertTrue(os.path.exists(self.solar_irr.filename)) self.assertEqual(self.solar_irr.wavelength.shape[0], 1697) self.assertEqual(self.solar_irr.irradiance.shape[0], 1697)
def srf_exatmospheric_irradiance(srf, dlambda_nm=0.5, start_nm=200.0, end_nm=2000.0): """ Compute the exatmospheric solar irradiance of some sensor (band) at 1a.u. :param srf: SRF `dlambda_nm`, `start_nm`, `end_nm`: interpolation parameters for the solar spectrum :return: band irradiance at 1au, in [W/(m^2 nm)] """ srr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=dlambda_nm/1000) srr.interpolate(ival_wavelength=(start_nm/1000, end_nm/1000)) lambdas = srr.ipol_wavelength * 1000 values = srr.ipol_irradiance / 1000.0 response = srf(lambdas) avg = np.dot(response, values) / np.sum(response) return avg
def exatmospheric_irradiance(srf, dlambda_nm=0.5, start_nm=200.0, end_nm=2000.0): """ Compute the exatmospheric solar irradiance of some sensor (band) at 1a.u. :param srf: SRF `dlambda_nm`, `start_nm`, `end_nm`: interpolation parameters for the solar spectrum :return: band irradiance at 1au, in [W/(m^2 um)] """ warnings.warn(DeprecationWarning( '`exatmospheric_irradiance` is scheduled to be removed, ' 'use `srf_exatmospheric_irradiance` (nm based units) instead.')) srr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=dlambda_nm/1000) srr.interpolate(ival_wavelength=(start_nm/1000, end_nm/1000)) lambdas = srr.ipol_wavelength * 1000 response = srf(lambdas) avg = np.dot(response, srr.ipol_irradiance) / np.sum(response) return avg
class TestSolarflux(unittest.TestCase): """Unit testing the solar flux calculations""" def setUp(self): """Set up""" self.solar_irr = None self.rsr = TEST_RSR return def test_read(self): """Test that solar irradiance spctrum""" self.solar_irr = \ SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.005) self.assertTrue(os.path.exists(self.solar_irr.filename)) self.assertEqual(self.solar_irr.wavelength.shape[0], 1697) self.assertEqual(self.solar_irr.irradiance.shape[0], 1697) def test_solar_flux(self): """Calculate the solar-flux""" self.solar_irr = \ SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.005) # rsr function (se above) is given in micronsm therefore the scale # factor is 1.0 and not 1e+6 (default)! sflux = self.solar_irr.inband_solarflux(self.rsr, scale=1.0) self.assertAlmostEqual(sflux, 2.0029277645144234) #self.assertAlmostEqual(sflux, 2.5) def tearDown(self): """Clean up""" return
def test_solar_flux(self): """Calculate the solar-flux""" self.solar_irr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.005) # rsr function (se above) is given in micronsm therefore the scale # factor is 1.0 and not 1e+6 (default)! sflux = self.solar_irr.inband_solarflux(self.rsr, scale=1.0) self.assertAlmostEqual(sflux, 2.0029277645144234)
def __init__(self, wave1=200*u.nm, wave2=1200*u.nm, dlambda=1*u.nm, i=75*u.deg, d=1.5): self.wave1 = wave1 self.wave2 = wave2 self.dlambda = dlambda self.i = i # incidence angle self.d = d # Mars distance in AU (scaling the solar flux) sol = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM) sol.interpolate(dlambda=dlambda.to(u.micron).value, ival_wavelength=(wave1.to(u.micron).value, wave2.to(u.micron).value)) self.waves = (sol.ipol_wavelength*u.micron).to(u.nm) self.E_w = (sol.ipol_irradiance*self.E_w_unit_in).to(self.E_w_unit_out) self.read_reflectance() self.read_QE() for k, v in dic.items(): setattr(self, k, v)
def setUp(self): """Set up.""" self.solar_irr = SolarIrradianceSpectrum( TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.005) self.rsr = TEST_RSR
import sys handler = logging.StreamHandler(sys.stderr) handler.setLevel(logging.DEBUG) formatter = logging.Formatter(fmt=_DEFAULT_LOG_FORMAT, datefmt=_DEFAULT_TIME_FORMAT) handler.setFormatter(formatter) logging.getLogger('').addHandler(handler) logging.getLogger('').setLevel(logging.DEBUG) LOG = logging.getLogger('example') modis = RelativeSpectralResponse('eos', 2, 'modis') modis.read(channel='20', scale=0.001) solar_irr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.005) solar_irr.read() # Calculate the solar-flux: sflux = solar_irr.solar_flux_over_band(modis.rsr) print("Solar flux over Band: ", sflux) from pyspectral.nir_reflectance import Calculator #refl37 = Calculator(modis.rsr, solar_flux=sflux) refl37 = Calculator(modis.rsr) SUNZ = 80. TB3 = 290 TB4 = 282 REFL = refl37.reflectance_from_tbs(SUNZ, TB3, TB4) print REFL
print("*** plot day microphysics RGB for ", str(tslot)) #glbd = GeostationaryFactory.create_scene("meteosat", "09", "seviri", tslot) glbd = GeostationaryFactory.create_scene("Meteosat-9", "", "seviri", tslot) print("... load sat data") glbd.load(['VIS006','VIS008','IR_016','IR_039','IR_108','IR_134'], area_extent=europe.area_extent) #area="EuropeCanaryS95" area="EuroMercator" # blitzortung projection local_data = glbd.project(area, precompute=True) print("... read responce functions") from pyspectral.near_infrared_reflectance import Calculator from pyspectral.solar import (SolarIrradianceSpectrum, TOTAL_IRRADIANCE_SPECTRUM_2000ASTM) solar_irr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.0005) #from pyspectral.seviri_rsr import load #seviri = load() #rsr = {'wavelength': seviri['IR3.9']['wavelength'], # 'response': seviri['IR3.9']['met10']['95']} #sflux = solar_irr.solar_flux_over_band(rsr) solar_irr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.0005) from pyspectral.rsr_reader import RelativeSpectralResponse seviri = RelativeSpectralResponse('Meteosat-10', 'seviri') sflux = solar_irr.inband_solarflux(seviri.rsr['IR3.9']) ch39 = local_data['IR_039'] ch11 = local_data['IR_108'] ch13 = local_data['IR_134']
x, y = [np.ma.ravel(x.image) / 65536.0 for x in [l8_tile, s2_tile]] plt.figure() plt.plot(x, y, ',') plt.plot([0.15, 0.35], [0.15, 0.35], 'k-') plt.xlabel('l8') plt.ylabel('s2') plt.grid(True) # some spectral plots if (0): import numpy as np import matplotlib.pyplot as plt from calval.satellites.srf import Sentinel2Green, Sentinel2Red, Landsat8Blue, NewsatBlue, NewsatRed from pyspectral.solar import (SolarIrradianceSpectrum, TOTAL_IRRADIANCE_SPECTRUM_2000ASTM) srr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.0005) srr.interpolate(ival_wavelength=(0.200, 2.000)) print(srr.units) print(srr.ipol_wavelength, srr.ipol_irradiance) plt.figure() plt.plot(srr.ipol_wavelength, srr.ipol_irradiance, 'k-.') srf = Sentinel2Green() x = srr.ipol_wavelength * 1000 vals = srf(x) * srr.ipol_irradiance avg = np.dot(srf(x), srr.ipol_irradiance) / np.sum(srf(x)) plt.plot(srr.ipol_wavelength, vals, 'g-') plt.plot([srf.start / 1000, srf.end / 1000], [avg, avg], 'g--') srf = Sentinel2Red() x = srr.ipol_wavelength * 1000
handler = logging.StreamHandler(sys.stderr) handler.setLevel(logging.DEBUG) formatter = logging.Formatter(fmt=_DEFAULT_LOG_FORMAT, datefmt=_DEFAULT_TIME_FORMAT) handler.setFormatter(formatter) logging.getLogger('').addHandler(handler) logging.getLogger('').setLevel(logging.DEBUG) LOG = logging.getLogger('example') modis = RelativeSpectralResponse('eos', 2, 'modis') modis.read(channel='20', scale=0.001) solar_irr = SolarIrradianceSpectrum(TOTAL_IRRADIANCE_SPECTRUM_2000ASTM, dlambda=0.005) solar_irr.read() # Calculate the solar-flux: sflux = solar_irr.solar_flux_over_band(modis.rsr) print("Solar flux over Band: ", sflux) from pyspectral.nir_reflectance import Calculator #refl37 = Calculator(modis.rsr, solar_flux=sflux) refl37 = Calculator(modis.rsr) SUNZ = 80. TB3 = 290 TB4 = 282 REFL = refl37.reflectance_from_tbs(SUNZ, TB3, TB4) print REFL