Re: questions regarding Taylor diagram scripts

From: Erik N <nobleeu_at_nyahnyahspammersnyahnyah>
Date: Fri Jun 08 2012 - 21:27:20 MDT

Another question regarding the Taylor plot script:

How can I use either the gsn_text or gsn_add_text command in the
script below to add text onto the diagram once it is plotted? I tried
both using ex. 1 and ex. 8 here
http://www.ncl.ucar.edu/Applications/text.shtml
but I seem to run tin trouble because the required taylor_diagram.ncl
already has these commands inside of it.

Any help would be greatly appreciated.
-Erik

;**********************************
; taylor_1_Erik.ncl
;**********************************
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 "./taylor_diagram.ncl"
;**********************************
begin
        a = addfile("0.25x0.25_grid_WA_HRRP_TRMM_0902-0914-2006_daily_Total.nc","r")
        ; All other files
        prefix = "0.25x0.25_grid_"
        all_files = systemfunc ("ls "+prefix+"*.nc")
        print(all_files)
        numFILES = dimsizes(all_files)
        b = addfiles(all_files,"r")
        ListSetType (b, "join")

        rain_Obs = a->ACC_RAIN
        rain_Model = b[:]->ACC_RAIN
        
        dimp = dimsizes(rain_Model)
                                                             ; CREATE ARRAYS
FOR STATISTICS
        re = new (dimp(0), float,-9999)
        var_test = new (dimp(0), float,-9999)
        ratio_var = new (dimp(0), float,-9999)
        sd_test = new (dimp(0), float,-9999)
        ratio_var = new (dimp(0), float,-9999)
        ratio_sd = new (dimp(0), float,-9999)
        

        do it = 0,dimp(0)-1
                ; What is your defined area?
                x = rain_Obs(0,{7:18},{-30:10})
                y = rain_Model(it,0,{7:18},{-30:10})
                ;******************************
                ; Generate Correlation Coefficient
                ;******************************
                ; Normally one could use r(it) = escorc(ndtooned(y),ndtooned(x))
                ; Compute centered pattern correlation for Taylor plot, though.
                rad = 4.*atan(1.0)/180.
                lat = doubletofloat(y&lat)
                   clat = cos(lat*rad) ; simple cosine weighting
                re(it) = pattern_cor(x, y,clat, 0) ; cos(lat) weighting, centered
                ;******************************
                ; Generate variance and SD
                ;******************************
                var_cntl = variance(x)
                var_test(it) = variance(y)
                ratio_var(it) = var_test(it)/var_cntl
        end do
        ratio_sd = ratio_var^0.5
        sd_cntl = var_cntl^0.5
        sd_test = var_test^0.5
        
    ;**********************************
    ; Put the ratios and pattern correlations into
    ; arrays for plotting
    ;**********************************
    nDataSets = 4 ; number of datasets
    npts = dimp(0)
    ratio = new ((/nDataSets, npts/),typeof(ratio_sd) )
    cc = new ((/nDataSets, npts/),typeof(re) )
    ; WRF
    ratio(0,0:63) = ratio_sd(0:63)
    cc(0,0:63) = re(0:63)
        ; Precipitation Observations
    ratio(1,64:66) = ratio_sd(64:66)
    cc(1,64:66) = re(64:66)
        ; Reanalysis Data
    ratio(2,67:68) = ratio_sd(67:68)
    cc(2,67:68) = re(67:68)
        ; Benchmark Model RM3
    ratio(3,69) = ratio_sd(69)
    cc(3,69) = re(69)
        
    ;**********************************
    ; create plot
    ;**********************************
    wks = gsn_open_wks("x11","taylor_test_2-bold")

    res = True ; diagram mods desired
    res@tiMainString = "Example" ; title
    res@Colors = (/"red","blue","green","cyan"/) ;
marker colors
        res@caseLabels = (/"WRF","HRRP","Reanalysis","RM3"/)
    res@Markers = (/16,16,16,16/) ; marker styles
    res@markerTxYOffset = 0.04 ; offset btwn marker & label
    res@gsMarkerSizeF = 0.009 ; marker size
    ;res@txFontHeightF = 0.039 ; text size

    ;res@stnRad = (/ 0.5, 1.5 /) ; additional standard radii
    res@ccRays = (/ 0.6, 0.9 /) ; correllation rays
    res@ccRays_color = "LightGray" ; default is "black"

    res@centerDiffRMS = False ; RMS 'circles'
    res@centerDiffRMS_color = "LightGray" ; default is "black"/)
        
    plot = taylor_diagram(wks, ratio, cc, res)

; Now put labels on some of the points.....
        
end

On Thu, Jun 7, 2012 at 2:23 PM, Noble, Erik U. (GISS)[COLUMBIA
UNIVERSITY] <erik.noble@nasa.gov> wrote:
> Disregard my last question. I figured out how to do this. Thank you.
> -Erik
>
> On Jun 7, 2012, at 2:20 PM, Erik N wrote:
>
> Adam Thank you. Trying these suggestions now.
>
> I am also trying to to draw more RMS circles. If you look at the .pdf I
> sent, they stop midway within the plot. I want to make them go all the way
> to 3.0 ( on the x-axis). Do I need to alter the code on lines 283-292 in
> taylor_diagram.ncl to do this?
> -Erik
>
> On Wed, Jun 6, 2012 at 4:42 PM, Adam Phillips <asphilli@ucar.edu> wrote:
>>
>> Hi Erik,
>> For all of those things you will need to alter taylor_diagram.ncl.
>> However, I don't think any of them would be terribly difficult to do.
>>
>> For instance, to remove the labeling above the markers you could simply
>> comment out these 3 lines (lines 380, 389 and 475):
>>
>> dum11 = dum10
>> dum11(n*nVar+i) =
>> gsn_add_text(wks,taylor,(i+1),X(n,i),Y(n,i)+markerTxYOffset,ptRes)
>> taylor@$unique_string("dum")$ = dum11 ; text
>>
>> That of course would remove all the text. If you want some labeling to
>> appear (as text) and other markers to not be labeled, you could pass in an
>> array of labels to taylor_diagram.ncl attached as a resource:
>>
>> ; in your script
>> labels = new(70,string)
>> labels = ""
>> labels(64:66) = (/"PrecipObs1","PrecipObs2","PrecipObs3"/)
>> labels(67:68) = (/"Rean1","Rean2"/)
>> labels(69) = (/"Benchmark1"/)
>> res@markerLabels = labels
>>
>> ; in taylor_diagram.ncl
>> ; replace line 389 (note that "(i+1)" represents the label):
>>
>> dum11(n*nVar+i) =
>> gsn_add_text(wks,taylor,(i+1),X(n,i),Y(n,i)+markerTxYOffset,ptRes)
>>
>> with this:
>>
>> if (rOpts .and. isatt(rOpts,"markerLabels")) then
>>    dum11(n*nVar+i) =
>> gsn_add_text(wks,taylor,rOpts@markerLabels(i),X(n,i),Y(n,i)+markerTxYOffset,ptRes)
>> else
>>    dum11(n*nVar+i) =
>> gsn_add_text(wks,taylor,(i+1),X(n,i),Y(n,i)+markerTxYOffset,ptRes)
>> end if
>>
>> With regards to labeling the RMS circles, see lines 292-330. Adding labels
>> to the circles is a matter of using the resource gsLineLabelString. I would
>> add this at say line 301: rms_labels = (/0.75,0.5,0.25,0.0/), then add a
>> line right after the do loop starts at line 309: respl@gsLineLabelString =
>> rms_labels(n-1)
>>
>> Other options (change the color of the labels, font size, etc.) can be
>> added as desired...
>>
>> Hope that helps.. Adam
>>
>>
>>
>>
>> On 06/06/2012 01:00 PM, Erik N wrote:
>>
>> Hi.
>>
>>   How can I have RMS values appear on the RMS cycles?
>>
>>   How can I turn on/off the numbers that appear with each point plotted on
>> the diagram?
>>
>>   Lastly, how can I make some of the point labels into strings ( e.g...one
>> point says NNRP2 whereas another point nearby says MERRA?)
>>
>> Can all of this be solved with makeing changes in the required
>> taylor_diagram.ncl script or can thye be solved using the interface script
>> (below)?
>>
>> Below is the script I used to make the following picture.
>> Basically, I want to keep the red numbers as they are (or make them
>> disappear), but put labels on the blue green and orange points instead of
>> numbers.
>>
>> Any tips? Thank you ahead of time.
>> Sincerely,
>> Erik
>>
>> Erik Noble | Research Assistant | NASA Goddard Institute for Space Studies
>> Direct: 1 (212) 678-5512 | www.giss.nasa.gov | 2880 Broadway, New York,
>> NY-10025
>>
>>
>> ;**********************************
>> ; taylor_1_Erik.ncl
>> ;**********************************
>> 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 "./taylor_diagram.ncl"
>> ;**********************************
>> begin
>>     ;**********************************
>>     data =
>> readAsciiTable("../results_all_vs_trmm_7-18_ratio.text",5,"float",0)
>>     ; Only dataset. One text file. Split the data up into
>>     model=data(:,0)
>>             ; Model points
>>     cc_1=data(0:63,1)
>>     ratio_1=data(0:63,3)
>>             ; Precipitation Observations
>>     cc_2=data(64:66,1)
>>     ratio_2=data(64:66,3)
>>             ; Reanalysis Data
>>     cc_3=data(67:68,1)
>>     ratio_3=data(67:68,3)
>>             ; Benchmark Model
>>     cc_4=data(69,1)
>>     ratio_4=data(69,3)
>>
>>     ;**********************************
>>     ; Put the ratios and pattern correlations into
>>     ; arrays for plotting
>>     ;**********************************
>>     nDataSets  = 4                               ; number of datasets
>>     npts       = dimsizes(data(:,0))
>>     ratio      = new ((/nDataSets, npts/),typeof(ratio_1) )
>>     cc         = new ((/nDataSets, npts/),typeof(cc_1) )
>>
>>     ratio(0,0:63) = ratio_1
>>     cc(0,0:63)    = cc_1
>>
>>     ratio(1,64:66) = ratio_2
>>         cc(1,64:66)    = cc_2
>>
>>     ratio(2,67:68) = ratio_3
>>         cc(2,67:68)    = cc_3
>>
>>     ratio(3,69) = ratio_4
>>         cc(3,69)    = cc_4
>>     ;**********************************
>>     ; create plot
>>     ;**********************************
>>     wks   = gsn_open_wks("pdf","taylor_test")
>>
>>     res                 = True                     ; diagram mods desired
>>     res@tiMainString    = "Example"                ; title
>>     res@Colors          = (/"red","blue","green","orange"/)         ;
>> marker colors
>>     res@Markers         = (/2,7,6,15/)                 ; marker styles
>>     res@markerTxYOffset = 0.04                     ; offset btwn marker &
>> label
>>     ;res@gsMarkerSizeF   = 0.008                     ; marker size
>>     ;res@txFontHeightF   = 0.039                    ; text size
>>
>>     res@stnRad          = (/ 0.5, 1.5 /)     ; additional standard radii
>>     res@ccRays          = (/ 0.6, 0.9 /)     ; correllation rays
>>     res@ccRays_color    = "LightGray"        ; default is "black"
>>
>>     res@centerDiffRMS   = True               ; RMS 'circles'
>>     res@centerDiffRMS_color = "LightGray"    ; default is "black"/)
>>
>>     plot  = taylor_diagram(wks, ratio, cc, res)
>> end
>>
>>
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>> --
>> ______________________________________________________________
>> Adam Phillips asphilli@ucar.edu
>> NCAR/Climate and Global Dynamics Division (303) 497-1726
>> P.O. Box 3000
>> Boulder, CO 80307-3000 http://www.cgd.ucar.edu/cas/asphilli
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
>
>
> --
> - Erik -
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

-- 
- Erik -
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Jun 8 21:27:32 2012

This archive was generated by hypermail 2.1.8 : Tue Jun 12 2012 - 13:58:38 MDT