Example #1
2
    def test_6s_example1(self):
        # Implements Example_In_1.txt from the 6S distribution in Py6S
        # Tests against manual run of that file

        s = SixS()
        s.geometry = Geometry.User()
        s.geometry.solar_z = 40
        s.geometry.solar_a = 100
        s.geometry.view_z = 45
        s.geometry.view_a = 50
        s.geometry.month = 7
        s.geometry.day = 23

        s.atmos_profile = AtmosProfile.UserWaterAndOzone(3.0, 3.5)
        s.aero_profile = AeroProfile.User(dust=0.25,
                                          water=0.25,
                                          oceanic=0.25,
                                          soot=0.25)

        s.aot550 = 0.5
        s.altitudes.set_target_custom_altitude(0.2)
        s.altitudes.set_sensor_custom_altitude(3.3, aot=0.25)
        s.wavelength = Wavelength(PredefinedWavelengths.AVHRR_NOAA9_B1)

        s.ground_reflectance = GroundReflectance.HeterogeneousLambertian(
            0.5, GroundReflectance.ClearWater,
            GroundReflectance.GreenVegetation)

        s.atmos_corr = AtmosCorr.AtmosCorrBRDFFromReflectance(0.1)
        s.run()
        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               12.749,
                               delta=0.002)
Example #2
1
    def test_atmos_corr_radiance(self):
        s = SixS()
        s.atmos_corr = AtmosCorr.AtmosCorrLambertianFromRadiance(130.1)
        s.run()

        self.assertAlmostEqual(
            s.outputs.atmos_corrected_reflectance_lambertian,
            0.29048,
            delta=0.002)
Example #3
0
    def test_vis_aot_small(self):
        s = SixS()
        s.aot550 = 0.001
        s.run()

        self.assertAlmostEqual(s.outputs.visibility, float("Inf"))
        self.assertAlmostEqual(s.outputs.aot550, 0.001, delta=0.002)
Example #4
0
    def test_custom_target_altitude(self):
        s = SixS()
        s.altitudes.set_target_custom_altitude(7)
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               139.192,
                               delta=0.002)
Example #5
0
    def test_specific_wavelength(self):
        s = SixS()
        s.wavelength = Wavelength(0.567)
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               129.792,
                               delta=0.002)
Example #6
0
    def test_wavelength_filter(self):
        s = SixS()
        s.wavelength = Wavelength(0.400, 0.410, [0.7, 0.9, 1.0, 0.3, 1.0])
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               109.435,
                               delta=0.002)
Example #7
0
    def test_custom_sensor_altitude(self):
        s = SixS()
        s.altitudes.set_sensor_custom_altitude(3, 0.26)
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               147.964,
                               delta=0.002)
Example #8
0
    def test_wavelength_range(self):
        s = SixS()
        s.wavelength = Wavelength(0.5, 0.7)
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               122.166,
                               delta=0.002)
Example #9
0
    def test_satellite_level(self):
        s = SixS()
        s.altitudes.set_sensor_satellite_level()
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               165.188,
                               delta=0.002)
Example #10
0
    def test_custom_altitudes(self):
        s = SixS()
        s.altitudes.set_target_custom_altitude(7)
        s.altitudes.set_sensor_custom_altitude(50, 0.26)
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               158.101,
                               delta=0.002)
Example #11
0
 def test_all_predefined_wavelengths(self):
     s = SixS()
     attribs = dir(PredefinedWavelengths)
     for wavelength in attribs:
         wv = eval("PredefinedWavelengths.%s" % wavelength)
         if type(wv) is tuple:
             print(wavelength)
             s.wavelength = Wavelength(wv)
             s.run()
Example #12
0
    def test_usgs_spectra_from_file(self):
        s = SixS()
        s.ground_reflectance = GroundReflectance.HomogeneousLambertian(
            Spectra.import_from_usgs(
                os.path.join(test_dir, "butlerite_gds25.3947.asc")))
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               180.818,
                               delta=0.002)
Example #13
0
    def test_import_aeronet(self):
        s = SixS()
        s = SixSHelpers.Aeronet.import_aeronet_data(
            s, os.path.join(test_dir, "070101_101231_Marambio.dubovik"),
            "2008-02-22")
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               137.324,
                               delta=0.002)
Example #14
0
    def test_after_prev_run(self):
        s = SixS()
        s.run()

        try:
            SixSHelpers.Wavelengths.run_vnir(s,
                                             spacing=0.05,
                                             output_name="apparent_radiance",
                                             n=1)
        except OutputParsingError:
            self.fail(
                "OutputParsingError raised by run_vnir after previous SixS.run"
            )
Example #15
0
    def test_aster_spectra_from_file(self):
        s = SixS()
        s.altitudes.set_target_sea_level()
        s.altitudes.set_sensor_satellite_level()
        s.ground_reflectance = GroundReflectance.HomogeneousLambertian(
            Spectra.import_from_aster(
                os.path.join(
                    test_dir,
                    "jhu.becknic.vegetation.trees.conifers.solid.conifer.spectrum.txt",
                )))
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_reflectance,
                               0.1403693,
                               delta=0.002)
Example #16
0
    def test_running_multiple_add_components(self):
        s = SixS()
        real_intp = [0.0] * 20
        imag_intp = [0.0] * 20

        # Running these lines more than twice used to give an error
        for i in range(4):
            s.aeroprofile = AeroProfile.MultimodalLogNormalDistribution(
                0.085, 2.9)
            s.aeroprofile.add_component(
                rmean=2.65,
                sigma=0.62,
                percentage_density=0.093,
                refr_real=real_intp,
                refr_imag=imag_intp,
            )
Example #17
0
    def test_simple_radiosonde_import(self):
        s = SixS()
        s.altitudes.set_sensor_satellite_level()
        s.altitudes.set_target_sea_level()
        try:
            s.atmos_profile = SixSHelpers.Radiosonde.import_uow_radiosonde_data(
                "http://weather.uwyo.edu/cgi-bin/sounding?region=europe&TYPE=TEXT%3ALIST&YEAR=2012&MONTH=02&FROM=2712&TO=2712&STNM=03808",
                AtmosProfile.MidlatitudeWinter,
            )
            s.run()
        except urllib.error.HTTPError:
            print("HTTP error in test, skipping")
            pytest.skip()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               164.482,
                               delta=0.02)
Example #18
0
    def test_run_all_wavelengths(self):
        s = SixS()
        attribs = dir(SixSHelpers.Wavelengths)
        for f in attribs:
            if "run" in f and f != "run_wavelengths":
                func = eval("SixSHelpers.Wavelengths." + f)
                func(s, output_name="apparent_radiance")

                func(s)
Example #19
0
    def test_extract_output(self):
        s = SixS()
        wvs, values = SixSHelpers.Wavelengths.run_landsat_etm(
            s, output_name="apparent_reflectance")
        wvs, objs = SixSHelpers.Wavelengths.run_landsat_etm(s)

        obj_values = SixSHelpers.Wavelengths.extract_output(
            objs, "apparent_reflectance")

        self.assertTrue(np.all(values == obj_values))
Example #20
0
    def test_atmos_profile(self):
        aps = [
            AtmosProfile.Tropical,
            AtmosProfile.NoGaseousAbsorption,
            AtmosProfile.UserWaterAndOzone(0.9, 3),
        ]
        results = [0.2723143, 0.2747224, 0.2476101]

        for i in range(len(aps)):
            s = SixS()
            s.atmos_profile = aps[i]
            s.run()

            self.assertAlmostEqual(
                s.outputs.apparent_reflectance,
                results[i],
                msg="Error in atmos profile with ID %s. Got %f, expected %f." %
                (str(aps[i]), s.outputs.apparent_reflectance, results[i]),
                delta=0.002,
            )
Example #21
0
    def test_wavelengths_equiv(self):
        s = SixS()
        s.altitudes.set_sensor_satellite_level()
        s.altitudes.set_target_sea_level()

        serial_res = SixSHelpers.Wavelengths.run_vnir(
            s, spacing=0.05, output_name="apparent_radiance", n=1)

        # Run for 2, 4 and 6 jobs (8 seems to fail on the Github Actions Windows runners)
        for i in range(2, 8, 2):
            parallel_res = SixSHelpers.Wavelengths.run_vnir(
                s, spacing=0.05, output_name="apparent_radiance", n=i)
            np.testing.assert_allclose(parallel_res, serial_res)
Example #22
0
    def test_angles_equiv(self):
        s = SixS()

        serial_res = SixSHelpers.Angles.run360(s,
                                               "view",
                                               output_name="apparent_radiance",
                                               n=1)

        # Run for 2, 4 and 6 jobs (8 seems to fail on the Github Actions Windows runners)
        for i in range(2, 8, 2):
            parallel_res = SixSHelpers.Angles.run360(
                s, "view", output_name="apparent_radiance", n=i)
            np.testing.assert_allclose(parallel_res[0], serial_res[0])
Example #23
0
    def test_wavelength_predefined(self):
        s = SixS()
        s.wavelength = Wavelength(PredefinedWavelengths.LANDSAT_TM_B1)
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               138.126,
                               delta=0.002)

        s.wavelength = Wavelength(PredefinedWavelengths.MODIS_B6)
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               17.917,
                               delta=0.002)
Example #24
0
    def test_set_vis(self):
        s = SixS()
        s.aot550 = None
        s.visibility = 40
        s.run()

        self.assertAlmostEqual(s.outputs.phase_function_Q.aerosol,
                               -0.04939,
                               delta=0.002)
Example #25
0
    def test_aero_profile(self):
        user_ap = AeroProfile.UserProfile(AeroProfile.Maritime)
        user_ap.add_layer(5, 0.34)

        aps = [
            AeroProfile.Continental,
            AeroProfile.NoAerosols,
            AeroProfile.User(dust=0.3, oceanic=0.7),
            user_ap,
        ]
        results = [122.854, 140.289, 130.866, 136.649]

        for i in range(len(aps)):
            s = SixS()
            s.aero_profile = aps[i]
            s.run()

            self.assertAlmostEqual(
                s.outputs.apparent_radiance,
                results[i],
                "Error in aerosol profile with ID %s. Got %f, expected %f." %
                (str(aps[i]), s.outputs.apparent_radiance, results[i]),
                delta=0.002,
            )
Example #26
0
    def test_run_for_landsat_etm(self):
        s = SixS()
        results = SixSHelpers.Wavelengths.run_landsat_etm(
            s, output_name="apparent_radiance")

        a = np.array([138.392, 129.426, 111.635, 75.822, 16.684, 5.532])

        self.assertAlmostEqual(
            results[0],
            [
                0.47750000000000004,
                0.56125000000000003,
                0.65874999999999995,
                0.82624999999999993,
                1.6487500000000002,
                2.19625,
            ],
            delta=0.002,
        )
        np.testing.assert_allclose(a, results[1], atol=0.1)
Example #27
0
    def test_changing_levels(self):
        s = SixS()
        s.altitudes.set_sensor_custom_altitude(1)
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               142.053,
                               delta=0.002)

        s.altitudes.set_sensor_satellite_level()
        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               165.188,
                               delta=0.002)
Example #28
0
    def test_hetero_ground_reflectance(self):
        s = SixS()
        s.altitudes.set_sensor_satellite_level()
        s.altitudes.set_target_sea_level()
        s.wavelength = Wavelength(PredefinedWavelengths.LANDSAT_ETM_B2)

        wavelengths = np.arange(0.5, 0.6, 0.025)
        ro_target = np.array([wavelengths, [1.0] * 4]).T
        ro_env = np.array([wavelengths, [0.5] * 4]).T

        s.ground_reflectance = GroundReflectance.HeterogeneousLambertian(
            0.3, ro_target, ro_env)

        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               271.377,
                               delta=0.002)
Example #29
0
    def test_6s_example2(self):
        # Implements Example_In_2.txt from the 6S distribution in Py6S
        # Tests against manual run of that file

        s = SixS()
        s.geometry = Geometry.User()
        s.geometry.solar_z = 0
        s.geometry.solar_a = 20
        s.geometry.view_z = 30
        s.geometry.view_a = 0
        s.geometry.month = 8
        s.geometry.day = 22

        s.atmos_profile = AtmosProfile.PredefinedType(
            AtmosProfile.NoGaseousAbsorption)

        s.aero_profile = AeroProfile.SunPhotometerDistribution(
            [
                0.050000001,
                0.065604001,
                0.086076997,
                0.112939,
                0.148184001,
                0.194428995,
                0.255104989,
                0.334715992,
                0.439173013,
                0.576227009,
                0.756052017,
                0.99199599,
                1.30157101,
                1.707757,
                2.24070191,
                2.93996596,
                3.85745192,
                5.06126022,
                6.64074516,
                8.71314526,
                11.4322901,
                15,
            ],
            [
                0.001338098,
                0.007492487,
                0.026454749,
                0.058904506,
                0.082712278,
                0.073251031,
                0.040950641,
                0.014576218,
                0.003672085,
                0.001576356,
                0.002422644,
                0.004472982,
                0.007452302,
                0.011037065,
                0.014523974,
                0.016981738,
                0.017641816,
                0.016284294,
                0.01335547,
                0.009732267,
                0.006301342,
                0.003625077,
            ],
            [1.47] * 20,
            [0.0093] * 20,
        )

        s.aot550 = 1.0
        s.altitudes.set_target_sea_level()
        s.altitudes.set_sensor_satellite_level()
        s.wavelength = Wavelength(0.550)
        s.ground_reflectance = GroundReflectance.HomogeneousRoujean(
            0.037, 0.0, 0.133)

        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               76.999,
                               delta=0.002)
        self.assertAlmostEqual(s.outputs.background_radiance,
                               10.017,
                               delta=0.002)
Example #30
0
    def test_6s_example4(self):
        s = SixS()

        s.geometry = Geometry.User()
        s.geometry.solar_z = 61.23
        s.geometry.solar_a = 18.78
        s.geometry.solar_a = 0
        s.geometry.view_z = 18.78
        s.geometry.view_a = 159.2
        s.geometry.month = 4
        s.geometry.day = 30

        s.atmos_profile = AtmosProfile.UserWaterAndOzone(0.29, 0.41)
        s.aero_profile = AeroProfile.PredefinedType(AeroProfile.Continental)

        s.aot550 = 0.14

        s.altitudes.set_target_sea_level()
        s.altitudes.set_sensor_satellite_level()

        s.wavelength = Wavelength(PredefinedWavelengths.AVHRR_NOAA11_B1)

        s.ground_reflectance = GroundReflectance.HomogeneousLambertian([
            0.827,
            0.828,
            0.828,
            0.827,
            0.827,
            0.827,
            0.827,
            0.826,
            0.826,
            0.826,
            0.826,
            0.825,
            0.826,
            0.826,
            0.827,
            0.827,
            0.827,
            0.827,
            0.828,
            0.828,
            0.828,
            0.829,
            0.829,
            0.828,
            0.826,
            0.826,
            0.825,
            0.826,
            0.826,
            0.826,
            0.827,
            0.827,
            0.827,
            0.826,
            0.825,
            0.826,
            0.828,
            0.829,
            0.830,
            0.831,
            0.833,
            0.834,
            0.835,
            0.836,
            0.836,
            0.837,
            0.838,
            0.838,
            0.837,
            0.836,
            0.837,
            0.837,
            0.837,
            0.840,
            0.839,
            0.840,
            0.840,
            0.841,
            0.841,
            0.841,
            0.841,
            0.842,
            0.842,
            0.842,
            0.842,
            0.843,
            0.842,
            0.843,
            0.843,
            0.843,
            0.843,
            0.843,
            0.843,
            0.841,
            0.841,
            0.842,
            0.842,
            0.842,
            0.842,
            0.842,
            0.841,
            0.840,
            0.841,
            0.838,
            0.839,
            0.837,
            0.837,
            0.836,
            0.832,
            0.832,
            0.830,
            0.829,
            0.826,
            0.826,
            0.824,
            0.821,
            0.821,
            0.818,
            0.815,
            0.813,
            0.812,
            0.811,
            0.810,
            0.808,
            0.807,
            0.807,
            0.812,
            0.808,
            0.806,
            0.807,
            0.807,
            0.807,
            0.807,
        ])

        s.run()

        self.assertAlmostEqual(s.outputs.apparent_radiance,
                               170.771,
                               delta=0.002)
Example #31
0
    def __init__(self, bandnums, wavelengths, geometry, date_time, sensor=None):
        """ Run SixS atmospheric model using Py6S """
        start = datetime.datetime.now()
        VerboseOut('Running atmospheric model (6S)', 2)

        s = SixS()
        # Geometry
        s.geometry = Geometry.User()
        s.geometry.from_time_and_location(geometry['lat'], geometry['lon'], str(date_time),
                                          geometry['zenith'], geometry['azimuth'])
        s.altitudes = Altitudes()
        s.altitudes.set_target_sea_level()
        s.altitudes.set_sensor_satellite_level()

        doy = (date_time - datetime.datetime(date_time.year, 1, 1)).days + 1
        # Atmospheric profile
        s.atmos_profile = atmospheric_model(doy, geometry['lat'])

        # Aerosols
        # TODO - dynamically adjust AeroProfile?
        s.aero_profile = AeroProfile.PredefinedType(AeroProfile.Continental)

        self.aod = aodData.get_aod(geometry['lat'], geometry['lon'], date_time.date())
        s.aot550 = self.aod[1]

        # Other settings
        s.ground_reflectance = GroundReflectance.HomogeneousLambertian(GroundReflectance.GreenVegetation)
        s.atmos_corr = AtmosCorr.AtmosCorrLambertianFromRadiance(1.0)

        # Used for testing
        try:
            stdout = sys.stdout
            funcs = {
                'LT5': SixSHelpers.Wavelengths.run_landsat_tm,
                'LT7': SixSHelpers.Wavelengths.run_landsat_etm,
                # LC8 doesn't seem to work
                #'LC8': SixSHelpers.Wavelengths.run_landsat_oli
            }
            if sensor in funcs.keys():
                sys.stdout = open(os.devnull, 'w')
                wvlens, outputs = funcs[sensor](s)
                sys.stdout = stdout
            else:
                # Use wavelengths
                outputs = []
                for wv in wavelengths:
                    s.wavelength = Wavelength(wv[0], wv[1])
                    s.run()
                    outputs.append(s.outputs)
        except Exception, e:
            sys.stdout = stdout
            raise AtmCorrException("Error running 6S: %s" % e)