{ "cells": [ { "cell_type": "markdown", "id": "0", "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/Taiwan_2024.ipynb)\n", "\n", "**Cloud Computing with Earth Engine and Geemap**\n", "\n", "- Registration: \n", "- Notebook: \n", "- Earth Engine: \n", "- Geemap: \n", "\n", "## Introduction\n", "\n", "This notebook is designed for workshop presented at the [Center for GIS, RCHSS, Academia Sinica](https://gis.rchss.sinica.edu.tw/), Taiwan, on August 7, 2024. Part 1 of the workshop will introduce the Earth Engine Python API and the geemap Python package. Part 2 will focus on 3D mapping with Leafmap and MapLibre. \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/gee-community/geemap/blob/master/docs/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 short course without installing anything on their computer.\n", "\n", "\n", "### Agenda\n", "\n", "The main topics to be covered in this workshop include:\n", "\n", "* Create interactive maps\n", "* Visualize Earth Engine data\n", "* Explore Earth Engine Data Catalogs\n", "* Analyze Earth Engine data\n", "* Export Earth Engine data\n", "* Create timelapse animations\n", "\n", "\n", "## Introduction to Earth Engine and geemap\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 3,300 GitHub stars and is being used by over 2,700 projects on GitHub.\n", "\n", "## Google Colab and Earth Engine Python API authentication\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/Taiwan_2024.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 code block to install geemap and some optional dependencies." ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "# %pip install -U \"geemap[workshop]\"" ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "Note that some geemap features may not work properly in the Google Colab environmennt. If you are familiar with [Anaconda](https://www.anaconda.com/download) or [Miniconda](https://docs.anaconda.com/free/miniconda), 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", "id": "3", "metadata": {}, "source": [ "### Import libraries\n", "\n", "Import the earthengine-api and geemap." ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap" ] }, { "cell_type": "markdown", "id": "5", "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, "id": "6", "metadata": {}, "outputs": [], "source": [ "ee.Authenticate()" ] }, { "cell_type": "code", "execution_count": null, "id": "7", "metadata": {}, "outputs": [], "source": [ "ee.Initialize(project=\"YOUR-PROJECT-ID\")" ] }, { "cell_type": "markdown", "id": "8", "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, "id": "9", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()" ] }, { "cell_type": "markdown", "id": "10", "metadata": {}, "source": [ "To display it in a Jupyter notebook, simply ask for the object representation:" ] }, { "cell_type": "code", "execution_count": null, "id": "11", "metadata": {}, "outputs": [], "source": [ "m" ] }, { "cell_type": "markdown", "id": "12", "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, "id": "13", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4, height=\"600xp\")\n", "m" ] }, { "cell_type": "markdown", "id": "14", "metadata": {}, "source": [ "To hide a control, set `control_name` to `False`, e.g., `draw_ctrl=False`." ] }, { "cell_type": "code", "execution_count": null, "id": "15", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(data_ctrl=False, toolbar_ctrl=False, draw_ctrl=False)\n", "m" ] }, { "cell_type": "markdown", "id": "16", "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, "id": "17", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(basemap=\"Esri.WorldImagery\")\n", "m" ] }, { "cell_type": "markdown", "id": "18", "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, "id": "19", "metadata": {}, "outputs": [], "source": [ "m.add_basemap(\"OpenTopoMap\")" ] }, { "cell_type": "markdown", "id": "20", "metadata": {}, "source": [ "You can also change basemaps interactively using the basemap GUI." ] }, { "cell_type": "code", "execution_count": null, "id": "21", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add(\"basemap_selector\")\n", "m" ] }, { "cell_type": "markdown", "id": "22", "metadata": {}, "source": [ "## Using Earth Engine data\n", "\n", "### Earth Engine data types\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, "id": "23", "metadata": {}, "outputs": [], "source": [ "image = ee.Image(\"USGS/SRTMGL1_003\")\n", "image" ] }, { "cell_type": "markdown", "id": "24", "metadata": {}, "source": [ "#### Visualizing Earth Engine images" ] }, { "cell_type": "code", "execution_count": null, "id": "25", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[23.5790, 121.4181], zoom=8)\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", "id": "26", "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, "id": "27", "metadata": {}, "outputs": [], "source": [ "collection = ee.ImageCollection(\"COPERNICUS/S2_SR\")" ] }, { "cell_type": "markdown", "id": "28", "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, "id": "29", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "collection = (\n", " ee.ImageCollection(\"COPERNICUS/S2_SR\")\n", " .filterDate(\"2023-01-01\", \"2024-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(121.4181, 23.5790, 8)\n", "m.add_layer(image, vis, \"Sentinel-2\")\n", "m" ] }, { "cell_type": "markdown", "id": "30", "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, "id": "31", "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", "id": "32", "metadata": {}, "source": [ "#### Filtering feature collections\n", "\n", "* [geoBoundaries: Political administrative boundaries at Country level (ADM0)](https://developers.google.com/earth-engine/datasets/catalog/WM_geoLab_geoBoundaries_600_ADM0)\n", "* [geoBoundaries: Political administrative boundaries at District level (ADM1)](https://developers.google.com/earth-engine/datasets/catalog/WM_geoLab_geoBoundaries_600_ADM1)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "33", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM0\")\n", "fc = countries.filter(ee.Filter.eq(\"shapeName\", \"Taiwan\"))\n", "m.add_layer(fc, {}, \"Taiwan\")\n", "m.center_object(fc, 8)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "34", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM1\")\n", "fc = countries.filter(ee.Filter.eq(\"shapeGroup\", \"TWN\"))\n", "m.add_layer(fc, {}, \"Taiwan\")\n", "m.center_object(fc, 8)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "35", "metadata": {}, "outputs": [], "source": [ "region = m.user_roi\n", "if region is None:\n", " region = ee.Geometry.BBox(119.1687, 21.7799, 122.981, 25.4234)\n", "\n", "fc = fc.filterBounds(region)\n", "m.add_layer(fc, {}, \"Taiwan 2\")\n", "m.center_object(fc, 8)" ] }, { "cell_type": "markdown", "id": "36", "metadata": {}, "source": [ "#### Visualizing feature collections" ] }, { "cell_type": "code", "execution_count": null, "id": "37", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM1\")\n", "fc = countries.filter(ee.Filter.eq(\"shapeGroup\", \"TWN\"))\n", "m.add_layer(fc, {}, \"Taiwan\")\n", "m.center_object(fc, 8)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "38", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM1\")\n", "fc = countries.filter(ee.Filter.eq(\"shapeGroup\", \"TWN\"))\n", "style = {\"color\": \"000000ff\", \"width\": 2, \"lineType\": \"solid\", \"fillColor\": \"FF000000\"}\n", "m.add_layer(fc.style(**style), {}, \"Taiwan\")\n", "m.center_object(fc, 8)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "39", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM1\")\n", "fc = countries.filter(ee.Filter.eq(\"shapeGroup\", \"TWN\"))\n", "style = {\"color\": \"0000ffff\", \"width\": 2, \"lineType\": \"solid\", \"fillColor\": \"FF000080\"}\n", "m.add_layer(fc.style(**style), {}, \"Taiwan\")\n", "m.center_object(fc, 8)\n", "m" ] }, { "cell_type": "markdown", "id": "40", "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 July 2024, the catalog contains over [1,100 datasets](https://github.com/opengeos/Earth-Engine-Catalog/blob/master/gee_catalog.tsv) with a total size of over 100 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. 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, "id": "41", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "42", "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": "code", "execution_count": null, "id": "43", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "counties = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM0\")\n", "fc = counties.filter(ee.Filter.eq(\"shapeName\", \"Taiwan\"))\n", "dem = ee.Image(\"USGS/SRTMGL1_003\").clipToCollection(fc)\n", "vis_params = {\n", " \"min\": 0,\n", " \"max\": 4000,\n", " \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],\n", "}\n", "\n", "m.add_layer(fc, {}, \"Taiwan\")\n", "m.add_layer(dem, vis_params, \"SRTM DEM\")\n", "m.center_object(fc, 8)\n", "m" ] }, { "cell_type": "markdown", "id": "44", "metadata": {}, "source": [ "### Exercise 1 - Creating cloud-free imagery\n", "\n", "Create a cloud-free imagery of Taiwan for the year of 2023. 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", "A sample map of cloud-free imagery for the state of Texas is shown below:\n", "\n", "![](https://i.imgur.com/i3IT0lF.png)" ] }, { "cell_type": "code", "execution_count": null, "id": "45", "metadata": {}, "outputs": [], "source": [ "# Type your code here" ] }, { "cell_type": "markdown", "id": "46", "metadata": {}, "source": [ "## Visualizing Earth Engine data\n", "\n", "### Using the inspector tool\n", "\n", "Inspect pixel values and vector features using the inspector tool. " ] }, { "cell_type": "code", "execution_count": null, "id": "47", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "\n", "counties = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM0\")\n", "fc = counties.filter(ee.Filter.eq(\"shapeName\", \"Taiwan\"))\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", "\n", "vis_params = {\n", " \"min\": 0,\n", " \"max\": 4000,\n", " \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],\n", "}\n", "\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(dem, vis_params, \"SRTM DEM\")\n", "m.add_layer(fc, {}, \"Taiwan\")\n", "m.add(\"inspector\")\n", "m.center_object(fc, 8)\n", "m" ] }, { "cell_type": "markdown", "id": "48", "metadata": {}, "source": [ "### Using the plotting tool\n", "\n", "Plot spectral profiles of pixels using the plotting tool." ] }, { "cell_type": "code", "execution_count": null, "id": "49", "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.center_object(fc, 8)\n", "m" ] }, { "cell_type": "markdown", "id": "50", "metadata": {}, "source": [ "Set plotting options for Landsat." ] }, { "cell_type": "code", "execution_count": null, "id": "51", "metadata": {}, "outputs": [], "source": [ "m.set_plot_options(add_marker_cluster=True, overlay=True)" ] }, { "cell_type": "markdown", "id": "52", "metadata": {}, "source": [ "Set plotting options for Hyperion." ] }, { "cell_type": "code", "execution_count": null, "id": "53", "metadata": {}, "outputs": [], "source": [ "m.set_plot_options(add_marker_cluster=True, plot_type=\"bar\")" ] }, { "cell_type": "markdown", "id": "54", "metadata": {}, "source": [ "### Legends, color bars, and labels\n", "\n", "#### Built-in legends" ] }, { "cell_type": "code", "execution_count": null, "id": "55", "metadata": {}, "outputs": [], "source": [ "from geemap.legends import builtin_legends" ] }, { "cell_type": "code", "execution_count": null, "id": "56", "metadata": {}, "outputs": [], "source": [ "for legend in builtin_legends:\n", " print(legend)" ] }, { "cell_type": "markdown", "id": "57", "metadata": {}, "source": [ "Add ESA WorldCover and legend to the map.\n", "\n", "https://developers.google.com/earth-engine/datasets/catalog/ESA_WorldCover_v200" ] }, { "cell_type": "code", "execution_count": null, "id": "58", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_basemap(\"Esri.WorldImagery\")\n", "\n", "dataset = ee.ImageCollection(\"ESA/WorldCover/v200\").first()\n", "visualization = {\"bands\": [\"Map\"]}\n", "m.add_layer(dataset, visualization, \"Landcover\")\n", "m.add_legend(title=\"Land Cover Type\", builtin_legend=\"ESA_WorldCover\")\n", "m.set_center(121.4181, 23.5790, 8)\n", "m" ] }, { "cell_type": "markdown", "id": "59", "metadata": {}, "source": [ "#### Custom legends" ] }, { "cell_type": "markdown", "id": "60", "metadata": {}, "source": [ "Add a custom legend by specifying a dictionary of colors and labels." ] }, { "cell_type": "code", "execution_count": null, "id": "61", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_basemap(\"Esri.WorldImagery\")\n", "\n", "dataset = ee.ImageCollection(\"ESA/WorldCover/v200\").first()\n", "visualization = {\"bands\": [\"Map\"]}\n", "m.add_layer(dataset, visualization, \"Landcover\")\n", "legend_dict = {\n", " \"10 Trees\": \"006400\",\n", " \"20 Shrubland\": \"ffbb22\",\n", " \"30 Grassland\": \"ffff4c\",\n", " \"40 Cropland\": \"f096ff\",\n", " \"50 Built-up\": \"fa0000\",\n", " \"60 Barren / sparse vegetation\": \"b4b4b4\",\n", " \"70 Snow and ice\": \"f0f0f0\",\n", " \"80 Open water\": \"0064c8\",\n", " \"90 Herbaceous wetland\": \"0096a0\",\n", " \"95 Mangroves\": \"00cf75\",\n", " \"100 Moss and lichen\": \"fae6a0\",\n", "}\n", "m.add_legend(title=\"Land Cover Type\", legend_dict=legend_dict)\n", "m.set_center(121.4181, 23.5790, 8)\n", "m" ] }, { "cell_type": "markdown", "id": "62", "metadata": {}, "source": [ "#### Creating color bars\n", "\n", "Add a horizontal color bar." ] }, { "cell_type": "code", "execution_count": null, "id": "63", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM0\")\n", "fc = countries.filter(ee.Filter.eq(\"shapeName\", \"Taiwan\"))\n", "dem = ee.Image(\"USGS/SRTMGL1_003\").clipToCollection(fc)\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.center_object(fc, 8)\n", "m" ] }, { "cell_type": "markdown", "id": "64", "metadata": {}, "source": [ "Add a vertical color bar." ] }, { "cell_type": "code", "execution_count": null, "id": "65", "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", "id": "66", "metadata": {}, "source": [ "Make the color bar background transparent." ] }, { "cell_type": "code", "execution_count": null, "id": "67", "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", "id": "68", "metadata": {}, "source": [ "### Split-panel map and linked maps\n", "\n", "### 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, "id": "69", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.split_map(left_layer=\"Esri.WorldTopoMap\", right_layer=\"OpenTopoMap\")\n", "m.set_center(121.4181, 23.5790, 8)\n", "m" ] }, { "cell_type": "markdown", "id": "70", "metadata": {}, "source": [ "Create a split map with Earth Engine layers." ] }, { "cell_type": "code", "execution_count": null, "id": "71", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "\n", "esa_2020 = ee.ImageCollection(\"ESA/WorldCover/v100\").first()\n", "esa_2021 = ee.ImageCollection(\"ESA/WorldCover/v200\").first()\n", "visualization = {\"bands\": [\"Map\"]}\n", "\n", "left_layer = geemap.ee_tile_layer(esa_2020, visualization, \"Land Cover 2020\")\n", "right_layer = geemap.ee_tile_layer(esa_2021, visualization, \"Land Cover 2021\")\n", "\n", "m.split_map(\n", " left_layer, right_layer, left_label=\"Land Cover 2020\", right_label=\"Land Cover 2021\"\n", ")\n", "m.add_legend(title=\"Land Cover Type\", builtin_legend=\"ESA_WorldCover\")\n", "m.set_center(121.4181, 23.5790, 8)\n", "m" ] }, { "cell_type": "markdown", "id": "72", "metadata": {}, "source": [ "### Linked maps\n", "\n", "Create a 2x2 linked map for visualizing Sentinel-2 imagery with different band combinations. Note that this feature does not work properly with Colab. Panning one map would not pan other maps." ] }, { "cell_type": "code", "execution_count": null, "id": "73", "metadata": {}, "outputs": [], "source": [ "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM0\")\n", "fc = countries.filter(ee.Filter.eq(\"shapeName\", \"Taiwan\"))\n", "image = (\n", " ee.ImageCollection(\"COPERNICUS/S2\")\n", " .filterDate(\"2023-01-01\", \"2024-01-01\")\n", " .filter(ee.Filter.lt(\"CLOUDY_PIXEL_PERCENTAGE\", 5))\n", " .filterBounds(fc)\n", " .map(lambda img: img.divide(10000))\n", " .median()\n", " .clipToCollection(fc)\n", ")\n", "\n", "vis_params = [\n", " {\"bands\": [\"B4\", \"B3\", \"B2\"], \"min\": 0, \"max\": 0.3, \"gamma\": 1.3},\n", " {\"bands\": [\"B8\", \"B11\", \"B4\"], \"min\": 0, \"max\": 0.3, \"gamma\": 1.3},\n", " {\"bands\": [\"B8\", \"B4\", \"B3\"], \"min\": 0, \"max\": 0.3, \"gamma\": 1.3},\n", " {\"bands\": [\"B12\", \"B12\", \"B4\"], \"min\": 0, \"max\": 0.3, \"gamma\": 1.3},\n", "]\n", "\n", "labels = [\n", " \"Natural Color (B4/B3/B2)\",\n", " \"Land/Water (B8/B11/B4)\",\n", " \"Color Infrared (B8/B4/B3)\",\n", " \"Vegetation (B12/B11/B4)\",\n", "]\n", "\n", "geemap.linked_maps(\n", " rows=2,\n", " cols=2,\n", " height=\"400px\",\n", " center=[23.5790, 121.4181],\n", " zoom=8,\n", " ee_objects=[image],\n", " vis_params=vis_params,\n", " labels=labels,\n", " label_position=\"topright\",\n", ")" ] }, { "cell_type": "markdown", "id": "74", "metadata": {}, "source": [ "### Timeseries inspector and time slider\n", "\n", "#### Timeseries inspector\n", "\n", "Check the available years of NLCD." ] }, { "cell_type": "code", "execution_count": null, "id": "75", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[40, -100], zoom=4)\n", "collection = ee.ImageCollection(\"USGS/NLCD_RELEASES/2019_REL/NLCD\").select(\"landcover\")\n", "vis_params = {\"bands\": [\"landcover\"]}\n", "years = collection.aggregate_array(\"system:index\").getInfo()\n", "years" ] }, { "cell_type": "markdown", "id": "76", "metadata": {}, "source": [ "Create a timeseries inspector for NLCD. Note that ipyleaflet has a bug with the SplitControl. You can't pan the map, which should be resolved in a future ipyleaflet release." ] }, { "cell_type": "code", "execution_count": null, "id": "77", "metadata": {}, "outputs": [], "source": [ "m.ts_inspector(\n", " left_ts=collection,\n", " right_ts=collection,\n", " left_names=years,\n", " right_names=years,\n", " left_vis=vis_params,\n", " right_vis=vis_params,\n", " width=\"80px\",\n", ")\n", "m" ] }, { "cell_type": "markdown", "id": "78", "metadata": {}, "source": [ "#### Time slider\n", "\n", "Note that this feature may not work properly with in the Colab environment. Restart Colab runtime if the time slider does not work.\n", "\n", "Create a map for visualizing MODIS vegetation data." ] }, { "cell_type": "code", "execution_count": null, "id": "79", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "\n", "collection = (\n", " ee.ImageCollection(\"MODIS/MCD43A4_006_NDVI\")\n", " .filter(ee.Filter.date(\"2018-06-01\", \"2018-07-01\"))\n", " .select(\"NDVI\")\n", ")\n", "vis_params = {\n", " \"min\": 0.0,\n", " \"max\": 1.0,\n", " \"palette\": \"ndvi\",\n", "}\n", "\n", "m.add_time_slider(collection, vis_params, time_interval=2)\n", "m" ] }, { "cell_type": "markdown", "id": "80", "metadata": {}, "source": [ "Create a map for visualizing weather data." ] }, { "cell_type": "code", "execution_count": null, "id": "81", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "\n", "collection = (\n", " ee.ImageCollection(\"NOAA/GFS0P25\")\n", " .filterDate(\"2018-12-22\", \"2018-12-23\")\n", " .limit(24)\n", " .select(\"temperature_2m_above_ground\")\n", ")\n", "\n", "vis_params = {\n", " \"min\": -40.0,\n", " \"max\": 35.0,\n", " \"palette\": [\"blue\", \"purple\", \"cyan\", \"green\", \"yellow\", \"red\"],\n", "}\n", "\n", "labels = [str(n).zfill(2) + \":00\" for n in range(0, 24)]\n", "m.add_time_slider(collection, vis_params, labels=labels, time_interval=1, opacity=0.8)\n", "m" ] }, { "cell_type": "markdown", "id": "82", "metadata": {}, "source": [ "Visualizing Sentinel-2 imagery" ] }, { "cell_type": "code", "execution_count": null, "id": "83", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(center=[37.75, -122.45], zoom=12)\n", "\n", "collection = (\n", " ee.ImageCollection(\"COPERNICUS/S2_SR\")\n", " .filterBounds(ee.Geometry.Point([-122.45, 37.75]))\n", " .filterMetadata(\"CLOUDY_PIXEL_PERCENTAGE\", \"less_than\", 10)\n", ")\n", "\n", "vis_params = {\"min\": 0, \"max\": 4000, \"bands\": [\"B8\", \"B4\", \"B3\"]}\n", "\n", "m.add_time_slider(collection, vis_params)\n", "m" ] }, { "cell_type": "markdown", "id": "84", "metadata": {}, "source": [ "### Exercise 2 - Visualizing satellite data for an area of interest\n", "\n", "Visualize the time series of [Sentinel-2](https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR_HARMONIZED) imagery for an area of interest in Taiwan. You can use the following Earth Engine assets:\n", "\n", "- `ee.ImageCollection(\"COPERNICUS/S2_SR_HARMONIZED\")`" ] }, { "cell_type": "markdown", "id": "85", "metadata": {}, "source": [ "## Analyzing Earth Engine data\n", "\n", "### Zonal statistics" ] }, { "cell_type": "code", "execution_count": null, "id": "86", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM1\")\n", "fc = countries.filter(ee.Filter.eq(\"shapeGroup\", \"TWN\"))\n", "# Add NASA SRTM\n", "dem = ee.Image(\"USGS/SRTMGL1_003\").clipToCollection(fc)\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\").clipToCollection(fc)\n", "landsat_vis = {\"bands\": [\"B4\", \"B3\", \"B2\"], \"gamma\": 1.4, \"min\": 20, \"max\": 150}\n", "m.add_layer(landsat, landsat_vis, \"Landsat\", False)\n", "m.add_layer(fc, {}, \"Taiwan\")\n", "m.center_object(fc, 8)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "87", "metadata": {}, "outputs": [], "source": [ "out_dem_stats = \"dem_stats.csv\"\n", "geemap.zonal_stats(dem, fc, out_dem_stats, stat_type=\"MEAN\", scale=30, return_fc=False)" ] }, { "cell_type": "code", "execution_count": null, "id": "88", "metadata": {}, "outputs": [], "source": [ "geemap.csv_to_df(out_dem_stats).sort_values(by=[\"mean\"])" ] }, { "cell_type": "code", "execution_count": null, "id": "89", "metadata": {}, "outputs": [], "source": [ "out_landsat_stats = \"landsat_stats.csv\"\n", "geemap.zonal_stats(\n", " landsat,\n", " fc,\n", " out_landsat_stats,\n", " stat_type=\"MEAN\",\n", " scale=30,\n", " return_fc=False,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "90", "metadata": {}, "outputs": [], "source": [ "geemap.csv_to_df(out_landsat_stats)" ] }, { "cell_type": "markdown", "id": "91", "metadata": {}, "source": [ "### Zonal statistics by group" ] }, { "cell_type": "code", "execution_count": null, "id": "92", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_basemap(\"Esri.WorldImagery\")\n", "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM1\")\n", "fc = countries.filter(ee.Filter.eq(\"shapeGroup\", \"TWN\"))\n", "dataset = ee.ImageCollection(\"ESA/WorldCover/v200\").first().clipToCollection(fc)\n", "visualization = {\"bands\": [\"Map\"]}\n", "m.add_layer(dataset, visualization, \"Landcover\")\n", "m.add_legend(title=\"Land Cover Type\", builtin_legend=\"ESA_WorldCover\")\n", "m.add_layer(fc, {}, \"Taiwan\")\n", "m.set_center(121.4181, 23.5790, 8)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "93", "metadata": {}, "outputs": [], "source": [ "landcover_stats = \"landcover_stats.csv\"\n", "\n", "geemap.zonal_stats_by_group(\n", " dataset,\n", " fc,\n", " landcover_stats,\n", " stat_type=\"SUM\",\n", " denominator=1e6,\n", " decimal_places=2,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "94", "metadata": {}, "outputs": [], "source": [ "geemap.csv_to_df(landcover_stats)" ] }, { "cell_type": "code", "execution_count": null, "id": "95", "metadata": {}, "outputs": [], "source": [ "landcover_stats = \"landcover_stats_pct.csv\"\n", "\n", "geemap.zonal_stats_by_group(\n", " dataset,\n", " fc,\n", " landcover_stats,\n", " stat_type=\"PERCENTAGE\",\n", " denominator=1e6,\n", " decimal_places=2,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "96", "metadata": {}, "outputs": [], "source": [ "geemap.csv_to_df(landcover_stats)" ] }, { "cell_type": "markdown", "id": "97", "metadata": {}, "source": [ "## Exporting Earth Engine data\n", "\n", "### Exporting images" ] }, { "cell_type": "code", "execution_count": null, "id": "98", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "roi = ee.Geometry.Point([121.615219, 25.041219])\n", "image = (\n", " ee.ImageCollection(\"COPERNICUS/S2_SR_HARMONIZED\")\n", " .filterDate(\"2024-01-01\", \"2024-08-01\")\n", " .filter(ee.Filter.lt(\"CLOUDY_PIXEL_PERCENTAGE\", 10))\n", " .filterBounds(roi)\n", " .sort(\"CLOUDY_PIXEL_PERCENTAGE\")\n", " .first()\n", " .select([\"B8\", \"B4\", \"B3\"])\n", ")\n", "\n", "vis_params = {\"min\": 0, \"max\": 3000}\n", "\n", "m.add_layer(image, vis_params, \"Sentinel-2\")\n", "m.center_object(roi, 8)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "99", "metadata": {}, "outputs": [], "source": [ "region = ee.Geometry.BBox(121.3824, 24.9325, 121.6653, 25.1496)\n", "fc = ee.FeatureCollection(region)\n", "style = {\"color\": \"ffff00ff\", \"fillColor\": \"00000000\"}\n", "m.add_layer(fc.style(**style), {}, \"ROI\")" ] }, { "cell_type": "code", "execution_count": null, "id": "100", "metadata": {}, "outputs": [], "source": [ "geemap.ee_export_image(image, filename=\"sentinel-2.tif\", scale=30, region=region)" ] }, { "cell_type": "code", "execution_count": null, "id": "101", "metadata": {}, "outputs": [], "source": [ "geemap.ee_export_image_to_drive(\n", " image, description=\"sentinel-2\", folder=\"export\", region=region, scale=30\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "102", "metadata": {}, "outputs": [], "source": [ "geemap.download_ee_image(image, \"sentinel-2_10m.tif\", region=region, scale=10)" ] }, { "cell_type": "markdown", "id": "103", "metadata": {}, "source": [ "### Export image collections" ] }, { "cell_type": "code", "execution_count": null, "id": "104", "metadata": {}, "outputs": [], "source": [ "point = ee.Geometry.Point(-99.2222, 46.7816)\n", "collection = (\n", " ee.ImageCollection(\"USDA/NAIP/DOQQ\")\n", " .filterBounds(point)\n", " .filterDate(\"2008-01-01\", \"2018-01-01\")\n", " .filter(ee.Filter.listContains(\"system:band_names\", \"N\"))\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "105", "metadata": {}, "outputs": [], "source": [ "collection.aggregate_array(\"system:index\")" ] }, { "cell_type": "code", "execution_count": null, "id": "106", "metadata": {}, "outputs": [], "source": [ "geemap.ee_export_image_collection(collection, out_dir=\"naip\", scale=10)" ] }, { "cell_type": "code", "execution_count": null, "id": "107", "metadata": {}, "outputs": [], "source": [ "geemap.ee_export_image_collection_to_drive(collection, folder=\"export\", scale=10)" ] }, { "cell_type": "markdown", "id": "108", "metadata": {}, "source": [ "### Exporting feature collections" ] }, { "cell_type": "code", "execution_count": null, "id": "109", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "countries = ee.FeatureCollection(\"WM/geoLab/geoBoundaries/600/ADM0\")\n", "fc = countries.filter(ee.Filter.eq(\"shapeName\", \"Taiwan\"))\n", "m.add_layer(fc, {}, \"Taiwan\")\n", "m.center_object(fc, 8)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "110", "metadata": {}, "outputs": [], "source": [ "geemap.ee_to_shp(fc, filename=\"Taiwan.shp\")" ] }, { "cell_type": "code", "execution_count": null, "id": "111", "metadata": {}, "outputs": [], "source": [ "geemap.ee_export_vector(fc, filename=\"Taiwan.shp\")" ] }, { "cell_type": "code", "execution_count": null, "id": "112", "metadata": {}, "outputs": [], "source": [ "geemap.ee_to_geojson(fc, filename=\"Taiwan.geojson\")" ] }, { "cell_type": "code", "execution_count": null, "id": "113", "metadata": {}, "outputs": [], "source": [ "geemap.ee_to_csv(fc, filename=\"Taiwan.csv\")" ] }, { "cell_type": "code", "execution_count": null, "id": "114", "metadata": {}, "outputs": [], "source": [ "gdf = geemap.ee_to_gdf(fc)\n", "gdf" ] }, { "cell_type": "code", "execution_count": null, "id": "115", "metadata": {}, "outputs": [], "source": [ "df = geemap.ee_to_df(fc)\n", "df" ] }, { "cell_type": "code", "execution_count": null, "id": "116", "metadata": {}, "outputs": [], "source": [ "geemap.ee_export_vector_to_drive(\n", " fc, description=\"Alaska\", fileFormat=\"SHP\", folder=\"export\"\n", ")" ] }, { "cell_type": "markdown", "id": "117", "metadata": {}, "source": [ "## Creating timelapse animations\n", "\n", "### Landsat timelapse" ] }, { "cell_type": "code", "execution_count": null, "id": "118", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.set_center(121.615219, 25.041219, 12)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "119", "metadata": {}, "outputs": [], "source": [ "roi = m.user_roi\n", "if roi is None:\n", " roi = ee.Geometry.BBox(121.3824, 24.9325, 121.6653, 25.1496)\n", " m.add_layer(roi)\n", " m.center_object(roi)" ] }, { "cell_type": "code", "execution_count": null, "id": "120", "metadata": {}, "outputs": [], "source": [ "timelapse = geemap.landsat_timelapse(\n", " roi,\n", " out_gif=\"Taiwan.gif\",\n", " start_year=1988,\n", " end_year=2024,\n", " start_date=\"01-01\",\n", " end_date=\"12-31\",\n", " bands=[\"SWIR1\", \"NIR\", \"Red\"],\n", " frames_per_second=5,\n", " title=\"Taipei\",\n", " progress_bar_color=\"blue\",\n", " mp4=True,\n", ")\n", "geemap.show_image(timelapse)" ] }, { "cell_type": "code", "execution_count": null, "id": "121", "metadata": {}, "outputs": [], "source": [ "roi = ee.Geometry.BBox(113.8252, 22.1988, 114.0851, 22.3497)\n", "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": "code", "execution_count": null, "id": "122", "metadata": {}, "outputs": [], "source": [ "roi = ee.Geometry.BBox(-115.5541, 35.8044, -113.9035, 36.5581)\n", "timelapse = geemap.landsat_timelapse(\n", " roi,\n", " out_gif=\"las_vegas.gif\",\n", " start_year=1984,\n", " end_year=2023,\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": "markdown", "id": "123", "metadata": {}, "source": [ "### Sentinel-2 timelapse" ] }, { "cell_type": "code", "execution_count": null, "id": "124", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.set_center(121.615219, 25.041219, 12)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "id": "125", "metadata": {}, "outputs": [], "source": [ "roi = m.user_roi\n", "if roi is None:\n", " roi = ee.Geometry.BBox(121.3824, 24.9325, 121.6653, 25.1496)\n", " m.add_layer(roi)\n", " m.center_object(roi)" ] }, { "cell_type": "code", "execution_count": null, "id": "126", "metadata": {}, "outputs": [], "source": [ "timelapse = geemap.sentinel2_timelapse(\n", " roi,\n", " out_gif=\"sentinel2.gif\",\n", " start_year=2017,\n", " end_year=2024,\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", "id": "127", "metadata": {}, "source": [ "### MODIS vegetation indices" ] }, { "cell_type": "code", "execution_count": null, "id": "128", "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "id": "129", "metadata": {}, "outputs": [], "source": [ "roi = Map.user_roi\n", "if roi is None:\n", " roi = ee.Geometry.BBox(-18.6983, -36.1630, 52.2293, 38.1446)\n", " Map.addLayer(roi)\n", " Map.centerObject(roi)" ] }, { "cell_type": "code", "execution_count": null, "id": "130", "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", "id": "131", "metadata": {}, "source": [ "### MODIS temperature data" ] }, { "cell_type": "code", "execution_count": null, "id": "132", "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "id": "133", "metadata": {}, "outputs": [], "source": [ "roi = Map.user_roi\n", "if roi is None:\n", " roi = ee.Geometry.BBox(-171.21, -57.13, 177.53, 79.99)\n", " Map.addLayer(roi)\n", " Map.centerObject(roi)" ] }, { "cell_type": "code", "execution_count": null, "id": "134", "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", "id": "135", "metadata": {}, "source": [ "### GOES timelapse" ] }, { "cell_type": "code", "execution_count": null, "id": "136", "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, "id": "137", "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, "id": "138", "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, "id": "139", "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, "id": "140", "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, "id": "141", "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", "id": "142", "metadata": {}, "source": [ "### Exercise 3 - 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 hashtag 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, "id": "143", "metadata": {}, "outputs": [], "source": [ "m = geemap.Map()\n", "m.add_gui(\"timelapse\")\n", "m" ] } ], "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.11.8" } }, "nbformat": 4, "nbformat_minor": 5 }