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

Home » Public Forums » archive » Re: Log-scaled colorbar example
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: Log-scaled colorbar example [message #76215] Tue, 24 May 2011 08:34
Kim is currently offline  Kim
Messages: 19
Registered: January 2009
Junior Member
On May 24, 11:27 am, David Fanning <n...@idlcoyote.com> wrote:
> Kim writes:
>> I think I was able to reproduce your colorbar and generate a similar
>> graphic as the example I provided above.  I did find an error in the
>> original code with the tickmarks and added /xlog to the plot command.
>> I would appreciate you opinion on the following example.
>
> This seems to be working correctly now. Can you make
> a general purpose routine out of it, so it can be
> called as, say, a function?
>

That is my plan, but it will probably take some time make it versatile
and completely functional.
Kim
Re: Log-scaled colorbar example [message #76217 is a reply to message #76215] Tue, 24 May 2011 08:27 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kim writes:

> I think I was able to reproduce your colorbar and generate a similar
> graphic as the example I provided above. I did find an error in the
> original code with the tickmarks and added /xlog to the plot command.
> I would appreciate you opinion on the following example.

This seems to be working correctly now. Can you make
a general purpose routine out of it, so it can be
called as, say, a function?

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Log-scaled colorbar example [message #76220 is a reply to message #76217] Tue, 24 May 2011 07:56 Go to previous message
Kim is currently offline  Kim
Messages: 19
Registered: January 2009
Junior Member
> Can you reproduce this figure and color bar with your
> code? (I haven't been able to, but I've spent less than
> an hour trying.) When you can reproduce this figure, then
> I think you are on the right track.


> Cheers,


> David



I think I was able to reproduce your colorbar and generate a similar
graphic as the example I provided above. I did find an error in the
original code with the tickmarks and added /xlog to the plot command.
I would appreciate you opinion on the following example.
Thank you for your assistance,
Kim

; Read image
image = cgDemoData(7) ; World Elevation Data
image = Scale_Vector(image, 1, 2500L)
logImage = Alog10(image)
X = FLOAT([MIN(IMAGE),MAX(IMAGE)])
XLOG = [MIN(LOGIMAGE),MAX(LOGIMAGE)]


; Create the color bar image
PX = 200 & PY = 20
RGB_TABLE=33
COLOR_RANGE = [0.0,255.0]
NCOLORS = COLOR_RANGE(1) - COLOR_RANGE(0) + 1
SARR = X(0)+((X(1)-X(0))/
256)*FINDGEN(256) ; scale the array to 256
intervals (adapted from the jhuapl routine maken)
Z = REFORM(((SARR - X(0))*FLOAT(COLOR_RANGE(1)-COLOR_RANGE(0))/(X(1)-
X(0)) + COLOR_RANGE(0)),[256,1])<255 ; adapted from the jhuapl
routine scalearray
XX = FIX(COLOR_RANGE(0)+((COLOR_RANGE(1)-COLOR_RANGE(0))/
(NCOLORS-1))*FINDGEN(PX)) ; create a scaled x
array
YY = FIX(COLOR_RANGE(0)+((COLOR_RANGE(1)-COLOR_RANGE(0))/
(NCOLORS-1))*FINDGEN(PY)) ; create a scaled y
array
BARARR = INTERPOLATE(Z,XX,YY,/
GRID) ; interpolate to fill in the
image array

; Linear example
W = WINDOW(DIMENSIONS=[800,800],LAYOUT=[2,1,1])
IMG = IMAGE(IMAGE,RGB_TABLE=RGB_TABLE,/
CURRENT,LAYOUT=[2,1,1],TITLE='Linear')
CB = COLORBAR(TARGET=IMG,TITLE='IDL')
POS =
CB.POSITION ;
determine position for the second colorbar
POS(1) = pos(1)-.1
POS(3) = POS(3)-.1
BARIMG = IMAGE(BARARR,/
CURRENT,POSITION=POS,RGB_TABLE=RGB_TABLE) ; diplay the bar image
then overplot the tick values
P = PLOT(X,
[0,1],POSITION=POS,XRANGE=X,YRANGE=[0,1],XTICKLEN=0.25,MIN_V ALUE=X(0),MAX_V­
ALUE=X(1),XMINOR=4,YMINOR=0,YMAJOR=0,XTITLE='CUSTOM',/NODATA ,/
CURRENT,AXIS_STYLE=1)


; Log example
IMG2 = IMAGE(LOGIMAGE,RGB_TABLE=RGB_TABLE,/
CURRENT,LAYOUT=[2,1,2],TITLE='Log Scales')
CB = COLORBAR(TARGET=IMG2,TITLE='IDL')
POS = CB.POSITION
POS(1) = pos(1)-.1
POS(3) = POS(3)-.1
BARIMG = IMAGE(BARARR,/CURRENT,POSITION=POS,RGB_TABLE=RGB_TABLE)
P = PLOT(XLOG,[0,1],/
XLOG,POSITION=POS,XRANGE=X,YRANGE=[0,1],XTICKLEN=0.25,MIN_VA LUE=X(0),MAX_VA­
LUE=(1),XMINOR=4,YMINOR=0,YMAJOR=0,XTITLE='CUSTOM',/NODATA,/
CURRENT,AXIS_STYLE=1)
Re: Log-scaled colorbar example [message #76251 is a reply to message #76220] Mon, 23 May 2011 08:37 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kim writes:

> After several unsuccessful attempts at trying to generate a log-scaled
> colorbar using the COLORBAR function, I came up with a way to manually
> create the colorbar. If someone could please look at the code and let
> me know if this seems correct I would really appreciate it.

Well, your plots are beautiful, but I am not sure they
are correct. :-)

Here is code that I *know* produces the correct result:

image = cgDemoData(7) ; World Elevation Data
image = Scale_Vector(image, 1, 2500L)
logImage = Alog10(image)
s = Size(image, /Dimensions)
cgDisplay, 600, 400, Title='Logarithmic Color Bar'
LoadCT, 33, /Silent, NColors=254
pos = [0.1, 0.1, 0.8, 0.9]
cgImage, BytScl(logImage, Top=253), Position=pos, /Keep_Aspect
cgPlot, [0], [0], /NoErase, XRange=[0,s[0]], YRange=[0,s[1]], $
XStyle=1, YStyle=1, Color=cgColor('black', 255), Position=pos
cgColorbar, /YLOG, YTICKS=0, Range=[Min(image), Max(image)], $
NColors=254, Color=cgColor('black', 255), /Vertical
END

How do I know? I can check it.

IDL> cgImageInfo, image

You can click in the graphics window and the image position
and value will be printed in the command log. (Right click
to exit the cgImageInfo program.) You can clearly see that
the image value corresponds to the colors on the color bar.

Can you reproduce this figure and color bar with your
code? (I haven't been able to, but I've spent less than
an hour trying.) When you can reproduce this figure, then
I think you are on the right track.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Log-scaled colorbar example [message #76252 is a reply to message #76251] Mon, 23 May 2011 07:41 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> Well, hang on, I can't even create a simple plot this morning.
> The only thing I have done so far is change my !DLM_DIR. But
> that has seemed to cause some havoc.
>
> Let me see if I can figure this out. :-(

My fault, I guess. There was some confusion about
which version of IDL I was running. Setting everything
back to "defaults", then trying to set my !DLM_PATH
again in IDL 8.1 has seemed to work.

Anyway, your code runs fine now. Looks good. :-)

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Log-scaled colorbar example [message #76253 is a reply to message #76252] Mon, 23 May 2011 07:26 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> I can't get the first part of the program to run. In fact, I can't
> get past the first line in the program that creates the graphics
> window

Well, hang on, I can't even create a simple plot this morning.
The only thing I have done so far is change my !DLM_DIR. But
that has seemed to cause some havoc.

Let me see if I can figure this out. :-(

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Log-scaled colorbar example [message #76254 is a reply to message #76253] Mon, 23 May 2011 07:21 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kim writes:

> After several unsuccessful attempts at trying to generate a log-scaled
> colorbar using the COLORBAR function, I came up with a way to manually
> create the colorbar. If someone could please look at the code and let
> me know if this seems correct I would really appreciate it.

I can't get the first part of the program to run. In fact, I can't
get past the first line in the program that creates the graphics
window. I'm running IDL 8.1. :-(

IDL> .go
% Attempt to call undefined procedure/function: 'AXIS_PROPERTIES'.
% Error occurred at: GRAPHIC 22 C:\Program Files\ITT\IDL
\IDL80\lib\graphics\graphic_error.pro
% WINDOW 35 C:\Program Files\ITT\IDL
\IDL80\lib\graphics\window.pro
% $MAIN$ 1 C:\IDL\coyote_8\cbar_example_
1.pro
% Execution halted at: $MAIN$ 1 C:\IDL\coyote_8
\cbar_example_1.pro

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Log-scaled colorbar example [message #84615 is a reply to message #76251] Tue, 24 May 2011 07:42 Go to previous message
Kim is currently offline  Kim
Messages: 19
Registered: January 2009
Junior Member
>
> Can you reproduce this figure and color bar with your
> code? (I haven't been able to, but I've spent less than
> an hour trying.) When you can reproduce this figure, then
> I think you are on the right track.
>
> Cheers,
>
> David
>

I think I was able to reproduce your colorbar and generate a similar
graphic as the example I provided above. I did find an error in the
original code with the tickmarks and added /xlog to the plot command.
I would appreciate you opinion on the following example.
Thank you for your assistance,
Kim

; Read image
image = cgDemoData(7) ; World Elevation Data
image = Scale_Vector(image, 1, 2500L)
logImage = Alog10(image)
X = FLOAT([MIN(IMAGE),MAX(IMAGE)])
XLOG = [MIN(LOGIMAGE),MAX(LOGIMAGE)]

; Create the color bar image
PX = 200 & PY = 20
RGB_TABLE=33
COLOR_RANGE = [0.0,255.0]
NCOLORS = COLOR_RANGE(1) - COLOR_RANGE(0) + 1
SARR = X(0)+((X(1)-X(0))/
256)*FINDGEN(256) ; scale the array to 256
intervals (adapted from the jhuapl routine maken)
Z = REFORM(((SARR - X(0))*FLOAT(COLOR_RANGE(1)-COLOR_RANGE(0))/(X(1)-
X(0)) + COLOR_RANGE(0)),[256,1])<255 ; adapted from the jhuapl
routine scalearray
XX = FIX(COLOR_RANGE(0)+((COLOR_RANGE(1)-COLOR_RANGE(0))/
(NCOLORS-1))*FINDGEN(PX)) ; create a scaled x
array
YY = FIX(COLOR_RANGE(0)+((COLOR_RANGE(1)-COLOR_RANGE(0))/
(NCOLORS-1))*FINDGEN(PY)) ; create a scaled y
array
BARARR = INTERPOLATE(Z,XX,YY,/
GRID) ; interpolate to fill in the
image array

; Linear example
W = WINDOW(DIMENSIONS=[800,800],LAYOUT=[2,1,1])
IMG = IMAGE(IMAGE,RGB_TABLE=RGB_TABLE,/
CURRENT,LAYOUT=[2,1,1],TITLE='Linear')
CB = COLORBAR(TARGET=IMG,TITLE='IDL')
POS =
CB.POSITION ;
determine position for the second colorbar
POS(1) = pos(1)-.1
POS(3) = POS(3)-.1
BARIMG = IMAGE(BARARR,/
CURRENT,POSITION=POS,RGB_TABLE=RGB_TABLE) ; diplay the bar image
then overplot the tick values
P = PLOT(X,
[0,1],POSITION=POS,XRANGE=X,YRANGE=[0,1],XTICKLEN=0.25,MIN_V ALUE=X(0),MAX_VALUE=X(1),XMINOR=4,YMINOR=0,YMAJOR=0,XTITLE=' CUSTOM',/
NODATA,/CURRENT,AXIS_STYLE=1)

; Log example
IMG2 = IMAGE(LOGIMAGE,RGB_TABLE=RGB_TABLE,/
CURRENT,LAYOUT=[2,1,2],TITLE='Log Scales')
CB = COLORBAR(TARGET=IMG2,TITLE='IDL')
POS = CB.POSITION
POS(1) = pos(1)-.1
POS(3) = POS(3)-.1
BARIMG = IMAGE(BARARR,/
CURRENT,POSITION=POS,RGB_TABLE=RGB_TABLE)
P = PLOT(XLOG,[0,1],/
XLOG,POSITION=POS,XRANGE=X,YRANGE=[0,1],XTICKLEN=0.25,MIN_VA LUE=X(0),MAX_VALUE=(1),XMINOR=4,YMINOR=0,YMAJOR=0,XTITLE='CU STOM',/
NODATA,/CURRENT,AXIS_STYLE=1)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Displaying thicker lines on an image
Next Topic: Re: IDL for dummies

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

Current Time: Wed Oct 08 19:42:31 PDT 2025

Total time taken to generate the page: 0.00519 seconds