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