{ "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", "\n", "def get_best_image(year):\n", " start_date = ee.Date.fromYMD(year, 1, 1)\n", " end_date = ee.Date.fromYMD(year, 12, 31)\n", " image = (\n", " ee.ImageCollection(\"LANDSAT/LT05/C01/T1_SR\")\n", " .filterBounds(point)\n", " .filterDate(start_date, end_date)\n", " .sort(\"CLOUD_COVER\")\n", " .first()\n", " )\n", " return ee.Image(image)\n", "\n", "\n", "collection = ee.ImageCollection(years.map(get_best_image))\n", "\n", "\n", "vis_params = {\"bands\": ['B4', 'B3', 'B2'], \"min\": 0, \"max\": 5000}\n", "\n", "image = ee.Image(collection.first())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }