co2/taylor_metrics_table.ncl
changeset 1 4be95183fbcd
equal deleted inserted replaced
-1:000000000000 0:dda254f03740
       
     1 ;*******************************************************************
       
     2 ; procedure to draw the Taylor Diagram Metrics Table
       
     3 ;
       
     4 ; AWWG METRICS 0.3 ;;;
       
     5 ; 27 Jun 06   ASP
       
     6 ;  5 Jul 06   DJS 
       
     7 ;
       
     8 ; Arguments:
       
     9 ;     mfname     : name of the output table
       
    10 ;     varNames   : variable names [metrics]
       
    11 ;     cases      : case (model) names
       
    12 ;     seasons    : season names
       
    13 ;     values     : array containing the values to be plotted
       
    14 ;     opt        : used to pass optional arguments
       
    15 
       
    16 procedure taylor_metrics_table(mfname[1]:string        \       ; plot name
       
    17                               ,varNames[*]:string      \       ; variables
       
    18                               ,cases[*]:string         \
       
    19                               ,seasons[*]:string       \
       
    20                               ,values[*][*][*]:numeric  \
       
    21                               ,opt:logical              )
       
    22 
       
    23 
       
    24 ;;;
       
    25 ;;; Output of metrics to a table [grid]
       
    26 
       
    27 begin  
       
    28     if (.not.isatt(opt,"pltType") .or. \
       
    29        (opt@pltType.eq."eps" .or. opt@pltType.eq."png" .or. opt@pltType.eq."gif")) then
       
    30         wks = gsn_open_wks("eps",mfname)    ; default 
       
    31     else
       
    32         wks = gsn_open_wks(opt@pltType,mfname)   
       
    33     end if
       
    34     
       
    35     xbox0  = (/0.0,1.0,1.0,0.0,0.0/) ; Box template.
       
    36     ybox0  = (/0.0,0.0,1.0,1.0,0.0/)
       
    37     
       
    38     nvar   = dimsizes(varNames)
       
    39     ncases = dimsizes(cases)
       
    40     nseas  = dimsizes(seasons)
       
    41     
       
    42     dimt   = dimsizes(values)        ; table dimensions
       
    43     
       
    44     if (ncases.ne.dimt(0)) then
       
    45        print("taylor_metrics_table fatal error: Number of case names ("+ncases+ \
       
    46              ") does not match the number of cases passed in ("+dimt(0)+")")
       
    47        exit
       
    48     end if
       
    49     if (nseas.ne.dimt(1)) then
       
    50        print("taylor_metrics_table fatal error: Number of season names ("+nseas+ \
       
    51              ") does not match the number of seasons passed in ("+dimt(1)+")")
       
    52        exit
       
    53     end if
       
    54     if (dimsizes(varNames).ne.dimt(2)) then
       
    55        print("taylor_metrics_table fatal error: Number of metric variables names ("+dimsizes(varNames)+ \
       
    56              ") does not match the number of metric variables passed in ("+dimt(2)+")")
       
    57        exit
       
    58     end if
       
    59     
       
    60     ncolm1 = dimt(0)*dimt(1)
       
    61     if (ncolm1.le.12) then
       
    62        if (ncolm1.le.6) then
       
    63           tt_width = .4
       
    64        end if
       
    65        if (ncolm1.ge.7.and.ncolm1.le.12) then
       
    66           tt_width = .2
       
    67        end if
       
    68        tt_height     = 0.1
       
    69        tt_theight    = 0.02
       
    70        mn_height     = 0.03  
       
    71        mn_theight    = 0.012   
       
    72     else
       
    73        if (ncolm1.le.20) then
       
    74           tt_width   = .15
       
    75           tt_height  = 0.06
       
    76           tt_theight = 0.012
       
    77           mn_height  = 0.018  
       
    78           mn_theight = 0.0072
       
    79        else
       
    80           tt_width   = .1
       
    81           tt_height  = 0.05
       
    82           tt_theight = 0.01
       
    83           mn_height  = 0.015  
       
    84           mn_theight = 0.006
       
    85        end if
       
    86     end if
       
    87     if (ncolm1.gt.26.or.dimt(2).gt.63) then
       
    88        print("Warning: Recommended maximium size of array passed into taylor_metrics_table is "+ \
       
    89              "26 columns (#cases * #seasons) by 63 rows (#variables), continuing")
       
    90     end if
       
    91 
       
    92     mn_width   = tt_width
       
    93     mv_height  = mn_height
       
    94     mv_width   = 0.1
       
    95     mv_theight = mn_theight
       
    96     
       
    97     tt_pRes = True
       
    98     tt_pRes@gsFillColor   = "CornflowerBlue"      ; background color for + values
       
    99     
       
   100     tt_tRes  = True
       
   101     tt_tRes@txFontHeightF = tt_theight
       
   102     
       
   103     mn_pRes = True
       
   104     mn_pRes@gsFillColor   = "Gray70"              ; background color for variable names
       
   105     
       
   106     mn_tRes = True
       
   107     mn_tRes@txFontHeightF = mn_theight
       
   108     
       
   109     mv_pRes = True
       
   110     mv_pRes@gsFillColor   = "White"               ; background color for reference values
       
   111     
       
   112     mv_tRes = True
       
   113     mv_tRes@txFontHeightF = mn_theight     
       
   114     
       
   115 ; Title
       
   116     
       
   117     xbox   = tt_width*xbox0
       
   118     ybox   = 1.-tt_height*ybox0
       
   119     
       
   120     ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0))
       
   121     iytbox = ybox(0)+0.5*(ybox(2)-ybox(0))
       
   122     
       
   123     gsn_polygon_ndc(wks,xbox,ybox,tt_pRes)
       
   124     if (isatt(opt,"tableTitle") ) then
       
   125         gsn_text_ndc(wks, opt@tableTitle ,ixtbox,iytbox, tt_tRes)
       
   126     else
       
   127         gsn_text_ndc(wks,"CAM METRICS",ixtbox,iytbox, tt_tRes)
       
   128     end if
       
   129     gsn_polyline_ndc(wks,xbox,ybox,False)
       
   130     
       
   131     do im = 0,nvar-1
       
   132       ybox   = min(ybox)-(ybox0*mn_height)
       
   133       ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0))
       
   134       iytbox = ybox(0)+0.5*(ybox(2)-ybox(0))
       
   135       
       
   136       gsn_polygon_ndc(wks,xbox,ybox,mn_pRes)
       
   137       gsn_polyline_ndc(wks,xbox,ybox,False)
       
   138       gsn_text_ndc(wks,varNames(im),ixtbox,iytbox, mn_tRes)
       
   139     end do
       
   140     
       
   141     do icase = 0, ncases-1
       
   142       ybox   = 1.-0.5*tt_height*ybox0
       
   143       xbox   = ((1.-tt_width)/ncases)*(xbox0+icase)+tt_width
       
   144       xboxi  = min(xbox)
       
   145       ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0))
       
   146       iytbox = ybox(0)+0.5*(ybox(2)-ybox(0))
       
   147       gsn_polygon_ndc(wks,xbox,ybox,mn_pRes)
       
   148       gsn_polyline_ndc(wks,xbox,ybox,False)
       
   149       gsn_text_ndc(wks,cases(icase),ixtbox,iytbox, mn_tRes)
       
   150        
       
   151       do iseas = 0, nseas-1
       
   152       ybox     = 1.-0.5*tt_height-0.5*tt_height*ybox0
       
   153       xbox     = xboxi +  ((1.-tt_width)/(ncases*nseas))*(xbox0+iseas) 
       
   154       ixtbox   = xbox(0)+0.5*(xbox(1)-xbox(0))
       
   155       iytbox   = ybox(0)+0.5*(ybox(2)-ybox(0))
       
   156       gsn_polygon_ndc(wks,xbox,ybox,mn_pRes)
       
   157       gsn_polyline_ndc(wks,xbox,ybox,False)
       
   158       gsn_text_ndc(wks,seasons(iseas),ixtbox,iytbox, mn_tRes) 
       
   159       
       
   160       do im=0,nvar-1
       
   161           if (im .eq. 0) then
       
   162             ybox = 1.-tt_height-mv_height*ybox0
       
   163           else
       
   164             ybox = ybox - mv_height
       
   165           end if
       
   166           iytbox = ybox(0)+0.5*(ybox(2)-ybox(0))
       
   167           mv_pRes@gsFillColor = "White" 
       
   168           if (icase .gt. 0) then
       
   169             if (ismissing(values(icase,iseas,im)) .or. \    ; ???
       
   170                 ismissing(values(icase,iseas,im)))then 
       
   171     ;          print ("Missing values skipped")
       
   172             else
       
   173               if (values(icase,iseas,im).le.values(0,iseas,im)) then
       
   174     		  if (isatt(opt,"color0")) then
       
   175                    mv_pRes@gsFillColor = opt@color0
       
   176                 else
       
   177                    mv_pRes@gsFillColor = "DarkOliveGreen3"
       
   178     		  end if
       
   179               else
       
   180     		  if (isatt(opt,"color1")) then
       
   181                    mv_pRes@gsFillColor = opt@color1
       
   182     		  else	
       
   183     		   mv_pRes@gsFillColor = "IndianRed1"
       
   184     		  end if
       
   185               end if
       
   186             end if
       
   187           end if
       
   188           gsn_polygon_ndc(wks,xbox,ybox,mv_pRes)
       
   189           gsn_polyline_ndc(wks,xbox,ybox,False)
       
   190           gsn_text_ndc(wks,sprintf("%4.3f",values(icase,iseas,im)),ixtbox,iytbox, mv_tRes)     
       
   191         end do
       
   192       end do
       
   193     end do
       
   194     
       
   195     draw(wks)
       
   196   ;; activate the ;; lines if this is made a function
       
   197   ;;if (.not.isatt(opt,"gsnFrame") .or. opt@gsnFrame) then
       
   198         frame(wks)
       
   199                              ; if png or gif then use convert
       
   200         if (isatt(opt,"pltType")    .and. \ 
       
   201            (opt@pltType.eq."png" .or. opt@pltType.eq."gif")) then
       
   202             system("convert -trim +repage "+mfname+".eps "+mfname+"."+opt@pltType)
       
   203         end if
       
   204   ;;end if
       
   205     
       
   206 end