{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 01 - Getting watershed boundaries" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Region Selection and Map Preview with Ipyleaflet\n", "In this notebook, you will extract a selected watershed from the HydroSHEDS database (see the reference manual for more information on HydroSHEDS). A GeoJSON with the watershed boundaries will be available for download and usable for other tasks such as extracting meteorological data covered in the next notebooks." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Import the necessary libraries to format, send, and parse our returned results\n", "import os\n", "\n", "import birdy\n", "import geopandas as gpd\n", "import ipyleaflet\n", "import ipywidgets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you are running this locally (and not on the PAVICS-Hydro server), and your `notebook` is version prior to `5.3`, you might need to run this command `jupyter nbextension enable --py --sys-prefix ipyleaflet`. For more information see https://ipyleaflet.readthedocs.io/en/latest/installation.html.\n", "\n", "This next box is all boilerplate, you do not need to understand it or play with it. Simply run it! Many such code snippets are provided throughout the notebooks to make your life easier. You can then modify some options to taylor the code to your needs." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Create WPS instances# Set environment variable WPS_URL to \"http://localhost:9099\" to run on the default local server\n", "pavics_url = \"https://pavics.ouranos.ca\"\n", "raven_url = os.environ.get(\"WPS_URL\", f\"{pavics_url}/twitcher/ows/proxy/raven/wps\")\n", "\n", "raven = birdy.WPSClient(raven_url)\n", "\n", "# Build an interactive map with ipyleaflet\n", "initial_lat_lon = (48.63, -74.71)\n", "\n", "leaflet_map = ipyleaflet.Map(\n", " center=initial_lat_lon,\n", " basemap=ipyleaflet.basemaps.OpenTopoMap,\n", ")\n", "\n", "# Add a custom zoom slider\n", "zoom_slider = ipywidgets.IntSlider(description=\"Zoom level:\", min=1, max=10, value=6)\n", "ipywidgets.jslink((zoom_slider, \"value\"), (leaflet_map, \"zoom\"))\n", "widget_control1 = ipyleaflet.WidgetControl(widget=zoom_slider, position=\"topright\")\n", "leaflet_map.add_control(widget_control1)\n", "\n", "# Add a marker to the map\n", "marker = ipyleaflet.Marker(location=initial_lat_lon, draggable=True)\n", "leaflet_map.add_layer(marker)\n", "\n", "# Add an overlay widget\n", "html = ipywidgets.HTML(\"\"\"Hover over a feature!\"\"\")\n", "html.layout.margin = \"0px 10px 10px 10px\"\n", "\n", "control = ipyleaflet.WidgetControl(widget=html, position=\"bottomleft\")\n", "leaflet_map.add_control(control)\n", "\n", "\n", "def update_html(feature, **kwargs):\n", " html.value = \"\"\"\n", "