예제 #1
0
import ee 
from ee_plugin import Map 

# Image.ConnectedPixelCount example.

# Split pixels of band 01 into "bright" (arbitrarily defined as
# reflectance > 0.3) and "dim". Highlight small (<30 pixels)
# standalone islands of "bright" or "dim" type.
img = ee.Image('MODIS/006/MOD09GA/2012_03_09') \
              .select('sur_refl_b01') \
              .multiply(0.0001)

# Create a threshold image.
bright = img.gt(0.3)

# Compute connected pixel counts; stop searching for connected pixels
# once the size of the connected neightborhood reaches 30 pixels, and
# use 8-connected rules.
conn = bright.connectedPixelCount({
  'maxSize': 30,
  'eightConnected': True
})

# Make a binary image of small clusters.
smallClusters = conn.lt(30)

Map.setCenter(-107.24304, 35.78663, 8)
Map.addLayer(img, {'min': 0, 'max': 1}, 'original')
Map.addLayer(smallClusters.updateMask(smallClusters),
         {'min': 0, 'max': 1, 'palette': 'FF0000'}, 'cc')
예제 #2
0
import ee
from ee_plugin import Map

dataset = ee.Image('CSP/ERGo/1_0/US/physiography')
physiography = dataset.select('constant')
physiographyVis = {
    'min': 1100.0,
    'max': 4220.0,
}
Map.setCenter(-105.4248, 40.5242, 8)
Map.addLayer(physiography, physiographyVis, 'Physiography')
예제 #3
0
import ee
from ee_plugin import Map

dataset = ee.Image('CSP/ERGo/1_0/US/mTPI')
usMtpi = dataset.select('elevation')
usMtpiVis = {
    'min': -200.0,
    'max': 200.0,
    'palette': ['0b1eff', '4be450', 'fffca4', 'ffa011', 'ff0000'],
}
Map.setCenter(-105.8636, 40.3439, 11)
Map.addLayer(usMtpi, usMtpiVis, 'US mTPI')
# GitHub URL: https://github.com/giswqs/qgis-earthengine-examples/tree/master/Datasets/Vectors/us_census_states.py

#!/usr/bin/env python
"""Display US States.

"""

import ee
from ee_plugin import Map

fc = ee.FeatureCollection('TIGER/2018/States')
# .filter(ee.Filter.eq('STUSPS', 'MN'))

image = ee.Image().paint(fc, 0, 2)
Map.setCenter(-99.844, 37.649, 5)
Map.addLayer(image, {'palette': 'FF0000'}, 'TIGER/2018/States')
# Map.addLayer(fc, {}, 'US States')
    rotation = eigenVectors.transpose() \
      .matrixMultiply(scaled) \
      .matrixMultiply(eigenVectors)

    # Reshape the 1-D 'normalized' array, so we can left matrix multiply
    # with the rotation. This requires embedding it in 2-D space and
    # transposing.
    transposed = centered.arrayRepeat(bandAxis, 1).arrayTranspose()

    # Convert rotated results to 3 RGB bands, and shift the mean to 127.
    return transposed.matrixMultiply(ee.Image(rotation)) \
      .arrayProject([bandAxis]) \
      .arrayFlatten([bandNames]) \
      .add(127).byte()


image = ee.Image('MODIS/006/MCD43A4/2002_07_04')

Map.setCenter(-52.09717, -7.03548, 7)

# View the original bland image.
rgb = [0, 3, 2]
Map.addLayer(image.select(rgb), {'min': -100, 'max': 2000}, 'Original Image')

# Stretch the values within an interesting region.
region = ee.Geometry.Rectangle(-57.04651, -8.91823, -47.24121, -5.13531)
Map.addLayer(dcs(image, region, 1000).select(rgb), {}, 'DCS Image')

# Display the region in which covariance stats were computed.
Map.addLayer(ee.Image().paint(region, 0, 2), {}, 'Region')
예제 #6
0
import ee 
from ee_plugin import Map 

dataset = ee.Image('CSP/ERGo/1_0/US/landforms')
landforms = dataset.select('constant')
landformsVis = {
  'min': 11.0,
  'max': 42.0,
  'palette': [
    '141414', '383838', '808080', 'EBEB8F', 'F7D311', 'AA0000', 'D89382',
    'DDC9C9', 'DCCDCE', '1C6330', '68AA63', 'B5C98E', 'E1F0E5', 'a975ba',
    '6f198c'
  ],
}
Map.setCenter(-105.58, 40.5498, 11)
Map.addLayer(landforms, landformsVis, 'NED Landforms')
# GitHub URL: https://github.com/giswqs/qgis-earthengine-examples/tree/master/Image/find_image_by_path_row.py

import ee
from ee_plugin import Map

# Load an image collection, filtered so it's not too much data.
collection = ee.ImageCollection('LANDSAT/LT05/C01/T1') \
  .filterDate('2008-01-01', '2008-12-31') \
  .filter(ee.Filter.eq('WRS_PATH', 44)) \
  .filter(ee.Filter.eq('WRS_ROW', 34))

# Compute the median in each band, each pixel.
# Band names are B1_median, B2_median, etc.
median = collection.reduce(ee.Reducer.median())

# The output is an Image.  Add it to the map.
vis_param = {'bands': ['B4_median', 'B3_median', 'B2_median'], 'gamma': 1.6}
Map.setCenter(-122.3355, 37.7924, 9)
Map.addLayer(median, vis_param, 'Median Image')
예제 #8
0
import ee 
from ee_plugin import Map 

dataset = ee.FeatureCollection('TIGER/2010/Blocks')
visParams = {
  'min': 0.0,
  'max': 700.0,
  'palette': ['black', 'brown', 'yellow', 'orange', 'red']
}

# Turn the strings into numbers
dataset = dataset.map(lambda f: f.set('pop10', ee.Number.parse(f.get('pop10'))))

image = ee.Image().float().paint(dataset, 'pop10')

Map.setCenter(-73.99172, 40.74101, 13)
Map.addLayer(image, visParams, 'TIGER/2010/Blocks')
# Map.addLayer(dataset, {}, 'for Inspector', False)


dataset = ee.FeatureCollection('TIGER/2010/Tracts_DP1')
visParams = {
  'min': 0,
  'max': 4000,
  'opacity': 0.8,
}

# Turn the strings into numbers
dataset = dataset.map(lambda f: f.set('shape_area', ee.Number.parse(f.get('dp0010001'))))

# Map.setCenter(-103.882, 43.036, 8)
import ee
from ee_plugin import Map

# add some data to the Map
dem = ee.Image("AHN/AHN2_05M_RUW")
Map.addLayer(dem, {
    'min': -5,
    'max': 50,
    'palette': ['000000', 'ffffff']
}, 'DEM', True)

# zoom in somewhere
Map.setCenter(4.4585, 52.0774, 14)

# TEST
center = Map.getCenter()

# add bounds to the map
Map.addLayer(center, {'color': 'red'}, 'center')
예제 #10
0
#!/usr/bin/env python
"""HDR Landsat.

Display portions of an image with different dynamic ranges.
The land areas are displayed normally, but the water areas
are streched to show more details.
"""

import ee
from ee_plugin import Map
import datetime

Map.setCenter(-95.738, 18.453, 9)

# Filter the LE7 collection to a single date.
collection = (ee.ImageCollection('LE7_L1T').filterDate(
    datetime.datetime(2002, 11, 8), datetime.datetime(2002, 11, 9)))
image = collection.mosaic().select('B3', 'B2', 'B1')

# Display the image normally.
Map.addLayer(image, {'gain': '1.6, 1.4, 1.1'}, 'Land')

# Add and stretch the water.  Once where the elevation is masked,
# and again where the elevation is zero.
elev = ee.Image('srtm90_v4')
mask1 = elev.mask().eq(0).And(image.mask())
mask2 = elev.eq(0).And(image.mask())
Map.addLayer(image.mask(mask1), {'gain': 6.0, 'bias': -200}, 'Water: Masked')
Map.addLayer(image.mask(mask2), {'gain': 6.0, 'bias': -200}, 'Water: Elev 0')
예제 #11
0
#!/usr/bin/env python
"""Select rows from a fusion table."""

import ee
from ee_plugin import Map


Map.setCenter(-93, 40, 4)

# Select the 'Sonoran desert' feature from the TNC Ecoregions fusion table.

fc = (ee.FeatureCollection('ft:1Ec8IWsP8asxN-ywSqgXWMuBaxI6pPaeh6hC64lA')
      .filter(ee.Filter().eq('ECO_NAME', 'Sonoran desert')))

# Paint it into a blank image.
image1 = ee.Image(0).mask(0)
Map.addLayer(image1.paint(fc, 0, 5), {}, "TNC Ecoregions")
  ee.Feature(
      ee.Geometry.Polygon({
        'coords': [[-109.05, 41], [-109.05, 37], [-102.05, 37], [-102.05, 41]],
        'geodesic': False, # The state boundaries are not geodesic.
        'maxError': 1000 # Make the error margin large; we don't need accuracy.
      }), {'name': 'Colorado', 'fill': 1}), # Pass properties as a dictionary.
  ee.Feature(
      ee.Geometry.Polygon({
        'coords': [
          [-114.05, 37.0], [-109.05, 37.0], [-109.05, 41.0],
          [-111.05, 41.0], [-111.05, 42.0], [-114.05, 42.0]
        ],
        'geodesic': False,
        'maxError': 1000
      }), {'name': 'Utah', 'fill': 2})
])

# Fill, then outline the polygons into a blank image.
image = ee.Image() \
    .paint(fc, 'fill') \
    .paint(fc, 3, 5) \
    .toByte()

Map.addLayer(image, {
    'palette': ['000000', 'FF0000', '00FF00', '0000FF'],
    'max': 3,
    'opacity': 0.5
})

Map.setCenter(-107, 41, 6)
예제 #13
0
# GitHub URL: https://github.com/giswqs/qgis-earthengine-examples/tree/master/Datasets/us_cropland.py

# Metadata: https://developers.google.com/earth-engine/datasets/catalog/USDA_NASS_CDL

import ee
from ee_plugin import Map

dataset = ee.ImageCollection('USDA/NASS/CDL') \
                  .filter(ee.Filter.date('2017-01-01', '2018-12-31')) \
                  .first()
cropLandcover = dataset.select('cropland')
Map.setCenter(-100.55, 40.71, 4)
Map.addLayer(cropLandcover, {}, 'Crop Landcover')
예제 #14
0
from ee_plugin import Map

# Feature buffer example.
# Display the area within 2 kilometers of San Francisco BART stations.

# Instantiate a FeatureCollection of BART locations in Downtown San Francisco
# (points).
stations = [
    ee.Feature(ee.Geometry.Point(-122.42, 37.77),
               {'name': '16th St. Mission (16TH)'}),
    ee.Feature(ee.Geometry.Point(-122.42, 37.75),
               {'name': '24th St. Mission (24TH)'}),
    ee.Feature(ee.Geometry.Point(-122.41, 37.78),
               {'name': 'Civic Center/UN Plaza (CIVC)'})
]
bartStations = ee.FeatureCollection(stations)

# Map a function over the collection to buffer each feature.


def func_dky(f):
    return f.buffer(2000, 100)
    # Note that the errorMargin is set to 100.


buffered = bartStations.map(func_dky)

Map.addLayer(buffered, {'color': '800080'})

Map.setCenter(-122.4, 37.7, 11)
예제 #15
0
def func_mrj(image):
    date = ee.Date(image.get('system:time_start'))
    yearOffset = date.difference(ee.Date(start), 'year')
    ndvi = image.normalizedDifference(['B4', 'B3'])
    return ee.Image(1).addBands(yearOffset).addBands(ndvi).toDouble() \
  .map(func_mrj)







# Convert to an array. Give the axes names for more readable code.
array = images.toArray()
imageAxis = 0
bandAxis = 1

# Slice off the year and ndvi, and solve for the coefficients.
x = array.arraySlice(bandAxis, 0, 2)
y = array.arraySlice(bandAxis, 2)
fit = x.matrixSolve(y)

# Get the coefficient for the year, effectively the slope of the long-term
# NDVI trend.
slope = fit.arrayGet([1, 0])

Map.setCenter(lng, lat, 12)
Map.addLayer(slope, {'min': -0.03, 'max': 0.03}, 'Slope')

예제 #16
0
# GitHub URL: https://github.com/giswqs/qgis-earthengine-examples/tree/master/ImageCollection/select_image_by_index.py

import ee
from ee_plugin import Map

collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')\
    .filter(ee.Filter.eq('WRS_PATH', 44))\
    .filter(ee.Filter.eq('WRS_ROW', 34))\
    .filterDate('2014-01-01', '2015-01-01')

image = ee.Image(collection.toList(
    collection.size()).get(0))  # select by index from 0 to size-1
print(image.get('system:id').getInfo())

Map.setCenter(-122.3578, 37.7726, 12)
Map.addLayer(image, {"bands": ['B4', 'B3', 'B2'], "max": 0.3}, 'median')
예제 #17
0
import ee
from ee_plugin import Map

# This example demonstrates the use of the Landsat 8 QA band to mask clouds.


# Function to mask clouds using the quality band of Landsat 8.
def maskL8(image):
    qa = image.select('BQA')
    #/ Check that the cloud bit is off.
    # See https:#www.usgs.gov/land-resources/nli/landsat/landsat-collection-1-level-1-quality-assessment-band
    mask = qa.bitwiseAnd(1 << 4).eq(0)
    return image.updateMask(mask)


# Map the function over one year of Landsat 8 TOA data and take the median.
composite = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') \
    .filterDate('2016-01-01', '2016-12-31') \
    .map(maskL8) \
    .median()

# Display the results in a cloudy place.
Map.setCenter(114.1689, 22.2986, 12)
Map.addLayer(composite, {'bands': ['B4', 'B3', 'B2'], 'max': 0.3})
import ee
from ee_plugin import Map

# Load a MODIS EVI image.
modis = ee.Image(ee.ImageCollection('MODIS/006/MOD13A1').first()) \
    .select('EVI')

# Display the EVI image near La Honda, California.
Map.setCenter(-122.3616, 37.5331, 12)
Map.addLayer(modis, {'min': 2000, 'max': 5000}, 'MODIS EVI')

# Get information about the MODIS projection.
modisProjection = modis.projection()
print('MODIS projection:', modisProjection.getInfo())

# Load and display forest cover data at 30 meters resolution.
forest = ee.Image('UMD/hansen/global_forest_change_2015') \
    .select('treecover2000')
Map.addLayer(forest, {'max': 80}, 'forest cover 30 m')

# Get the forest cover data at MODIS scale and projection.
forestMean = forest \
    .reduceResolution(**{
      'reducer': ee.Reducer.mean(),
      'maxPixels': 1024
    }) \
    .reproject(**{
      'crs': modisProjection
    })

# Display the aggregated, reprojected forest cover data.
예제 #19
0
# Mask the sources image with itself.
sources = sources.updateMask(sources)

# The cost data is generated from classes in ESA/GLOBCOVER.
cover = ee.Image('ESA/GLOBCOVER_L4_200901_200912_V2_3').select(0)

# Classes 60, 80, 110, 140 have cost 1.
# Classes 40, 90, 120, 130, 170 have cost 2.
# Classes 50, 70, 150, 160 have cost 3.
cost = \
  cover.eq(60).Or(cover.eq(80)).Or(cover.eq(110)).Or(cover.eq(140)) \
      .multiply(1).add(
    cover.eq(40).Or(cover.eq(90)).Or(cover.eq(120)).Or(cover.eq(130)) \
    .Or(cover.eq(170)) \
      .multiply(2).add(
        cover.eq(50).Or(cover.eq(70)).Or(cover.eq(150)).Or(cover.eq(160)) \
      .multiply(3)))

# Compute the cumulative cost to traverse the lAnd cover.
cumulativeCost = cost.cumulativeCost(**{
    'source': sources,
    'maxDistance': 80 * 1000  # 80 kilometers
})

# Display the results
Map.setCenter(18.71, 4.2, 9)
Map.addLayer(cover, {}, 'Globcover')
Map.addLayer(cumulativeCost, {'min': 0, 'max': 5e4}, 'accumulated cost')
Map.addLayer(geometry, {'color': 'FF0000'}, 'source geometry')
예제 #20
0
# Define an SLD style of discrete intervals to apply to the image.
sld_intervals = \
  '<RasterSymbolizer>' + \
    '<ColorMap  type="intervals" extended="false" >' + \
      '<ColorMapEntry color="#0000ff" quantity="0" label="0"/>' + \
      '<ColorMapEntry color="#00ff00" quantity="100" label="1-100" />' + \
      '<ColorMapEntry color="#007f30" quantity="200" label="110-200" />' + \
      '<ColorMapEntry color="#30b855" quantity="300" label="210-300" />' + \
      '<ColorMapEntry color="#ff0000" quantity="400" label="310-400" />' + \
      '<ColorMapEntry color="#ffff00" quantity="1000" label="410-1000" />' + \
    '</ColorMap>' + \
  '</RasterSymbolizer>';

# Define an sld style color ramp to apply to the image.
sld_ramp = \
  '<RasterSymbolizer>' + \
    '<ColorMap type="ramp" extended="false" >' + \
      '<ColorMapEntry color="#0000ff" quantity="0" label="0"/>' + \
      '<ColorMapEntry color="#00ff00" quantity="100" label="100" />' + \
      '<ColorMapEntry color="#007f30" quantity="200" label="200" />' + \
      '<ColorMapEntry color="#30b855" quantity="300" label="300" />' + \
      '<ColorMapEntry color="#ff0000" quantity="400" label="400" />' + \
      '<ColorMapEntry color="#ffff00" quantity="500" label="500" />' + \
    '</ColorMap>' + \
  '</RasterSymbolizer>';

# Add the image to the map using both the color ramp and interval schemes.
Map.setCenter(-76.8054, 42.0289, 8);
Map.addLayer(image.sldStyle(sld_intervals), {}, 'SLD intervals');
Map.addLayer(image.sldStyle(sld_ramp), {}, 'SLD ramp');
예제 #21
0
# GitHub URL: https://github.com/giswqs/qgis-earthengine-examples/tree/master/Datasets/Vectors/global_land_ice_measurements.py

import ee
from ee_plugin import Map

dataset = ee.FeatureCollection('GLIMS/current')
visParams = {
    'palette': ['gray', 'cyan', 'blue'],
    'min': 0.0,
    'max': 10.0,
    'opacity': 0.8,
}

image = ee.Image().float().paint(dataset, 'area')
Map.setCenter(-35.618, 66.743, 7)
Map.addLayer(image, visParams, 'GLIMS/current')
# Map.addLayer(dataset, {}, 'for Inspector', False)
#!/usr/bin/env python
"""Reverse mask a region.

Create an image that masks everything except for the specified polygon.
"""

import ee
from ee_plugin import Map

Map.setCenter(-100, 40, 4)

fc = (ee.FeatureCollection('RESOLVE/ECOREGIONS/2017').filter(ee.Filter().eq(
    'ECO_NAME', 'Great Basin shrub steppe')))

# Start with a black image.
empty = ee.Image(0).toByte()
# Fill and outline the polygons in two colors
filled = empty.paint(fc, 2)
both = filled.paint(fc, 1, 5)
# Mask off everything that matches the fill color.
result = both.mask(filled.neq(2))

Map.addLayer(result, {
    'palette': '000000,FF0000',
    'max': 1,
    'opacity': 0.5
}, "Basin")
예제 #23
0
import ee
from ee_plugin import Map


cover = ee.Image('MODIS/051/MCD12Q1/2012_01_01').select('Land_Cover_Type_1')

igbpPalette = [
    'aec3d4',
    '152106', '225129', '369b47', '30eb5b', '387242',
    '6a2325', 'c3aa69', 'b76031', 'd9903d', '91af40',
    '111149',
    'cdb33b',
    'cc0013',
    '33280d',
    'd7cdcc',
    'f7e084',
    '6f6f6f'
]

Map.setCenter(-99.229, 40.413, 5)
Map.addLayer(cover, {'min': 0, 'max': 17, 'palette': igbpPalette}, 'MODIS Land Cover')

예제 #24
0
import ee
import math
from ee_plugin import Map

# Load a high-resolution NAIP image.
image = ee.Image('USDA/NAIP/DOQQ/m_3712213_sw_10_1_20140613')

# Zoom to San Francisco, display.
Map.setCenter(-122.466123, 37.769833, 17)
Map.addLayer(image, {'max': 255}, 'image')

# Get the NIR band.
nir = image.select('N')

# Define a neighborhood with a kernel.
square = ee.Kernel.square(**{'radius': 4})

# Compute entropy and display.
entropy = nir.entropy(square)
Map.addLayer(entropy, {
    'min': 1,
    'max': 5,
    'palette': ['0000CC', 'CC0000']
}, 'entropy')

# Compute the gray-level co-occurrence matrix (GLCM), get contrast.
glcm = nir.glcmTexture(**{'size': 4})
contrast = glcm.select('N_contrast')
Map.addLayer(contrast, {
    'min': 0,
    'max': 1500,
from ee_plugin import Map
from ee_plugin import palettes
import ee

dem = ee.Image("JAXA/ALOS/AW3D30_V1_1").select('MED')
dem = dem.updateMask(dem.gt(0))
palette = palettes.cb['Pastel1']['7']
#palette = ['black', 'white']
rgb = dem.visualize(**{'min': 0, 'max': 5000, 'palette': palette})
hsv = rgb.unitScale(0, 255).rgbToHsv()

extrusion = 30
weight = 0.3

hs = ee.Terrain.hillshade(dem.multiply(extrusion), 315,
                          35).unitScale(10, 250).resample('bicubic')

hs = hs.multiply(1 - weight).add(hsv.select('value').multiply(weight))
hsv = hsv.addBands(hs.rename('value'), ['value'], True)
rgb = hsv.hsvToRgb()

Map.setCenter(0, 28, 2.5)
Map.addLayer(rgb, {}, 'ALOS DEM', True)
예제 #26
0
#!/usr/bin/env python
"""Display an image given its ID."""

import ee
from ee_plugin import Map

image = ee.Image('srtm90_v4')
vis_params = {'min': 0, 'max': 3000}
Map.addLayer(image, vis_params, "SRTM")
Map.setCenter(0, 0, 2)
예제 #27
0
  # we have to do some kind of reduction, but it won't really calculate pixels
  # if we only access the band names.
  bandNames = bands.min().bandNames().slice(1)
  return best.arrayProject([bandAxis]).arrayFlatten([bandNames])


# Load the l7_l1t collection for the year 2000, and make sure the first band
# is our quality measure, in this case the normalized difference values.
l7 = ee.ImageCollection('LANDSAT/LE07/C01/T1') \
    .filterDate('2000-01-01', '2001-01-01')

def func_tqs(image):
  return image.normalizedDifference(['B4', 'B3']).addBands(image)

withNd = l7.map(func_tqs)




# Build a mosaic using the NDVI of bands 4 and 3, essentially showing the
# greenest pixels from the year 2000.
greenest = qualityMosaic(withNd)

# Select out the color bands to visualize. An interesting artifact of this
# approach is that clouds are greener than water. So all the water is white.
rgb = greenest.select(['B3', 'B2', 'B1'])

Map.addLayer(rgb, {'gain': [1.4, 1.4, 1.1]}, 'Greenest')
Map.setCenter(-90.08789, 16.38339, 11)

예제 #28
0
import ee
from ee_plugin import Map
from ee_plugin.contrib import palettes

dem = ee.Image("AHN/AHN2_05M_RUW").convolve(
    ee.Kernel.gaussian(0.5, 0.3, 'meters'))

extrusion = 3
weight = 0.7
palette = palettes.crameri['oleron'][50]

rgb = dem.visualize(**{'min': 0, 'max': 3, 'palette': palette})
hsv = rgb.unitScale(0, 255).rgbToHsv()
hs = ee.Terrain.hillshade(dem.multiply(extrusion), 315, 35).unitScale(0, 255)
hs = hs.multiply(weight).add(hsv.select('value').multiply(1 - weight))
saturation = hsv.select('saturation').multiply(0.5)
hsv = hsv.addBands(hs.rename('value'), ['value'], True)
hsv = hsv.addBands(saturation, ['saturation'], True)
rgb = hsv.hsvToRgb()

# rgb = rgb.updateMask(dem.unitScale(0, 3))

Map.addLayer(rgb, {}, 'Dutch AHN DEM', True)
Map.setCenter(4.5618, 52.1664, 18)
import ee
from ee_plugin import Map

# Compute Enhanced Vegetation Index (EVI) over the MODIS MOD09GA product
# using an expression.

# Load a MODIS image and apply the scaling factor.
img = ee.Image('MODIS/006/MOD09GA/2012_03_09').multiply(0.0001)

# Compute EVI using an expression.  The second argument is a map from
# variable name to band name in the input image.
evi = img.expression(
    '2.5 * (nir - red) / (nir + 6 * red - 7.5 * blue + 1)',
    {
        'red': img.select('sur_refl_b01'),  # 620-670nm, RED
        'nir': img.select('sur_refl_b02'),  # 841-876nm, NIR
        'blue': img.select('sur_refl_b03')  # 459-479nm, BLUE
    })

# Center the map.
Map.setCenter(-94.84497, 39.01918, 8)

# Display the input image and the EVI computed from it.
Map.addLayer(img.select(['sur_refl_b01', 'sur_refl_b04', 'sur_refl_b03']), {
    'min': 0,
    'max': 0.2
}, 'MODIS bands 1/4/3')
Map.addLayer(evi, {'min': 0, 'max': 1}, 'EVI')
# Filter to only include images intersecting Colorado or Utah.
polygon = ee.Geometry.Polygon({
    'coords': [[
        [-109.05, 37.0],
        [-102.05, 37.0],
        [-102.05, 41.0],  # Colorado
        [-109.05, 41.0],
        [-111.05, 41.0],
        [-111.05, 42.0],  # Utah
        [-114.05, 42.0],
        [-114.05, 37.0],
        [-109.05, 37.0]
    ]],
    'geodesic':
    False
})

# Create a Landsat 7 composite for Spring of 2000, and filter by
# the bounds of the FeatureCollection.
collection = ee.ImageCollection('LANDSAT/LE07/C01/T1') \
    .filterDate('2000-04-01', '2000-07-01') \
    .filterBounds(polygon)

# Compute the median in each band, in each pixel.
median = collection.median()

# Select the red, green and blue bands.
result = median.select('B3', 'B2', 'B1')
Map.addLayer(result, {'gain': [1.4, 1.4, 1.1]})
Map.setCenter(-110, 40, 5)