Skip to content

Wind barb rounding bug #4385

Closed as not planned
Closed as not planned

Description

@jblarsen

When I make wind barbs with rounding enabled and custom barb increments I noticed that there were no wind barbs with half barbs above 2 full barbs. The reason seems to be a bug in the _find_tails method. The bug only surfaces when the barb increments are set to non-integer values.

I believe the reason for the bug is the float comparison (half_flag = mag >= half) where the value is rounded to a value very close to/identical to the 'half' increment. And it seems like python does the right thing when the "half" increment is a whole number but not always when it is not.

This example should give True for the "half" increment:

    barb_incs = {'half': 0.44444,
                 'full': 1.0,
                 'flag': 5.0}
    mag = np.array([1.5])
    num_flags, num_barb, half_flag, empty_flag =  _find_tails(None, mag, rounding=True, **barb_incs)
    print half_flag # Should be True

where _find_tails is copied from matplotlib:

import numpy as np

def _find_tails(self, mag, rounding=True, half=5, full=10, flag=50):
    '''
    Find how many of each of the tail pieces is necessary.  Flag
    specifies the increment for a flag, barb for a full barb, and half for
    half a barb. Mag should be the magnitude of a vector (ie. >= 0).

    This returns a tuple of:

        (*number of flags*, *number of barbs*, *half_flag*, *empty_flag*)

    *half_flag* is a boolean whether half of a barb is needed,
    since there should only ever be one half on a given
    barb. *empty_flag* flag is an array of flags to easily tell if
    a barb is empty (too low to plot any barbs/flags.
    '''

    #If rounding, round to the nearest multiple of half, the smallest
    #increment
    if rounding:
        mag = half * (mag / half + 0.5).astype(np.int)

    num_flags = np.floor(mag / flag).astype(np.int)
    mag = np.mod(mag, flag)

    num_barb = np.floor(mag / full).astype(np.int)
    mag = np.mod(mag, full)

    half_flag = mag >= half
    empty_flag = ~(half_flag | (num_flags > 0) | (num_barb > 0))

    return num_flags, num_barb, half_flag, empty_flag

I believe that a fix is to change:
mag = half * (mag / half + 0.5).astype(np.int)
to:
mag = half * (mag / half + 0.5).astype(np.int) + small_number

but I am not sure how to get small_number. Should it be based on the dtype of "mag"?

Activity

  1. tacaswell commented on Apr 27, 2015

    @tacaswell
    Member
  2. self-assigned this
    on Apr 27, 2015
  3. dopplershift commented on Aug 1, 2015

    @dopplershift
    Contributor

    I think the actual problem is caused by the fact that full and flag are not multiples of half. The order of processing for 1.5 is:

    1. Round to multiple of 0.44444: mag = 1.33332
    2. Find flags: 0
    3. Subtract flag: mag = 1.33332
    4. Find full: 1
    5. Subtract full: mag = 0.33332
    6. Check against half: half_flag = False

    I can't decide if rounding at each step is a good idea or not. It might better just to enforce half as 0.5 * full. I wrote it, and I don't even remember why setting half is an option.

    Anyone have an opinion?

  4. added this to the milestone on Feb 15, 2016
  5. modified the milestones: , on Oct 3, 2017
  6. github-actions commented on Mar 12, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  7. jklymak commented on Mar 12, 2023

    @jklymak
    Member

    The code looks like it only allows one half barb, in which case, it had best be forced to be half a full barb. One could imagine allowing more than one half barb, eg if half = 1/3, you would have one or two half barbs, but since that is not currently the case, it should be forced to 0.5 * full.

    The work here would be to remove half from the dict in the docs, and enforce it being set to 0.5 * full, or to allow more than one half flag, but still enforce that full / half is an integer.

  8. github-actions commented on Mar 13, 2024

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  9. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Action

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions