{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "![Saudia XYZ logo](http://alasmari.net/saudia-logo.png)\n", "***Code:*** create landsat timelapse
\n", "***Main Source:*** geemap
\n", "***Edited by:*** Saudia.xyz\n", "\n", "Uncomment the following line to install geemap if needed." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# !pip install geemap" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create Landsat timeseries" ] }, { "cell_type": "code", "execution_count": 113, "metadata": {}, "outputs": [], "source": [ "import os\n", "import ee\n", "import geemap" ] }, { "cell_type": "code", "execution_count": 114, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1db602e2fd8c439786a0360dc94b8808", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Map(center=[24.7169, 46.6755], controls=(WidgetControl(options=['position', 'transparent_bg'], widget=HBox(chiā€¦" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Map = geemap.Map(center=(24.7169, 46.6755), zoom=10)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define an roi or draw a rectangle on the map" ] }, { "cell_type": "code", "execution_count": 116, "metadata": {}, "outputs": [], "source": [ "roi = ee.Geometry.Polygon(\n", " [[[46.4502, 24.4809],\n", " [46.9680, 24.4734],\n", " [46.9584, 25.0221],\n", " [46.4694, 24.9873]]], None, False)" ] }, { "cell_type": "code", "execution_count": 117, "metadata": {}, "outputs": [], "source": [ "#roi = Map.draw_last_feature" ] }, { "cell_type": "code", "execution_count": 118, "metadata": {}, "outputs": [], "source": [ "collection = geemap.landsat_timeseries(roi=roi, start_year=1985, end_year=2021, start_date='06-10', end_date='09-20')" ] }, { "cell_type": "code", "execution_count": 119, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "37\n" ] } ], "source": [ "print(collection.size().getInfo())" ] }, { "cell_type": "code", "execution_count": 120, "metadata": {}, "outputs": [], "source": [ "first_image = collection.first()\n", "\n", "vis = {\n", " 'bands': ['NIR', 'Red', 'Green'],\n", " 'min': 0,\n", " 'max': 4000,\n", " 'gamma': [1, 1, 1]\n", "}\n", "\n", "Map.addLayer(first_image, vis, 'First image')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download ImageCollection as a GIF" ] }, { "cell_type": "code", "execution_count": 121, "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": 122, "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": 123, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Generating URL...\n", "Downloading GIF image from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/videoThumbnails/dd60057a4dd5cdbb72959825183e603f-e7de6052cd68016428d5b9bbd439d5ea:getPixels\n", "Please wait ...\n", "The GIF image has been saved to: C:\\Users\\alasm\\Downloads\\landsat_ts.gif\n" ] } ], "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": 124, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "55947c3a909e4e1a9104fddbfe438659", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "geemap.show_image(out_gif)" ] }, { "cell_type": "code", "execution_count": 128, "metadata": {}, "outputs": [], "source": [ "texted_gif = os.path.join(work_dir, \"landsat_ts_text.gif\")\n", "geemap.add_text_to_gif(out_gif, texted_gif, xy=('3%', '5%'), text_sequence=1985, font_size=30, font_color='#000000', add_progress_bar=False)" ] }, { "cell_type": "code", "execution_count": 129, "metadata": {}, "outputs": [], "source": [ "label = 'Urban Growth in Riyadh'\n", "geemap.add_text_to_gif(texted_gif, texted_gif, xy=('2%', '88%'), text_sequence=label, font_size=30, font_color='#000000', progress_bar_color='cyan')" ] }, { "cell_type": "code", "execution_count": 130, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "fc4d1e933fcd4e0f85a8633c107ff33c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "geemap.show_image(texted_gif)" ] } ], "metadata": { "hide_input": false, "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.9.4" }, "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 }