{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open\n", "\n", "Uncomment the following line to install [geemap](https://geemap.org) and [cartopy](https://scitools.org.uk/cartopy/docs/latest/installing.html#installing) if needed. Keep in mind that cartopy can be challenging to install. If you are unable to install cartopy on your computer, you can try Google Colab with this the [notebook example](https://colab.research.google.com/github/giswqs/geemap/blob/master/examples/notebooks/cartoee_colab.ipynb). \n", "\n", "See below the commands to install cartopy and geemap using conda/mamba:\n", "\n", "```\n", "conda create -n carto python=3.8\n", "conda activate carto\n", "conda install mamba -c conda-forge\n", "mamba install cartopy scipy -c conda-forge\n", "mamba install geemap -c conda-forge\n", "jupyter notebook\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install cartopy scipy\n", "# !pip install geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Creating publication-quality maps with multiple Earth Engine layers" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap\n", "from geemap import cartoee\n", "import cartopy.crs as ccrs\n", "\n", "%pylab inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create an interactive map" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "image = ee.ImageCollection('MODIS/MCD43A4_006_NDVI') \\\n", " .filter(ee.Filter.date('2018-04-01', '2018-05-01')) \\\n", " .select(\"NDVI\")\\\n", " .first()\n", "\n", "vis_params = {\n", " 'min': 0.0,\n", " 'max': 1.0,\n", " 'palette': [\n", " 'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',\n", " '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',\n", " '012E01', '011D01', '011301'\n", " ],\n", "}\n", "Map.setCenter(-7.03125, 31.0529339857, 2)\n", "Map.addLayer(image, vis_params, 'MODIS NDVI')\n", "\n", "countries = ee.FeatureCollection('users/giswqs/public/countries')\n", "style = {\n", " \"color\": \"00000088\",\n", " \"width\": 1,\n", " \"fillColor\": \"00000000\"}\n", "Map.addLayer(countries.style(**style), {}, \"Countries\")\n", "\n", "ndvi = image.visualize(**vis_params)\n", "blend = ndvi.blend(countries.style(**style))\n", "\n", "Map.addLayer(blend, {}, \"Blend\")\n", "\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot an image with the default projection" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# specify region to focus on\n", "bbox = [-180, -88, 180, 88]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(figsize=(15,10))\n", "\n", "# plot the result with cartoee using a PlateCarre projection (default)\n", "ax = cartoee.get_map(blend, region=bbox)\n", "cb = cartoee.add_colorbar(ax, vis_params=vis_params, loc='right')\n", "\n", "ax.set_title(label='MODIS NDVI', fontsize = 15)\n", "\n", "# ax.coastlines()\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot an image with a different projection" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(figsize=(15,10))\n", "\n", "projection = ccrs.EqualEarth(central_longitude=-180)\n", "\n", "# plot the result with cartoee using a PlateCarre projection (default)\n", "ax = cartoee.get_map(blend, region=bbox, proj=projection)\n", "cb = cartoee.add_colorbar(ax, vis_params=vis_params, loc='right')\n", "\n", "ax.set_title(label='MODIS NDVI', fontsize=15)\n", "\n", "# ax.coastlines()\n", "plt.show()" ] } ], "metadata": { "hide_input": false, "kernel_info": { "name": "python3" }, "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" }, "nteract": { "version": "0.12.3" }, "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 }