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