Ejemplo n.º 1
0
    def radianceFromTOA():
        """
    calculate at-sensor radiance from top-of-atmosphere (TOA) reflectance
    """

        # top of atmosphere reflectance
        toa = mission_specifics.TOA(TimeSeries.image, TimeSeries.mission)

        # solar irradiances
        ESUNs = mission_specifics.ESUNs(TimeSeries.image, TimeSeries.mission)

        # wavebands
        bands = mission_specifics.ee_bandnames(TimeSeries.mission)

        # solar zenith (radians)
        theta = mission_specifics.solar_z(
            TimeSeries.image, TimeSeries.mission).multiply(0.017453293)

        # circular math
        pi = ee.Number(3.14159265359)

        # Earth-Sun distance squared (AU)
        d = ee.Number(TimeSeries.day_of_year).subtract(4).multiply(
            0.017202).cos().multiply(-0.01672).add(1)
        d_squared = d.multiply(d)

        # radiace at-sensor
        rad = toa.select(ee.List(bands)).multiply(ESUNs).multiply(
            theta.cos()).divide(pi).divide(d_squared)

        return rad
Ejemplo n.º 2
0
def extractAllTimeSeries(target,
                         geom,
                         startDate,
                         stopDate,
                         missions,
                         removeClouds=True):
    """
    Extracts time series for each mission and join them together
    """

    # will store results here (and use consistent band names)
    allTimeSeries = {
        'blue': [],
        'green': [],
        'red': [],
        'nir': [],
        'swir1': [],
        'swir2': [],
        'timeStamp': []
    }

    # for mission in ['Landsat4']:
    for mission in missions:

        timeseries = timeseries_extrator(geom,
                                         startDate,
                                         stopDate,
                                         mission,
                                         removeClouds=removeClouds)

        # names of wavebands
        eeNames = ee_bandnames(mission)
        commonNames = common_bandnames(mission)

        # add mission to timeseries
        for key in timeseries.keys():
            if key[0] == 'B':
                commonName = commonNames[eeNames.index(key)]
                if commonName in allTimeSeries.keys():
                    allTimeSeries[commonName].append(timeseries[key])
            if key == 'timeStamp':
                allTimeSeries['timeStamp'].append(timeseries['timeStamp'])

    # flatten each variables (from separate missions) into a single list
    def flatten(multilist):
        if isinstance(multilist[0], list):
            return [item for sublist in multilist for item in sublist]
        else:
            return multilist

    for key in allTimeSeries.keys():
        allTimeSeries[key] = flatten(allTimeSeries[key])

    return allTimeSeries
Ejemplo n.º 3
0
def surface_reflectance_timeseries(meanRadiance, iLUTs, mission):
    """
  Atmospherically corrects mean (cloud-free) pixel radiances
  returning a time series of surface reflectance values.
  """

    feature_collection = meanRadiance['features']

    # band names
    ee_bandnames = mission_specifics.ee_bandnames(mission)
    py6s_bandnames = mission_specifics.py6s_bandnames(mission)

    # time series output variable
    timeSeries = {'timeStamp': [], 'mission': mission}
    for ee_bandname in ee_bandnames:
        timeSeries[ee_bandname] = []

    # atmospherically correct each scene in collection
    for feature in feature_collection:

        # time stamp
        timeSeries['timeStamp'].append(feature['properties']['timeStamp'])

        # mean average pixel radiances
        mean_averages = feature['properties']['mean_averages']

        # atmospheric correction inputs
        atmcorr_inputs = feature['properties']['atmcorr_inputs']
        solar_z = atmcorr_inputs['solar_z']  # solar zenith [degrees]
        h2o = atmcorr_inputs['h2o']  # water vapour column
        o3 = atmcorr_inputs['o3']  # ozone
        aot = atmcorr_inputs['aot']  # aerosol optical thickness
        alt = atmcorr_inputs['alt']  # altitude (above sea level, [km])
        day_of_year = atmcorr_inputs['doy']  # i.e. Jan 1st = 1

        # atmospheric correction (each waveband)
        for i, ee_bandname in enumerate(ee_bandnames):
            radiance = mean_averages[ee_bandname]
            iLUT = iLUTs.iLUTs[py6s_bandnames[i]]
            perihelion = iLUT(solar_z, h2o, o3, aot, alt)
            timeSeries[ee_bandname].append(
                atmcorr(radiance, perihelion, day_of_year))

    return timeSeries