{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Mapping surface water dynamics using Earth Engine\n", "\n", "\n", "Author: Qiusheng Wu ([Website](https://wetlands.io) - [GitHub](https://github.com/giswqs))\n", "\n", "**Keyboard shortcuts for Jupyter notebook:**\n", "\n", "- **Shift-Enter**: run cell, select below\n", "- **Ctrl-Enter**: run selected cells\n", "- **Alt-Enter**: run cell and insert below\n", "- **Ctrl-/**: comment\n", "- **Tab**: code completion or indent\n", "- **Shift-Tab**: tooltip" ] }, { "cell_type": "markdown", "metadata": { "toc": true }, "source": [ "

Contents

\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Install geemap\n", "\n", "To follow this tutorial, you need to install the [geemap](https://github.com/giswqs/geemap) Python package.Uncomment the following line to install and update the package to the latest version (v0.7.3). " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install -U geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check package version. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(ee.__version__)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(geemap.__version__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get help\n", "\n", "- [Earth Engine API Documentation](https://developers.google.com/earth-engine/)\n", "- [geeamp API Documentation](https://geemap.readthedocs.io/en/latest/source/geemap.html#geemap-package)\n", "- [Report a geemap bug or submit a feature request](https://github.com/giswqs/geemap/issues)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.api_docs()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.open_youtube()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "geemap.ee_search()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create an interactive map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[40, -100], zoom=4)\n", "Map.add_basemap('HYBRID')\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create Landsat timelapse\n", "\n", "Use the Drawing tool to draw any rectangle on the map.\n", "\n", "https://earthengine.google.com/timelapse/\n", "\n", "https://geemap.readthedocs.io/en/latest/source/geemap.html#geemap.geemap.Map.add_landsat_ts_gif" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.setCenter(-114.762293, 36.06462, 9)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "label = 'Surface water dynamics in Lake Mead'\n", "Map.add_landsat_ts_gif(label=label, start_year=1985, bands=['NIR', 'Red', 'Green'], font_color='white', frames_per_second=10, progress_bar_color='blue')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.setCenter(-74.4557, -8.4289, 9)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "label = 'Surface Water Dynamics of Ucayali River, Peru'\n", "Map.add_landsat_ts_gif(label=label, start_year=1985, start_date='01-01', end_date='12-31', bands=['SWIR1', 'NIR', 'Red'], font_color='white', frames_per_second=10, progress_bar_color='blue')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Select the best cloud-free image\n", "\n", "In this case study, we can going to use [USGS Landsat 8 Surface Reflectance Tier 1](https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LC08_C01_T1_SR).\n", "\n", "- `ee.ImageCollection(\"LANDSAT/LC08/C01/T1_SR\")`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map.add_basemap('HYBRID')\n", "Map.setCenter(-114.762293, 36.06462, 9)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pan and zoom the map to Lake Mead near Las Vegas, NV. Use the Drawing Tools to place a marker inside Lake Mead." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = Map.user_roi\n", "print(roi.getInfo())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively, you can define an ee.Geometry() as an ROI. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = ee.Geometry.Point([-114.762293, 36.06462])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's filter the ImageCollection by roi and date, and then sort by cloud cover." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "images = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n", " .filterBounds(roi) \\\n", " .filterDate('2015-01-01', '2019-12-31') \\\n", " .sort('CLOUD_COVER')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "How many Landsat 8 images (2015-2019) are available for the study area?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(images.size().getInfo())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since the returned images are already sorted by CLOUD_COVER in ascending order, the first image would be the best cloud-free image." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# best_image = images.toList(images.size()).get(0)\n", "best_image = images.first().select(['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's add the best image to the Map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vis_params = {\n", " 'bands': ['B5', 'B4', 'B3'],\n", " 'min': 0,\n", " 'max': 6000,\n", " 'gamma': 1.4,\n", "}\n", "Map.addLayer(best_image, vis_params, 'Best image')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use the Inspector and Plotting to check pixel values and spectral signature." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get image properties" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(best_image.getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(best_image.propertyNames().getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(best_image.get('system:id').getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_039035_20150724')\n", "vis_params = {\n", " 'bands': ['B6', 'B5', 'B4'],\n", " 'min': 0,\n", " 'max': 6000,\n", " 'gamma': 1.4,\n", "}\n", "Map.addLayer(image, vis_params, 'image')\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(best_image.get('CLOUD_COVER').getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(best_image.get('system:band_names').getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(best_image.get('system:time_start').getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(ee.Date(best_image.get('system:time_start')).format('YYYY-MM-dd').getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"WRS_Path={}, WRS_ROW={}\".format(best_image.get('WRS_PATH').getInfo(), best_image.get('WRS_ROW').getInfo()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Calculate NDWI\n", "\n", "The Normalized Difference Water Index (NDWI) is used to monitor changes related to water content in water bodies, using green and NIR wavelengths, defined by McFeeters (1996):\n", "\n", "![](https://wikimedia.org/api/rest_v1/media/math/render/svg/fd21ea077007b78b7bf753498d4953991837cb26)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_039035_20150724')\n", "vis_params = {\n", " 'bands': ['B5', 'B4', 'B3'],\n", " 'min': 0,\n", " 'max': 6000,\n", " 'gamma': 1.4,\n", "}\n", "Map.addLayer(image, vis_params, 'image')\n", "Map.centerObject(image, 8)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ndwi_image = image.normalizedDifference(['B3', 'B5'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vis_ndwi = {\n", " 'min': -1, \n", " 'max': 1,\n", " 'palette': ['#ece7f2', '#d0d1e6', '#a6bddb', '#74a9cf', '#3690c0', '#0570b0', '#045a8d', '#023858']\n", "}\n", "Map.addLayer(ndwi_image, vis_ndwi, 'NDWI image')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Extract water" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ndwi_threshold = 0\n", "water_image = ndwi_image.gt(ndwi_threshold).selfMask()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.addLayer(water_image, {'palette': 'blue'}, 'Water image')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.layers" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "water_layer = Map.layers[-1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "water_layer.interact(opacity=(0.0,1.0,0.1))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Convert raster to vector" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "water_vector = water_image.reduceToVectors(scale=30, maxPixels=60000000)\n", "Map.addLayer(water_vector, {}, 'Water vector')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = ee.Geometry.Point([-114.762293, 36.06462])\n", "lake_mead = water_vector.filterBounds(roi)\n", "Map.addLayer(lake_mead, {}, 'Lake Mead')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.addLayer(ee.Image().paint(lake_mead, 0, 2), {'palette': 'blue'}, 'Lake Mead Outline')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "area = lake_mead.geometry().area(1).divide(1e6).round().getInfo()\n", "print(\"Area = {} km2\".format(area))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Apply the algorithm to all images" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define input parameters" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = ee.Geometry.Point([-114.762293, 36.06462])\n", "start_date = '2015-01-01'\n", "end_date = '2019-12-31'\n", "cloud_threshold = 0.05\n", "ndwi_threshold = 0" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "images = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n", " .filterBounds(roi) \\\n", " .filterDate(start_date, end_date) \\\n", " .filterMetadata('CLOUD_COVER', 'less_than', cloud_threshold)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(images.size().getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(images.aggregate_array('system:id').getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dates = images.aggregate_array('system:time_start').map(lambda d: ee.Date(d).format('YYYY-MM-dd'))\n", "print(dates.getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "first_image = ee.Image(images.toList(images.size()).get(3))\n", "vis_params = {\n", " 'bands': ['B5', 'B4', 'B3'],\n", " 'min': 0,\n", " 'max': 6000,\n", " 'gamma': 1.4,\n", "}\n", "Map.addLayer(first_image, vis_params, 'First image')\n", "Map.centerObject(roi, 8)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def extract_water(img):\n", " \n", " ndwi_image = img.normalizedDifference(['B3', 'B5'])\n", " water_image = ndwi_image.gt(ndwi_threshold)\n", " return water_image" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ndwi_images = images.map(extract_water)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "first_ndwi_image = ee.Image(ndwi_images.toList(ndwi_images.size()).get(0)).selfMask()\n", "Map.addLayer(first_ndwi_image, {'palette': 'blue'}, 'First NDWI')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "occurrence = ndwi_images.sum().selfMask()\n", "Map.addLayer(occurrence.randomVisualizer(), {}, 'Water occurrence')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def ras_to_vec(img):\n", " vec = img.selfMask().reduceToVectors(scale=30, maxPixels=60000000)\n", " vec = vec.filterBounds(roi)\n", " return vec.set({'area': vec.geometry().area(1).divide(1e6).round()})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ndwi_vectors = ndwi_images.map(ras_to_vec)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "areas = ndwi_vectors.aggregate_array('area')\n", "print(areas.getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "%matplotlib inline \n", "# %matplotlib qt \n", "\n", "fig= plt.figure(figsize=(12,6))\n", "\n", "x = dates.getInfo()\n", "y = areas.getInfo()\n", "\n", "plt.plot(x, y, marker='o')\n", "plt.xlabel('Date')\n", "plt.ylabel('Lake Mead Area (km2)')\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create a split-panel map to visualize results" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "water_images = ndwi_images.map(lambda img: img.selfMask())\n", "landsat_images = images" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "water_layer_names = ['Water ' + str(date) for date in x]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "landsat_layer_names = ['Landsat ' + str(date) for date in x]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "water_vis = {\n", " 'palette': 'blue'\n", "}\n", "\n", "landsat_vis = {\n", " 'bands': ['B5', 'B4', 'B3'],\n", " 'min': 0,\n", " 'max': 6000,\n", " 'gamma': 1.4,\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map.ts_inspector(left_ts=water_images, right_ts=landsat_images, left_names=water_layer_names, right_names=landsat_layer_names, left_vis=water_vis, right_vis=landsat_vis)\n", "Map.centerObject(roi, zoom=8)\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layer_index = 9 # Change this index to your desired date\n", "print(\"Image date: {}\".format(x[layer_index]))\n", "\n", "water_image = ee.Image(water_images.toList(water_images.size()).get(layer_index))\n", "landsat_image = ee.Image(landsat_images.toList(landsat_images.size()).get(layer_index))\n", "\n", "\n", "left_layer = geemap.ee_tile_layer(water_image, water_vis, 'Water')\n", "right_layer = geemap.ee_tile_layer(landsat_image, landsat_vis, 'Landsat')\n", "\n", "Map = geemap.Map()\n", "Map.addLayer(landsat_image, landsat_vis, 'Landsat')\n", "Map.split_map(left_layer, right_layer)\n", "Map.centerObject(roi, zoom=12)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Export results to Google Drive" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.ee_export_image_collection_to_drive(water_images, folder='export', scale=90)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.ee_export_image_to_drive(occurrence.toInt(), description='water_occurrence', folder='export', region=first_ndwi_image\n", ".geometry(), scale=90)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Large-scale surface water mapping" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "states_shp = geemap.shp_to_ee('../data/us-states.shp')\n", "Map.addLayer(states_shp, {}, 'US States SHP')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "state_name = 'Nevada'\n", "roi = ee.FeatureCollection('TIGER/2018/States') \\\n", " .filter(ee.Filter.eq('NAME', state_name))\n", "# roi = states_shp.filterBounds(Map.user_roi)\n", "Map.addLayer(ee.Image().paint(roi, 0, 2), {'palette': 'red'}, state_name)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "images = geemap.landsat_timeseries(roi=roi, start_year=1984, end_year=2019, start_date='06-01', end_date='09-30')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "first_image = ee.Image(images.toList(images.size()).get(0))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "landsat_vis = {\n", " 'bands': ['NIR', 'Red', 'Green'],\n", " 'min': 0, \n", " 'max': 3500\n", "}\n", "Map.addLayer(first_image, landsat_vis, 'First image')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layer_names = ['Landsat ' + str(year) for year in range(1984, 2020)]\n", "Map = geemap.Map()\n", "Map.ts_inspector(left_ts=images, right_ts=images, left_names=layer_names, right_names=layer_names, left_vis=landsat_vis, right_vis=landsat_vis)\n", "Map.centerObject(roi, zoom=8)\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ndwi_threshold = 0\n", "def extract_water(img):\n", " \n", " ndwi_image = img.normalizedDifference(['Green', 'NIR'])\n", " water_image = ndwi_image.gt(ndwi_threshold)\n", " return water_image" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "water_images = images.map(extract_water)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "first_image = ee.Image(images.toList(images.size()).get(0))\n", "landsat_vis = {\n", " 'bands': ['NIR', 'Red', 'Green'],\n", " 'min': 0, \n", " 'max': 3500\n", "}\n", "Map.addLayer(first_image, landsat_vis, 'First image')\n", "\n", "first_water_image = ee.Image(water_images.toList(water_images.size()).get(0)).selfMask()\n", "Map.addLayer(first_water_image, {'palette': 'blue'}, 'First NDWI')\n", "\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layer_index = 0 # Change this index to your desired date\n", "print(layer_names[layer_index])\n", "\n", "water_image = ee.Image(water_images.toList(water_images.size()).get(layer_index)).selfMask()\n", "landsat_image = ee.Image(images.toList(images.size()).get(layer_index))\n", "\n", "water_vis = {\n", " 'palette': 'blue'\n", "}\n", "\n", "landsat_vis = {\n", " 'bands': ['NIR', 'Red', 'Green'],\n", " 'min': 0,\n", " 'max': 4000,\n", " 'gamma': 1.4,\n", "}\n", "\n", "left_layer = geemap.ee_tile_layer(water_image, water_vis, 'Water')\n", "right_layer = geemap.ee_tile_layer(landsat_image, landsat_vis, 'Landsat')\n", "\n", "Map = geemap.Map()\n", "Map.addLayer(landsat_image, landsat_vis, 'Landsat')\n", "Map.split_map(left_layer, right_layer)\n", "Map.centerObject(roi, zoom=12)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use JRC Global Surface Water Product" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map.add_basemap('HYBRID')\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gsw = ee.Image('JRC/GSW1_1/GlobalSurfaceWater')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(gsw.bandNames().getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "occurrence = gsw.select('occurrence')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vis_occurrence = {\n", " 'min':0,\n", " 'max':100,\n", " 'palette': ['red', 'blue']\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.addLayer(occurrence, vis_occurrence, 'Occurrence')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "water_mask = occurrence.gt(90).selfMask()\n", "vis_water_mask = {\n", " 'palette': ['white', 'blue']\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.addLayer(water_mask, vis_water_mask, 'Water Mask (>90%)')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.setCenter(-74.4557, -8.4289, 11)\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "change = gsw.select(\"change_abs\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vis_change = {\n", " 'min':-50,\n", " 'max':50,\n", " 'palette': ['red', 'black', 'limegreen']\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.addLayer(change, vis_change, 'Occurrence change intensity')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "transition = gsw.select('transition')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.addLayer(transition, {}, 'Transition classes')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "label = 'Surface Water Dynamics'\n", "Map.add_landsat_ts_gif(label=label, start_year=1985, start_date='01-01', end_date='12-31', bands=['SWIR1', 'NIR', 'Red'], font_color='white', frames_per_second=10, progress_bar_color='blue')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.2" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": true, "title_cell": "Contents", "title_sidebar": "Table of Contents", "toc_cell": true, "toc_position": { "height": "calc(100% - 180px)", "left": "10px", "top": "150px", "width": "308px" }, "toc_section_display": true, "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 4 }