コード例 #1
0
def getImage(sources, bands, mask, year):

    start = str(year) + '-01-01'
    end = str(year) + '-12-31'

    #priority selector for satellites
    for satelliteId in pm.getSatellites(sources):
        dataset = ee.ImageCollection(pm.getSatellites(sources)[satelliteId]) \
            .filterDate(start, end) \
            .filterBounds(mask) \
            .map(pm.getCloudMask(satelliteId))

        if dataset.size().getInfo() > 0:
            satellite = satelliteId
            break

    clip = dataset.median().clip(mask).select(
        pm.getAvailableBands()[bands][satelliteId])

    return (clip, satelliteId)
コード例 #2
0
def getNDWI(sources, satellite, bands, mask, year):

    start = str(year) + '-01-01'
    end = str(year) + '-12-31'

    #select the images from the appropriate satellite
    image = ee.ImageCollection(pm.getSatellites(sources)[satellite]) \
            .filterDate(start, end) \
            .filterBounds(mask) \
            .map(pm.getCloudMask(satellite)) \
            .mosaic()

    nir = image.select(pm.getAvailableBands()['ndwi'][satellite][0])
    swir = image.select(pm.getAvailableBands()['ndwi'][satellite][1])

    ndwi = nir.subtract(swir).divide(nir.add(swir)).rename('NDWI')

    reducer = ndwi.reduceRegion(**{
        'reducer': ee.Reducer.mean(),
        'geometry': mask,
        'scale': 30
    }).getInfo()

    return reducer['NDWI']