[ncl-talk] Bug in gsn_histogram
Mary Haley
haley at ucar.edu
Mon Mar 9 13:16:17 MDT 2015
Carl,
I've looked into this a bit, and wrote some tests of my own and looked at
your tests as well.
It's definitely the documentation that's wrong, because it's the *last*
interval that's unique, in the sense that it's the only interval where the
values are binned to that range if they are >= binMin and <= binMax.
All the other intervals are binned based on ">= binMin and < binMax"
I updated the "gsn" resource page and the "gsn_histogram" documentation to
reflect this.
I also added some examples to the gsn_histogram documentation to help
clarify how it works.
Thanks for bringing this to our attention.
--Mary
On Wed, Mar 4, 2015 at 6:49 AM, Carl Schreck <cjschrec at ncsu.edu> wrote:
> Thanks Mary. I hope it'll stay closer to the current code than to the
> current documentation. At least to my mind, it makes more sense group 1.00
> - 1.99 together than it does 1.01 - 2.00. But getting everything consistent
> is the most important thing!
>
> Carl
>
> On Tue, Mar 3, 2015 at 4:54 PM, Mary Haley <haley at ucar.edu> wrote:
>
>> Carl,
>>
>> I'll have to look into this. Thanks for taking the time to provide a fix.
>>
>> It's also possible that the documentation was written incorrectly,
>> because I know I created several tests for the histogram binning routines,
>> and the change you are suggesting will likely change the results of the
>> binning.
>>
>> It does seem like the routine should be changed to meet the
>> documentation, however.
>>
>> I'll keep you posted. The ticket for this is NCL-2167 for your reference.
>>
>> --Mary
>>
>>
>> On Tue, Mar 3, 2015 at 7:00 AM, Carl Schreck <cjschrec at ncsu.edu> wrote:
>>
>>> After some more testing, I figured out that it's a misalignment between
>>> the gsn_code and the documentation:
>>>
>>> http://www.ncl.ucar.edu/Document/Graphics/Resources/gsn.shtml#gsnHistogramBinIntervals
>>>
>>> It says that gsnHistogramBinIntervals of (/1,2,5,7/) would be binned as:
>>>
>>> 1 <= bin_1 <= 2
>>> 2 < bin_2 <= 5
>>> 5 < bin_3 <= 7
>>>
>>> But actually it's binning it as
>>>
>>> 1 <= bin_1 < 2
>>> 2 <= bin_2 < 5
>>> 5 <= bin_3 <= 7
>>>
>>> What I recommend is editing the code in compute_hist_vals in gsn_code.
>>> Change:
>>> ;
>>> ; Special tests for last interval are required.
>>> ;
>>> if(i.eq.(nbars-1)) then
>>> if(nbars.gt.1.and.new_binlocs(i).eq.new_binlocs(i-1)) then
>>> num_in_bins(j,i) = num(x(j,:).gt.new_binlocs(i).and. \
>>> x(j,:).le.new_binlocs(i+1))
>>> else
>>> num_in_bins(j,i) = num(x(j,:).ge.new_binlocs(i).and. \
>>> x(j,:).le.new_binlocs(i+1))
>>> end if
>>> else
>>> ;
>>> ; If the previous interval was not really an interval, but an exact
>>> ; bin value, then be careful not to count those values in the current
>>> ; interval.
>>> ;
>>> if(i.gt.0.and.new_binlocs(i).eq.new_binlocs(i-1)) then
>>> num_in_bins(j,i) = num(x(j,:).gt.new_binlocs(i).and. \
>>> x(j,:).lt.new_binlocs(i+1))
>>> else
>>> num_in_bins(j,i) = num(x(j,:).ge.new_binlocs(i).and. \
>>> x(j,:).lt.new_binlocs(i+1))
>>> end if
>>> end if
>>> end if
>>> ---------
>>> TO:
>>> ; If the previous interval was not really an interval, but an exact
>>> ; bin value, then be careful not to count those values in the current
>>> ; interval.
>>> ;
>>> if(i.gt.0.and.new_binlocs(i).eq.new_binlocs(i-1)) then
>>> num_in_bins(j,i) = num(x(j,:).gt.new_binlocs(i).and. \
>>> x(j,:).lt.new_binlocs(i+1))
>>> else
>>> num_in_bins(j,i) = num(x(j,:).ge.new_binlocs(i).and. \
>>> x(j,:).lt.new_binlocs(i+1))
>>> end if
>>> end if
>>> --------
>>> Essentially remove the special handling for the last bin. And then
>>> change the documentation to:
>>>
>>> 1 <= bin_1 < 2
>>> 2 <= bin_2 < 5
>>> 5 <= bin_3 < 7
>>>
>>> Let me know what you think of if you have further questions.
>>>
>>> Carl
>>>
>>>
>>> On Mon, Mar 2, 2015 at 3:40 PM, Carl Schreck <cjschrec at ncsu.edu> wrote:
>>>
>>>> Sorry to come back with another binning issue, but I've found a similar
>>>> problem in gsn_histogram.
>>>>
>>>> This time, the problem only happens with the right-most bin, and only
>>>> when the data can equal the bin boundary, such as with integer data.
>>>>
>>>> Here's some simple sample code and a plot. Notice how in the first
>>>> group of figures, when the data is a float, the bars move seamlessly to the
>>>> left as the range increases.
>>>>
>>>> In the second half of the figures, the data are integer, and sometimes
>>>> will equal the top boundary. In this case, the rightmost bar changes before
>>>> as a new bar is added to its right.
>>>>
>>>> Let me know if you have any questions or suggestions. Thanks!
>>>>
>>>> Carl
>>>>
>>>> --
>>>>
>>>> <http://www.cicsnc.org/>
>>>> <http://www.researcherid.com/rid/B-8711-2011>
>>>> * Cyclone <http://www.cyclonecenter.org/>*Center.org
>>>> <http://www.cyclonecenter.org/> *Carl J. Schreck III, PhD*
>>>> *Research Associate*
>>>> Cooperative Institute for Climate and Satellites NC
>>>> <http://www.cicsnc.org/>
>>>> North Carolina State University <http://ncsu.edu/>
>>>> NOAA's National Climatic Data Center <http://ncdc.noaa.gov/>
>>>> 151 Patton Ave, Asheville, NC 28801
>>>> e: cjschrec at ncsu.edu
>>>> o: +1 828 257 3140
>>>> Publications
>>>> <http://scholar.google.com/citations?hl=en&user=th8ONEcAAAAJ&view_op=list_works&sortby=pubdate>
>>>> monitor.cicsnc.org/mjo
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> <http://www.cicsnc.org/>
>>> <http://www.researcherid.com/rid/B-8711-2011>
>>> * Cyclone <http://www.cyclonecenter.org/>*Center.org
>>> <http://www.cyclonecenter.org/> *Carl J. Schreck III, PhD*
>>> *Research Associate*
>>> Cooperative Institute for Climate and Satellites NC
>>> <http://www.cicsnc.org/>
>>> North Carolina State University <http://ncsu.edu/>
>>> NOAA's National Climatic Data Center <http://ncdc.noaa.gov/>
>>> 151 Patton Ave, Asheville, NC 28801
>>> e: cjschrec at ncsu.edu
>>> o: +1 828 257 3140
>>> Publications
>>> <http://scholar.google.com/citations?hl=en&user=th8ONEcAAAAJ&view_op=list_works&sortby=pubdate>
>>> monitor.cicsnc.org/mjo
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
>
> --
>
> <http://www.cicsnc.org/>
> <http://www.researcherid.com/rid/B-8711-2011>
> * Cyclone <http://www.cyclonecenter.org/>*Center.org
> <http://www.cyclonecenter.org/> *Carl J. Schreck III, PhD*
> *Research Associate*
> Cooperative Institute for Climate and Satellites NC
> <http://www.cicsnc.org/>
> North Carolina State University <http://ncsu.edu/>
> NOAA's National Climatic Data Center <http://ncdc.noaa.gov/>
> 151 Patton Ave, Asheville, NC 28801
> e: cjschrec at ncsu.edu
> o: +1 828 257 3140
> Publications
> <http://scholar.google.com/citations?hl=en&user=th8ONEcAAAAJ&view_op=list_works&sortby=pubdate>
> monitor.cicsnc.org/mjo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150309/e25def1c/attachment.html
More information about the ncl-talk
mailing list