comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: There is NO TRUTH! Re: Histogram Hot-shots Required
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: There is NO TRUTH! Re: Histogram Hot-shots Required [message #16346] Tue, 20 July 1999 00:00
eddie haskell is currently offline  eddie haskell
Messages: 29
Registered: September 1998
Junior Member
David Fanning wrote:

> More evidence that the apocalypse is upon us....
<snip>
> ; Liam's method 1:
> binNum1 = FLOOR((value - Min(array)) / binsize)
>
> ; Eddie's method:
> binNum4 =(where(R ge ((where(((where(array eq value))[0]) eq $
> R[R[0]:*]))[0]+R[0])))[0]

Well this had me confused for a bit. I admit I came up with this method
friday evening sitting in a local pub drinking lager but it seemed it
should have been fool proof as all the information was given and no
rounding of any kind needed to be done. After doing a quick check I
realised I had made a slight omission in my thinking and forgot about
the possiblity of cells with zero elements (shows what drinking can do
to those brain cells). If I change the GE in my method to GT and
subtract 1 off the end, this method then seems to produce the same
results as Liam's solution and your brute force method, i.e.:

binNum6 =(where(R GT ((where(((where(array eq value))[0]) eq $
R[R[0]:*]))[0]+R[0])))[0]-1

I admit this looks much more messy than Liam's solution and probably
takes longer to execute but I wanted to correct my mistake just for
completeness. I am glad that you solved your problem and also wonder
what the original error in the histogram function was.

Cheers,
eddie

----- ---- --- --- ---- --- -- --- --- -- -- - - - -
|\ A G Edward Haskell
|\ Center for Coastal Physical Oceanography
|\ Old Dominion University, Norfolk VA 23529
|\ Voice 757.683.4816 Fax 757.683.5550
|\ e-mail haskell*ccpo.odu.edu
----- ---- --- ---- --- --- --- --- -- -- -- - - - -
Re: There is NO TRUTH! Re: Histogram Hot-shots Required [message #16349 is a reply to message #16346] Tue, 20 July 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Liam Gumley (Liam.Gumley@ssec.wisc.edu) writes:

> The following procedure from the Astronomy library seems to do a pretty
> good job of computing and plotting histograms:
> http://www.astro.washington.edu/deutsch-bin/getpro/library01 .html?PLOTHIST

I tried this in my application. Indeed, it does a
*pretty* good job, but it is not always accurate.
I found it about as accurate as ROUNDing the
bin number.

I think most people who have struggled with this
problem have realized that the PLOT command in
Histogram mode (PSYM=10) is about half a bin
from what you really want. In other words,
the histogram "bar" is not positioned over the
values that are in that particular bin, but is
offset by half a bin size.

Some people correct this by adding half a binsize
to the bins when they draw the plot:

PLOT, bins+binsize/2, Histogram(data)

That is close enough for government work, but
it doesn't cut it when you need complete accuracy.
I think you would only really discover that this
method *wasn't* accurate if you are drawing the
real value on the graph, as I was in this application.
This would be especially true if your histogram
was fairly smooth. Mine happened to be missing
certain values, which made the problem especially
apparent to me.

I'm really of the mind that the only way to solve
this problem is to hand-draw your own histogram bars
at the edges of the actual bin values.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: There is NO TRUTH! Re: Histogram Hot-shots Required [message #16352 is a reply to message #16346] Tue, 20 July 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Liam Gumley (Liam.Gumley@ssec.wisc.edu) writes:

> Sounds like we need a nice histogram plotting procedure: any takers?

Uh, I'm busy this morning. :-(

> I'd keep the protection against integer binsize values by converting to
> a float, e.g.
>
> bin_index = (pixel_value - histogram_min_value) / FLOAT(binsize)
> bin_index = FLOOR(bin_index)
>
> and then to protect against pixel values LT histogram minimum value, or
> GE histogram maximum value
>
> bin_index = (bin_index > 0L) < (number_of_bins - 1L)

Liam's absolutely right here. And, of course, I had this in
my *real* code, even if I didn't have it in the demo I showed
here. :-)

> I'm very fond of testing algorithms on paper before I implement them in
> code. I tested the method shown above with a few examples on a notepad,
> so I was 99% sure it would work. My advice to those starting out in IDL
> is this: even though IDL offers a wonderful range of time-saving
> shortcuts (e.g. HISTOGRAM), it often pays to do a reality-check on paper
> before coding up an algorithm.

Testing algorithms is probably a great idea, but
truthfully, I solved this problem by using IDL! The
best and most powerful feature of IDL is the ability
to *see* what you are doing. I could literally see
the pixels I was selecting (by turning them green) and
count the suckers. A couple of lines of code here and
there brought the visual problem into sharp focus.

I thought it odd, too, that the problem turned out
to be a graphical problem. That is the *last* place
I was looking for it. (I thought sure it was buried
deep in reverse indices. :-) But what I like about IDL
is that once I knew what the problem was, I was able
to fix it in one line of code. You gotta like that!

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: There is NO TRUTH! Re: Histogram Hot-shots Required [message #16353 is a reply to message #16346] Tue, 20 July 1999 00:00 Go to previous message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
Liam Gumley wrote:
> Sounds like we need a nice histogram plotting procedure: any takers?

Note to self: before proposing new IDL routines, check the existing IDL
user libraries:
http://www.astro.washington.edu/deutsch/idl/htmlhelp/index.h tml

The following procedure from the Astronomy library seems to do a pretty
good job of computing and plotting histograms:
http://www.astro.washington.edu/deutsch-bin/getpro/library01 .html?PLOTHIST

For example:

data = dist(256)
plothist, data, bin=2.0

Cheers,
Liam.

--
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
Re: There is NO TRUTH! Re: Histogram Hot-shots Required [message #16354 is a reply to message #16346] Tue, 20 July 1999 00:00 Go to previous message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
David Fanning wrote:
> Forget it, problem solved. The bottom line: draw
> your own *&%@# histogram plots with the PLOTS command.
>
> Best method is:
>
> ; Liam's method 1:
>
> binNum1 = FLOOR((value - Min(array)) / binsize)
>
> But you have to draw your *OWN* histogram plots, or
> your graphical representation will *never* look like
> what it is suppose to look like:
>
> Plot, bins, histdata, /NoData, XRange=range, XStyle=1
> FOR j=0,N_Elements(bins)-2 DO BEGIN
> PlotS, [bins[j], bins[j], bins[j+1], bins[j+1]], $
> [0, histdata[j], histdata[j], 0], Color=yellow
> ENDFOR
> PLOTS, [value, value], !Y.CRange

Sounds like we need a nice histogram plotting procedure: any takers?

I'd keep the protection against integer binsize values by converting to
a float, e.g.

bin_index = (pixel_value - histogram_min_value) / FLOAT(binsize)
bin_index = FLOOR(bin_index)

and then to protect against pixel values LT histogram minimum value, or
GE histogram maximum value

bin_index = (bin_index > 0L) < (number_of_bins - 1L)

I'm very fond of testing algorithms on paper before I implement them in
code. I tested the method shown above with a few examples on a notepad,
so I was 99% sure it would work. My advice to those starting out in IDL
is this: even though IDL offers a wonderful range of time-saving
shortcuts (e.g. HISTOGRAM), it often pays to do a reality-check on paper
before coding up an algorithm.

Cheers,
Liam.

--
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
Re: There is NO TRUTH! Re: Histogram Hot-shots Required [message #16360 is a reply to message #16346] Tue, 20 July 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Incidentally, in case anyone is wondering. This little programming
conundrum--normally executed in private, but done here under the full
glare of public scrutiny--is how one *becomes* an IDL expert. :-)

Cheers,

David

P.S. Let's just say I dare you to ask me a question about
histogram plots.

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: There is NO TRUTH! Re: Histogram Hot-shots Required [message #16361 is a reply to message #16346] Tue, 20 July 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
David Fanning (davidf@dfanning.com) writes:

> More evidence that the apocalypse is upon us....

Forget it, problem solved. The bottom line: draw
your own *&%@# histogram plots with the PLOTS command.

Best method is:

; Liam's method 1:

binNum1 = FLOOR((value - Min(array)) / binsize)

But you have to draw your *OWN* histogram plots, or
your graphical representation will *never* look like
what it is suppose to look like:

Plot, bins, histdata, /NoData, XRange=range, XStyle=1
FOR j=0,N_Elements(bins)-2 DO BEGIN
PlotS, [bins[j], bins[j], bins[j+1], bins[j+1]], $
[0, histdata[j], histdata[j], 0], Color=yellow
ENDFOR
PLOTS, [value, value], !Y.CRange

Whew! Now I *WILL* have a beer.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Seeking IDL Programmers with Interests in Coastal Oceanography/Geology
Next Topic: Re: CALL_EXTERNAL failure.

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 06:03:07 PDT 2025

Total time taken to generate the page: 0.00557 seconds