{ "metadata": { "name": "", "signature": "sha256:509540561ce48e9ff8f4ccbe194cd1a6c9560a35cebe46ba1dd2ef9f17394e6f" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Initialize Earth Engine." ] }, { "cell_type": "code", "collapsed": false, "input": [ "# Load code to setup authorization for an IPython Notebook. Note that this is a temporary step\n", "# that is required until the Earth Engine Python API is updated to include this logic.\n", "%run 'authorize_earth_engine_in_notebook.ipynb'\n", "\n", "# Initialize Earth Engine\n", "# Note that we are calling a function defined in the previously run IPython Notebook, rather than\n", "# the typical call to ee.Initialize()\n", "ee_initialize()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Load the Google Maps Interactive Widget" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%run 'define_google_maps_interactive_widget.ipynb'" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Nile Delta Classification example" ] }, { "cell_type": "code", "collapsed": false, "input": [ "map = GoogleMapsWidget(lat=31.073, lng=30.732, zoom=8)\n", "display(map)\n", "\n", "composite = ee.Image(\"L7_TOA_1YEAR_2000\")\n", "\n", "bands = [\"10\", \"20\", \"30\", \"40\", \"50\", \"62\", \"70\"]\n", "\n", "# Use the MCD12 land-cover as training data.\n", "cover = ee.Image(\"MCD12Q1/MCD12Q1_005_2001_01_01\").select(\"Land_Cover_Type_1\")\n", "\n", "# A region of the image to train with.\n", "region = ee.Geometry.Rectangle(30, 30, 32.5, 31.6)\n", "\n", "PALETTE = ','.join([\n", " 'aec3d4', # water\n", " '152106', '225129', '369b47', '30eb5b', '387242', # forest\n", " '6a2325', 'c3aa69', 'b76031', 'd9903d', '91af40', # shrub, grass, savanah\n", " '111149', # wetlands\n", " '8dc33b', # croplands\n", " 'cc0013', # urban\n", " '6ca80d', # crop mosaic\n", " 'd7cdcc', # snow and ice\n", " 'f7e084', # barren\n", " '6f6f6f' # tundra\n", "])\n", "\n", "map.addLayer(\n", " image=composite, \n", " vis_params={'min':0, 'max':100, 'bands':\"30,20,10\"}, \n", " name='Landsat 7 TOA 2000')\n", "map.addLayer(\n", " image=cover,\n", " vis_params={'palette': PALETTE, 'min':0, 'max':17},\n", " name='MODIS land-cover',\n", " visible=False)\n", "\n", "# Multiple trainings with different numbers of points.\n", "nums = [1000, 10000, 100000]\n", "for num in nums:\n", " # Extract random points.\n", " points = ee.FeatureCollection.randomPoints(region, num, num, 1)\n", " training = cover.addBands(composite).reduceToVectors(\n", " reducer=\"mean\",\n", " geometry=points,\n", " geometryType=\"centroid\",\n", " scale=30, \n", " crs=\"EPSG:4326\"\n", " )\n", " \n", " classifier = training.trainClassifier(\n", " property_list=bands,\n", " class_property=\"label\",\n", " classifier_name=\"FastNaiveBayes\"\n", " )\n", "\n", " # Apply the classifier to the original composite.\n", " out = composite.classify(classifier)\n", " map.addLayer(\n", " image=out,\n", " vis_params={'palette': PALETTE, 'min':0, 'max':17},\n", " name=\"{0} points\".format(num),\n", " visible=False\n", " )\n", "\n", "# Add the region that constrains the random sampling.\n", "map.addLayer(\n", " image=ee.Image().paint(ee.Feature(region), 0, 2),\n", " name=\"Region\"\n", ")" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }