Re: Associating specific colors with specific contour levels?

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu, 31 Jul 2008 14:16:01 -0600

Try the attached. it represents one approach.
I'm sure others can do better.

I scaled the ferret colors ... then mapped to NCL's 0-1 range

Cheers
D

Adam Phillips wrote:
> Hi Gary,
>
> Gary Strand wrote:
>>
>> I'm attempting to replicate a Ferret code that I have in NCL, and one
>> of the things Ferret allows you to do is associate specific colors
>> with specific contour levels. One does this by giving the contour
>> level and color triplet in the colormap file used, e.g.:
>>
>> RGB_Mapping By_Value
>> ! Val R G B
>> -6000. 0. 0. 20. ! blue-black
>> -4000. 10. 18. 90.
>> -2000. 20. 35. 100. ! blue
>> -300. 40. 70. 100. -100. 50. 100. 100.
>> -50. 40. 80. 70.
>> -0.1 90. 100. 100. ! light green-blue
>> 0. 0. 40. 00. ! dark green
>> 100. 0. 70. 30. ! light green
>> 300. 90. 100. 0. ! light yellow
>> 1200. 60. 30. 0. ! rust
>> 4000. 90. 90. 100. ! ice blue
>> 5000. 100. 100. 100. ! white
>>
>> Is there a way to do something like this in NCL?
>
> You can manually specify the contour levels via the cnLevels resource,
> and then manually specify the fill colors using cnFillColors like this:
>
> res_at_cnLevelSelectionMode = "ManualLevels"
> res_at_cnLevels =
> (/-6000,-4000,-2000,-300,-100,-50,-0.1,0,100,300,1200,4000,5000/)
> res_at_cnFillOn = True
> res_at_cnFillColors = (/2,4,5,6,8, etc /)
>
> But I don't know of a way to set them together, or to use RGB values
> instead of color index values. Someone else can chime in on this one.
>
>>
>> Also, can I specify contour levels in "chunks" without having to
>> specify all of them explicitly? Ferret allows you to this via the
>> "LEV" command:
>>
>> shade/lev=(-10250,-250,250)(-250,250,25)(250,8250,250) topo
>>
>> That is, from -10250 to -250, use 250 increments, from -250 to 250,
>> increment by 25, and then from 250 to 8250, go back to 250.
>>
>
> Yes, although it's not as not nearly as neat as the Ferret way:
>
> chunk1 = ispan(-10250,-250,250)
> chunk2 = ispan(-225,250,25)
> chunk3 = ispan(275,8250,250)
> arr = new(dimsizes(chunk1)+dimsizes(chunk2)+dimsizes(chunk3),integer)
> arr(:dimsizes(chunk1)-1) = (/ chunk1 /)
> arr(dimsizes(chunk1):dimsizes(chunk1)+dimsizes(chunk2)-1) = (/ chunk2 /)
> arr(dimsizes(chunk1)+dimsizes(chunk2):) = (/ chunk3 /)
> res_at_cnLevelSelectionMode = "ManualLevels"
> res_at_cnLevels = arr
>
> Adam
>
>
>
>> Thanks!
>>
>> Gary Strand
>> strandwg_at_ucar.edu <mailto:strandwg_at_ucar.edu>
>>
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk_at_ucar.edu
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

-- 
======================================================
Dennis J. Shea                  tel: 303-497-1361    |
P.O. Box 3000                   fax: 303-497-1333    |
Climate Analysis Section                             |
Climate & Global Dynamics Div.                       |
National Center for Atmospheric Research             |
Boulder, CO  80307                                   |
USA                        email: shea 'at' ucar.edu |
======================================================

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

function mimicFerret(res[1] , levRGB[*][*]:numeric)
begin
  dims = dimsizes(levRGB)

  res_at_cnLevelSelectionMode = "ExplicitLevels" ; set explicit contour levels
  res_at_cnLevels = levRGB(:,0)

  LEV = levRGB(:,0)
  nLEV = dimsizes(LEV)
 
  scale = 1/100. ; convert ferret RGB to NCL RGB

  RGB = new( (/nLEV+2, 3/), "float")
  RGB(0 ,:) = (/1,1,1/)
  RGB(1 ,:) = (/0,0,0/)
  RGB(2:,:) = (levRGB(:,1:)*scale)

  return(RGB)
end

 z = generate_2d_array(20,20, -6230, 5100 ,0,(/30,50/))

       ; ferret RGB range from 0=>100, NCL 0->1
ferret =(/ \
        (/ -6000., 0., 0., 20. /) \ ; blue-black
       ,(/ -4000., 10., 18., 90. /) \
       ,(/ -2000., 20., 35.,100. /) \ ; blue
       ,(/ -300. , 40., 70.,100. /) \
       ,(/ -100. , 50.,100.,100. /) \
       ,(/ -50. , 40., 80., 70. /) \
       ,(/ -0.1, 90.,100.,100. /) \ ; light green-blue
       ,(/ 0. , 0., 40., 00. /) \ ; dark green
       ,(/ 100. , 0., 70., 30. /) \ ; light green
       ,(/ 300. , 90.,100., 0. /) \ ; light yellow
       ,(/ 1200. , 60., 30., 0. /) \ ; rust
       ,(/ 4000. , 90., 90.,100. /) \ ; ice blue
       ,(/ 5000. ,100.,100.,100. /) \ ; white
        /)

 res = True
 res_at_cnFillOn = True
 res_at_lbLabelAutoStride = True ; automatically choose best stride

 rgb = mimicFerret(res, ferret)

 wks = gsn_open_wks("x11","gary")
 gsn_define_colormap(wks,rgb)
 
 gsn_draw_colormap(wks) ; draw isolated color map for test
 
 plot = gsn_csm_contour(wks, z, res)

 res_at_cnLabelBarEndStyle = "ExcludeOuterBoxes" ; change end style
 res_at_gsnCenterString = res_at_cnLabelBarEndStyle
 plot = gsn_csm_contour(wks, z, res)

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Jul 31 2008 - 14:16:01 MDT

This archive was generated by hypermail 2.2.0 : Thu Jul 31 2008 - 14:58:46 MDT