{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "You will need to install the following packages:\n", "- `ipyleaflet`\n", "- `requests`\n", "- `xarray`\n", "- `netcdf4`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipyleaflet import Map, TileLayer, basemaps\n", "from ipyleaflet.velocity import Velocity\n", "import xarray as xr" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "center = [44.33956524809713, -130.60546875000003]\n", "zoom = 3\n", "m = Map(\n", " center=center,\n", " zoom=zoom,\n", " interpolation=\"nearest\",\n", " basemap=basemaps.CartoDB.DarkMatter,\n", ")\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "if not os.path.exists(\"wind-global.nc\"):\n", " url = \"https://github.com/benbovy/xvelmap/raw/master/notebooks/wind-global.nc\"\n", " import requests\n", "\n", " r = requests.get(url)\n", " wind_data = r.content\n", " with open(\"wind-global.nc\", \"wb\") as f:\n", " f.write(wind_data)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ds = xr.open_dataset(\"wind-global.nc\")\n", "ds" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "display_options = {\n", " \"velocityType\": \"Global Wind\",\n", " \"displayPosition\": \"bottomleft\",\n", " \"displayEmptyString\": \"No wind data\",\n", "}\n", "wind = Velocity(\n", " data=ds,\n", " zonal_speed=\"u_wind\",\n", " meridional_speed=\"v_wind\",\n", " latitude_dimension=\"lat\",\n", " longitude_dimension=\"lon\",\n", " velocity_scale=0.01,\n", " max_velocity=20,\n", " display_options=display_options,\n", ")\n", "m.add(wind)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.11" } }, "nbformat": 4, "nbformat_minor": 4 }