Example #1
1
    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)
Example #2
1
    def __init__(self, bandnums, wavelengths, geometry, date_time, sensor=None):
        """ Run SixS atmospheric model using Py6S """
        start = datetime.datetime.now()
        verbose_out('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()
        )

        # sixs throws IEEE_UNDERFLOW_FLAG IEEE_DENORMAL for small aod.
        # and if using a predefined AeroProfile, visible or aot550 must be
        # specified.   Small here was determined emprically on my laptop, and
        # visible = 1000 km is essentially setting the visibility to infinite.
        if self.aod[1] < 0.0103:
            s.visible = 1000
        else:
            s.aot550 = self.aod[1]

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

        # Used for testing
        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():
            saved_stdout = sys.stdout
            try:
                sys.stdout = open(os.devnull, 'w')
                wvlens, outputs = funcs[sensor](s)
            finally:
                sys.stdout = saved_stdout
        else:
            # Use wavelengths
            outputs = []
            for wv in wavelengths:
                s.wavelength = Wavelength(wv[0], wv[1])
                s.run()
                outputs.append(s.outputs)

        self.results = {}
        verbose_out("{:>6} {:>8}{:>8}{:>8}".format('Band', 'T', 'Lu', 'Ld'), 4)
        for b, out in enumerate(outputs):
            t = out.trans['global_gas'].upward
            Lu = out.atmospheric_intrinsic_radiance
            Ld = (out.direct_solar_irradiance + out.diffuse_solar_irradiance + out.environmental_irradiance) / numpy.pi
            self.results[bandnums[b]] = [t, Lu, Ld]
            verbose_out("{:>6}: {:>8.3f}{:>8.2f}{:>8.2f}".format(bandnums[b], t, Lu, Ld), 4)

        verbose_out('Ran atmospheric model in %s' % str(datetime.datetime.now() - start), 2)
Example #3
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)