energy/97.all.ncl
changeset 0 0c6405ab2ff4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/energy/97.all.ncl	Mon Jan 26 22:08:20 2009 -0500
     1.3 @@ -0,0 +1,421 @@
     1.4 +; ***********************************************
     1.5 +; using gsn_table for all
     1.6 +; output: line plot for each site (4 fields)
     1.7 +;         table for M_score
     1.8 +; ***********************************************
     1.9 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test"
    1.10 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test"
    1.11 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
    1.12 +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl"
    1.13 +;************************************************
    1.14 +begin
    1.15 +
    1.16 +  plot_type     = "ps"
    1.17 +  plot_type_new = "png"
    1.18 +
    1.19 +;************************************************
    1.20 +; read model data
    1.21 +;************************************************
    1.22 +  model_name = "newcn"
    1.23 +  film = "newcn05_ncep_1i_MONS_climo_lnd.nc"
    1.24 +
    1.25 +; model_name = "b30.061n"
    1.26 +; film = "b30.061n_1995-2004_MONS_climo_lnd.nc"
    1.27 +;--------------------------------------------
    1.28 +  dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
    1.29 +  fm    = addfile(dirm+film,"r")
    1.30 +
    1.31 +  xm    = fm->lon
    1.32 +  ym    = fm->lat
    1.33 +  nlat = dimsizes(ym)
    1.34 +  nlon = dimsizes(xm)
    1.35 +
    1.36 +  nmon      = 12
    1.37 +  nfield    = 4
    1.38 +
    1.39 +  data_mod0 = new ((/nfield,nmon,nlat,nlon/),float)
    1.40 +
    1.41 +; change to unit of observed (u mol/m2/s)
    1.42 +; Model_units [=] gC/m2/s
    1.43 +; 12. = molecular weight of C
    1.44 +; u mol = 1e-6 mol 
    1.45 +  data = fm->NEE
    1.46 +
    1.47 +  factor = 1e6/12.
    1.48 +
    1.49 +  data_mod0(0,:,:,:) = data(:,:,:) * factor
    1.50 +  delete (data)
    1.51 +; data  = fm->LATENT
    1.52 +  data1 = fm->FCEV
    1.53 +  data2 = fm->FCTR
    1.54 +  data3 = fm->FGEV
    1.55 +  data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) 
    1.56 +  delete (data1)
    1.57 +  delete (data2)
    1.58 +  delete (data3)
    1.59 +
    1.60 +  data  = fm->FSH
    1.61 +  data_mod0(3,:,:,:) = data(:,:,:) 
    1.62 +  delete (data)
    1.63 +
    1.64 +; data  = fm->NETRAD
    1.65 +  data1 = fm->FSA
    1.66 +  data2 = fm->FIRA
    1.67 +  data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:) 
    1.68 +  delete (data1)
    1.69 +  delete (data2)
    1.70 +
    1.71 +; printVarSummary (data_mod0)
    1.72 +;************************************************
    1.73 +; read in data: observed
    1.74 +;************************************************
    1.75 + station = (/"BOREAS_NSA_OBS" \
    1.76 +            ,"CastelPorziano" \
    1.77 +            ,"Hyytiala" \
    1.78 +            ,"Kaamanen" \
    1.79 +            ,"LBA_Tapajos_KM67" \
    1.80 +            ,"Lethbridge" \
    1.81 +            ,"Tharandt" \
    1.82 +            ,"Vielsalm" \
    1.83 +            /)
    1.84 +
    1.85 + year_ob = (/"1994-2004" \
    1.86 +            ,"1997-2003" \
    1.87 +            ,"1996-2003" \
    1.88 +            ,"2000-2003" \
    1.89 +            ,"2002-2005" \
    1.90 +            ,"1999-2004" \
    1.91 +            ,"1996-2003" \
    1.92 +            ,"1998-2003" \
    1.93 +            /)
    1.94 +
    1.95 + field   = (/"CO2 Flux" \
    1.96 +            ,"Net Radiation" \
    1.97 +            ,"Latent Heat" \
    1.98 +            ,"Sensible Heat" \
    1.99 +            /)
   1.100 +
   1.101 + nstation  = dimsizes(station)
   1.102 + nmon      = 12
   1.103 + nfield    = dimsizes(field)
   1.104 +
   1.105 + data_ob   = new ((/nstation, nfield, nmon/),float)
   1.106 + lat_ob    = new ((/nstation/),float)
   1.107 + lon_ob    = new ((/nstation/),float)
   1.108 +
   1.109 + diri_root  = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/"
   1.110 +
   1.111 + do n = 0,nstation-1
   1.112 +    diri = diri_root + station(n)+"/"
   1.113 +    fili = station(n)+"_"+year_ob(n)+"_monthly.nc"
   1.114 +    g     = addfile (diri+fili,"r")
   1.115 + 
   1.116 +    lon_ob(n) = g->lon 
   1.117 +    lat_ob(n) = g->lat
   1.118 +
   1.119 +    data      = g->CO2_FLUX
   1.120 +    data_ob(n,0,:) = dim_avg(data(month|:,year|:))
   1.121 +    delete (data)
   1.122 +
   1.123 +    data      = g->RAD_FLUX
   1.124 +    data_ob(n,1,:) = dim_avg(data(month|:,year|:))
   1.125 +    delete (data)
   1.126 +
   1.127 +    data      = g->LH_FLUX
   1.128 +    data_ob(n,2,:) = dim_avg(data(month|:,year|:))
   1.129 +    delete (data)
   1.130 +
   1.131 +    data      = g->SH_FLUX
   1.132 +    data_ob(n,3,:) = dim_avg(data(month|:,year|:))
   1.133 +    delete (data)
   1.134 +
   1.135 +    delete (g)
   1.136 + end do
   1.137 + 
   1.138 +;print (lat_ob)
   1.139 +;print (lon_ob)
   1.140 +;printVarSummary (data_ob)
   1.141 +
   1.142 +;************************************************************
   1.143 +; interpolate model data into observed station
   1.144 +; note: model is 0-360E, 90S-90N
   1.145 +;************************************************************
   1.146 +
   1.147 +; to be able to handle observation at (-89.98,-24.80)
   1.148 +; print (ym(0))
   1.149 +  ym(0) = -90.  
   1.150 +
   1.151 +  yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0)
   1.152 +
   1.153 +  delete (data_mod0)
   1.154 +  yy!0 = "field"
   1.155 +  data_mod = yy(pts|:,field|:,time|:)
   1.156 +; printVarSummary (data_mod)
   1.157 +
   1.158 +;************************************************************
   1.159 +; compute correlation coef and M score
   1.160 +;************************************************************
   1.161 +
   1.162 + score_max = 5.
   1.163 +
   1.164 + ccr     = new ((/nstation, nfield/),float)
   1.165 + M_score = new ((/nstation, nfield/),float) 
   1.166 +
   1.167 + do n=0,nstation-1
   1.168 + do m=0,nfield-1   
   1.169 +    ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
   1.170 +    bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
   1.171 +    M_score(n,m) = (1. -(bias/nmon)) * score_max
   1.172 + end do
   1.173 + end do
   1.174 +
   1.175 +;*******************************************************************
   1.176 +; for station line plot
   1.177 +;*******************************************************************
   1.178 +
   1.179 +; for x-axis in xyplot
   1.180 +  mon = ispan(1,12,1)
   1.181 +  mon@long_name = "month"
   1.182 +
   1.183 +  res                   = True               ; plot mods desired
   1.184 +  res@xyLineThicknesses = (/2.0,2.0/)        ; make 2nd lines thicker
   1.185 +  res@xyLineColors      = (/"blue","red"/)   ; line color (ob,model)
   1.186 +;-------------------------------------------------------------------------
   1.187 +; Add a boxed legend using the more simple method
   1.188 +
   1.189 +  res@pmLegendDisplayMode    = "Always"
   1.190 +; res@pmLegendWidthF         = 0.1
   1.191 +  res@pmLegendWidthF         = 0.08
   1.192 +  res@pmLegendHeightF        = 0.06
   1.193 +; res@pmLegendOrthogonalPosF = -1.17
   1.194 +; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
   1.195 +  res@pmLegendOrthogonalPosF = -0.30  ;(downward)
   1.196 +
   1.197 +; res@pmLegendParallelPosF   =  0.18
   1.198 +  res@pmLegendParallelPosF   =  0.23  ;(rightward)
   1.199 +
   1.200 +; res@lgPerimOn             = False
   1.201 +  res@lgLabelFontHeightF     = 0.015
   1.202 +  res@xyExplicitLegendLabels = (/"observed",model_name/)
   1.203 +;-------------------------------------------------------------------
   1.204 +; for panel plot
   1.205 +  res@gsnFrame     = False                   ; Do not draw plot 
   1.206 +  res@gsnDraw      = False                   ; Do not advance frame
   1.207 +
   1.208 +  pres                            = True     ; panel plot mods desired
   1.209 +  pres@gsnPanelYWhiteSpacePercent = 5        ; increase white space around
   1.210 +                                             ; indiv. plots in panel
   1.211 +  pres@gsnMaximize                = True     ; fill the page
   1.212 +;-------------------------------------------------------------------
   1.213 +
   1.214 +  plot_data   = new((/2,12/),float)
   1.215 +  plot_data!0 = "case"
   1.216 +  plot_data!1 = "month"
   1.217 +
   1.218 +  do n = 0,nstation-1
   1.219 +;----------------------------
   1.220 +; for observed
   1.221 +
   1.222 +    plot_name = station(n)+"_ob"    
   1.223 +    title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
   1.224 +    res@tiMainString = title
   1.225 +
   1.226 +    wks = gsn_open_wks (plot_type,plot_name)
   1.227 +    plot=new(4,graphic)                        ; create graphic array   
   1.228 +                           
   1.229 +    plot_data(0,:) = (/data_ob (n,0,:)/)
   1.230 +    plot_data@long_name = field(0)   
   1.231 +    plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 1
   1.232 +
   1.233 +    plot_data(0,:) = (/data_ob (n,1,:)/)
   1.234 +    plot_data@long_name = field(1)
   1.235 +    plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 2
   1.236 +
   1.237 +    plot_data(0,:) = (/data_ob (n,2,:)/)
   1.238 +    plot_data@long_name = field(2)   
   1.239 +    plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 3
   1.240 +
   1.241 +    plot_data(0,:) = (/data_ob (n,3,:)/)
   1.242 +    plot_data@long_name = field(3)
   1.243 +    plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 4
   1.244 +
   1.245 +    gsn_panel(wks,plot,(/2,2/),pres)                 ; create panel plot
   1.246 +
   1.247 +    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
   1.248 +    system("rm "+plot_name+"."+plot_type)
   1.249 +    clear (wks)  
   1.250 +    delete (plot)
   1.251 +;----------------------------
   1.252 +; for model_vs_ob
   1.253 +
   1.254 +    plot_name = station(n)+"_model_vs_ob"
   1.255 +    title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"    
   1.256 +    res@tiMainString = title
   1.257 +
   1.258 +    wks = gsn_open_wks (plot_type,plot_name)
   1.259 +    plot=new(4,graphic)                        ; create graphic array   
   1.260 +                           
   1.261 +    plot_data(0,:) = (/data_ob (n,0,:)/)
   1.262 +    plot_data(1,:) = (/data_mod(n,0,:)/)
   1.263 +    plot_data@long_name = field(0)   
   1.264 +    plot(0)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 1
   1.265 +
   1.266 +    plot_data(0,:) = (/data_ob (n,1,:)/)
   1.267 +    plot_data(1,:) = (/data_mod(n,1,:)/)
   1.268 +    plot_data@long_name = field(1)
   1.269 +    plot(1)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 2
   1.270 +
   1.271 +    plot_data(0,:) = (/data_ob (n,2,:)/)
   1.272 +    plot_data(1,:) = (/data_mod(n,2,:)/)
   1.273 +    plot_data@long_name = field(2)   
   1.274 +    plot(2)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 3
   1.275 +
   1.276 +    plot_data(0,:) = (/data_ob (n,3,:)/)
   1.277 +    plot_data(1,:) = (/data_mod(n,3,:)/)
   1.278 +    plot_data@long_name = field(3)
   1.279 +    plot(3)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 4
   1.280 +
   1.281 +    gsn_panel(wks,plot,(/2,2/),pres)                 ; create panel plot
   1.282 +
   1.283 +    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
   1.284 +    system("rm "+plot_name+"."+plot_type)
   1.285 +    clear (wks)  
   1.286 +    delete (plot)
   1.287 + end do
   1.288 +
   1.289 +;*******************************************************************
   1.290 +; for table of site score
   1.291 +;*******************************************************************
   1.292 +
   1.293 +  table_length = 0.8 
   1.294 +
   1.295 +; table header name
   1.296 +  table_header_name = "Site" 
   1.297 +
   1.298 +; column (not including header column)
   1.299 +  col_header = (/"Latitude","Longitude","observed" \
   1.300 +                ,"CO2 Flux","Net Radiation","Latent Heat" \
   1.301 +                ,"Sensible Heat","Average" \
   1.302 +                /)
   1.303 +  ncol = dimsizes(col_header) 
   1.304 +
   1.305 +; row (not including header row) 
   1.306 +  nrow       = nstation + 1
   1.307 +  row_header = new ((/nrow/),string )
   1.308 +  row_header(0:nstation-1) = station(:)
   1.309 +  row_header(nrow-1)       = "All Sites" 
   1.310 +
   1.311 +; Table header
   1.312 +  ncr1  = (/1,1/)               ; 1 row, 1 column
   1.313 +  x1    = (/0.005,0.15/)        ; Start and end X
   1.314 +  y1    = (/0.800,0.895/)       ; Start and end Y
   1.315 +  text1 = table_header_name
   1.316 +  res1               = True
   1.317 +  res1@txFontHeightF = 0.03
   1.318 +  res1@gsFillColor   = "CornFlowerBlue"
   1.319 +
   1.320 +; Column header (equally space in x2)
   1.321 +  ncr2  = (/1,ncol/)            ; 1 rows, ncol columns
   1.322 +  x2    = (/x1(1),0.995/)       ; start from end of x1
   1.323 +  y2    = y1                    ; same as y1
   1.324 +  text2 = col_header
   1.325 +  res2               = True
   1.326 +  res2@txFontHeightF = 0.010
   1.327 +  res2@gsFillColor   = "Gray"
   1.328 +
   1.329 +; Row header (equally space in y2)
   1.330 +  ncr3  = (/nrow,1/)                 ; nrow rows, 1 columns
   1.331 +  x3    = x1                         ; same as x1
   1.332 +  y3    = (/1.0-table_length,y1(0)/) ; end at start of y1
   1.333 +  text3 = row_header
   1.334 +  res3               = True
   1.335 +  res3@txFontHeightF = 0.010
   1.336 +  res3@gsFillColor   = "Gray"
   1.337 +
   1.338 +; Main table body
   1.339 +  ncr4  = (/nrow,ncol/)           ; nrow rows, ncol columns
   1.340 +  x4    = x2                      ; Start and end x
   1.341 +  y4    = y3                      ; Start and end Y
   1.342 +  text4 = new((/nrow,ncol/),string)
   1.343 +
   1.344 +  color_fill4           = new((/nrow,ncol/),string)
   1.345 +  color_fill4           = "white"
   1.346 +  color_fill4(:,ncol-1) = "grey"
   1.347 +  color_fill4(nrow-1,:) = "green"
   1.348 +
   1.349 +  res4               = True       ; Set up resource list
   1.350 +; res4@gsnDebug      = True       ; Useful to print NDC row,col values used.
   1.351 +  res4@txFontHeightF = 0.015
   1.352 +  res4@gsFillColor   = color_fill4
   1.353 +
   1.354 +  delete (color_fill4)
   1.355 +;-------------------------------------------------------------------
   1.356 +; for table value
   1.357 +
   1.358 +  do n = 0,nrow-2
   1.359 +     text4(n,0) = sprintf("%5.2f", lat_ob(n))  
   1.360 +     text4(n,1) = sprintf("%5.2f", lon_ob(n))  
   1.361 +     text4(n,2) = year_ob(n)  
   1.362 +     text4(n,3) = sprintf("%5.2f", M_score(n,0))      ; CO2 Flux
   1.363 +     text4(n,4) = sprintf("%5.2f", M_score(n,1))      ; Net Radiation
   1.364 +     text4(n,5) = sprintf("%5.2f", M_score(n,2))      ; Latent Heat
   1.365 +     text4(n,6) = sprintf("%5.2f", M_score(n,3))      ; Sensible Heat
   1.366 +     text4(n,7) = sprintf("%5.2f", avg(M_score(n,:))) ; avg all fields    
   1.367 +  end do
   1.368 +
   1.369 +;    for the last row
   1.370 +
   1.371 +     M_co2 = avg(M_score(:,0))
   1.372 +     M_rad = avg(M_score(:,1))
   1.373 +     M_lh  = avg(M_score(:,2))
   1.374 +     M_sh  = avg(M_score(:,3))
   1.375 +     M_all = M_co2+ M_rad +M_lh + M_sh
   1.376 +     
   1.377 +     text4(nrow-1,0) = "-"
   1.378 +     text4(nrow-1,1) = "-"
   1.379 +     text4(nrow-1,2) = "-"
   1.380 +     text4(nrow-1,3) = sprintf("%5.2f", M_co2) ; avg all sites
   1.381 +     text4(nrow-1,4) = sprintf("%5.2f", M_rad) ; avg all sites
   1.382 +     text4(nrow-1,5) = sprintf("%5.2f", M_lh ) ; avg all sites
   1.383 +     text4(nrow-1,6) = sprintf("%5.2f", M_sh ) ; avg all sites
   1.384 +     text4(nrow-1,7) = sprintf("%5.2f", M_all) ; avg all sites
   1.385 +
   1.386 +     print (M_co2)
   1.387 +     print (M_rad)
   1.388 +     print (M_lh )
   1.389 +     print (M_sh)
   1.390 +     print (M_all) 
   1.391 +;---------------------------------------------------------------------------
   1.392 + 
   1.393 +  plot_name = "table_site_score"
   1.394 + 
   1.395 +  wks = gsn_open_wks (plot_type,plot_name)
   1.396 +;------------------------------------------
   1.397 +; for table title
   1.398 +
   1.399 +  gRes               = True
   1.400 +  gRes@txFontHeightF = 0.02
   1.401 +; gRes@txAngleF      = 90
   1.402 +
   1.403 +  title_text = "Model  " + model_name +  "  M_Score"
   1.404 +
   1.405 +  gsn_text_ndc(wks,title_text,0.50,0.95,gRes)
   1.406 +;------------------------------------------   
   1.407 +
   1.408 +  gsn_table(wks,ncr1,x1,y1,text1,res1)
   1.409 +  gsn_table(wks,ncr2,x2,y2,text2,res2)
   1.410 +  gsn_table(wks,ncr3,x3,y3,text3,res3)
   1.411 +  gsn_table(wks,ncr4,x4,y4,text4,res4) 
   1.412 +
   1.413 +  frame(wks)
   1.414 +
   1.415 +  system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
   1.416 +  system("rm "+plot_name+"."+plot_type)
   1.417 +;-------------------------------------------------------------------
   1.418 +  temp_name = "temp." + model_name
   1.419 +  system("mkdir -p " + temp_name)
   1.420 +  system("mv *.png " + temp_name)
   1.421 +  system("tar cf "+ temp_name +".tar " + temp_name)
   1.422 +;------------------------------------------------------------------- 
   1.423 +
   1.424 +end