Re: gsnSpreadColors doesn't work?; Color Scheme Issue; Plotting A Certain Range of Values

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Oct 28 2013 - 11:10:26 MDT

Just for the record: The reason why gsnSpreadColors wasn't working is because you were setting cnFillColors, which sets the fill colors for a contour fill plot. Once you do this, you are taking control of the color of your contours, and gsnSpreadColors is ignored.

If you need black for out-of-range values, you can try the cnMissingValFillColor resource:

res@cnMissingValFillColor = "black"
res@cnMissingValFillPattern = 0 ; necessary for cnMissingValFillColor to work, 0=solid fill

This only works if your out-of-range values are actually missing values, so you may need to do something like this to convert them to missing:

   out_of_range_value = …appropriate value here...
   data = where(data.eq.out_of_range_value,data@_FillValue,data)

To see how to use cnMissingValFillColor, see example #12 at:

http://www.ncl.ucar.edu/Applications/coneff.shtml#ex12

--Mary

On Oct 24, 2013, at 12:39 PM, James Madden <jmmadden@alaska.edu> wrote:

> That was a great fix! Thank you much!
>
> Mike Madden
>
>
> On Thu, Oct 24, 2013 at 10:14 AM, Rick Brownrigg <brownrig@ucar.edu> wrote:
> Hi James,
>
> Not sure why gsnSpreadColors is not working for you (I don't see it in your script however). But you might try:
>
> colorMap = read_colormap_file("BlAqGrYeOrRe")
> res@cnFillPalette = colorMap
> res@cnSpanFillPalette = True
>
> I'm uncertain whether leaving "res@cnFillColors = (/1/)" will still get you your black background. It might be the case you need to set the first element of colorMap to black:
>
> colorMap(0,:) = (/ 0., 0., 0., 1./) ; read_colormap_map() returns 4-tuples
>
> This is untested, but hopefully it helps…
> Rick
>
> On Oct 24, 2013, at 11:41 AM, James Madden <jmmadden@alaska.edu> wrote:
>
>> Hello everyone,
>>
>> I am plotting Attenuated Depolarization Ratio from CALIPSO data, and I am trying to put more emphasis on the smoke particles that has a typical depolarization value of 0.05. Depolarization ranges, on typical plots, from 0 to 1, and I am trying to take a specific part of that range and look more closely at the values I want.
>>
>> I shorted the range, from 0 to 0.4, and the values increase irregularly. This can be found at res@cnLevels.
>>
>> The problem is my color scheme is not allowing me to go into much detail. I want a background of black to exclude the values outside of my range, but then the color scheme doesn't go from Blue to Red. It just stops around light blue (probably because it still thinks the range is from 0 to 1?).
>>
>> I need black for the values outside of my range, and the full color plot spread over all values (that is from blue to red) within my specified range. Reiterating my range is from 0 to 0.4, and the values increase irregularly.
>>
>> When I use gsnSpreadColors, the plot doesn't change.
>>
>> Thank you much. I have attached a picture of my current plot, and the code is below.
>>
>>
>> ;**************************************************
>> ; This will plot CALIPSO data for your domain
>> ; Author: Cory Wolff from UCAR (thank him in thesis!), edits by J. Madden
>> ;**************************************************
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/ut_string.ncl"
>> load "color_map.ncl"
>> ;**************************************************
>> begin
>>
>> ; --- Read Calipso Data ------------;
>> fili = systemfunc("ls /import/archive/u1/uaf/jmmadden/WILDFIRE2009/CALIPSOdata/SUBSETS/CAL_LID*")
>> nfil = dimsizes(fili) ; this is 26
>>
>> f = addfiles(fili + ".hdf","r")
>> wks = gsn_open_wks("x11","depol")
>> ;wks = gsn_open_wks("pdf","depol")
>>
>>
>> do ifile = 0, nfil-1
>>
>> ; YOU NEED THE RATIO OF PERPENDICULAR ATTENUATED BACKSCATTER OVER TOTAL ATTENUATED BACKSCATTER, BOTH AT 532 TO GET ATTENUATED DEPOLARIZATION RATIO
>>
>> tot = f[ifile]->Total_Attenuated_Backscatter_532
>> perp = f[ifile]->Perpendicular_Attenuated_Backscatter_532
>> back1 = perp/tot
>> back1!0 = "first"
>> back1!1 = "second"
>> dims = getvardims(back1)
>>
>> ; Reverse the vertical array
>> back1 = back1(:,::-1)
>>
>> ; Reorder using string dimension names
>> back = back1(second|:,first|:)
>> ; back = back1($dims(1)$|:,$dims(0)$|:)
>> back@_FillValue = -9999
>> back@units = "km~S~-1~NN~ sr~S~-1~NN~"
>>
>> ; Get the lat and lon arrays for the x-axis
>> lat = (/f[ifile]->Latitude/)
>> lon = (/f[ifile]->Longitude/)
>>
>> xlabel = sprintf("%.2f",lat)+"~C~"+sprintf("%.2f",lon)
>>
>> ; Work with the time fields to get a valid time string
>> time = (/f[ifile]->Profile_Time/)
>> time@units = "seconds since 1993-01-01 00:00"
>> tstring = ut_string(time(:,0), "%Y-%N-%D %H:%M:%S")
>>
>> ; Set stride intervals for x-axis
>> stride = dimsizes(tstring)/15
>>
>> ; Get the altitude values.
>> hgt = asciiread("lidar_altitudes.txt", -1, "float")
>> hgt = hgt(::-1) ; Reverse this array too
>> hgt!0 = "hgt"
>> hgt@long_name = "Altitude, km"
>> hgt@units = "km"
>>
>> printVarSummary(hgt)
>>
>> ; Assign new dimensions and attributes
>> back!0 = "hgt"
>> back&hgt = hgt
>> xcoord = ispan(0,dimsizes(lat(:,0)) - 1,1)
>> back!1 = "xcoord"
>> back&xcoord = xcoord
>>
>> ;*************************
>> ; create plot
>> ;*************************
>> setvalues NhlGetWorkspaceObjectId()
>> "wsMaximumSize": 300000000
>> end setvalues
>>
>> gsn_define_colormap(wks, "BlAqGrYeOrRe")
>>
>> res = True
>> res@cnFillOn = True ; color plot desired
>> res@cnLinesOn = False
>>
>> ; set a black background
>> res@cnFillColors = (/1/) ; 1 is black
>> res@cnRasterModeOn = True
>> res@gsnAddCyclic = False
>> res@gsnMaximize = True
>> res@gsnLeftString = "UTC: "+tstring(0)+" to "+tstring(dimsizes(tstring)-1)
>> res@tiMainString = "Attenuated Depolarization Ratio"
>> res@tiMainFontHeightF = 0.025
>> res@tiYAxisFontHeightF = 0.02
>> res@cnLevelSelectionMode = "ExplicitLevels"
>> res@cnLevels = (/0.0,0.005,0.01,0.015,0.02,0.025,0.05,0.075,0.1,0.15,0.2,0.3,0.4/)
>> res@lbLabelStrings = (/0.0,0.005,0.01,0.015,0.02,0.025,0.05,0.075,0.1,0.15,0.2,0.3,0.4/)
>>
>> res@tmXTOn = False
>> res@tmXBMode = "Explicit"
>> res@tmXBValues = xcoord(::stride)
>> res@tmXBLabels = xlabel(::stride,0)
>> res@tmXBLabelFontHeightF = 0.01
>>
>> ; Set a vertical range of 5 km.
>> res@trYMaxF = 5
>>
>> res@lbLabelFontHeightF = 0.01
>> res@lbLabelAngleF = 0.0
>> res@lbOrientation = "vertical"
>> res@vpWidthF = 1.0
>>
>> res@gsnDraw = True
>> res@gsnFrame = False
>>
>> plot = gsn_csm_contour(wks,back,res)
>>
>> frame(wks)
>>
>>
>> delete(tot)
>> delete(perp)
>> delete(back)
>> delete(back1)
>> delete(lat)
>> delete(lon)
>> delete(xlabel)
>> delete(time)
>> delete(tstring)
>> delete(xcoord)
>>
>> end do
>> end
>>
>> --
>> Mike Madden
>> Graduate Research Assistant
>> Department of Atmospheric Sciences
>> University of Alaska Fairbanks
>> IARC 338N
>> Office: (907) 474-7618
>> Cell: (417) 439-2830
>> ---------------------------------------------------------------------
>> "Buy the ticket, take the ride." Hunter S. Thompson
>> <depol.JPG>_______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
>
> --
> Mike Madden
> Graduate Research Assistant
> Department of Atmospheric Sciences
> University of Alaska Fairbanks
> IARC 338N
> Office: (907) 474-7618
> Cell: (417) 439-2830
> ---------------------------------------------------------------------
> "Buy the ticket, take the ride." Hunter S. Thompson
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Oct 28 11:10:49 2013

This archive was generated by hypermail 2.1.8 : Fri Nov 01 2013 - 08:58:14 MDT