{ "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": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.show_youtube('OwjSJnGWKJs')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Update the geemap package\n", "\n", "If you run into errors with this notebook, please uncomment the line below to update the [geemap](https://github.com/giswqs/geemap#installation) package to the latest version from GitHub. \n", "Restart the Kernel (Menu -> Kernel -> Restart) to take effect." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# geemap.update_package()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create an interactive map\n", "\n", "### Use the Drawing tool to draw a rectangle on the map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate a Landsat timelapse animation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "out_dir = os.path.join(os.path.expanduser(\"~\"), 'Downloads')\n", "if not os.path.exists(out_dir):\n", " os.makedirs(out_dir)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "label = 'Urban Growth in Las Vegas'\n", "Map.add_landsat_ts_gif(\n", " label=label,\n", " start_year=1985,\n", " bands=['Red', 'Green', 'Blue'],\n", " font_color='white',\n", " frames_per_second=10,\n", " progress_bar_color='blue',\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create Landsat timeseries" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import ee\n", "import geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You and define an roi or draw a rectangle on the map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = ee.Geometry.Polygon(\n", " [\n", " [\n", " [-115.471773, 35.892718],\n", " [-115.471773, 36.409454],\n", " [-114.271283, 36.409454],\n", " [-114.271283, 35.892718],\n", " [-115.471773, 35.892718],\n", " ]\n", " ],\n", " None,\n", " False,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# roi = Map.draw_last_feature" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "collection = geemap.landsat_timeseries(\n", " roi=roi, start_year=1985, end_year=2019, start_date='06-10', end_date='09-20'\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(collection.size().getInfo())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "first_image = collection.first()\n", "\n", "vis = {'bands': ['NIR', 'Red', 'Green'], 'min': 0, 'max': 4000, 'gamma': [1, 1, 1]}\n", "\n", "Map.addLayer(first_image, vis, 'First image')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download ImageCollection as a GIF" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Define arguments for animation function parameters.\n", "video_args = {\n", " 'dimensions': 768,\n", " 'region': roi,\n", " 'framesPerSecond': 10,\n", " 'bands': ['NIR', 'Red', 'Green'],\n", " 'min': 0,\n", " 'max': 4000,\n", " 'gamma': [1, 1, 1],\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "work_dir = os.path.join(os.path.expanduser(\"~\"), 'Downloads')\n", "if not os.path.exists(work_dir):\n", " os.makedirs(work_dir)\n", "out_gif = os.path.join(work_dir, \"landsat_ts.gif\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.download_ee_video(collection, video_args, out_gif)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Add animated text to GIF" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.show_image(out_gif)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "texted_gif = os.path.join(work_dir, \"landsat_ts_text.gif\")\n", "geemap.add_text_to_gif(\n", " out_gif,\n", " texted_gif,\n", " xy=('3%', '5%'),\n", " text_sequence=1985,\n", " font_size=30,\n", " font_color='#ffffff',\n", " add_progress_bar=False,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "label = 'Urban Growth in Las Vegas'\n", "geemap.add_text_to_gif(\n", " texted_gif,\n", " texted_gif,\n", " xy=('2%', '88%'),\n", " text_sequence=label,\n", " font_size=30,\n", " font_color='#ffffff',\n", " progress_bar_color='cyan',\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.show_image(texted_gif)" ] } ], "metadata": { "hide_input": false, "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": true }, "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 }