-
-
Notifications
You must be signed in to change notification settings - Fork 113
Expose windbarbs #1711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ahuang11
wants to merge
10
commits into
main
Choose a base branch
from
expose_windbarbs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Expose windbarbs #1711
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6288baa
Expose windbarbs
ahuang11 252828b
Bug fix and tweak
ahuang11 c4a1bd9
Add import guard
ahuang11 3d51c29
rm unnecessary change
ahuang11 767e060
rm unnecessary change
ahuang11 f0c626b
address review
ahuang11 f311293
fix
ahuang11 dae45b5
dynamically add barbs
ahuang11 9dae4fa
Fix tests
ahuang11 892ea29
Add error handling for both
ahuang11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "c73d803c-a005-496f-9812-7eb414ce6449", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Wind Barbs\n", | ||
| "\n", | ||
| "A wind barbs plot showing wind speed and direction using meteorological wind barb symbols.\n", | ||
| "\n", | ||
| ":::{note}\n", | ||
| "Wind barb plots require `geoviews` to be installed.\n", | ||
| ":::" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "ac5ea091-6484-4fc8-9852-d48acd90cc74", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import hvplot.xarray # noqa\n", | ||
| "import numpy as np\n", | ||
| "import xarray as xr\n", | ||
| "\n", | ||
| "def sample_wind_data(shape=(20, 30)):\n", | ||
| " x = np.linspace(311.9, 391.1, shape[1])\n", | ||
| " y = np.linspace(-23.6, 24.8, shape[0])\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", | ||
| " return x, y, u, v\n", | ||
| "\n", | ||
| "xs, ys, U, V = sample_wind_data()\n", | ||
| "# Calculate magnitude and angle for wind barbs\n", | ||
| "mag = np.sqrt(U**2 + V**2)\n", | ||
| "angle = (np.pi/2.) - np.arctan2(U/mag, V/mag)\n", | ||
| "\n", | ||
| "ds = xr.Dataset({\n", | ||
| " 'speed': xr.DataArray(mag, dims=('y', 'x'), coords={'y': ys, 'x': xs}),\n", | ||
| " 'angle': xr.DataArray(angle, dims=('y', 'x'), coords={'y': ys, 'x': xs})\n", | ||
| "})\n", | ||
| "\n", | ||
| "ds.hvplot.windbarbs(\n", | ||
| " x='x',\n", | ||
| " y='y',\n", | ||
| " angle='angle',\n", | ||
| " mag='speed',\n", | ||
| " color='speed',\n", | ||
| " cmap='viridis',\n", | ||
| " colorbar=True,\n", | ||
| " title='Wind Barbs Plot',\n", | ||
| " width=700,\n", | ||
| " height=400\n", | ||
| ")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "4f0cd955-3e03-42a5-b581-f828036e1716", | ||
| "metadata": {}, | ||
| "source": [ | ||
| ":::{seealso}\n", | ||
| "- [Wind Barbs reference documentation](../../ref/api/manual/hvplot.hvPlot.barbs.ipynb).\n", | ||
| ":::" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "language_info": { | ||
| "name": "python", | ||
| "pygments_lexer": "ipython3" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# hvPlot.windbarbs\n", | ||
| "\n", | ||
| "```{eval-rst}\n", | ||
| ".. currentmodule:: hvplot\n", | ||
| "\n", | ||
| ".. automethod:: hvPlot.windbarbs\n", | ||
| "```\n", | ||
| "\n", | ||
| ":::{note}\n", | ||
| "Wind barb plots require `geoviews` to be installed.\n", | ||
| ":::\n", | ||
| "\n", | ||
| "## Backend-specific styling options\n", | ||
| "\n", | ||
| "```{eval-rst}\n", | ||
| ".. backend-styling-options:: windbarbs\n", | ||
| "```\n", | ||
| "\n", | ||
| "## Examples\n", | ||
| "\n", | ||
| "### Basic wind barbs plot\n", | ||
| "\n", | ||
| "In this example we create a simple DataFrame with 4 columns `x`, `y`, `angle` and `speed`. `x` and `y` represent the location of the wind barbs. `angle` defines the wind direction expressed in radians (meteorological convention: direction FROM which the wind is blowing, with 0 being North). `speed` defines the wind speed magnitude." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import hvplot.pandas\n", | ||
| "import pandas as pd\n", | ||
| "import numpy as np\n", | ||
| "\n", | ||
| "df = pd.DataFrame(dict(\n", | ||
| " x=[0, -1, 0, 1, 0, 1, 1, -1, -1],\n", | ||
| " y=[0, 0, -1, 0, 1, 1, -1, -1, 1],\n", | ||
| " angle=[0, 0, np.pi/2, np.pi, 3*np.pi/2, np.pi/4, np.pi/3, np.pi/6, np.pi/8],\n", | ||
| " speed=[0, 5, 10, 15, 20, 50, 75, 100, 150],\n", | ||
| "))\n", | ||
| "\n", | ||
| "df.hvplot.windbarbs(\n", | ||
| " x=\"x\", y=\"y\", angle=\"angle\", mag=\"speed\",\n", | ||
| " data_aspect=1, padding=0.2, width=400, height=400,\n", | ||
| ")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "### Xarray example\n", | ||
| "\n", | ||
| "In this example we show how to create a barb plot using Xarray data with hvPlot." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import hvplot.xarray # noqa\n", | ||
| "import numpy as np\n", | ||
| "import xarray as xr\n", | ||
| "\n", | ||
| "def sample_wind_data(shape=(20, 30)):\n", | ||
| " x = np.linspace(311.9, 391.1, shape[1])\n", | ||
| " y = np.linspace(-23.6, 24.8, shape[0])\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", | ||
| " return x, y, u, v\n", | ||
| "\n", | ||
| "xs, ys, U, V = sample_wind_data()\n", | ||
| "mag = np.sqrt(U**2 + V**2)\n", | ||
| "angle = (np.pi/2.) - np.arctan2(U/mag, V/mag)\n", | ||
| "ds = xr.Dataset({\n", | ||
| " 'speed': xr.DataArray(mag, dims=('y', 'x'), coords={'y': ys, 'x': xs}),\n", | ||
| " 'angle': xr.DataArray(angle, dims=('y', 'x'), coords={'y': ys, 'x': xs})\n", | ||
| "})\n", | ||
| "\n", | ||
| "ds.hvplot.windbarbs(\n", | ||
| " x='x', y='y', angle='angle', mag='speed',\n", | ||
| " width=700, height=400, scale=0.3\n", | ||
| ")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "### Geographic example with Xarray\n", | ||
| "\n", | ||
| "The `xarray.Dataset` constructed in this example has a `'crs'` key in its `attrs` dictionary, which lets us simply set `geo=True` to turn this plot into a correctly projected geographic plot overlaid on web map tiles." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import cartopy.crs as ccrs\n", | ||
| "import hvplot.xarray # noqa\n", | ||
| "import numpy as np\n", | ||
| "import xarray as xr\n", | ||
| "\n", | ||
| "def sample_data(shape=(20, 30)):\n", | ||
| " \"\"\"\n", | ||
| " Return ``(x, y, u, v, crs)`` of some vector data computed mathematically.\n", | ||
| " The returned crs will be a rotated pole CRS, meaning that the vectors\n", | ||
| " will be unevenly spaced in regular PlateCarree space.\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", | ||
| " 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", | ||
| " 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(U/mag, V/mag)\n", | ||
| "ds = xr.Dataset(\n", | ||
| " {\n", | ||
| " 'speed': xr.DataArray(mag, dims=('y', 'x'), coords={'y': ys, 'x': xs}),\n", | ||
| " 'angle': xr.DataArray(angle, dims=('y', 'x'), coords={'y': ys, 'x': xs})\n", | ||
| " },\n", | ||
| " attrs={'crs': crs},\n", | ||
| ")\n", | ||
| "\n", | ||
| "ds.hvplot.windbarbs(\n", | ||
| " x=\"x\", y=\"y\", angle=\"angle\", mag=\"speed\",\n", | ||
| " geo=True, tiles=\"CartoLight\", width=700, height=400\n", | ||
| ").opts(\"WindBarbs\", scale=0.3)" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "language_info": { | ||
| "name": "python", | ||
| "pygments_lexer": "ipython3" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 4 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.