Beispiel #1
0
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))
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
    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)
Beispiel #5
0
    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
    vals = srf(x) * srr.ipol_irradiance