{ "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, Velocity, TileLayer\n", "import requests\n", "import xarray as xr\n", "import os" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "center = [0, 0]\n", "zoom = 1\n", "m = Map(center=center, zoom=zoom, interpolation='nearest')\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tl = TileLayer(url='https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png')\n", "m.add_layer(tl)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "if not os.path.exists('wind-global.nc'):\n", " url = 'https://github.com/benbovy/xvelmap/raw/master/notebooks/wind-global.nc'\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", "display_options = {\n", " 'velocityType': 'Global Wind',\n", " 'displayPosition': 'bottomleft',\n", " 'displayEmptyString': 'No wind data'\n", "}\n", "wind = Velocity(data=ds, u_var='u_wind', v_var='v_wind', lat_dim='lat', lon_dim='lon', velocity_scale=0.01, max_velocity=20, display_options=display_options)\n", "m.add_layer(wind)" ] } ], "metadata": { "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.6.3" } }, "nbformat": 4, "nbformat_minor": 2 }