Open EvanWill8 opened 4 years ago
def getNDVI(image): return image.normalizedDifference(['B4', 'B3'])
image1 = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_044034_19900604') image2 = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_044034_20100611')
ndvi1 = getNDVI(image1) ndvi2 = getNDVI(image2)
ndviDifference = ndvi2.subtract(ndvi1)
ndviParams = {'palette': ['#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b', '#a6d96a', '#66bd63', '#1a9850']} ndwiParams = {'min': -0.5, 'max': 0.5, 'palette': ['FF0000', 'FFFFFF', '0000FF']}
Map.centerObject(image1, 10) Map.addLayer(ndvi1, ndviParams, 'NDVI 1') Map.addLayer(ndvi2, ndviParams, 'NDVI 2') Map.addLayer(ndviDifference, ndwiParams, 'NDVI difference')
Response to: What is the reason for aggregating data over time, space, bands, etc... using the reducer function in Google Earth Engine?
"Merely adding the collection to the map results in selecting the most recent pixel - the one from the latest image in the stack. This behavior may be altered, using Earth Engine reducers. For example, rather than take the most recent pixel from the stack, Earth Engine can be instructed to pick the median value in the stack. This has the benefit of removing clouds (which have a high value) and shadows (which have a low value). When an image collection is reduced using the median reducer, the composite value is the median in each band, over time."