[ncl-talk] Bug in gsn_histogram
Carl Schreck
cjschrec at ncsu.edu
Tue Mar 3 07:00:18 MST 2015
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150303/bf444281/attachment.html
More information about the ncl-talk
mailing list