{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import geoviews as gv\n", "import cartopy.crs as ccrs\n", "\n", "gv.extension('bokeh')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def sample_data(shape=(20, 30)):\n", " \"\"\"\n", " Return ``(x, y, u, v, crs)`` of some vector data\n", " computed mathematically. The returned crs will be a rotated\n", " pole CRS, meaning that the vectors will be unevenly spaced in\n", " regular PlateCarree space.\n", "\n", " \"\"\"\n", " crs = ccrs.RotatedPole(pole_longitude=177.5, pole_latitude=37.5)\n", "\n", " x = np.linspace(311.9, 391.1, shape[1])\n", " y = np.linspace(-23.6, 24.8, shape[0])\n", "\n", " x2d, y2d = np.meshgrid(x, y)\n", " u = 10 * (2 * np.cos(2 * np.deg2rad(x2d) + 3 * np.deg2rad(y2d + 30)) ** 2)\n", " v = 20 * np.cos(6 * np.deg2rad(x2d))\n", "\n", " return x, y, u, v, crs\n", "\n", "xs, ys, U, V, crs = sample_data()\n", "mag = np.sqrt(U**2 + V**2)\n", "angle = np.pi / 2 - np.arctan2(-V, -U)\n", "tiles = gv.tile_sources.OSM\n", "vectorfield = gv.VectorField((xs, ys, angle, mag), crs=crs)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tiles * vectorfield.opts(magnitude='Magnitude', width=600, height=500, padding=0.1)" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }