-
Notifications
You must be signed in to change notification settings - Fork 265
/
band_math.py
26 lines (20 loc) · 863 Bytes
/
band_math.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import ee
from ee_plugin import Map
# Load two 5-year Landsat 7 composites.
landsat1999 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003')
landsat2008 = ee.Image('LANDSAT/LE7_TOA_5YEAR/2008_2012')
# Compute NDVI the hard way.
ndvi1999 = landsat1999.select('B4').subtract(landsat1999.select('B3')) \
.divide(landsat1999.select('B4').add(landsat1999.select('B3')))
# Compute NDVI the easy way.
ndvi2008 = landsat2008.normalizedDifference(['B4', 'B3'])
# Compute the multi-band difference image.
diff = landsat2008.subtract(landsat1999)
Map.addLayer(diff,
{'bands': ['B4', 'B3', 'B2'], 'min': -32, 'max': 32},
'difference')
# Compute the squared difference in each band.
squaredDifference = diff.pow(2)
Map.addLayer(squaredDifference,
{'bands': ['B4', 'B3', 'B2'], 'max': 1000},
'squared diff.')