{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap\n", "from geemap import cartoee\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.ee_initialize()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Get image\n", "lon = -115.1585\n", "lat = 36.1500\n", "start_year = 1984\n", "end_year = 2011\n", "\n", "point = ee.Geometry.Point(lon, lat)\n", "years = ee.List.sequence(start_year, end_year)\n", "\n", "def get_best_image(year): \n", "\n", " start_date = ee.Date.fromYMD(year, 1, 1)\n", " end_date = ee.Date.fromYMD(year, 12, 31)\n", " image = ee.ImageCollection(\"LANDSAT/LT05/C01/T1_SR\") \\\n", " .filterBounds(point) \\\n", " .filterDate(start_date, end_date) \\\n", " .sort(\"CLOUD_COVER\") \\\n", " .first() \n", " return ee.Image(image)\n", "\n", "collection = ee.ImageCollection(years.map(get_best_image))\n", "\n", "\n", "vis_params = {\n", " \"bands\": ['B4', 'B3', 'B2'],\n", " \"min\": 0,\n", " \"max\": 5000\n", "}\n", "\n", "image = ee.Image(collection.first())" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "w = 0.4\n", "h = 0.3\n", "\n", "region = [lon-w, lat-h, lon+w, lat+h]\n", "\n", "fig = plt.figure(figsize=(10, 8))\n", "\n", "# use cartoee to get a map\n", "ax = cartoee.get_map(image, region=region, vis_params=vis_params)\n", "\n", "# add gridlines to the map at a specified interval\n", "cartoee.add_gridlines(ax, interval=[0.2, 0.2], linestyle=\":\")\n", "\n", "# add north arrow\n", "north_arrow_dict = {\n", " \"text\": \"N\",\n", " \"xy\": (0.10, 0.36),\n", " \"arrow_length\": 0.15,\n", " \"text_color\": \"white\",\n", " \"arrow_color\": \"white\",\n", " \"fontsize\": 20,\n", " \"width\": 5,\n", " \"headwidth\": 15,\n", " \"ha\": \"center\",\n", " \"va\": \"center\"\n", "}\n", "cartoee.add_north_arrow(ax, **north_arrow_dict)\n", "\n", "# add scale bar\n", "scale_bar_dict = {\n", " 'metric_distance': 4,\n", " 'unit': \"km\",\n", " 'at_x':(0.05, 0.2),\n", " 'at_y':(0.08, 0.11),\n", " 'max_stripes': 5,\n", " 'ytick_label_margins': 0.25,\n", " 'fontsize': 8,\n", " 'font_weight': \"bold\",\n", " 'rotation': 0,\n", " 'zorder': 999,\n", " 'paddings': {\"xmin\": 0.05, \"xmax\": 0.05, \"ymin\": 1.5, \"ymax\": 0.5},\n", "}\n", "\n", "cartoee.add_scale_bar(ax, **scale_bar_dict)\n", "\n", "ax.set_title(label = 'Las Vegas, NV', fontsize=15)\n", "plt.show()" ] } ], "metadata": { "gist": { "data": { "description": "examples/notebooks/Untitled.ipynb", "public": true }, "id": "" }, "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": false, "title_cell": "Table of Contents", "title_sidebar": "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 }