Skip to content
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

Reduce Number of Wind Barbs for SkewT plot #99

Open
ghost opened this issue Nov 5, 2015 · 8 comments
Open

Reduce Number of Wind Barbs for SkewT plot #99

ghost opened this issue Nov 5, 2015 · 8 comments
Labels
Area: Plots Pertains to producing plots Type: Enhancement Enhancement to existing functionality

Comments

@ghost
Copy link

ghost commented Nov 5, 2015

An added feature of MetPy that would be great would be to have a way to plot fewer wind barbs based on whether there is a wind barb close by.

koun_1999050318_skewt

Currently, the quick fix is to just plot every other or every third wind barb, but that doesn't really achieve the goal when there are four right on top of each other and then potentially getting rid of desired wind barbs elsewhere.

koun_1999050318_skewt_fewer_barbs

@dopplershift dopplershift added the Type: Enhancement Enhancement to existing functionality label Nov 5, 2015
@dopplershift
Copy link
Member

I agree this is a nice to have. I think it's going to require digging into matplotlib to get the underlying collection object to handle such stuff at draw time. So not trivial, but very useful.

@ahaberlie
Copy link
Contributor

I wrote a function and tested it on the simple and advanced sounding notebooks. It takes corresponding lists of pressure, u-wind, and v-wind and returns only those data closest to each step in a user defined interval. By default, I set this to every 50 mb between 1000 mb and 100 mb. This is all done on the front-end so it could be an acceptable alternative until a permanent back-end solution is implemented. Could potentially make it more generalized so it could accept very specific intervals.

def pressure_interval(p,u,v,upper=100,lower=1000,spacing=50):

    intervals = list(range(upper,lower,spacing))

    ix = []
    for center in intervals:
        index = (np.abs(p-center)).argmin()
        if index not in ix:
            ix.append(index)

    return p[ix],u[ix],v[ix]

You would use it like this:

#If p has units
#p_,u_,v_ = pressure_interval(p.magnitude,u,v)

p_,u_,v_ = pressure_interval(p,u,v)
skew.plot_barbs(p_,u_,v_)

defined_interval_barbs

@dopplershift
Copy link
Member

I like the idea of having a generic version of this function (not specific to u, v or even pressure). It's essentially nearest neighbor resampling, but keeping the original coordinates. @ahaberlie would you be willing to submit a PR with the generic version?

I think this function might even work to underpin a future dynamic downsample--though the more I think about how the matplotlib part of barbs works (one polygon collection) that sounds even more complicated.

@ahaberlie
Copy link
Contributor

Sure. If you have an idea in mind where you need a nearest neighbor from a large array, it might be a better idea to use scipy.spatial's KDTree (http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.spatial.KDTree.html), as the looping in this function would not scale very well. I was initially thinking about using KDTree but decided that it would be overkill for this specific application. Thoughts?

@dopplershift
Copy link
Member

If the interface is properly done, then KDTree vs. loop is purely an implementation detail. I'd be happy to have a KDTree version, but it seems like you have something useful already.

I do anticipate needing a kdtree-based reduction for things like surface data, but I don't think that will be taking a set of coordinates.

@jrleeman
Copy link
Contributor

What about the barbs that plot off the top of the plot? Should anything about 100 hPa be axed from the data prior to plotting?

@dopplershift
Copy link
Member

My only hesitation with something like that (which would have to be a plot parameter or setting on the SkewT) is panning/zooming--and it would break with standard matplotlib. Matplotlib's usual solution is clipping, but that could lead to partial barbs...ugh.

Geez, right now the best solution that comes to mind is a patch to matplotlib to clip based on polygon positions (like scatter plot center points or barb pivot points). Other suggestions?

@dopplershift
Copy link
Member

And to be clear, I think we currently clip, just beyond the top. (I think)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Plots Pertains to producing plots Type: Enhancement Enhancement to existing functionality
Projects
None yet
Development

No branches or pull requests

3 participants