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

Home » Public Forums » archive » Re: CG Elevation image + arbitrary discrete colorbar
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: CG Elevation image + arbitrary discrete colorbar [message #79785] Fri, 30 March 2012 13:12
DavidF[1] is currently offline  DavidF[1]
Messages: 94
Registered: April 2012
Member
Matteo wrote:

> Dave, thank you. If I do what you suggested, Himalaya comes out in
> between 1800 and 2000m, and most of the world's oceans at 200-400
> m. :-|
> Nothing is black or white.
>
> I guess Nata's way is the hard way but I thought this is what OOB_Low
> and OOB_High were for?

Well, this was a pretty ill-formed question. Maybe you are looking
for something like this, where I arbitrarily scale the data between
-400 and 9000 meters:

image = cgdemodata(7)
image = scale_vector(Float(image), -400.0, 9000.0)
belowSeaLevel = Where(image LT 0.0, belowCnt)
above6000meters = Where(image GT 6000.0, aboveCnt)
scaledImage = BytScl(image, MIN=0, MAX=6000, TOP=9) + 2B
IF belowCnt GT 0 THEN scaledImage[belowSeaLevel] = 1B
IF aboveCnt GT 0 THEN scaledImage[above6000Meters] = 12B

tvlct, cgcolor('black', /Triple), 1
cgLoadCT, 33, NColors=10, Bottom=2
tvlct, cgColor('white', /Triple), 12

cgDisplay, color='gray'
cgimage, scaledImage, position=[0.1, 0.1, 0.9, 0.75], /Keep
cgColorbar, NColors=10, Bottom=2, oob_Low=1, oob_High=12, $
Divisions=10, Range=[0,6000], /Discrete
END

Cheers,

David

P.S. My news provider is failing me! No news for days now. Resorting to Google Groups. :-(
Re: CG Elevation image + arbitrary discrete colorbar [message #79786 is a reply to message #79785] Fri, 30 March 2012 12:55 Go to previous message
Matteo is currently offline  Matteo
Messages: 28
Registered: August 2011
Junior Member
Oh wait...

The world elevation is already a BYTARR...what I need is a floating
point image to scale.
I'm trying now with image=CGdemodata(2), which has min and max values
of 0. and 1550., but don't get much further trying to plot 10 levels
between 10. and 1000. .
Also, why are scaled_vector and byscl not giving the same result?


pro cbar
compile_opt idl2

nclrs=10
minelev=100.
maxelev=1000.
p = [0.02, 0.15, 0.98, 0.98]

cgLoadCT, 33, NColors=nclrs, Bottom=1
TVLCT, cgcolor('black',/Triple), 0
TVLCT, cgcolor('white',/Triple), nclrs+1

image=cgDemoData(2)
;scaledImage = Scale_Vector(image, 0, nclrs, MINVALUE=minelev,
MAXVALUE=maxelev, /nan)
scaledImage = bytscl(image, MIN=minelev, MAX=maxelev, top=nclrs, /nan)

cgWindow, WXSize=700, WYSize=700
cgImage, scaledimage, position = p, MinValue=0, MaxValue=nclrs,
Top=nclrs-1, $
bottom=1, /Keep, /Add
cgColorbar, Position=[p[0], p[1]-0.1, p[2], p[1]-0.05], NColors=nclrs,
$
Range=[minelev,maxelev], Divisions=10, bottom=1, $
/discrete, OOB_Low='black', OOB_High='white', /Add
stop
end




m
Re: CG Elevation image + arbitrary discrete colorbar [message #79787 is a reply to message #79786] Fri, 30 March 2012 12:13 Go to previous message
Matteo is currently offline  Matteo
Messages: 28
Registered: August 2011
Junior Member
Dave, thank you. If I do what you suggested, Himalaya comes out in
between 1800 and 2000m, and most of the world's oceans at 200-400
m. :-|
Nothing is black or white.

I guess Nata's way is the hard way but I thought this is what OOB_Low
and OOB_High were for?

m
Re: CG Elevation image + arbitrary discrete colorbar [message #79788 is a reply to message #79787] Fri, 30 March 2012 10:54 Go to previous message
DavidF[1] is currently offline  DavidF[1]
Messages: 94
Registered: April 2012
Member
Matteo write:

> I've checked many of David's links and I seem to find all pieces for a
> little problem I'm trying to solve...still I can't manage to glue them
> together properly.
> I'm trying to scale an image between arbitrary min and max values,
> with an arbitrary number of levels, and getting the proper (discrete)
> colorbar associated with it. I'm trying to use the new OOB_* options
> to leave values < min in one color and values > max of another.
>
> In the example below, I'd for example to have 10 levels between 0 and
> 3000m, and elevations <0 set to black and elevations > 2000 set to
> white.
>
> I'm also trying to get the same result using bytscl and scale_vector.
>
> Does anybody have any suggestions?
>

Add a BOTTOM=1 keyword to your cgImage command.

Cheers,

David
Re: CG Elevation image + arbitrary discrete colorbar [message #79794 is a reply to message #79788] Fri, 30 March 2012 04:47 Go to previous message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
On Friday, March 30, 2012 4:48:42 AM UTC-4, Matteo wrote:
> Hallo,
> I've checked many of David's links and I seem to find all pieces for a
> little problem I'm trying to solve...still I can't manage to glue them
> together properly.
> I'm trying to scale an image between arbitrary min and max values,
> with an arbitrary number of levels, and getting the proper (discrete)
> colorbar associated with it. I'm trying to use the new OOB_* options
> to leave values < min in one color and values > max of another.
>
> In the example below, I'd for example to have 10 levels between 0 and
> 3000m, and elevations <0 set to black and elevations > 2000 set to
> white.
>
> I'm also trying to get the same result using bytscl and scale_vector.
>
> Does anybody have any suggestions?
>
> Many thanks,
> Matteo
>
>
> pro cbar
> compile_opt idl2
>
> nclrs=10
> minelev=0.
> maxelev=2000.
> p = [0.02, 0.15, 0.98, 0.98]
>
> cgLoadCT, 33, NColors=nclrs, Bottom=1
> TVLCT, cgcolor('white',/Triple), nclrs+1
>
> image=cgDemoData(7)
> ;scaledImage = Scale_Vector(image, 0, nclrs, MINVALUE=minelev,
> MAXVALUE=maxelev, /nan)
> scaledImage = bytscl(image, MIN=minelev, MAX=maxelev, top=nclrs+1, /
> nan)
>
> cgWindow, WXSize=700, WYSize=700
> cgImage, scaledimage, position = p, MinValue=0, MaxValue=nclrs,
> Top=nclrs-1, /Keep, /Add
> cgColorbar, Position=[p[0], p[1]-0.1, p[2], p[1]-0.05], NColors=nclrs,
> $
> Range=[minelev,maxelev], Divisions=10, bottom=1, $
> /discrete, OOB_Low='black', OOB_High='white', /Add
>
> end

My code to convert images to colors looks like this :

n_colors= ;; whatever you have

sz=SIZE(data,/DIM)
data_colors=FLTARR(sz)

;; in your case
range_values=FINDGEN(n_colors+1)*3000./(n_colors)
;; convert to colors
FOR i=0, n_colors DO data_colors+=data GE range_values[i]

ww=WHERE(data LT 0 OR data GT 3000,nn_w)
IF nn_w GT 0 THEN data_colors[ww]=white_index

Regards,
nata
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Cannot see anything in the postscript file. Any help?
Next Topic: Taskbar and Windows

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

Current Time: Wed Oct 08 11:44:24 PDT 2025

Total time taken to generate the page: 0.00513 seconds