1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/co2/99.all.ncl.2 Mon Jan 26 22:08:20 2009 -0500
1.3 @@ -0,0 +1,521 @@
1.4 +; ***********************************************
1.5 +; using gsn_table for all
1.6 +; combine 19.metric_plot.ncl and 24.lines.ncl
1.7 +; ***********************************************
1.8 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test"
1.9 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test"
1.10 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
1.11 +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl"
1.12 +;************************************************
1.13 +procedure set_line(lines:string,nline:integer,newlines:string)
1.14 +begin
1.15 +; add line to ascci/html file
1.16 +
1.17 + nnewlines = dimsizes(newlines)
1.18 + if(nline+nnewlines-1.ge.dimsizes(lines))
1.19 + print("set_line: bad index, not setting anything.")
1.20 + return
1.21 + end if
1.22 + lines(nline:nline+nnewlines-1) = newlines
1.23 +; print ("lines = " + lines(nline:nline+nnewlines-1))
1.24 + nline = nline + nnewlines
1.25 + return
1.26 +end
1.27 +;****************************************************************************
1.28 +
1.29 +begin
1.30 +
1.31 + plot_type = "ps"
1.32 + plot_type_new = "png"
1.33 +
1.34 +;************************************************
1.35 +; read model data
1.36 +;************************************************
1.37 +
1.38 +; from command line inputs
1.39 +
1.40 +;--------------------------------------------------
1.41 +; edit table.html of current model for movel1_vs_model2
1.42 +
1.43 + if (isvar("compare")) then
1.44 + html_name2 = compare+"/table.html"
1.45 + html_new2 = html_name2 +".new"
1.46 +
1.47 +; the following only needs to execute once
1.48 +; system("sed 1,/model_nameA/s//"+model_name+"/ "+html_name2+" > "+html_new2+";"+ \
1.49 +; "mv -f "+html_new2+" "+html_name2+";"+ \
1.50 +; "sed 1,/model_nameB/s//"+model_name+"/ "+html_name2+" > "+html_new2+";"+ \
1.51 +; "mv -f "+html_new2+" "+html_name2+";"+ \
1.52 +; "sed s#"+modeln+"#"+model_name+"# "+html_name2+" > "+html_new2+";"+ \
1.53 +; "mv -f "+html_new2+" "+html_name2)
1.54 + end if
1.55 +
1.56 +;-------------------------------------
1.57 +; edit table.html for current model
1.58 +
1.59 + html_name = model_name+"/table.html"
1.60 + html_new = html_name +".new"
1.61 +
1.62 +; the following only needs to execute once
1.63 +; system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new+";"+ \
1.64 +; "mv -f "+html_new+" "+html_name)
1.65 +;------------------------------------------------
1.66 + fm = addfile(dirm+film3,"r")
1.67 +
1.68 + x = fm->CO2
1.69 + xi = fm->lon
1.70 + yi = fm->lat
1.71 +
1.72 + xdim = dimsizes(x)
1.73 + nlev = xdim(1)
1.74 + y = x(:,0,:,:)
1.75 +
1.76 +; get co2 at the lowest level
1.77 + y = x(:,nlev-1,:,:)
1.78 +
1.79 +; change to unit of observed (u mol/mol)
1.80 +; Model_units [=] kgCO2 / kgDryAir
1.81 +; 28.966 = molecular weight of dry air
1.82 +; 44. = molecular weight of CO2
1.83 +; u mol = 1e-6 mol
1.84 +
1.85 + factor = (28.966/44.) * 1e6
1.86 + y = y * factor
1.87 +
1.88 + y@_FillValue = 1.e36
1.89 + y@units = "u mol/mol"
1.90 +;************************************************
1.91 +; read data: observed
1.92 +;************************************************
1.93 + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/ob/"
1.94 + fili = "co2_globalView_98.nc"
1.95 + g = addfile (diri+fili,"r")
1.96 + val = g->CO2_SEAS
1.97 + lon = g->LON
1.98 + lat = g->LAT
1.99 + sta = chartostring(g->STATION)
1.100 + delete (g)
1.101 +
1.102 + ncase = dimsizes(lat)
1.103 +;**************************************************************
1.104 +; get only the lowest level at each station
1.105 +;**************************************************************
1.106 + lat_tmp = lat
1.107 + lat_tmp@_FillValue = 1.e+36
1.108 +
1.109 + do n = 0,ncase-1
1.110 + if (.not. ismissing(lat_tmp(n))) then
1.111 + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon)
1.112 + if (dimsizes(indexes) .gt. 1) then
1.113 + lat_tmp(indexes(1:)) = lat_tmp@_FillValue
1.114 + end if
1.115 + delete (indexes)
1.116 + end if
1.117 + end do
1.118 +
1.119 + indexes = ind(.not. ismissing(lat_tmp))
1.120 +
1.121 + lat_ob = lat(indexes)
1.122 + lon_ob = lon(indexes)
1.123 + val_ob = val(indexes,:)
1.124 +;************************************************************
1.125 +; interpolate model data into observed station
1.126 +; note: model is 0-360E, 90S-90N
1.127 +;************************************************************
1.128 +; to be able to handle observation at (-89.98,-24.80)
1.129 + yi(0) = -90.
1.130 +
1.131 + i = ind(lon_ob .lt. 0.)
1.132 + lon_ob(i) = lon_ob(i) + 360.
1.133 +
1.134 + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0)
1.135 +
1.136 + val_model = yo(pts|:,time|:)
1.137 + val_model_0 = val_model
1.138 +;************************************************************
1.139 +; remove annual mean
1.140 +;************************************************************
1.141 + val_model = val_model - conform(val_model,dim_avg(val_model),0)
1.142 +
1.143 +;*******************************************************************
1.144 +; res for station line plot
1.145 +;*******************************************************************
1.146 +; for x-axis in xyplot
1.147 + mon = ispan(1,12,1)
1.148 + mon@long_name = "month"
1.149 +
1.150 + res = True ; plot mods desired
1.151 + res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker
1.152 + res@xyLineColors = (/"red","black"/) ; change line color
1.153 +
1.154 +; Add a boxed legend using the more simple method
1.155 + res@pmLegendDisplayMode = "Always"
1.156 +; res@pmLegendWidthF = 0.1
1.157 + res@pmLegendWidthF = 0.08
1.158 + res@pmLegendHeightF = 0.06
1.159 +; res@pmLegendOrthogonalPosF = -1.17
1.160 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
1.161 + res@pmLegendOrthogonalPosF = -0.30 ;(downward)
1.162 +
1.163 +; res@pmLegendParallelPosF = 0.18
1.164 + res@pmLegendParallelPosF = 0.23 ;(rightward)
1.165 +
1.166 +; res@lgPerimOn = False
1.167 + res@lgLabelFontHeightF = 0.015
1.168 + res@xyExplicitLegendLabels = (/model_name,"observed"/)
1.169 +;************************************************************
1.170 +; number of latitude zone
1.171 +;************************************************************
1.172 + nzone = 4
1.173 +
1.174 +; number of rows for zone table
1.175 + nrow_zone = nzone + 1
1.176 +
1.177 +; number of columns for zone table
1.178 + ncol_zone = 6
1.179 +
1.180 +; saving data for zone
1.181 + text4 = new((/nrow_zone,ncol_zone/),string)
1.182 +
1.183 +do z = 0,nzone-1
1.184 +
1.185 + if (z .eq. 0) then
1.186 + zone = "60N-90N"
1.187 + score_max = 5.0
1.188 + ind_z = ind(lat_ob .ge. 60.)
1.189 + end if
1.190 +
1.191 + if (z .eq. 1) then
1.192 + zone = "30N-60N"
1.193 + score_max = 5.0
1.194 + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.)
1.195 + end if
1.196 +
1.197 + if (z .eq. 2) then
1.198 + zone = "EQ-30N"
1.199 + score_max = 5.0
1.200 + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.)
1.201 + end if
1.202 +
1.203 + if (z .eq. 3) then
1.204 + zone = "90S-EQ"
1.205 + score_max = 5.0
1.206 + ind_z = ind(lat_ob .lt. 0. )
1.207 + end if
1.208 +
1.209 + npts = dimsizes(ind_z)
1.210 +
1.211 +;------------------------------------------------------
1.212 +; for metric table computation
1.213 + amp_ob = new((/npts/),float)
1.214 + amp_model = new((/npts/),float)
1.215 +
1.216 + amp_ratio_sta = new((/npts/),float)
1.217 + ccr_sta = new((/npts/),float)
1.218 + M_sta = new((/npts/),float)
1.219 + score_sta = new((/npts/),float)
1.220 +;-----------------------------------------------------
1.221 +; for station line plot
1.222 + npts_str = ""
1.223 + npts_str = npts
1.224 +
1.225 + plot_data = new((/2,12,npts/),float)
1.226 + plot_data_0 = new((/12,npts/),float)
1.227 +
1.228 + plot_data!0 = "case"
1.229 + plot_data!1 = "month"
1.230 + plot_data!2 = "pts"
1.231 + plot_data@long_name = "CO2 Seasonal"
1.232 +
1.233 + plot_data_0!0 = "month"
1.234 + plot_data_0!1 = "pts"
1.235 + plot_data_0@long_name = "CO2"
1.236 +;--------------------------------------------------------------------------
1.237 + do n=0,npts-1
1.238 +
1.239 + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:))
1.240 + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:))
1.241 +
1.242 + amp_ratio_sta(n) = amp_model(n)/amp_ob(n)
1.243 + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0)
1.244 + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.)
1.245 + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max
1.246 +
1.247 +;----------------------------------------------------------------------
1.248 +; for station line plot
1.249 +
1.250 + plot_data(0,:,n) = (/val_model(ind_z(n),:)/)
1.251 + plot_data(1,:,n) = (/val_ob(ind_z(n),:)/)
1.252 +
1.253 + plot_data_0(:,n) = (/val_model_0(ind_z(n),:)/)
1.254 +
1.255 + plot_name = sta(ind_z(n))
1.256 + title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")"
1.257 +
1.258 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.259 +;------------------------------------------
1.260 +; for panel plot
1.261 +
1.262 + plot=new(2,graphic) ; create graphic array
1.263 + res@gsnFrame = False ; Do not draw plot
1.264 + res@gsnDraw = False ; Do not advance frame
1.265 +
1.266 + pres = True ; panel plot mods desired
1.267 + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
1.268 + ; indiv. plots in panel
1.269 + pres@gsnMaximize = True ; fill the page
1.270 +;------------------------------------------
1.271 + res@tiMainString = title ; add title
1.272 +
1.273 + plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1
1.274 +
1.275 + plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,n),res) ; create plot 2
1.276 +
1.277 + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot
1.278 +
1.279 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.280 + system("rm "+plot_name+"."+plot_type)
1.281 +
1.282 + clear (wks)
1.283 +;---------------------------------------------------------------------------
1.284 + end do
1.285 +;-------------------------------------------------------------------------
1.286 +; for line plot in a zone
1.287 +
1.288 + plot_name = "All_"+npts_str
1.289 + title = plot_name + " in "+ zone
1.290 +
1.291 + wks = gsn_open_wks (plot_type,plot_name) ; open workstation
1.292 +;-----------------------------------------
1.293 +; for panel plot
1.294 +
1.295 + plot=new(2,graphic) ; create graphic array
1.296 + res@gsnFrame = False ; Do not draw plot
1.297 + res@gsnDraw = False ; Do not advance frame
1.298 +
1.299 + pres = True ; panel plot mods desired
1.300 + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
1.301 + ; indiv. plots in panel
1.302 + pres@gsnMaximize = True ; fill the page
1.303 +;-----------------------------------------
1.304 + res@tiMainString = title ; add title
1.305 +
1.306 + plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1
1.307 +
1.308 + plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2
1.309 +
1.310 + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot
1.311 +
1.312 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
1.313 + system("rm "+plot_name+"."+plot_type)
1.314 +
1.315 + clear (wks)
1.316 +; delete (ind_z)
1.317 + delete (plot_data)
1.318 + delete (plot_data_0)
1.319 +;---------------------------------------------------------------------------
1.320 +; values saved for zone table
1.321 +
1.322 + amp_ratio_zone = avg(amp_ratio_sta)
1.323 + ccr_zone = avg(ccr_sta)
1.324 + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts)
1.325 + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max
1.326 +
1.327 + text4(z,0) = zone
1.328 + text4(z,1) = sprintf("%.0f", npts)
1.329 + text4(z,2) = sprintf("%.2f", amp_ratio_zone)
1.330 + text4(z,3) = sprintf("%.2f", ccr_zone)
1.331 + text4(z,4) = sprintf("%.2f", M_zone)
1.332 + text4(z,5) = sprintf("%.2f", score_zone)
1.333 +
1.334 +;*******************************************************************
1.335 +; html table -- station
1.336 +;*******************************************************************
1.337 + output_html = "score+line_"+zone+".html"
1.338 +
1.339 + header = (/"<HTML>" \
1.340 + ,"<HEAD>" \
1.341 + ,"<TITLE>CLAMP metrics</TITLE>" \
1.342 + ,"</HEAD>" \
1.343 + ,"<H1>CO2 in Zone "+zone+": Model "+model_name+"</H1>" \
1.344 + /)
1.345 + footer = "</HTML>"
1.346 +
1.347 + table_header = (/ \
1.348 + "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
1.349 + ,"<tr>" \
1.350 + ," <th bgcolor=DDDDDD >Site Name</th>" \
1.351 + ," <th bgcolor=DDDDDD >Latitude</th>" \
1.352 + ," <th bgcolor=DDDDDD >Longitude</th>" \
1.353 + ," <th bgcolor=DDDDDD >Amplitude Ratio</th>" \
1.354 + ," <th bgcolor=DDDDDD >Correleration Coef</th>" \
1.355 + ," <th bgcolor=DDDDDD >M Score</th>" \
1.356 + ," <th bgcolor=DDDDDD >Combined Score</th>" \
1.357 + ,"</tr>" \
1.358 + /)
1.359 + table_footer = "</table>"
1.360 + row_header = "<tr>"
1.361 + row_footer = "</tr>"
1.362 +
1.363 + lines = new(50000,string)
1.364 + nline = 0
1.365 +
1.366 + set_line(lines,nline,header)
1.367 + set_line(lines,nline,table_header)
1.368 +;-----------------------------------------------
1.369 +; row of table
1.370 +
1.371 + do n = 0,npts-1
1.372 + set_line(lines,nline,row_header)
1.373 +
1.374 + txt0 = sta(ind_z(n))
1.375 + txt1 = sprintf("%5.2f", (/lat(ind_z(n))/))
1.376 + txt2 = sprintf("%5.2f", (/lon(ind_z(n))/))
1.377 + txt3 = sprintf("%5.2f", (/amp_ratio_sta(n)/))
1.378 + txt4 = sprintf("%5.2f", (/ccr_sta(n)/))
1.379 + txt5 = sprintf("%5.2f", (/M_sta(n)/))
1.380 + txt6 = sprintf("%5.2f", (/score_sta(n)/))
1.381 +
1.382 + set_line(lines,nline,"<th><a href="+txt0+".png>"+txt0+"</a></th>")
1.383 + set_line(lines,nline,"<th>"+txt1+"</th>")
1.384 + set_line(lines,nline,"<th>"+txt2+"</th>")
1.385 + set_line(lines,nline,"<th>"+txt3+"</th>")
1.386 + set_line(lines,nline,"<th>"+txt4+"</th>")
1.387 + set_line(lines,nline,"<th>"+txt5+"</th>")
1.388 + set_line(lines,nline,"<th>"+txt6+"</th>")
1.389 +
1.390 + set_line(lines,nline,row_footer)
1.391 + end do
1.392 +
1.393 +; last row, summary
1.394 + set_line(lines,nline,row_header)
1.395 +
1.396 + txt0 = "All_"+sprintf("%.0f", (/npts/))
1.397 + txt1 = "-"
1.398 + txt2 = "-"
1.399 + txt3 = sprintf("%5.2f", (/amp_ratio_zone/))
1.400 + txt4 = sprintf("%5.2f", (/ccr_zone/))
1.401 + txt5 = sprintf("%5.2f", (/M_zone/))
1.402 + txt6 = sprintf("%5.2f", (/score_zone/))
1.403 +
1.404 + set_line(lines,nline,"<th><a href="+txt0+".png>"+txt0+"</a></th>")
1.405 + set_line(lines,nline,"<th>"+txt1+"</th>")
1.406 + set_line(lines,nline,"<th>"+txt2+"</th>")
1.407 + set_line(lines,nline,"<th>"+txt3+"</th>")
1.408 + set_line(lines,nline,"<th>"+txt4+"</th>")
1.409 + set_line(lines,nline,"<th>"+txt5+"</th>")
1.410 + set_line(lines,nline,"<th>"+txt6+"</th>")
1.411 +
1.412 + set_line(lines,nline,row_footer)
1.413 +;-----------------------------------------------
1.414 + set_line(lines,nline,table_footer)
1.415 + set_line(lines,nline,footer)
1.416 +
1.417 +; Now write to an HTML file.
1.418 + idx = ind(.not.ismissing(lines))
1.419 + if(.not.any(ismissing(idx))) then
1.420 + asciiwrite(output_html,lines(idx))
1.421 + else
1.422 + print ("error?")
1.423 + end if
1.424 + delete (idx)
1.425 +;-----------------------------------------------------------------
1.426 +
1.427 + delete (ind_z)
1.428 + delete (amp_model)
1.429 + delete (amp_ob)
1.430 + delete (amp_ratio_sta)
1.431 + delete (ccr_sta)
1.432 + delete (M_sta)
1.433 + delete (score_sta)
1.434 + clear (wks)
1.435 +end do
1.436 +
1.437 +;*******************************************************************
1.438 +; html table -- zone
1.439 +;*******************************************************************
1.440 + output_html = "score_zone.html"
1.441 +
1.442 + header = (/"<HTML>" \
1.443 + ,"<HEAD>" \
1.444 + ,"<TITLE>CLAMP metrics</TITLE>" \
1.445 + ,"</HEAD>" \
1.446 + ,"<H1>CO2 in Latitude Zone: Model "+model_name+"</H1>" \
1.447 + /)
1.448 + footer = "</HTML>"
1.449 +
1.450 + delete (table_header)
1.451 + table_header = (/ \
1.452 + "<table border=1 cellspacing=0 cellpadding=3 width=80%>" \
1.453 + ,"<tr>" \
1.454 + ," <th bgcolor=DDDDDD >Zone</th>" \
1.455 + ," <th bgcolor=DDDDDD >Number of Site</th>" \
1.456 + ," <th bgcolor=DDDDDD >Amplitide Ratio</th>" \
1.457 + ," <th bgcolor=DDDDDD >Correleration Coef</th>" \
1.458 + ," <th bgcolor=DDDDDD >M Score</th>" \
1.459 + ," <th bgcolor=DDDDDD >Combined Score</th>" \
1.460 + ,"</tr>" \
1.461 + /)
1.462 + table_footer = "</table>"
1.463 + row_header = "<tr>"
1.464 + row_footer = "</tr>"
1.465 +
1.466 + lines = new(50000,string)
1.467 + nline = 0
1.468 +
1.469 + set_line(lines,nline,header)
1.470 + set_line(lines,nline,table_header)
1.471 +;-----------------------------------------------
1.472 +;row of table
1.473 +
1.474 +; sum for the last row
1.475 + text4(4,0) = "All"
1.476 + text4(4,1) = sum(stringtofloat(text4(0:3,1)))
1.477 + text4(4,2) = "-"
1.478 + text4(4,3) = "-"
1.479 + text4(4,4) = "-"
1.480 + text4(4,5) = sum(stringtofloat(text4(0:3,5)))
1.481 +
1.482 + do n = 0,nrow_zone-1
1.483 + set_line(lines,nline,row_header)
1.484 +
1.485 + set_line(lines,nline,"<th>"+text4(n,0)+"</th>")
1.486 + set_line(lines,nline,"<th>"+text4(n,1)+"</th>")
1.487 + set_line(lines,nline,"<th>"+text4(n,2)+"</th>")
1.488 + set_line(lines,nline,"<th>"+text4(n,3)+"</th>")
1.489 + set_line(lines,nline,"<th>"+text4(n,4)+"</th>")
1.490 + set_line(lines,nline,"<th>"+text4(n,5)+"</th>")
1.491 +
1.492 + set_line(lines,nline,row_footer)
1.493 + end do
1.494 +;-----------------------------------------------
1.495 + set_line(lines,nline,table_footer)
1.496 + set_line(lines,nline,footer)
1.497 +
1.498 +; Now write to an HTML file.
1.499 + idx = ind(.not.ismissing(lines))
1.500 + if(.not.any(ismissing(idx))) then
1.501 + asciiwrite(output_html,lines(idx))
1.502 + else
1.503 + print ("error?")
1.504 + end if
1.505 + delete (idx)
1.506 +;--------------------------------------------------------------------------
1.507 +
1.508 + M_co2 = text4(4,5)
1.509 +
1.510 + if (isvar("compare")) then
1.511 + system("sed 1,/M_co2/s//"+M_co2+"/ "+html_name2+" > "+html_new2+";"+ \
1.512 + "mv -f "+html_new2+" "+html_name2)
1.513 + end if
1.514 +
1.515 + system("sed s#M_co2#"+M_co2+"# "+html_name+" > "+html_new+";"+ \
1.516 + "mv -f "+html_new+" "+html_name)
1.517 +;***************************************************************************
1.518 +; output plots
1.519 +;***************************************************************************
1.520 + output_dir = model_name+"/co2"
1.521 +
1.522 + system("mv *.png *.html " + output_dir)
1.523 +;***************************************************************************
1.524 +end