1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/co2/metrics_table.ncl.1 Mon Jan 26 22:08:20 2009 -0500
1.3 @@ -0,0 +1,209 @@
1.4 +;*******************************************************************
1.5 +; procedure to draw the Taylor Diagram Metrics Table
1.6 +;
1.7 +; AWWG METRICS 0.3 ;;;
1.8 +; 27 Jun 06 ASP
1.9 +; 5 Jul 06 DJS
1.10 +;
1.11 +; Arguments:
1.12 +; mfname : name of the output table
1.13 +; varNames : variable names [metrics]
1.14 +; cases : case (model) names
1.15 +; seasons : season names
1.16 +; values : array containing the values to be plotted
1.17 +; opt : used to pass optional arguments
1.18 +
1.19 +procedure metrics_table(mfname[1]:string \ ; plot name
1.20 + ,varNames[*]:string \ ; variables
1.21 + ,cases[*]:string \
1.22 + ,values[*][*]:numeric \
1.23 + ,opt:logical )
1.24 +
1.25 +
1.26 +;;;
1.27 +;;; Output of metrics to a table [grid]
1.28 +
1.29 +begin
1.30 + if (.not.isatt(opt,"pltType") .or. \
1.31 + (opt@pltType.eq."eps" .or. opt@pltType.eq."png" .or. opt@pltType.eq."gif")) then
1.32 + wks = gsn_open_wks("eps",mfname) ; default
1.33 + else
1.34 + wks = gsn_open_wks(opt@pltType,mfname)
1.35 + end if
1.36 +
1.37 + xbox0 = (/0.0,1.0,1.0,0.0,0.0/) ; Box template.
1.38 + ybox0 = (/0.0,0.0,1.0,1.0,0.0/)
1.39 +
1.40 + nvar = dimsizes(varNames)
1.41 + ncases = dimsizes(cases)
1.42 +
1.43 + dimt = dimsizes(values) ; table dimensions
1.44 +
1.45 + if (ncases.ne.dimt(0)) then
1.46 + print("metrics_table fatal error: Number of case names ("+ncases+ \
1.47 + ") does not match the number of cases passed in ("+dimt(0)+")")
1.48 + exit
1.49 + end if
1.50 +
1.51 + if (dimsizes(varNames).ne.dimt(1)) then
1.52 + print("metrics_table fatal error: Number of metric variables names ("+dimsizes(varNames)+ \
1.53 + ") does not match the number of metric variables passed in ("+dimt(1)+")")
1.54 + exit
1.55 + end if
1.56 +
1.57 + ncolm1 = dimt(0)
1.58 + if (ncolm1.le.12) then
1.59 + if (ncolm1.le.6) then
1.60 +; tt_width = .4
1.61 + tt_width = .2
1.62 + end if
1.63 + if (ncolm1.ge.7.and.ncolm1.le.12) then
1.64 + tt_width = .2
1.65 + end if
1.66 + tt_height = 0.1
1.67 + tt_theight = 0.02
1.68 + mn_height = 0.03
1.69 + mn_theight = 0.012
1.70 + else
1.71 + if (ncolm1.le.20) then
1.72 + tt_width = .15
1.73 + tt_height = 0.06
1.74 + tt_theight = 0.012
1.75 + mn_height = 0.018
1.76 + mn_theight = 0.0072
1.77 + else
1.78 + tt_width = .1
1.79 + tt_height = 0.05
1.80 + tt_theight = 0.01
1.81 + mn_height = 0.015
1.82 + mn_theight = 0.006
1.83 + end if
1.84 + end if
1.85 + if (ncolm1.gt.26.or.dimt(1).gt.63) then
1.86 + print("Warning: Recommended maximium size of array passed into metrics_table is "+ \
1.87 + "26 columns (#cases * #seasons) by 63 rows (#variables), continuing")
1.88 + end if
1.89 +
1.90 + mn_width = tt_width
1.91 + mv_height = mn_height
1.92 + mv_width = 0.1
1.93 + mv_theight = mn_theight
1.94 +
1.95 + tt_pRes = True
1.96 + tt_pRes@gsFillColor = "CornflowerBlue" ; background color for + values
1.97 +
1.98 + tt_tRes = True
1.99 + tt_tRes@txFontHeightF = tt_theight
1.100 +
1.101 + mn_pRes = True
1.102 + mn_pRes@gsFillColor = "Gray70" ; background color for variable names
1.103 +
1.104 + mn_tRes = True
1.105 + mn_tRes@txFontHeightF = mn_theight
1.106 +
1.107 + mv_pRes = True
1.108 + mv_pRes@gsFillColor = "White" ; background color for reference values
1.109 +
1.110 + mv_tRes = True
1.111 + mv_tRes@txFontHeightF = mn_theight
1.112 +
1.113 +; Title
1.114 +
1.115 + xbox = tt_width*xbox0
1.116 + ybox = 1.-tt_height*ybox0
1.117 +
1.118 + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0))
1.119 + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0))
1.120 +
1.121 + gsn_polygon_ndc(wks,xbox,ybox,tt_pRes)
1.122 + if (isatt(opt,"tableTitle") ) then
1.123 + gsn_text_ndc(wks, opt@tableTitle ,ixtbox,iytbox, tt_tRes)
1.124 + else
1.125 + gsn_text_ndc(wks,"METRICS",ixtbox,iytbox, tt_tRes)
1.126 + end if
1.127 + gsn_polyline_ndc(wks,xbox,ybox,False)
1.128 +
1.129 + do im = 0,nvar-1
1.130 + ybox = min(ybox)-(ybox0*mn_height)
1.131 + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0))
1.132 + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0))
1.133 +
1.134 + gsn_polygon_ndc(wks,xbox,ybox,mn_pRes)
1.135 + gsn_polyline_ndc(wks,xbox,ybox,False)
1.136 + gsn_text_ndc(wks,varNames(im),ixtbox,iytbox, mn_tRes)
1.137 + end do
1.138 +
1.139 + do icase = 0, ncases-1
1.140 +; ybox = 1.-0.5*tt_height*ybox0
1.141 + ybox = 1.-tt_height*ybox0
1.142 + xbox = ((1.-tt_width)/ncases)*(xbox0+icase)+tt_width
1.143 + xboxi = min(xbox)
1.144 + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0))
1.145 + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0))
1.146 + gsn_polygon_ndc(wks,xbox,ybox,mn_pRes)
1.147 + gsn_polyline_ndc(wks,xbox,ybox,False)
1.148 + gsn_text_ndc(wks,cases(icase),ixtbox,iytbox, mn_tRes)
1.149 +
1.150 +; do iseas = 0, nseas-1
1.151 +; ybox = 1.-0.5*tt_height-0.5*tt_height*ybox0
1.152 +; xbox = xboxi + ((1.-tt_width)/(ncases*nseas))*(xbox0+iseas)
1.153 +; ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0))
1.154 +; iytbox = ybox(0)+0.5*(ybox(2)-ybox(0))
1.155 +; gsn_polygon_ndc(wks,xbox,ybox,mn_pRes)
1.156 +; gsn_polyline_ndc(wks,xbox,ybox,False)
1.157 +; gsn_text_ndc(wks,seasons(iseas),ixtbox,iytbox, mn_tRes)
1.158 +
1.159 + if (icase .eq. ncases-1) then
1.160 + mv_pRes@gsFillColor = "Green"
1.161 + else
1.162 + mv_pRes@gsFillColor = "White"
1.163 + end if
1.164 +
1.165 + do im=0,nvar-1
1.166 + if (im .eq. 0) then
1.167 + ybox = 1.-tt_height-mv_height*ybox0
1.168 + else
1.169 + ybox = ybox - mv_height
1.170 + end if
1.171 + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) ; add
1.172 + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0))
1.173 +
1.174 +; if (icase .gt. 0) then
1.175 +; if (ismissing(values(icase,im)) .or. \ ; ???
1.176 +; ismissing(values(icase,im)))then
1.177 +; ; print ("Missing values skipped")
1.178 +; else
1.179 +; if (values(icase,im).le.values(0,im)) then
1.180 +; if (isatt(opt,"color0")) then
1.181 +; mv_pRes@gsFillColor = opt@color0
1.182 +; else
1.183 +; mv_pRes@gsFillColor = "DarkOliveGreen3"
1.184 +; end if
1.185 +; else
1.186 +; if (isatt(opt,"color1")) then
1.187 +; mv_pRes@gsFillColor = opt@color1
1.188 +; else
1.189 +; mv_pRes@gsFillColor = "IndianRed1"
1.190 +; end if
1.191 +; end if
1.192 +; end if
1.193 +; end if
1.194 + gsn_polygon_ndc(wks,xbox,ybox,mv_pRes)
1.195 + gsn_polyline_ndc(wks,xbox,ybox,False)
1.196 + gsn_text_ndc(wks,sprintf("%4.2f",values(icase,im)),ixtbox,iytbox, mv_tRes)
1.197 + end do
1.198 +; end do
1.199 + end do
1.200 +
1.201 + draw(wks)
1.202 + ;; activate the ;; lines if this is made a function
1.203 + ;;if (.not.isatt(opt,"gsnFrame") .or. opt@gsnFrame) then
1.204 + frame(wks)
1.205 + ; if png or gif then use convert
1.206 + if (isatt(opt,"pltType") .and. \
1.207 + (opt@pltType.eq."png" .or. opt@pltType.eq."gif")) then
1.208 + system("convert -trim +repage "+mfname+".eps "+mfname+"."+opt@pltType)
1.209 + end if
1.210 + ;;end if
1.211 +
1.212 +end