{ "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://gishub.org/timelapse, https://gishub.org/gee-ngrok\n", "\n", "**Contact:** Dr. Qiusheng Wu ([Website](https://wetlands.io/), [LinkedIn](https://www.linkedin.com/in/qiushengwu), [Twitter](https://twitter.com/giswqs), [YouTube](https://www.youtube.com/c/QiushengWu))" ] }, { "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:',\n", " value='Landsat Timelapse',\n", " width=200,\n", " style=style\n", ")\n", "\n", "bands = widgets.Dropdown(\n", " description='Select RGB Combo:',\n", " options=['Red/Green/Blue', 'NIR/Red/Green', 'SWIR2/SWIR1/NIR', 'NIR/SWIR1/Red','SWIR2/NIR/Red', \n", " 'SWIR2/SWIR1/Red', 'SWIR1/NIR/Blue', 'NIR/SWIR1/Blue', 'SWIR2/NIR/Green', 'SWIR1/NIR/Red'],\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,\n", " description='Apply fmask (remove clouds, shadows, snow)',\n", " style=style\n", ")\n", "\n", "hbox2 = widgets.HBox([speed, cloud])\n", "hbox2" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "start_year = widgets.IntSlider(description='Start Year:', value=1984, min=1984, max=2020, style=style)\n", "end_year = widgets.IntSlider(description='End Year:', value=2020, min=1984, max=2020, style=style)\n", "start_month = widgets.IntSlider(description='Start Month:', value=5, min=1, max=12, style=style)\n", "end_month = widgets.IntSlider(description='End Month:', value=10, min=1, max=12, style=style)\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(description='Font size:', value=30, min=10, max=50, style=style)\n", "\n", "font_color = widgets.ColorPicker(\n", " concise=False,\n", " description='Font color:',\n", " value='white',\n", " style=style\n", ")\n", "\n", "progress_bar_color = widgets.ColorPicker(\n", " concise=False,\n", " description='Progress bar color:',\n", " value='blue',\n", " 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 = ['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", "nd_indices = widgets.Dropdown(options=nd_options, value=None, description='Normalized Difference Index:', style=style)\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,\n", " description='Color:',\n", " value='blue',\n", " style=style\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", "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", " \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(roi=Map.user_roi, label=title.value, start_year=start_year.value, \n", " end_year=end_year.value, start_date=start_date, end_date=end_date, \n", " bands=bands.value.split('/'), font_color=font_color.value, \n", " frames_per_second=speed.value, font_size=font_size.value, \n", " add_progress_bar= add_progress_bar, progress_bar_color=progress_bar_color.value, \n", " download=True, apply_fmask=cloud.value, nd_bands=nd_bands, \n", " nd_threshold=nd_threshold.value, nd_palette=['black', nd_color.value]) \n", " \n", "create_gif.on_click(submit_clicked)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "output" ] } ], "metadata": { "hide_input": true, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": true, "title_cell": "Table of Contents", "title_sidebar": "Table of Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }