{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gee-community/geemap/blob/master/docs/workshops/NCSU_2023.ipynb)\n", "\n", "**Interactive Cloud Computing with Google Earth Engine and geemap**\n", "\n", "- Notebook: \n", "- Earth Engine: \n", "- Geemap: \n", "\n", "## Introduction (10 mins)\n", "\n", "This notebook is for the workshop presented at the [GIS Week](https://www.gisweekatncstate.org/events-page) at North Carolina State University. \n", "\n", "### Abstract\n", "\n", "This workshop provides an introduction to cloud-based geospatial analysis using the Earth Engine Python API. Attendees will learn the basics of Earth Engine data types and how to visualize, analyze, and export Earth Engine data in a Jupyter environment with geemap. Through practical examples and hands-on exercises, attendees will enhance their learning experience. During each hands-on session, attendees will walk through Jupyter Notebook examples on Google Colab. At the end of each session, they will complete a hands-on exercise to apply the knowledge they have learned.\n", "\n", "### Prerequisites\n", "\n", "- To use geemap and the Earth Engine Python API, you must [register](https://code.earthengine.google.com/register) for an Earth Engine account and follow the instructions [here](https://docs.google.com/document/d/1ZGSmrNm6_baqd8CHt33kIBWOlvkh-HLr46bODgJN1h0/edit?usp=sharing) to create a Cloud Project. Earth Engine is free for [noncommercial and research use](https://earthengine.google.com/noncommercial). To test whether you can use authenticate the Earth Engine Python API, please run [this notebook](https://colab.research.google.com/github/giswqs/geemap/blob/master/examples/notebooks/geemap_colab.ipynb) on Google Colab.\n", "\n", "- It is recommended that attendees have a basic understanding of Python and Jupyter Notebook.\n", "- Familiarity with the Earth Engine JavaScript API is not required but will be helpful.\n", "- Attendees can use Google Colab to follow this workshop without installing anything on their computer.\n", "\n", "## Introduction to Earth Engine and geemap (15 mins)\n", "\n", "Earth Engine is free for [noncommercial and research use](https://earthengine.google.com/noncommercial). For more than a decade, Earth Engine has enabled planetary-scale Earth data science and analysis by nonprofit organizations, research scientists, and other impact users.\n", "\n", "With the launch of Earth Engine for [commercial use](https://earthengine.google.com/commercial), commercial customers will be charged for Earth Engine services. However, Earth Engine will remain free of charge for noncommercial use and research projects. Nonprofit organizations, academic institutions, educators, news media, Indigenous governments, and government researchers are eligible to use Earth Engine free of charge, just as they have done for over a decade.\n", "\n", "The geemap Python package is built upon the Earth Engine Python API and open-source mapping libraries. It allows Earth Engine users to interactively manipulate, analyze, and visualize geospatial big data in a Jupyter environment. Since its creation in April 2020, geemap has received over 2,900 GitHub stars and is being used by over 1,000 projects on GitHub.\n", "\n", "## Google Colab and Earth Engine Python API authentication (5 mins)\n", "\n", "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gee-community/geemap/blob/master/docs/workshops/NCSU_2023.ipynb)\n", "\n", "### Change Colab dark theme\n", "\n", "Currently, ipywidgets does not work well with Colab dark theme. Some of the geemap widgets may not display properly in Colab dark theme.It is recommended that you change Colab to the light theme.\n", "\n", "![](https://i.imgur.com/EJ0GDP8.png)\n", "\n", "\n", "### Install geemap\n", "\n", "The geemap package is pre-installed in Google Colab and is updated to the latest minor or major release every few weeks. Some optional dependencies of geemap being used by this notebook are not pre-installed in Colab. Uncomment the following line to install geemap and some optional dependencies." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# %pip install -U \"geemap[workshop]\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that some geemap features do not work properly with Google Colab. If you are familiar with [Anaconda](https://www.anaconda.com/distribution/#download-section) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html), it is recommended to create a new conda environment to install geemap and its optional dependencies on your local computer. \n", "\n", "```bash\n", "conda create -n gee python=3.11\n", "conda activate gee\n", "conda install -c conda-forge mamba\n", "mamba install -c conda-forge geemap pygis\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Import libraries\n", "\n", "Import the earthengine-api and geemap." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Authenticate and initialize Earth Engine\n", "\n", "You will need to create a [Google Cloud Project](https://console.cloud.google.com/projectcreate) and enable the [Earth Engine API](https://console.cloud.google.com/apis/api/earthengine.googleapis.com) for the project. You can find detailed instructions [here](https://book.geemap.org/chapters/01_introduction.html#earth-engine-authentication)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.ee_initialize()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating interactive maps\n", "\n", "Let's create an interactive map using the `ipyleaflet` plotting backend. The [`geemap.Map`](https://geemap.org/geemap/#geemap.geemap.m) class inherits the [`ipyleaflet.Map`](https://ipyleaflet.readthedocs.io/en/latest/map_and_basemaps/map.html) class. Therefore, you can use the same syntax to create an interactive map as you would with `ipyleaflet.Map`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To display it in a Jupyter notebook, simply ask for the object representation:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To customize the map, you can specify various keyword arguments, such as `center` ([lat, lon]), `zoom`, `width`, and `height`. The default `width` is `100%`, which takes up the entire cell width of the Jupyter notebook. The `height` argument accepts a number or a string. If a number is provided, it represents the height of the map in pixels. If a string is provided, the string must be in the format of a number followed by `px`, e.g., `600px`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4, height=600)\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To hide a control, set `control_name` to `False`, e.g., `draw_ctrl=False`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(data_ctrl=False, toolbar_ctrl=False, draw_ctrl=False)\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Adding basemaps\n", "\n", "There are several ways to add basemaps to a map. You can specify the basemap to use in the `basemap` keyword argument when creating the map. Alternatively, you can add basemap layers to the map using the `add_basemap` method. Geemap has hundreds of built-in basemaps available that can be easily added to the map with only one line of code.\n", "\n", "Create a map by specifying the basemap to use as follows. For example, the `Esri.WorldImagery` basemap represents the Esri world imagery basemap." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(basemap='Esri.WorldImagery')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can add as many basemaps as you like to the map. For example, the following code adds the `OpenTopoMap` basemap to the map above:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.add_basemap('Esri.WorldTopoMap')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.add_basemap('OpenTopoMap')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print out the first 10 basemaps:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "basemaps = list(geemap.basemaps.keys())\n", "len(geemap.basemaps)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "basemaps[:10]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also change basemaps interactively using the basemap GUI." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using Earth Engine data (30 mins)\n", "\n", "### Earth Engine data types (Image, ImageCollection, Geometry, Feature, FeatureCollection)\n", "\n", "Earth Engine objects are server-side objects rather than client-side objects, which means that they are not stored locally on your computer. Similar to video streaming services (e.g., YouTube, Netflix, and Hulu), which store videos/movies on their servers, Earth Engine data are stored on the Earth Engine servers. We can stream geospatial data from Earth Engine on-the-fly without having to download the data just like we can watch videos from streaming services using a web browser without having to download the entire video to your computer.\n", "\n", "- **Image**: the fundamental raster data type in Earth Engine.\n", "- **ImageCollection**: a stack or time-series of images.\n", "- **Geometry**: the fundamental vector data type in Earth Engine.\n", "- **Feature**: a Geometry with attributes.\n", "- **FeatureCollection**: a set of features.\n", "\n", "### Image\n", "\n", "Raster data in Earth Engine are represented as **Image** objects. Images are composed of one or more bands and each band has its own name, data type, scale, mask and projection. Each image has metadata stored as a set of properties.\n", "\n", "#### Loading Earth Engine images" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image = ee.Image('USGS/SRTMGL1_003')\n", "image" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Visualizing Earth Engine images" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[21.79, 70.87], zoom=3)\n", "image = ee.Image('USGS/SRTMGL1_003')\n", "vis_params = {\n", " 'min': 0,\n", " 'max': 6000,\n", " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'], # 'terrain'\n", "}\n", "m.add_layer(image, vis_params, 'SRTM')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### ImageCollection\n", "\n", "An `ImageCollection` is a stack or sequence of images. An `ImageCollection` can be loaded by passing an Earth Engine asset ID into the `ImageCollection` constructor. You can find `ImageCollection` IDs in the [Earth Engine Data Catalog](https://developers.google.com/earth-engine/datasets).\n", "\n", "#### Loading image collections\n", "\n", "For example, to load the image collection of the [Sentinel-2 surface reflectance](https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "collection = ee.ImageCollection('COPERNICUS/S2_SR')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Visualizing image collections\n", "\n", "To visualize an Earth Engine **ImageCollection**, we need to convert an **ImageCollection** to an **Image** by compositing all the images in the collection to a single image representing, for example, the min, max, median, mean or standard deviation of the images. For example, to create a median value image from a collection, use the `collection.median()` method. Let's create a median image from the Sentinel-2 surface reflectance collection:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "collection = ee.ImageCollection('COPERNICUS/S2_SR')\n", "image = collection.median()\n", "\n", "vis = {\n", " 'min': 0.0,\n", " 'max': 3000,\n", " 'bands': ['B4', 'B3', 'B2'],\n", "}\n", "\n", "m.set_center(83.277, 17.7009, 12)\n", "m.add_layer(image, vis, 'Sentinel-2')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Filtering image collections" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "collection = (\n", " ee.ImageCollection('COPERNICUS/S2_SR')\n", " .filterDate('2021-01-01', '2022-01-01')\n", " .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 5))\n", ")\n", "image = collection.median()\n", "\n", "vis = {\n", " 'min': 0.0,\n", " 'max': 3000,\n", " 'bands': ['B4', 'B3', 'B2'],\n", "}\n", "\n", "m.set_center(83.277, 17.7009, 12)\n", "m.add_layer(image, vis, 'Sentinel-2')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### FeatureCollection\n", "\n", "A **FeatureCollection** is a collection of Features. A FeatureCollection is analogous to a GeoJSON FeatureCollection object, i.e., a collection of features with associated properties/attributes. Data contained in a shapefile can be represented as a FeatureCollection.\n", "\n", "#### Loading feature collections\n", "\n", "The [Earth Engine Data Catalog](https://developers.google.com/earth-engine/datasets) hosts a variety of vector datasets (e.g,, US Census data, country boundaries, and more) as feature collections. You can find feature collection IDs by searching the data catalog. For example, to load the [TIGER roads data](https://developers.google.com/earth-engine/datasets/catalog/TIGER_2016_Roads) by the U.S. Census Bureau:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "fc = ee.FeatureCollection('TIGER/2016/Roads')\n", "m.set_center(-73.9596, 40.7688, 12)\n", "m.add_layer(fc, {}, 'Census roads')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Filtering feature collections" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "states = ee.FeatureCollection('TIGER/2018/States')\n", "fc = states.filter(ee.Filter.eq('NAME', 'Louisiana'))\n", "m.add_layer(fc, {}, 'Louisiana')\n", "m.center_object(fc, 7)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "feat = fc.first()\n", "feat.toDictionary()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "states = ee.FeatureCollection('TIGER/2018/States')\n", "fc = states.filter(ee.Filter.inList('NAME', ['California', 'Oregon', 'Washington']))\n", "m.add_layer(fc, {}, 'West Coast')\n", "m.center_object(fc, 5)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "region = m.user_roi\n", "if region is None:\n", " region = ee.Geometry.BBox(-88.40, 29.88, -77.90, 35.39)\n", "\n", "fc = ee.FeatureCollection('TIGER/2018/States').filterBounds(region)\n", "m.add_layer(fc, {}, 'Southeastern U.S.')\n", "m.center_object(fc, 6)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Visualizing feature collections" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4)\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "m.add_layer(states, {}, \"US States\")\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4)\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "style = {'color': '0000ffff', 'width': 2, 'lineType': 'solid', 'fillColor': 'FF000080'}\n", "m.add_layer(states.style(**style), {}, \"US States\")\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4)\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "vis_params = {\n", " 'color': '000000',\n", " 'colorOpacity': 1,\n", " 'pointSize': 3,\n", " 'pointShape': 'circle',\n", " 'width': 2,\n", " 'lineType': 'solid',\n", " 'fillColorOpacity': 0.66,\n", "}\n", "palette = ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']\n", "m.add_styled_vector(\n", " states, column=\"NAME\", palette=palette, layer_name=\"Styled vector\", **vis_params\n", ")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Earth Engine Data Catalog\n", "\n", "The [Earth Engine Data Catalog](https://developers.google.com/earth-engine/datasets) hosts a variety of geospatial datasets. As of October 2023, the catalog contains over [1,000 datasets](https://github.com/opengeos/Earth-Engine-Catalog/blob/master/gee_catalog.tsv) with a total size of over 80 petabytes. Some notable datasets include: Landsat, Sentinel, MODIS, NAIP, etc. For a complete list of datasets in CSV or JSON formats, see the [Earth Engine Datasets List](https://github.com/giswqs/Earth-Engine-Catalog/blob/master/gee_catalog.tsv).\n", "\n", "#### Searching for datasets\n", "\n", "The [Earth Engine Data Catalog](https://developers.google.com/earth-engine/datasets/catalog) is searchable. You can search datasets by name, keyword, or tag. For example, enter \"elevation\" in the search box will filter the catalog to show only datasets containing \"elevation\" in their name, description, or tags. 52 datasets are returned for this search query. Scroll down the list to find the [NASA SRTM Digital Elevation 30m](https://developers.google.com/earth-engine/datasets/catalog/USGS_SRTMGL1_003#description) dataset. On each dataset page, you can find the following information, including Dataset Availability, Dataset Provider, Earth Engine Snippet, Tags, Description, Code Example, and more (see {numref}`ch03_gee_srtm`). One important piece of information is the Image/ImageCollection/FeatureCollection ID of each dataset, which is essential for accessing the dataset through the Earth Engine JavaScript or Python APIs.\n", "\n", "![](https://i.imgur.com/B3rf4QN.jpg)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset_xyz = ee.Image('USGS/SRTMGL1_003')\n", "m.add_layer(dataset_xyz, {}, \"USGS/SRTMGL1_003\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "dem = ee.Image('USGS/SRTMGL1_003')\n", "vis_params = {\n", " 'min': 0,\n", " 'max': 4000,\n", " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],\n", "}\n", "m.add_layer(dem, vis_params, 'SRTM DEM')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Using the datasets module" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from geemap.datasets import DATA" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4)\n", "dataset = ee.Image(DATA.USGS_GAP_CONUS_2011)\n", "m.add_layer(dataset, {}, 'GAP CONUS')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 1 - Creating cloud-free imagery\n", "\n", "Create a cloud-free imagery for a state of your choice for the year of 2022. You can use either Landsat 9 or Sentinel-2 imagery. Relevant Earth Engine assets:\n", "\n", "- [ee.FeatureCollection(\"TIGER/2018/States\")](https://developers.google.com/earth-engine/datasets/catalog/TIGER_2018_States)\n", "- [ee.ImageCollection(\"COPERNICUS/S2_SR\")](https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR)\n", "- [ee.ImageCollection(\"LANDSAT/LC09/C02/T1_L2\")](https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LC09_C02_T1_L2)\n", "\n", "![](https://i.imgur.com/i3IT0lF.png)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualizing Earth Engine data (30 mins)\n", "\n", "### Geemap Inspector tool, plotting tool, interactive GUI for data visualization\n", "\n", "### Using the inspector tool" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=(40, -100), zoom=4)\n", "\n", "dem = ee.Image('USGS/SRTMGL1_003')\n", "landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003').select(\n", " ['B1', 'B2', 'B3', 'B4', 'B5', 'B7']\n", ")\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "\n", "vis_params = {\n", " 'min': 0,\n", " 'max': 4000,\n", " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],\n", "}\n", "\n", "m.add_layer(dem, vis_params, 'SRTM DEM')\n", "m.add_layer(\n", " landsat7,\n", " {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 2.0},\n", " 'Landsat 7',\n", ")\n", "m.add_layer(states, {}, \"US States\")\n", "m.add('inspector')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Using the plotting tool" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4)\n", "\n", "landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003').select(\n", " ['B1', 'B2', 'B3', 'B4', 'B5', 'B7']\n", ")\n", "\n", "landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}\n", "m.add_layer(landsat7, landsat_vis, \"Landsat\")\n", "\n", "hyperion = ee.ImageCollection('EO1/HYPERION').filter(\n", " ee.Filter.date('2016-01-01', '2017-03-01')\n", ")\n", "\n", "hyperion_vis = {\n", " 'min': 1000.0,\n", " 'max': 14000.0,\n", " 'gamma': 2.5,\n", "}\n", "m.add_layer(hyperion, hyperion_vis, 'Hyperion')\n", "m.add_plot_gui()\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set plotting options for Landsat." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.set_plot_options(add_marker_cluster=True, overlay=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set plotting options for Hyperion." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.set_plot_options(add_marker_cluster=True, plot_type=\"bar\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Legends, color bars, and labels\n", "\n", "#### Built-in legends" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from geemap.legends import builtin_legends" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for legend in builtin_legends:\n", " print(legend)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add NLCD WMS layer and legend to the map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4)\n", "m.add_basemap('Esri.WorldImagery')\n", "m.add_basemap('NLCD 2021 CONUS Land Cover')\n", "m.add_legend(builtin_legend='NLCD', max_width='100px', height='455px')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add NLCD Earth Engine layer and legend to the map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4)\n", "m.add_basemap('Esri.WorldImagery')\n", "\n", "nlcd = ee.Image('USGS/NLCD_RELEASES/2021_REL/NLCD/2021')\n", "landcover = nlcd.select('landcover')\n", "\n", "m.add_layer(landcover, {}, 'NLCD Land Cover 2021')\n", "m.add_legend(\n", " title=\"NLCD Land Cover Classification\", builtin_legend='NLCD', height='455px'\n", ")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Custom legends" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a custom legend by specifying the colors and labels." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(add_google_map=False)\n", "\n", "keys = ['One', 'Two', 'Three', 'Four', 'etc']\n", "\n", "# colors can be defined using either hex code or RGB (0-255, 0-255, 0-255)\n", "colors = ['#8DD3C7', '#FFFFB3', '#BEBADA', '#FB8072', '#80B1D3']\n", "# legend_colors = [(255, 0, 0), (127, 255, 0), (127, 18, 25), (36, 70, 180), (96, 68 123)]\n", "\n", "m.add_legend(keys=keys, colors=colors, position='bottomright')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a custom legend by specifying a dictionary of colors and labels." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4)\n", "m.add_basemap('Esri.WorldImagery')\n", "\n", "legend_dict = {\n", " '11 Open Water': '466b9f',\n", " '12 Perennial Ice/Snow': 'd1def8',\n", " '21 Developed, Open Space': 'dec5c5',\n", " '22 Developed, Low Intensity': 'd99282',\n", " '23 Developed, Medium Intensity': 'eb0000',\n", " '24 Developed High Intensity': 'ab0000',\n", " '31 Barren Land (Rock/Sand/Clay)': 'b3ac9f',\n", " '41 Deciduous Forest': '68ab5f',\n", " '42 Evergreen Forest': '1c5f2c',\n", " '43 Mixed Forest': 'b5c58f',\n", " '51 Dwarf Scrub': 'af963c',\n", " '52 Shrub/Scrub': 'ccb879',\n", " '71 Grassland/Herbaceous': 'dfdfc2',\n", " '72 Sedge/Herbaceous': 'd1d182',\n", " '73 Lichens': 'a3cc51',\n", " '74 Moss': '82ba9e',\n", " '81 Pasture/Hay': 'dcd939',\n", " '82 Cultivated Crops': 'ab6c28',\n", " '90 Woody Wetlands': 'b8d9eb',\n", " '95 Emergent Herbaceous Wetlands': '6c9fb8',\n", "}\n", "\n", "nlcd = ee.Image('USGS/NLCD_RELEASES/2021_REL/NLCD/2021')\n", "landcover = nlcd.select('landcover')\n", "\n", "m.add_layer(landcover, {}, 'NLCD Land Cover 2021')\n", "m.add_legend(title=\"NLCD Land Cover Classification\", legend_dict=legend_dict)\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Creating color bars\n", "\n", "Add a horizontal color bar." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "\n", "dem = ee.Image('USGS/SRTMGL1_003')\n", "vis_params = {\n", " 'min': 0,\n", " 'max': 4000,\n", " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],\n", "}\n", "\n", "m.add_layer(dem, vis_params, 'SRTM DEM')\n", "m.add_colorbar(vis_params, label=\"Elevation (m)\", layer_name=\"SRTM DEM\")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a vertical color bar." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.add_colorbar(\n", " vis_params,\n", " label=\"Elevation (m)\",\n", " layer_name=\"SRTM DEM\",\n", " orientation=\"vertical\",\n", " max_width=\"100px\"\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make the color bar background transparent." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.add_colorbar(\n", " vis_params,\n", " label=\"Elevation (m)\",\n", " layer_name=\"SRTM DEM\",\n", " orientation=\"vertical\",\n", " max_width=\"100px\",\n", " transparent_bg=True\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Split-panel maps\n", "\n", "Create a split map with basemaps. Note that ipyleaflet has a bug with the SplitControl. You can't pan the map, which should be resolved in the next ipyleaflet release." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.split_map(left_layer='Esri.WorldTopoMap', right_layer='OpenTopoMap')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a split map with Earth Engine layers." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=(40, -100), zoom=4, height=600)\n", "\n", "nlcd_2001 = ee.Image('USGS/NLCD_RELEASES/2019_REL/NLCD/2001').select('landcover')\n", "nlcd_2019 = ee.Image('USGS/NLCD_RELEASES/2021_REL/NLCD/2021').select('landcover')\n", "\n", "left_layer = geemap.ee_tile_layer(nlcd_2001, {}, 'NLCD 2001')\n", "right_layer = geemap.ee_tile_layer(nlcd_2019, {}, 'NLCD 2021')\n", "\n", "m.split_map(left_layer, right_layer)\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 2 - Creating land cover maps with a legend\n", "\n", "Create a split map for visualizing NLCD land cover change in Texas between 2001 and 2019. Add the NLCD legend to the map. Relevant Earth Engine assets:\n", "\n", "- [ee.FeatureCollection(\"TIGER/2018/States\")](https://developers.google.com/earth-engine/datasets/catalog/TIGER_2018_States)\n", "- [ee.ImageCollection(\"USGS/NLCD_RELEASES/2019_REL/NLCD\")](https://developers.google.com/earth-engine/datasets/catalog/USGS_NLCD_RELEASES_2019_REL_NLCD)\n", "\n", "![](https://i.imgur.com/1b62CeI.jpg)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Analyzing Earth Engine data (30 mins)\n", "\n", "### Image descriptive statistics\n", "\n", "Use a sample Landsat image." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "\n", "centroid = ee.Geometry.Point([-122.4439, 37.7538])\n", "image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR').filterBounds(centroid).first()\n", "vis = {'min': 0, 'max': 3000, 'bands': ['B5', 'B4', 'B3']}\n", "\n", "m.center_object(centroid, 8)\n", "m.add_layer(image, vis, \"Landsat-8\")\n", "m.add_layer(centroid, {}, 'Centroid')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check image properties." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image.propertyNames()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check image property values." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image.toDictionary()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get specific image properties." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image.get('CLOUD_COVER') # 0.05" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get image properties with easy-to-read time format." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "props = geemap.image_props(image)\n", "props" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compute image descriptive statistics." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "stats = geemap.image_stats(image, scale=30)\n", "stats" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Zonal statistics\n", "\n", "#### Zonal statistics\n", "\n", "Add Earth Engine data to the map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4)\n", "\n", "# Add NASA SRTM\n", "dem = ee.Image('USGS/SRTMGL1_003')\n", "dem_vis = {\n", " 'min': 0,\n", " 'max': 4000,\n", " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],\n", "}\n", "m.add_layer(dem, dem_vis, 'SRTM DEM')\n", "\n", "# Add 5-year Landsat TOA composite\n", "landsat = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003')\n", "landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}\n", "m.add_layer(landsat, landsat_vis, \"Landsat\", False)\n", "\n", "# Add US Census States\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "style = {'fillColor': '00000000'}\n", "m.add_layer(states.style(**style), {}, 'US States')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compute zonal statistics. In this case, we compute the mean elevation of each state and export the results to a CSV file." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "out_dem_stats = 'dem_stats.csv'\n", "geemap.zonal_stats(\n", " dem, states, out_dem_stats, stat_type='MEAN', scale=1000, return_fc=False\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Display the csv file as a table." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.csv_to_df(out_dem_stats).sort_values(by=['mean'], ascending=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compute zonal statistics of mean spectral values of each state." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "out_landsat_stats = 'landsat_stats.csv'\n", "geemap.zonal_stats(\n", " landsat,\n", " states,\n", " out_landsat_stats,\n", " stat_type='MEAN',\n", " scale=1000,\n", " return_fc=False,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.csv_to_df(out_landsat_stats)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Zonal statistics by group\n", "\n", "Compute zonal statistics by group. In this case, we compute the area of each land cover type in each state and export the results to a CSV file." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4)\n", "\n", "# Add NLCD data\n", "dataset = ee.Image('USGS/NLCD_RELEASES/2021_REL/NLCD/2021')\n", "landcover = dataset.select('landcover')\n", "m.add_layer(landcover, {}, 'NLCD 2021')\n", "\n", "# Add US census states\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "style = {'fillColor': '00000000'}\n", "m.add_layer(states.style(**style), {}, 'US States')\n", "\n", "# Add NLCD legend\n", "m.add_legend(title='NLCD Land Cover', builtin_legend='NLCD')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compute zonal statistics by group and convert the area unit from square meters to square kilometers." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nlcd_stats = 'nlcd_stats.csv'\n", "\n", "geemap.zonal_stats_by_group(\n", " landcover,\n", " states,\n", " nlcd_stats,\n", " stat_type='SUM',\n", " denominator=1e6,\n", " decimal_places=2,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.csv_to_df(nlcd_stats)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate the percentage of each land cover type in each state." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nlcd_stats = 'nlcd_stats_pct.csv'\n", "\n", "geemap.zonal_stats_by_group(\n", " landcover,\n", " states,\n", " nlcd_stats,\n", " stat_type='PERCENTAGE',\n", " denominator=1e6,\n", " decimal_places=2,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.csv_to_df(nlcd_stats)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 3 - Zonal statistics\n", "\n", "Find out which state has the highest mean temperature on in the United States on June 28, 2023. Relevant Earth Engine assets:\n", "\n", "- [ee.FeatureCollection(\"TIGER/2018/States\")](https://developers.google.com/earth-engine/datasets/catalog/TIGER_2018_States)\n", "- [ee.ImageCollection(\"NOAA/GFS0P25\")](https://developers.google.com/earth-engine/datasets/catalog/NOAA_GFS0P25)\n", "\n", "![](https://i.imgur.com/GZCHHz3.png)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating satellite timelapse animations (30 mins)\n", "\n", "### Creating satellite timeseries\n", "\n", "Use the [Harmonized Sentinel-2 MSI](https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_HARMONIZED) dataset to create a timeseries for a given location." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "collection = ee.ImageCollection(\"COPERNICUS/S2_HARMONIZED\").filterMetadata(\n", " 'CLOUDY_PIXEL_PERCENTAGE', 'less_than', 10\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Specify the location of interest and date range." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "start_date = '2016-01-01'\n", "end_date = '2022-12-31'\n", "region = ee.Geometry.BBox(-122.5549, 37.6968, -122.3446, 37.8111)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create an annual composite." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "images = geemap.create_timeseries(\n", " collection, start_date, end_date, region, frequency='year', reducer='median'\n", ")\n", "images" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Display the timeseries." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "vis_params = {\"min\": 0, \"max\": 4000, \"bands\": [\"B8\", \"B4\", \"B3\"]}\n", "labels = [str(y) for y in range(2016, 2023)]\n", "m.add_layer(images, vis_params, \"Sentinel-2\", False)\n", "m.add_time_slider(images, vis_params, time_interval=2, labels=labels)\n", "m.center_object(region)\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Creating satellite timelapse animations\n", "\n", "#### NAIP timelapse" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = m.user_roi\n", "if roi is None:\n", " roi = ee.Geometry.BBox(-99.1019, 47.1274, -99.0334, 47.1562)\n", " m.add_layer(roi, {}, 'ROI')\n", " m.center_object(roi)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "collection = geemap.naip_timeseries(roi, start_year=2009, end_year=2022, RGBN=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "years = geemap.image_dates(collection, date_format='YYYY').getInfo()\n", "print(years)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "size = len(years)\n", "images = collection.toList(size)\n", "for i in range(size):\n", " image = ee.Image(images.get(i))\n", " m.add_layer(image, {'bands': ['N', 'R', 'G']}, years[i])\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "timelapse = geemap.naip_timelapse(\n", " roi,\n", " out_gif=\"naip.gif\",\n", " bands=['N', 'R', 'G'],\n", " frames_per_second=3,\n", " title='NAIP Timelapse',\n", ")\n", "geemap.show_image(timelapse)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Landsat timelapse" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pan and zoom the map to an area of interest. Use the drawing tools to draw a rectangle on the map. If no rectangle is drawn, the default rectangle shown below will be used." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = m.user_roi\n", "if roi is None:\n", " roi = ee.Geometry.BBox(-74.7222, -8.5867, -74.1596, -8.2824)\n", " m.add_layer(roi)\n", " m.center_object(roi)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "timelapse = geemap.landsat_timelapse(\n", " roi,\n", " out_gif='landsat.gif',\n", " start_year=1984,\n", " end_year=2022,\n", " start_date='01-01',\n", " end_date='12-31',\n", " bands=['SWIR1', 'NIR', 'Red'],\n", " frames_per_second=5,\n", " title='Landsat Timelapse',\n", " progress_bar_color='blue',\n", " mp4=True,\n", ")\n", "geemap.show_image(timelapse)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "roi = ee.Geometry.BBox(-115.5541, 35.8044, -113.9035, 36.5581)\n", "m.add_layer(roi)\n", "m.center_object(roi)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "timelapse = geemap.landsat_timelapse(\n", " roi,\n", " out_gif='las_vegas.gif',\n", " start_year=1984,\n", " end_year=2022,\n", " bands=['NIR', 'Red', 'Green'],\n", " frames_per_second=5,\n", " title='Las Vegas, NV',\n", " font_color='blue',\n", ")\n", "geemap.show_image(timelapse)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "roi = ee.Geometry.BBox(113.8252, 22.1988, 114.0851, 22.3497)\n", "m.add_layer(roi)\n", "m.center_object(roi)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "timelapse = geemap.landsat_timelapse(\n", " roi,\n", " out_gif='hong_kong.gif',\n", " start_year=1990,\n", " end_year=2022,\n", " start_date='01-01',\n", " end_date='12-31',\n", " bands=['SWIR1', 'NIR', 'Red'],\n", " frames_per_second=3,\n", " title='Hong Kong',\n", ")\n", "geemap.show_image(timelapse)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Sentinel-2 timelapse" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pan and zoom the map to an area of interest. Use the drawing tools to draw a rectangle on the map. If no rectangle is drawn, the default rectangle shown below will be used." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = m.user_roi\n", "if roi is None:\n", " roi = ee.Geometry.BBox(-74.7222, -8.5867, -74.1596, -8.2824)\n", " m.add_layer(roi)\n", " m.center_object(roi)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "timelapse = geemap.sentinel2_timelapse(\n", " roi,\n", " out_gif='sentinel2.gif',\n", " start_year=2016,\n", " end_year=2021,\n", " start_date='01-01',\n", " end_date='12-31',\n", " frequency='year',\n", " bands=['SWIR1', 'NIR', 'Red'],\n", " frames_per_second=3,\n", " title='Sentinel-2 Timelapse',\n", ")\n", "geemap.show_image(timelapse)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### MODIS timelapse\n", "\n", "MODIS vegetation indices" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = m.user_roi\n", "if roi is None:\n", " roi = ee.Geometry.BBox(-18.6983, -36.1630, 52.2293, 38.1446)\n", " m.add_layer(roi)\n", " m.center_object(roi)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "timelapse = geemap.modis_ndvi_timelapse(\n", " roi,\n", " out_gif='ndvi.gif',\n", " data='Terra',\n", " band='NDVI',\n", " start_date='2000-01-01',\n", " end_date='2022-12-31',\n", " frames_per_second=3,\n", " title='MODIS NDVI Timelapse',\n", " overlay_data='countries',\n", ")\n", "geemap.show_image(timelapse)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "MODIS temperature" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = m.user_roi\n", "if roi is None:\n", " roi = ee.Geometry.BBox(-171.21, -57.13, 177.53, 79.99)\n", " m.add_layer(roi)\n", " m.center_object(roi)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "timelapse = geemap.modis_ocean_color_timelapse(\n", " satellite='Aqua',\n", " start_date='2018-01-01',\n", " end_date='2020-12-31',\n", " roi=roi,\n", " frequency='month',\n", " out_gif='temperature.gif',\n", " overlay_data='continents',\n", " overlay_color='yellow',\n", " overlay_opacity=0.5,\n", ")\n", "geemap.show_image(timelapse)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### GOES timelapse" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = ee.Geometry.BBox(167.1898, -28.5757, 202.6258, -12.4411)\n", "start_date = \"2022-01-15T03:00:00\"\n", "end_date = \"2022-01-15T07:00:00\"\n", "data = \"GOES-17\"\n", "scan = \"full_disk\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "timelapse = geemap.goes_timelapse(\n", " roi, \"goes.gif\", start_date, end_date, data, scan, framesPerSecond=5\n", ")\n", "geemap.show_image(timelapse)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = ee.Geometry.BBox(-159.5954, 24.5178, -114.2438, 60.4088)\n", "start_date = \"2021-10-24T14:00:00\"\n", "end_date = \"2021-10-25T01:00:00\"\n", "data = \"GOES-17\"\n", "scan = \"full_disk\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "timelapse = geemap.goes_timelapse(\n", " roi, \"hurricane.gif\", start_date, end_date, data, scan, framesPerSecond=5\n", ")\n", "geemap.show_image(timelapse)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = ee.Geometry.BBox(-121.0034, 36.8488, -117.9052, 39.0490)\n", "start_date = \"2020-09-05T15:00:00\"\n", "end_date = \"2020-09-06T02:00:00\"\n", "data = \"GOES-17\"\n", "scan = \"full_disk\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "timelapse = geemap.goes_fire_timelapse(\n", " roi, \"fire.gif\", start_date, end_date, data, scan, framesPerSecond=5\n", ")\n", "geemap.show_image(timelapse)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 4 - Creating timelapse animations\n", "\n", "Use the geemap timelapse GUI to create a timelapse animation for any location of your choice. Share the timelapse on social media and use the hashtagd such as #EarthEngine and #geemap. See [this](https://i.imgur.com/YaCHvKC.gif) example.\n", "\n", "![](https://i.imgur.com/ohrXeFC.png)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_gui(\"timelapse\")\n", "m" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.6" } }, "nbformat": 4, "nbformat_minor": 5 }