%matplotlib inline import datetime import matplotlib.pyplot as plt import numpy as np from IPython.display import display # Load code to setup authorization for an IPython Notebook. Note that this is a temporary step # that is required until the Earth Engine Python API is updated to include this logic. %run 'authorize_earth_engine_in_notebook.ipynb' # Initialize Earth Engine # Note that we are calling a function defined in the previously run IPython Notebook, rather than # the typical call to ee.Initialize() ee_initialize() %run 'define_google_maps_interactive_widget.ipynb' map = GoogleMapsWidget(lat=70, lng=-140.0, zoom=6) display(map) image1 = ee.Image('LC81412332013146LGN00') vis_params1 = {'bands':'B4,B3,B2','min':5000,'max':10000} map.addLayer(image=image1, vis_params=vis_params1, name='Night') image2 = ee.Image('LC80660112013132LGN01') vis_params2 = {'bands':'B4,B3,B2','min':0,'max':40000} map.addLayer(image=image2, vis_params=vis_params2, name='Day', visible=False) (map.lat, map.lng, map.zoom, map.bounds) lng, lat = (-120.6, 40.0) map2 = GoogleMapsWidget(lat=lat, lng=lng, zoom=6) display(map2) # Add an Image Collection of Landsat 8 data to the map. collection = (ee.ImageCollection('LC8') .filterDate('2014-01-01', '2014-06-01') .filterMetadata('SUN_ELEVATION', 'greater_than', 0) ) vis_params3 = {'bands': 'B4,B3,B2', 'min':5000, 'max':30000, 'gamma': 1.6} map2.addLayer(image=collection.mosaic(), vis_params=vis_params3, name='Landsat 8 mosaic') map2.addLayer(image=collection.median(), vis_params=vis_params3, name='Landsat 8 median', visible=False) # Get the coordinates of the center of the map. (map2.lng, map2.lat) point = ee.Geometry.Point(map2.lng, map2.lat); info = collection.getRegion(point,500).getInfo() xBand = 'time' yBandList = ['B4','B5'] # extract the header column names header = info[0] # create a Numpy array of the data data = np.array(info[1:]) # extract the time information iTime = header.index(xBand) # convert to Python datetime objects time = [datetime.datetime.fromtimestamp(i/1000) for i in (data[0:,iTime].astype(int))] # Extract the data columns we want to plot. iBands = [header.index(b) for b in yBandList] yData = data[0:,iBands].astype(np.float) red = yData[:,0] nir = yData[:,1] ndvi = (nir - red) / (nir + red) fig, ax = plt.subplots(2, sharex=True, figsize=(10,10)) ax[0].plot(time, red, 'o', color="red", label="RED band") ax[0].plot(time, nir, 'o', color="blue", label="NIR band") ax[0].set_ylabel('Band Values') ax[0].legend(loc='best') ax[1].plot(time, ndvi, 'o', color="black", label="NDVI") ax[1].set_ylabel('NDVI') ax[1].legend(loc='best')