-
Notifications
You must be signed in to change notification settings - Fork 413
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
Wind barb plotting bug fix #1918
Conversation
Hmmm, we had been getting rid of the units when going to plot with So instead we could modify in station_plot.py on line 331-334 if plotting_units:
if hasattr(u, 'units') and hasattr(v, 'units'):
u = u.to(plotting_units).magnitude
v = v.to(plotting_units).magnitude Then we should also be able to remove lines 339-341 as we wouldn't need to strip any units at that point. |
24ea1dc
to
d8b4f57
Compare
@kgoebber I relocated some of my changes to The latest commit here modifies |
Handle arrays of Pint objects when plotting wind barbs
So after digging in some more with @23ccozad, the root cause here really is that |
This is why we have tests and great that we have that nightly test build! |
Background: The nightly build has been failing due to an error occurring in
test_declarative_station_plot_fontsize()
, which recently merged into the main branch. That test passed all checks when it was in PR #1899 before merging, where NumPy 1.20.3 and Pandas 1.2.4 were being used. The nightly build is running tests with NumPy 1.21.0rc2 and Pandas 1.3.0rc1, and this error is occurring with those versions.Problem (from the MetPy perspective): The problem is related to plotting wind barbs. The last point of contact the stack trace has in MetPy is in
StationPlot
'splot_barb()
method where we callbarbs()
on the matplotlib axes. I figured that might be the best place to start working on a solution. For this particular test, I found that we currently pass these variables tobarbs()
:x
: A NumPy array of x-coordinates for locations of the wind barbsy
: A NumPy array of y-coordinates for locations of the wind barbsu
: A NumPy array of Pint quantity objects containing the u-components of the wind vectorsv
: A NumPy array of Pint quantity objects containing the v-components of the wind vectorsIt turns out that if we just have the magnitudes of the components
u
andv
in the NumPy array, instead of the entire Pint object, then we avoid this error.It is worth noting that there are 15 other plotting tests use
plot_barb()
, and none of them had an error because they already had NumPy arrays of floats, rather than Pint objects, foru
andv
. I think the reason for this is thattest_declarative_station_plot_fontsize()
is the only test usingparse_metar_file()
to get surface wind data for plotting. This parsing method provides columnseastward_wind
andnorthward_wind
that contain Pint objects, and these end up being used foru
andv
.Solution: The suggested changes here will remove the units from the NumPy arrays passed to
u
andv
, only if needed. The only thing I'm hesitant about with this is addingfrom ..units import units
just to resolve a bug fix. Maybe there is another approach without needing that import.Checklist