-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add plot and gallery example * Add a what's new * Added test and reduced size of gallery example * Painted it black * Added test to imagerepo.json but name of file in repo will be wrong * Correct hash inserted * Correctly resolved merge conflict * Hopefully fully compliant with new style gallery now * Consistency with new style documentation * Improved language as Lake Victoria is not relevant and shorelines are not included in this simulated data. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Clarify units * Correct function name. * Test vector plots * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * isort:skip Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com> * Docstring note now visible in Sphinx output Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com>
- Loading branch information
1 parent
d4d0514
commit 619c62c
Showing
6 changed files
with
197 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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,62 @@ | ||
""" | ||
Plotting Wind Direction Using Barbs | ||
=================================== | ||
This example demonstrates using barbs to plot wind speed contours and wind | ||
direction barbs from wind vector component input data. The vector components | ||
are co-located in space in this case. | ||
The magnitude of the wind in the original data is low and so doesn't illustrate | ||
the full range of barbs. The wind is scaled to simulate a storm that better | ||
illustrates the range of barbs that are available. | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
import iris | ||
import iris.plot as iplt | ||
import iris.quickplot as qplt | ||
|
||
|
||
def main(): | ||
# Load the u and v components of wind from a pp file | ||
infile = iris.sample_data_path("wind_speed_lake_victoria.pp") | ||
|
||
uwind = iris.load_cube(infile, "x_wind") | ||
vwind = iris.load_cube(infile, "y_wind") | ||
|
||
uwind.convert_units("knot") | ||
vwind.convert_units("knot") | ||
|
||
# To illustrate the full range of barbs, scale the wind speed up to pretend | ||
# that a storm is passing over | ||
magnitude = (uwind ** 2 + vwind ** 2) ** 0.5 | ||
magnitude.convert_units("knot") | ||
max_speed = magnitude.collapsed( | ||
("latitude", "longitude"), iris.analysis.MAX | ||
).data | ||
max_desired = 65 | ||
|
||
uwind = uwind / max_speed * max_desired | ||
vwind = vwind / max_speed * max_desired | ||
|
||
# Create a cube containing the wind speed | ||
windspeed = (uwind ** 2 + vwind ** 2) ** 0.5 | ||
windspeed.rename("windspeed") | ||
windspeed.convert_units("knot") | ||
|
||
plt.figure() | ||
|
||
# Plot the wind speed as a contour plot | ||
qplt.contourf(windspeed) | ||
|
||
# Add wind barbs except for the outermost values which overhang the edge | ||
# of the plot if left | ||
iplt.barbs(uwind[1:-1, 1:-1], vwind[1:-1, 1:-1], pivot="middle", length=6) | ||
|
||
plt.title("Wind speed during a simulated storm") | ||
qplt.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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,30 @@ | ||
# Copyright Iris contributors | ||
# | ||
# This file is part of Iris and is released under the LGPL license. | ||
# See COPYING and COPYING.LESSER in the root of the repository for full | ||
# licensing details. | ||
|
||
# Import Iris tests first so that some things can be initialised before | ||
# importing anything else. | ||
import iris.tests as tests # isort:skip | ||
|
||
from .gallerytest_util import ( | ||
add_gallery_to_path, | ||
fail_any_deprecation_warnings, | ||
show_replaced_by_check_graphic, | ||
) | ||
|
||
|
||
class TestWindBarbs(tests.GraphicsTest): | ||
"""Test the wind_barbs example code.""" | ||
|
||
def test_wind_barbs(self): | ||
with fail_any_deprecation_warnings(): | ||
with add_gallery_to_path(): | ||
import plot_wind_barbs | ||
with show_replaced_by_check_graphic(self): | ||
plot_wind_barbs.main() | ||
|
||
|
||
if __name__ == "__main__": | ||
tests.main() |
This file contains 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 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 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 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