|
36 | 36 | },
|
37 | 37 | {
|
38 | 38 | "cell_type": "code",
|
39 |
| - "execution_count": 1, |
| 39 | + "execution_count": null, |
40 | 40 | "id": "5a65137f",
|
41 | 41 | "metadata": {},
|
42 |
| - "outputs": [], |
| 42 | + "outputs": [ |
| 43 | + { |
| 44 | + "ename": "", |
| 45 | + "evalue": "", |
| 46 | + "output_type": "error", |
| 47 | + "traceback": [ |
| 48 | + "\u001b[1;31mJupyter cannot be started. Error attempting to locate Jupyter: Running cells with 'Python 3.13.0 64-bit' requires jupyter and notebook package.\n", |
| 49 | + "\u001b[1;31mRun the following command to install 'jupyter and notebook' into the Python environment. \n", |
| 50 | + "\u001b[1;31mCommand: 'python -m pip install jupyter notebook -U\n", |
| 51 | + "\u001b[1;31mor\n", |
| 52 | + "\u001b[1;31mconda install jupyter notebook -U'\n", |
| 53 | + "\u001b[1;31mClick <a href='https://aka.ms/installJupyterForVSCode'>here</a> for more info." |
| 54 | + ] |
| 55 | + } |
| 56 | + ], |
43 | 57 | "source": [
|
44 | 58 | "import os\n",
|
45 | 59 | "from io import BytesIO\n",
|
|
57 | 71 | "import xml.etree.ElementTree as xmlet\n",
|
58 | 72 | "import lxml.etree as xmltree\n",
|
59 | 73 | "from PIL import Image as plimg\n",
|
| 74 | + "from PIL import ImageDraw\n", |
60 | 75 | "import numpy as np\n",
|
| 76 | + "import pandas as pd\n", |
61 | 77 | "from owslib.wms import WebMapService\n",
|
62 | 78 | "from IPython.display import Image, display\n",
|
63 | 79 | "import rasterio\n",
|
|
67 | 83 | "from rasterio.mask import mask\n",
|
68 | 84 | "from rasterio.warp import calculate_default_transform, reproject, Resampling\n",
|
69 | 85 | "import fiona\n",
|
| 86 | + "from datetime import datetime, timedelta\n", |
70 | 87 | "%matplotlib inline"
|
71 | 88 | ]
|
72 | 89 | },
|
|
989 | 1006 | "m"
|
990 | 1007 | ]
|
991 | 1008 | },
|
| 1009 | + { |
| 1010 | + "cell_type": "markdown", |
| 1011 | + "id": "8b567f79", |
| 1012 | + "metadata": {}, |
| 1013 | + "source": [ |
| 1014 | + "### Animated Web Map with WMS\n", |
| 1015 | + "\n", |
| 1016 | + "<DIV align=\"left\" style=\"line-height:1.5em;\">\n", |
| 1017 | + "<p>\n", |
| 1018 | + "\n", |
| 1019 | + "The next example shows how to display IMERG_Precipitation_Rate layer in an animated web map (may require additional Python libraries). \n", |
| 1020 | + "\n", |
| 1021 | + "</p>\n", |
| 1022 | + "</DIV>" |
| 1023 | + ] |
| 1024 | + }, |
| 1025 | + { |
| 1026 | + "cell_type": "code", |
| 1027 | + "execution_count": null, |
| 1028 | + "id": "2b7d7657", |
| 1029 | + "metadata": {}, |
| 1030 | + "outputs": [], |
| 1031 | + "source": [ |
| 1032 | + "wms = WebMapService('https://gibs.earthdata.nasa.gov/wms/epsg4326/best/wms.cgi?', version='1.3.0')\n", |
| 1033 | + "\n", |
| 1034 | + "layers = ['MODIS_Aqua_CorrectedReflectance_TrueColor',\n", |
| 1035 | + " 'IMERG_Precipitation_Rate',\n", |
| 1036 | + " 'Reference_Features',\n", |
| 1037 | + " 'Reference_Labels']\n", |
| 1038 | + "color = 'rgb(255,255,255)'\n", |
| 1039 | + "frames = []\n", |
| 1040 | + "\n", |
| 1041 | + "start_date = datetime(2022, 9, 25)\n", |
| 1042 | + "end_date = datetime(2022, 10, 1)\n", |
| 1043 | + "dates = pd.date_range(start_date,end_date-timedelta(days=1),freq='d')\n", |
| 1044 | + "\n", |
| 1045 | + "for day in dates:\n", |
| 1046 | + " datatime = day.strftime(\"%Y-%m-%d\")\n", |
| 1047 | + " img = wms.getmap(layers=layers, # Layers\n", |
| 1048 | + " srs='epsg:4326', # Map projection\n", |
| 1049 | + " bbox=(-87, 18, -72, 35), # Bounds\n", |
| 1050 | + " size=(600,600), # Image size\n", |
| 1051 | + " time=datatime, # Time of data\n", |
| 1052 | + " format='image/png', # Image format\n", |
| 1053 | + " transparent=True) # Nodata transparency\n", |
| 1054 | + "\n", |
| 1055 | + " image = plimg.open(img)\n", |
| 1056 | + " draw = ImageDraw.Draw(image)\n", |
| 1057 | + " (x, y) = (50, 20)\n", |
| 1058 | + " draw.text((x, y), f'IMERG Precipitation Rate - {datatime}', fill=color)\n", |
| 1059 | + " frames.append(image)\n", |
| 1060 | + " \n", |
| 1061 | + "frames[0].save('IMERG_Precipitation_Rate_Ian.gif',\n", |
| 1062 | + " format='GIF',\n", |
| 1063 | + " append_images=frames,\n", |
| 1064 | + " save_all=True,\n", |
| 1065 | + " duration=1000,\n", |
| 1066 | + " loop=0)\n", |
| 1067 | + "\n", |
| 1068 | + "Image('IMERG_Precipitation_Rate_Ian.gif')" |
| 1069 | + ] |
| 1070 | + }, |
992 | 1071 | {
|
993 | 1072 | "attachments": {},
|
994 | 1073 | "cell_type": "markdown",
|
|
1912 | 1991 | "print('')"
|
1913 | 1992 | ]
|
1914 | 1993 | },
|
| 1994 | + { |
| 1995 | + "cell_type": "markdown", |
| 1996 | + "id": "d5e46225", |
| 1997 | + "metadata": {}, |
| 1998 | + "source": [ |
| 1999 | + "<a id=\"visualize_wmts_raster_data\"></a>\n", |
| 2000 | + "\n", |
| 2001 | + "### Visualize WMTS Raster Data By Cartopy\n", |
| 2002 | + "\n", |
| 2003 | + "<DIV align=\"left\" style=\"line-height:1.5em;\">\n", |
| 2004 | + "<p>\n", |
| 2005 | + " \n", |
| 2006 | + "This example shows how to display WMTS raster data on a map using Cartopy.\n", |
| 2007 | + " \n", |
| 2008 | + "</p>\n", |
| 2009 | + "</DIV>" |
| 2010 | + ] |
| 2011 | + }, |
| 2012 | + { |
| 2013 | + "cell_type": "code", |
| 2014 | + "execution_count": null, |
| 2015 | + "id": "50131451", |
| 2016 | + "metadata": {}, |
| 2017 | + "outputs": [], |
| 2018 | + "source": [ |
| 2019 | + "# Define the WMTS URL\n", |
| 2020 | + "wmts_url = \"https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/wmts.cgi\"\n", |
| 2021 | + "\n", |
| 2022 | + "# Create a map with PlateCarree projection\n", |
| 2023 | + "ax = plt.axes(projection=ccrs.PlateCarree())\n", |
| 2024 | + "ax.set_extent([-180, 180, -90, 90]) # World extent\n", |
| 2025 | + "\n", |
| 2026 | + "# Add WMTS layer with a specific date\n", |
| 2027 | + "layer = \"VIIRS_SNPP_SurfaceReflectance_BandsM11-M7-M5\"\n", |
| 2028 | + "time = \"2023-01-01\"\n", |
| 2029 | + "ax.add_wmts(wmts_url, layer_name=layer, wmts_kwargs={\"time\": time})\n", |
| 2030 | + "\n", |
| 2031 | + "plt.title('Land Surface Reflectance (Bands M11-M7-M5, Best Available, VIIRS, Suomi NPP)')\n", |
| 2032 | + "plt.show()" |
| 2033 | + ] |
| 2034 | + }, |
1915 | 2035 | {
|
1916 | 2036 | "attachments": {},
|
1917 | 2037 | "cell_type": "markdown",
|
|
3694 | 3814 | ],
|
3695 | 3815 | "metadata": {
|
3696 | 3816 | "celltoolbar": "Raw Cell Format",
|
3697 |
| - "interpreter": { |
3698 |
| - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" |
3699 |
| - }, |
3700 | 3817 | "kernelspec": {
|
3701 |
| - "display_name": "Python 3.10.4 64-bit", |
| 3818 | + "display_name": "Python 3.13.0 ('gibsPythonNotebook2')", |
| 3819 | + "language": "python", |
3702 | 3820 | "name": "python3"
|
3703 | 3821 | },
|
3704 | 3822 | "language_info": {
|
|
3711 | 3829 | "name": "python",
|
3712 | 3830 | "nbconvert_exporter": "python",
|
3713 | 3831 | "pygments_lexer": "ipython3",
|
3714 |
| - "version": "3.10.4 (v3.10.4:9d38120e33, Mar 23 2022, 17:29:05) [Clang 13.0.0 (clang-1300.0.29.30)]" |
| 3832 | + "version": "3.13.0" |
| 3833 | + }, |
| 3834 | + "vscode": { |
| 3835 | + "interpreter": { |
| 3836 | + "hash": "cd6b7991ad4bc00fdd3e8f0f0395227ccb9271f102bce6443e69587a933de936" |
| 3837 | + } |
3715 | 3838 | }
|
3716 | 3839 | },
|
3717 | 3840 | "nbformat": 4,
|
|
0 commit comments