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