-
Notifications
You must be signed in to change notification settings - Fork 300
Add barbs plot #3710
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
Merged
Merged
Add barbs plot #3710
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a702f66
Add plot and gallery example
jonseddon 627ab4c
Add a what's new
jonseddon b8a3603
Added test and reduced size of gallery example
jonseddon 1b60559
Painted it black
jonseddon a8eab8f
Added test to imagerepo.json but name of file in repo will be wrong
jonseddon 05d43ca
Correct hash inserted
jonseddon 0b2d3fe
Correctly resolved merge conflict
jonseddon d72fcea
Hopefully fully compliant with new style gallery now
jonseddon fba7ab8
Consistency with new style documentation
jonseddon 564312b
Improved language as Lake Victoria is not relevant and shorelines are…
jonseddon 4303bde
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c99fa2a
Clarify units
jonseddon 69ff70d
Correct function name.
jonseddon 5d67a67
Test vector plots
jonseddon 7a8808d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4e300b4
isort:skip
jonseddon d671c27
Docstring note now visible in Sphinx output
jonseddon 310eaa2
Merge branch 'barbs' of github.com:jonseddon/iris into barbs
jonseddon 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,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 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,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 | ||
|
|
||
| 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 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
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
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.