Google Earth Engine's Python API

We will collect satellite imagery from the Landsat 8 collection via Google Earth Engine. Landsat 8 satellite images the entire earth every 16 days in an 8-day offset from Landsat 7. Images come in a GeoTIFF format, which is a tiff file with geospatial meta-data. The collection extends back to April 2013 and images are collected in 15-minute intervals. Daily imagery is then made available on Google Earth within 24 hours.

Landsat imagery is composed of 11 spectral bands that capture light reflectnace from the surface of the planet. Each band captures a range of wavelengths from the electro-magnetic spectrum.


In [15]:
# Import the Google Earth Engine Python Package
import ee

# Initialize the Earth Engine object, using the authentication credentials.
ee.Initialize()

# Get the landsat 8 imagery collection
l8 = ee.ImageCollection('LANDSAT/LC8_L1T_TOA')

# Get imagery that intersects with point of interest -- San Francisco
point_of_interest = ee.Geometry.Point([-122.4371337890625, 37.724225332072436]);
spatialFiltered = l8.filterBounds(point_of_interest);

In [128]:
# Filter colletion by date: 2010 to present
import datetime
now = datetime.datetime.now()
d = now.day
y = now.year
m = now.month

# l8_temporalFiltered = spatialFiltered.filterDate('{}-0{}-{}'.format(y,m-1,d-2), '{}-0{}-{}'.format(y,m-1,d))

l8_temporalFiltered = spatialFiltered.filterDate('2017-01-01', '2017-02-18')

# This will sort from least to most cloudy.
sorted_collection_clouds = l8_temporalFiltered.sort('CLOUD_COVER')

# Get the first (least cloudy) image.
scene = ee.Image(l8_temporalFiltered.first())

# Band Names
scene.bandNames().getInfo()


Out[128]:
['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'B10', 'B11', 'BQA']

Mix and match band combinations as RGB to visualize different features in the imagery


In [150]:
# Parameters to visualize vegetation
vegetationParams = {'bands': 'B5,B4,B3', 'min':0, 'max': 0.3}
naturalColorParams = {'bands': 'B4,B3,B2', 'min':0, 'max': 0.3}
agricultureParams = {'bands': 'B6,B5,B2', 'min':0, 'max': 0.3}
landwaterParams = {'bands': 'B5,B6,B4', 'min':0, 'max': 0.3}
urbanParams = {'bands': 'B7,B6,B4', 'min':0, 'max': 0.3}
atmosphericParams = {'bands': 'B7,B5,B4', 'min':0, 'max': 0.3}

In [148]:
# Display image 
from IPython.display import Image

print("Natural Color")
Image(url=scene.getThumbUrl(naturalColorParams))


Natural Color
Out[148]:

In [137]:
print("Land/Water")
Image(url=scene.getThumbUrl(landwaterParams))


Land/Water
Out[137]:

In [139]:
print("Urban")
Image(url=scene.getThumbUrl(urbanParams))


Urban
Out[139]:

In [130]:
print("Vegetation")
Image(url=scene.getThumbUrl(vegetationParams))


Vegetation
Out[130]:

In [133]:
print("Agriculture")
Image(url=scene.getThumbUrl(agricultureParams))


Agriculture
Out[133]:


In [43]:
# Metadata
scene.getInfo()


Out[43]:
{'bands': [{'crs': 'EPSG:32610',
   'crs_transform': [30.0, 0.0, 464985.0, 0.0, -30.0, 4258215.0],
   'data_type': {'precision': 'float', 'type': 'PixelType'},
   'dimensions': [7571, 7381],
   'id': 'B1'},
  {'crs': 'EPSG:32610',
   'crs_transform': [30.0, 0.0, 464985.0, 0.0, -30.0, 4258215.0],
   'data_type': {'precision': 'float', 'type': 'PixelType'},
   'dimensions': [7571, 7381],
   'id': 'B2'},
  {'crs': 'EPSG:32610',
   'crs_transform': [30.0, 0.0, 464985.0, 0.0, -30.0, 4258215.0],
   'data_type': {'precision': 'float', 'type': 'PixelType'},
   'dimensions': [7571, 7381],
   'id': 'B3'},
  {'crs': 'EPSG:32610',
   'crs_transform': [30.0, 0.0, 464985.0, 0.0, -30.0, 4258215.0],
   'data_type': {'precision': 'float', 'type': 'PixelType'},
   'dimensions': [7571, 7381],
   'id': 'B4'},
  {'crs': 'EPSG:32610',
   'crs_transform': [30.0, 0.0, 464985.0, 0.0, -30.0, 4258215.0],
   'data_type': {'precision': 'float', 'type': 'PixelType'},
   'dimensions': [7571, 7381],
   'id': 'B5'},
  {'crs': 'EPSG:32610',
   'crs_transform': [30.0, 0.0, 464985.0, 0.0, -30.0, 4258215.0],
   'data_type': {'precision': 'float', 'type': 'PixelType'},
   'dimensions': [7571, 7381],
   'id': 'B6'},
  {'crs': 'EPSG:32610',
   'crs_transform': [30.0, 0.0, 464985.0, 0.0, -30.0, 4258215.0],
   'data_type': {'precision': 'float', 'type': 'PixelType'},
   'dimensions': [7571, 7381],
   'id': 'B7'},
  {'crs': 'EPSG:32610',
   'crs_transform': [15.0, 0.0, 464992.5, 0.0, -15.0, 4258207.5],
   'data_type': {'precision': 'float', 'type': 'PixelType'},
   'dimensions': [15141, 14761],
   'id': 'B8'},
  {'crs': 'EPSG:32610',
   'crs_transform': [30.0, 0.0, 464985.0, 0.0, -30.0, 4258215.0],
   'data_type': {'precision': 'float', 'type': 'PixelType'},
   'dimensions': [7571, 7381],
   'id': 'B9'},
  {'crs': 'EPSG:32610',
   'crs_transform': [30.0, 0.0, 464985.0, 0.0, -30.0, 4258215.0],
   'data_type': {'precision': 'float', 'type': 'PixelType'},
   'dimensions': [7571, 7381],
   'id': 'B10'},
  {'crs': 'EPSG:32610',
   'crs_transform': [30.0, 0.0, 464985.0, 0.0, -30.0, 4258215.0],
   'data_type': {'precision': 'float', 'type': 'PixelType'},
   'dimensions': [7571, 7381],
   'id': 'B11'},
  {'crs': 'EPSG:32610',
   'crs_transform': [30.0, 0.0, 464985.0, 0.0, -30.0, 4258215.0],
   'data_type': {'max': 65535,
    'min': 0,
    'precision': 'int',
    'type': 'PixelType'},
   'dimensions': [7571, 7381],
   'id': 'BQA'}],
 'id': 'LANDSAT/LC8_L1T_TOA/LC80440342013106LGN01',
 'properties': {'BPF_NAME_OLI': 'LO8BPF20130416183813_20130416184936.01',
  'BPF_NAME_TIRS': 'LT8BPF20130416183419_20130416185028.01',
  'CLOUD_COVER': 0.35,
  'CORNER_LL_LAT_PRODUCT': 36.47585,
  'CORNER_LL_LON_PRODUCT': -123.3907,
  'CORNER_LL_PROJECTION_X_PRODUCT': 465000.0,
  'CORNER_LL_PROJECTION_Y_PRODUCT': 4036800.0,
  'CORNER_LR_LAT_PRODUCT': 36.45723,
  'CORNER_LR_LON_PRODUCT': -120.85628,
  'CORNER_LR_PROJECTION_X_PRODUCT': 692100.0,
  'CORNER_LR_PROJECTION_Y_PRODUCT': 4036800.0,
  'CORNER_UL_LAT_PRODUCT': 38.47143,
  'CORNER_UL_LON_PRODUCT': -123.40123,
  'CORNER_UL_PROJECTION_X_PRODUCT': 465000.0,
  'CORNER_UL_PROJECTION_Y_PRODUCT': 4258200.0,
  'CORNER_UR_LAT_PRODUCT': 38.45143,
  'CORNER_UR_LON_PRODUCT': -120.79857,
  'CORNER_UR_PROJECTION_X_PRODUCT': 692100.0,
  'CORNER_UR_PROJECTION_Y_PRODUCT': 4258200.0,
  'CPF_NAME': 'L8CPF20130401_20130627.08',
  'DATA_TYPE': 'L1T',
  'DATE_ACQUIRED': '2013-04-16',
  'DATUM': 'WGS84',
  'EARTH_SUN_DISTANCE': 1.0037447,
  'ELEVATION_SOURCE': 'GLS2000',
  'ELLIPSOID': 'WGS84',
  'FILE_DATE': 1421185515000,
  'FILE_NAME_BAND_1': 'LC80440342013106LGN01_B1.TIF',
  'FILE_NAME_BAND_10': 'LC80440342013106LGN01_B10.TIF',
  'FILE_NAME_BAND_11': 'LC80440342013106LGN01_B11.TIF',
  'FILE_NAME_BAND_2': 'LC80440342013106LGN01_B2.TIF',
  'FILE_NAME_BAND_3': 'LC80440342013106LGN01_B3.TIF',
  'FILE_NAME_BAND_4': 'LC80440342013106LGN01_B4.TIF',
  'FILE_NAME_BAND_5': 'LC80440342013106LGN01_B5.TIF',
  'FILE_NAME_BAND_6': 'LC80440342013106LGN01_B6.TIF',
  'FILE_NAME_BAND_7': 'LC80440342013106LGN01_B7.TIF',
  'FILE_NAME_BAND_8': 'LC80440342013106LGN01_B8.TIF',
  'FILE_NAME_BAND_9': 'LC80440342013106LGN01_B9.TIF',
  'FILE_NAME_BAND_QUALITY': 'LC80440342013106LGN01_BQA.TIF',
  'GEOMETRIC_RMSE_MODEL': 6.077,
  'GEOMETRIC_RMSE_MODEL_X': 4.225,
  'GEOMETRIC_RMSE_MODEL_Y': 4.368,
  'GEOMETRIC_RMSE_VERIFY': 3.607,
  'GRID_CELL_SIZE_PANCHROMATIC': 15.0,
  'GRID_CELL_SIZE_REFLECTIVE': 30.0,
  'GRID_CELL_SIZE_THERMAL': 30.0,
  'GROUND_CONTROL_POINTS_MODEL': 475,
  'GROUND_CONTROL_POINTS_VERIFY': 168,
  'GROUND_CONTROL_POINTS_VERSION': 2,
  'IMAGE_QUALITY_OLI': 9,
  'IMAGE_QUALITY_TIRS': 9,
  'K1_CONSTANT_BAND_10': 774.89,
  'K1_CONSTANT_BAND_11': 480.89,
  'K2_CONSTANT_BAND_10': 1321.08,
  'K2_CONSTANT_BAND_11': 1201.14,
  'LANDSAT_SCENE_ID': 'LC80440342013106LGN01',
  'MAP_PROJECTION': 'UTM',
  'METADATA_FILE_NAME': 'LC80440342013106LGN01_MTL.txt',
  'NADIR_OFFNADIR': 'NADIR',
  'ORIENTATION': 'NORTH_UP',
  'ORIGIN': 'Image courtesy of the U.S. Geological Survey',
  'OUTPUT_FORMAT': 'GEOTIFF',
  'PANCHROMATIC_LINES': 14761,
  'PANCHROMATIC_SAMPLES': 15141,
  'PROCESSING_SOFTWARE_VERSION': 'LPGS_2.4.0',
  'QUANTIZE_CAL_MAX_BAND_1': 65535,
  'QUANTIZE_CAL_MAX_BAND_10': 65535,
  'QUANTIZE_CAL_MAX_BAND_11': 65535,
  'QUANTIZE_CAL_MAX_BAND_2': 65535,
  'QUANTIZE_CAL_MAX_BAND_3': 65535,
  'QUANTIZE_CAL_MAX_BAND_4': 65535,
  'QUANTIZE_CAL_MAX_BAND_5': 65535,
  'QUANTIZE_CAL_MAX_BAND_6': 65535,
  'QUANTIZE_CAL_MAX_BAND_7': 65535,
  'QUANTIZE_CAL_MAX_BAND_8': 65535,
  'QUANTIZE_CAL_MAX_BAND_9': 65535,
  'QUANTIZE_CAL_MIN_BAND_1': 1,
  'QUANTIZE_CAL_MIN_BAND_10': 1,
  'QUANTIZE_CAL_MIN_BAND_11': 1,
  'QUANTIZE_CAL_MIN_BAND_2': 1,
  'QUANTIZE_CAL_MIN_BAND_3': 1,
  'QUANTIZE_CAL_MIN_BAND_4': 1,
  'QUANTIZE_CAL_MIN_BAND_5': 1,
  'QUANTIZE_CAL_MIN_BAND_6': 1,
  'QUANTIZE_CAL_MIN_BAND_7': 1,
  'QUANTIZE_CAL_MIN_BAND_8': 1,
  'QUANTIZE_CAL_MIN_BAND_9': 1,
  'RADIANCE_ADD_BAND_1': -62.31123,
  'RADIANCE_ADD_BAND_10': 0.1,
  'RADIANCE_ADD_BAND_11': 0.1,
  'RADIANCE_ADD_BAND_2': -63.80746,
  'RADIANCE_ADD_BAND_3': -58.79803,
  'RADIANCE_ADD_BAND_4': -49.58181,
  'RADIANCE_ADD_BAND_5': -30.3416,
  'RADIANCE_ADD_BAND_6': -7.54568,
  'RADIANCE_ADD_BAND_7': -2.5433,
  'RADIANCE_ADD_BAND_8': -56.11296,
  'RADIANCE_ADD_BAND_9': -11.85818,
  'RADIANCE_MAXIMUM_BAND_1': 754.4021,
  'RADIANCE_MAXIMUM_BAND_10': 22.0018,
  'RADIANCE_MAXIMUM_BAND_11': 22.0018,
  'RADIANCE_MAXIMUM_BAND_2': 772.5169,
  'RADIANCE_MAXIMUM_BAND_3': 711.86774,
  'RADIANCE_MAXIMUM_BAND_4': 600.287,
  'RADIANCE_MAXIMUM_BAND_5': 367.3457,
  'RADIANCE_MAXIMUM_BAND_6': 91.35554,
  'RADIANCE_MAXIMUM_BAND_7': 30.79171,
  'RADIANCE_MAXIMUM_BAND_8': 679.3597,
  'RADIANCE_MAXIMUM_BAND_9': 143.56703,
  'RADIANCE_MINIMUM_BAND_1': -62.29877,
  'RADIANCE_MINIMUM_BAND_10': 0.10033,
  'RADIANCE_MINIMUM_BAND_11': 0.10033,
  'RADIANCE_MINIMUM_BAND_2': -63.7947,
  'RADIANCE_MINIMUM_BAND_3': -58.78627,
  'RADIANCE_MINIMUM_BAND_4': -49.5719,
  'RADIANCE_MINIMUM_BAND_5': -30.33553,
  'RADIANCE_MINIMUM_BAND_6': -7.54417,
  'RADIANCE_MINIMUM_BAND_7': -2.54279,
  'RADIANCE_MINIMUM_BAND_8': -56.10174,
  'RADIANCE_MINIMUM_BAND_9': -11.85581,
  'RADIANCE_MULT_BAND_1': 0.012462,
  'RADIANCE_MULT_BAND_10': 0.0003342,
  'RADIANCE_MULT_BAND_11': 0.0003342,
  'RADIANCE_MULT_BAND_2': 0.012761,
  'RADIANCE_MULT_BAND_3': 0.01176,
  'RADIANCE_MULT_BAND_4': 0.0099164,
  'RADIANCE_MULT_BAND_5': 0.0060683,
  'RADIANCE_MULT_BAND_6': 0.0015091,
  'RADIANCE_MULT_BAND_7': 0.00050866,
  'RADIANCE_MULT_BAND_8': 0.011223,
  'RADIANCE_MULT_BAND_9': 0.0023716,
  'REFLECTANCE_ADD_BAND_1': -0.1,
  'REFLECTANCE_ADD_BAND_2': -0.1,
  'REFLECTANCE_ADD_BAND_3': -0.1,
  'REFLECTANCE_ADD_BAND_4': -0.1,
  'REFLECTANCE_ADD_BAND_5': -0.1,
  'REFLECTANCE_ADD_BAND_6': -0.1,
  'REFLECTANCE_ADD_BAND_7': -0.1,
  'REFLECTANCE_ADD_BAND_8': -0.1,
  'REFLECTANCE_ADD_BAND_9': -0.1,
  'REFLECTANCE_MAXIMUM_BAND_1': 1.2107,
  'REFLECTANCE_MAXIMUM_BAND_2': 1.2107,
  'REFLECTANCE_MAXIMUM_BAND_3': 1.2107,
  'REFLECTANCE_MAXIMUM_BAND_4': 1.2107,
  'REFLECTANCE_MAXIMUM_BAND_5': 1.2107,
  'REFLECTANCE_MAXIMUM_BAND_6': 1.2107,
  'REFLECTANCE_MAXIMUM_BAND_7': 1.2107,
  'REFLECTANCE_MAXIMUM_BAND_8': 1.2107,
  'REFLECTANCE_MAXIMUM_BAND_9': 1.2107,
  'REFLECTANCE_MINIMUM_BAND_1': -0.09998,
  'REFLECTANCE_MINIMUM_BAND_2': -0.09998,
  'REFLECTANCE_MINIMUM_BAND_3': -0.09998,
  'REFLECTANCE_MINIMUM_BAND_4': -0.09998,
  'REFLECTANCE_MINIMUM_BAND_5': -0.09998,
  'REFLECTANCE_MINIMUM_BAND_6': -0.09998,
  'REFLECTANCE_MINIMUM_BAND_7': -0.09998,
  'REFLECTANCE_MINIMUM_BAND_8': -0.09998,
  'REFLECTANCE_MINIMUM_BAND_9': -0.09998,
  'REFLECTANCE_MULT_BAND_1': 2e-05,
  'REFLECTANCE_MULT_BAND_2': 2e-05,
  'REFLECTANCE_MULT_BAND_3': 2e-05,
  'REFLECTANCE_MULT_BAND_4': 2e-05,
  'REFLECTANCE_MULT_BAND_5': 2e-05,
  'REFLECTANCE_MULT_BAND_6': 2e-05,
  'REFLECTANCE_MULT_BAND_7': 2e-05,
  'REFLECTANCE_MULT_BAND_8': 2e-05,
  'REFLECTANCE_MULT_BAND_9': 2e-05,
  'REFLECTIVE_LINES': 7381,
  'REFLECTIVE_SAMPLES': 7571,
  'REQUEST_ID': '0601501132587_00002',
  'RESAMPLING_OPTION': 'CUBIC_CONVOLUTION',
  'RLUT_FILE_NAME': 'L8RLUT20130211_20431231v09.h5',
  'ROLL_ANGLE': -0.001,
  'SCENE_CENTER_TIME': '18:47:53.5577434Z',
  'SENSOR_ID': 'OLI_TIRS',
  'SPACECRAFT_ID': 'LANDSAT_8',
  'STATION_ID': 'LGN',
  'SUN_AZIMUTH': 140.98756,
  'SUN_ELEVATION': 57.59147,
  'TARGET_WRS_PATH': 44,
  'TARGET_WRS_ROW': 34,
  'THERMAL_LINES': 7381,
  'THERMAL_SAMPLES': 7571,
  'UTM_ZONE': 10,
  'WRS_PATH': 44,
  'WRS_ROW': 34,
  'catalog_cloud_cover': 0,
  'catalog_image_quality1': 9,
  'google:cloud_storage_path': 'gs://earthengine-public/landsat/L8/044/034/LC80440342013106LGN01.tar.bz',
  'google:cloud_storage_path_bytes': 699722582,
  'google:cloud_storage_path_md5': '1d6a8024526c6425834d65ab771d1a1d',
  'google:registration_count': 21,
  'google:registration_offset_x': 292.5034,
  'google:registration_offset_y': -301.9111,
  'google:registration_ratio': 0.25925925,
  'system:asset_size': 1105641883,
  'system:footprint': {'coordinates': [[-122.9311059585722,
     38.468856926479994],
    [-123.38828670091274, 36.86340525197506],
    [-121.3153812511248, 36.46540749276601],
    [-120.81312146119429, 38.07027267387488],
    [-122.9311059585722, 38.468856926479994]],
   'type': 'LinearRing'},
  'system:index': 'LC80440342013106LGN01',
  'system:time_end': 1366138073557,
  'system:time_start': 1366138073557},
 'type': 'Image',
 'version': 1487381858282000}

In [ ]: