Repository navigation
Description
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
tacaswell commentedon Apr 27, 2015
attn @dopplershift
dopplershift commentedon Aug 1, 2015
I think the actual problem is caused by the fact that
fullandflagare not multiples ofhalf. The order of processing for 1.5 is:0.44444:mag = 1.333320flag:mag = 1.333321full:mag = 0.33332half:half_flag = FalseI can't decide if rounding at each step is a good idea or not. It might better just to enforce
halfas0.5 * full. I wrote it, and I don't even remember why setting half is an option.Anyone have an opinion?
github-actions commentedon Mar 12, 2023
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!
jklymak commentedon Mar 12, 2023
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.
github-actions commentedon Mar 13, 2024
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!