{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open\n", "\n", "Uncomment the following line to install [geemap](https://geemap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating Landsat Timelapse\n", "\n", "**Steps to create a Landsat timelapse:**\n", "\n", "1. Pan and zoom to your area of interest, or click the globe icon at the upper left corner to search for a location.\n", "2. Use the drawing tool to draw a rectangle anywhere on the map.\n", "3. Adjust the parameters (e.g., start year, end year, title) if needed.\n", "4. Click the `Create timelapse` button to create a timelapse.\n", "5. Once the timelapse has been added to the map, click the hyperlink at the end if you want to download the GIF.\n", "\n", "**Web Apps:** https://streamlit.geemap.org\n", "\n", "**Contact:** Dr. Qiusheng Wu ([Website](https://wetlands.io/), [LinkedIn](https://www.linkedin.com/in/qiushengwu), [Twitter](https://twitter.com/giswqs), [YouTube](https://youtube.com/@giswqs))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import ee\n", "import geemap\n", "import ipywidgets as widgets" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map.add_basemap('HYBRID')\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "style = {'description_width': 'initial'}\n", "title = widgets.Text(\n", " description='Title:', value='Landsat Timelapse', width=200, style=style\n", ")\n", "\n", "bands = widgets.Dropdown(\n", " description='Select RGB Combo:',\n", " options=[\n", " 'Red/Green/Blue',\n", " 'NIR/Red/Green',\n", " 'SWIR2/SWIR1/NIR',\n", " 'NIR/SWIR1/Red',\n", " 'SWIR2/NIR/Red',\n", " 'SWIR2/SWIR1/Red',\n", " 'SWIR1/NIR/Blue',\n", " 'NIR/SWIR1/Blue',\n", " 'SWIR2/NIR/Green',\n", " 'SWIR1/NIR/Red',\n", " ],\n", " value='NIR/Red/Green',\n", " style=style,\n", ")\n", "\n", "hbox1 = widgets.HBox([title, bands])\n", "hbox1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "speed = widgets.IntSlider(\n", " description=' Frames per second:',\n", " tooltip='Frames per second:',\n", " value=10,\n", " min=1,\n", " max=30,\n", " style=style,\n", ")\n", "\n", "cloud = widgets.Checkbox(\n", " value=True, description='Apply fmask (remove clouds, shadows, snow)', style=style\n", ")\n", "\n", "hbox2 = widgets.HBox([speed, cloud])\n", "hbox2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "start_year = widgets.IntSlider(\n", " description='Start Year:', value=1984, min=1984, max=2020, style=style\n", ")\n", "end_year = widgets.IntSlider(\n", " description='End Year:', value=2020, min=1984, max=2020, style=style\n", ")\n", "start_month = widgets.IntSlider(\n", " description='Start Month:', value=5, min=1, max=12, style=style\n", ")\n", "end_month = widgets.IntSlider(\n", " description='End Month:', value=10, min=1, max=12, style=style\n", ")\n", "hbox3 = widgets.HBox([start_year, end_year, start_month, end_month])\n", "hbox3" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "font_size = widgets.IntSlider(\n", " description='Font size:', value=30, min=10, max=50, style=style\n", ")\n", "\n", "font_color = widgets.ColorPicker(\n", " concise=False, description='Font color:', value='white', style=style\n", ")\n", "\n", "progress_bar_color = widgets.ColorPicker(\n", " concise=False, description='Progress bar color:', value='blue', style=style\n", ")\n", "\n", "hbox4 = widgets.HBox([font_size, font_color, progress_bar_color])\n", "hbox4" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Normalized Satellite Indices: https://www.usna.edu/Users/oceano/pguth/md_help/html/norm_sat.htm\n", "\n", "nd_options = [\n", " 'Vegetation Index (NDVI)',\n", " 'Water Index (NDWI)',\n", " 'Modified Water Index (MNDWI)',\n", " 'Snow Index (NDSI)',\n", " 'Soil Index (NDSI)',\n", " 'Burn Ratio (NBR)',\n", " 'Customized',\n", "]\n", "nd_indices = widgets.Dropdown(\n", " options=nd_options,\n", " value=None,\n", " description='Normalized Difference Index:',\n", " style=style,\n", ")\n", "\n", "first_band = widgets.Dropdown(\n", " description='1st band:',\n", " options=['Blue', 'Green', 'Red', 'NIR', 'SWIR1', 'SWIR2'],\n", " value=None,\n", " style=style,\n", ")\n", "\n", "second_band = widgets.Dropdown(\n", " description='2nd band:',\n", " options=['Blue', 'Green', 'Red', 'NIR', 'SWIR1', 'SWIR2'],\n", " value=None,\n", " style=style,\n", ")\n", "\n", "nd_threshold = widgets.FloatSlider(\n", " value=0,\n", " min=-1,\n", " max=1,\n", " step=0.01,\n", " description='Threshold:',\n", " orientation='horizontal',\n", ")\n", "\n", "nd_color = widgets.ColorPicker(\n", " concise=False, description='Color:', value='blue', style=style\n", ")\n", "\n", "\n", "def nd_index_change(change):\n", " if nd_indices.value == 'Vegetation Index (NDVI)':\n", " first_band.value = 'NIR'\n", " second_band.value = 'Red'\n", " elif nd_indices.value == 'Water Index (NDWI)':\n", " first_band.value = 'NIR'\n", " second_band.value = 'SWIR1'\n", " elif nd_indices.value == 'Modified Water Index (MNDWI)':\n", " first_band.value = 'Green'\n", " second_band.value = 'SWIR1'\n", " elif nd_indices.value == 'Snow Index (NDSI)':\n", " first_band.value = 'Green'\n", " second_band.value = 'SWIR1'\n", " elif nd_indices.value == 'Soil Index (NDSI)':\n", " first_band.value = 'SWIR1'\n", " second_band.value = 'NIR'\n", " elif nd_indices.value == 'Burn Ratio (NBR)':\n", " first_band.value = 'NIR'\n", " second_band.value = 'SWIR2'\n", " elif nd_indices.value == 'Customized':\n", " first_band.value = None\n", " second_band.value = None\n", "\n", "\n", "nd_indices.observe(nd_index_change, names='value')\n", "\n", "hbox5 = widgets.HBox([nd_indices, first_band, second_band, nd_threshold, nd_color])\n", "hbox5" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "create_gif = widgets.Button(\n", " description='Create timelapse',\n", " button_style='primary',\n", " tooltip='Click to create timelapse',\n", " style=style,\n", ")\n", "\n", "download_gif = widgets.Button(\n", " description='Download GIF',\n", " button_style='primary',\n", " tooltip='Click to download timelapse',\n", " disabled=False,\n", " style=style,\n", ")\n", "\n", "output = widgets.Output()\n", "\n", "hbox5 = widgets.HBox([create_gif])\n", "hbox5" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def submit_clicked(b):\n", " with output:\n", " output.clear_output()\n", " if start_year.value > end_year.value:\n", " print('The end year must be great than the start year.')\n", " return\n", " if start_month.value > end_month.value:\n", " print('The end month must be great than the start month.')\n", " return\n", " if start_year.value == end_year.value:\n", " add_progress_bar = False\n", " else:\n", " add_progress_bar = True\n", "\n", " start_date = str(start_month.value).zfill(2) + '-01'\n", " end_date = str(end_month.value).zfill(2) + '-30'\n", "\n", " print('Computing...')\n", "\n", " nd_bands = None\n", " if (first_band.value is not None) and (second_band.value is not None):\n", " nd_bands = [first_band.value, second_band.value]\n", "\n", " Map.add_landsat_ts_gif(\n", " roi=Map.user_roi,\n", " label=title.value,\n", " start_year=start_year.value,\n", " end_year=end_year.value,\n", " start_date=start_date,\n", " end_date=end_date,\n", " bands=bands.value.split('/'),\n", " font_color=font_color.value,\n", " frames_per_second=speed.value,\n", " font_size=font_size.value,\n", " add_progress_bar=add_progress_bar,\n", " progress_bar_color=progress_bar_color.value,\n", " download=True,\n", " apply_fmask=cloud.value,\n", " nd_bands=nd_bands,\n", " nd_threshold=nd_threshold.value,\n", " nd_palette=['black', nd_color.value],\n", " )\n", "\n", "\n", "create_gif.on_click(submit_clicked)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "output" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }