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