1 ; ***********************************************
2 ; using gsn_table for all
3 ; output: line plot for each site (4 fields)
5 ; ***********************************************
6 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test"
7 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test"
8 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
9 ;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl"
10 ;************************************************
16 ;************************************************
18 ;************************************************
20 film = "i01.10cn_1948-2004_MONS_climo.nc"
22 ; model_name = "10casa"
23 ; film = "i01.10casa_1948-2004_MONS_climo.nc"
24 ;------------------------------------------------------------------------
25 html_name = "table.html." + model_name
26 html_new = html_name +".new"
27 system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new+";"+ \
28 "mv -f "+html_new+" "+html_name)
30 dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
31 fm = addfile(dirm+film,"r")
41 data_mod0 = new ((/nfield,nmon,nlat,nlon/),float)
43 ; change to unit of observed (u mol/m2/s)
44 ; Model_units [=] gC/m2/s
45 ; 12. = molecular weight of C
51 data_mod0(0,:,:,:) = data(:,:,:) * factor
55 data_mod0(1,:,:,:) = data(:,:,:)
59 data_mod0(2,:,:,:) = data(:,:,:)
63 data_mod0(3,:,:,:) = data(:,:,:)
66 ; printVarSummary (data_mod0)
67 ;************************************************
68 ; read in data: observed
69 ;************************************************
70 station = (/"BOREAS_NSA_OBS" \
80 year_ob = (/"1994-2004" \
90 field = (/"CO2 Flux" \
96 nstation = dimsizes(station)
98 nfield = dimsizes(field)
100 data_ob = new ((/nstation, nfield, nmon/),float)
101 lat_ob = new ((/nstation/),float)
102 lon_ob = new ((/nstation/),float)
104 diri_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/"
107 diri = diri_root + station(n)+"/"
108 fili = station(n)+"_"+year_ob(n)+"_monthly.nc"
109 g = addfile (diri+fili,"r")
115 data_ob(n,0,:) = dim_avg(data(month|:,year|:))
119 data_ob(n,1,:) = dim_avg(data(month|:,year|:))
123 data_ob(n,2,:) = dim_avg(data(month|:,year|:))
127 data_ob(n,3,:) = dim_avg(data(month|:,year|:))
135 ;printVarSummary (data_ob)
137 ;************************************************************
138 ; interpolate model data into observed station
139 ; note: model is 0-360E, 90S-90N
140 ;************************************************************
142 ; to be able to handle observation at (-89.98,-24.80)
146 yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0)
150 data_mod = yy(pts|:,field|:,time|:)
151 ; printVarSummary (data_mod)
153 ;************************************************************
154 ; compute correlation coef and M score
155 ;************************************************************
159 ccr = new ((/nstation, nfield/),float)
160 M_score = new ((/nstation, nfield/),float)
164 ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
165 bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
166 M_score(n,m) = (1. -(bias/nmon)) * score_max
170 ;*******************************************************************
171 ; for station line plot
172 ;*******************************************************************
174 ; for x-axis in xyplot
176 mon@long_name = "month"
178 res = True ; plot mods desired
179 res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
180 res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
181 ;-------------------------------------------------------------------------
182 ; Add a boxed legend using the more simple method
184 res@pmLegendDisplayMode = "Always"
185 ; res@pmLegendWidthF = 0.1
186 res@pmLegendWidthF = 0.08
187 res@pmLegendHeightF = 0.06
188 ; res@pmLegendOrthogonalPosF = -1.17
189 ; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
190 res@pmLegendOrthogonalPosF = -0.30 ;(downward)
192 ; res@pmLegendParallelPosF = 0.18
193 res@pmLegendParallelPosF = 0.23 ;(rightward)
195 ; res@lgPerimOn = False
196 res@lgLabelFontHeightF = 0.015
197 res@xyExplicitLegendLabels = (/"observed",model_name/)
198 ;-------------------------------------------------------------------
200 res@gsnFrame = False ; Do not draw plot
201 res@gsnDraw = False ; Do not advance frame
203 pres = True ; panel plot mods desired
204 pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
205 ; indiv. plots in panel
206 pres@gsnMaximize = True ; fill the page
207 ;-------------------------------------------------------------------
209 plot_data = new((/2,12/),float)
211 plot_data!1 = "month"
214 ;----------------------------
217 plot_name = station(n)+"_ob"
218 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
219 res@tiMainString = title
221 wks = gsn_open_wks (plot_type,plot_name)
222 plot=new(4,graphic) ; create graphic array
224 plot_data(0,:) = (/data_ob (n,0,:)/)
225 plot_data@long_name = field(0)
226 plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1
228 plot_data(0,:) = (/data_ob (n,1,:)/)
229 plot_data@long_name = field(1)
230 plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2
232 plot_data(0,:) = (/data_ob (n,2,:)/)
233 plot_data@long_name = field(2)
234 plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3
236 plot_data(0,:) = (/data_ob (n,3,:)/)
237 plot_data@long_name = field(3)
238 plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4
240 gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot
242 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
243 "rm "+plot_name+"."+plot_type)
247 ;----------------------------
250 plot_name = station(n)+"_model_vs_ob"
251 title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
252 res@tiMainString = title
254 wks = gsn_open_wks (plot_type,plot_name)
255 plot=new(4,graphic) ; create graphic array
257 plot_data(0,:) = (/data_ob (n,0,:)/)
258 plot_data(1,:) = (/data_mod(n,0,:)/)
259 plot_data@long_name = field(0)
260 plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1
262 plot_data(0,:) = (/data_ob (n,1,:)/)
263 plot_data(1,:) = (/data_mod(n,1,:)/)
264 plot_data@long_name = field(1)
265 plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2
267 plot_data(0,:) = (/data_ob (n,2,:)/)
268 plot_data(1,:) = (/data_mod(n,2,:)/)
269 plot_data@long_name = field(2)
270 plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3
272 plot_data(0,:) = (/data_ob (n,3,:)/)
273 plot_data(1,:) = (/data_mod(n,3,:)/)
274 plot_data@long_name = field(3)
275 plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4
277 gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot
279 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
280 "rm "+plot_name+"."+plot_type)
286 ;*******************************************************************
287 ; for table of site score
288 ;*******************************************************************
293 table_header_name = "Site"
295 ; column (not including header column)
296 col_header = (/"Latitude","Longitude","observed" \
297 ,"CO2 Flux","Net Radiation","Latent Heat" \
298 ,"Sensible Heat","Average" \
300 ncol = dimsizes(col_header)
302 ; row (not including header row)
304 row_header = new ((/nrow/),string )
305 row_header(0:nstation-1) = station(:)
306 row_header(nrow-1) = "All Sites"
309 ncr1 = (/1,1/) ; 1 row, 1 column
310 x1 = (/0.005,0.15/) ; Start and end X
311 y1 = (/0.800,0.895/) ; Start and end Y
312 text1 = table_header_name
314 res1@txFontHeightF = 0.03
315 res1@gsFillColor = "CornFlowerBlue"
317 ; Column header (equally space in x2)
318 ncr2 = (/1,ncol/) ; 1 rows, ncol columns
319 x2 = (/x1(1),0.995/) ; start from end of x1
323 res2@txFontHeightF = 0.010
324 res2@gsFillColor = "Gray"
326 ; Row header (equally space in y2)
327 ncr3 = (/nrow,1/) ; nrow rows, 1 columns
329 y3 = (/1.0-table_length,y1(0)/) ; end at start of y1
332 res3@txFontHeightF = 0.010
333 res3@gsFillColor = "Gray"
336 ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns
337 x4 = x2 ; Start and end x
338 y4 = y3 ; Start and end Y
339 text4 = new((/nrow,ncol/),string)
341 color_fill4 = new((/nrow,ncol/),string)
342 color_fill4 = "white"
343 color_fill4(:,ncol-1) = "grey"
344 color_fill4(nrow-1,:) = "green"
346 res4 = True ; Set up resource list
347 ; res4@gsnDebug = True ; Useful to print NDC row,col values used.
348 res4@txFontHeightF = 0.015
349 res4@gsFillColor = color_fill4
352 ;-------------------------------------------------------------------
356 text4(n,0) = sprintf("%5.2f", lat_ob(n))
357 text4(n,1) = sprintf("%5.2f", lon_ob(n))
358 text4(n,2) = year_ob(n)
359 text4(n,3) = sprintf("%5.2f", M_score(n,0)) ; CO2 Flux
360 text4(n,4) = sprintf("%5.2f", M_score(n,1)) ; Net Radiation
361 text4(n,5) = sprintf("%5.2f", M_score(n,2)) ; Latent Heat
362 text4(n,6) = sprintf("%5.2f", M_score(n,3)) ; Sensible Heat
363 text4(n,7) = sprintf("%5.2f", avg(M_score(n,:))) ; avg all fields
368 M_co2 = avg(M_score(:,0))
369 M_rad = avg(M_score(:,1))
370 M_lh = avg(M_score(:,2))
371 M_sh = avg(M_score(:,3))
372 M_all = M_co2+ M_rad +M_lh + M_sh
374 text4(nrow-1,0) = "-"
375 text4(nrow-1,1) = "-"
376 text4(nrow-1,2) = "-"
377 text4(nrow-1,3) = sprintf("%5.2f", M_co2) ; avg all sites
378 text4(nrow-1,4) = sprintf("%5.2f", M_rad) ; avg all sites
379 text4(nrow-1,5) = sprintf("%5.2f", M_lh ) ; avg all sites
380 text4(nrow-1,6) = sprintf("%5.2f", M_sh ) ; avg all sites
381 text4(nrow-1,7) = sprintf("%5.2f", M_all) ; avg all sites
389 M_energy_co2 = sprintf("%.2f", M_co2)
390 system("sed s#M_energy_co2#"+M_energy_co2+"# "+html_name+" > "+html_new+";"+ \
391 "mv -f "+html_new+" "+html_name)
394 M_energy_rad = sprintf("%.2f", M_rad)
395 system("sed s#M_energy_rad#"+M_energy_rad+"# "+html_name+" > "+html_new+";"+ \
396 "mv -f "+html_new+" "+html_name)
399 M_energy_lh = sprintf("%.2f", M_lh)
400 system("sed s#M_energy_lh#"+M_energy_lh+"# "+html_name+" > "+html_new+";"+ \
401 "mv -f "+html_new+" "+html_name)
404 M_energy_sh = sprintf("%.2f", M_sh)
405 system("sed s#M_energy_sh#"+M_energy_sh+"# "+html_name+" > "+html_new+";"+ \
406 "mv -f "+html_new+" "+html_name)
408 ;---------------------------------------------------------------------------
410 plot_name = "table_site_score"
412 wks = gsn_open_wks (plot_type,plot_name)
413 ;------------------------------------------
417 gRes@txFontHeightF = 0.02
420 title_text = "Model " + model_name + " M_Score"
422 gsn_text_ndc(wks,title_text,0.50,0.95,gRes)
423 ;------------------------------------------
425 gsn_table(wks,ncr1,x1,y1,text1,res1)
426 gsn_table(wks,ncr2,x2,y2,text2,res2)
427 gsn_table(wks,ncr3,x3,y3,text3,res3)
428 gsn_table(wks,ncr4,x4,y4,text4,res4)
432 system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
433 "rm "+plot_name+"."+plot_type)
434 ;-------------------------------------------------------------------
435 temp_name = "energy." + model_name
436 system("mkdir -p " + temp_name+";"+ \
437 "cp "+ html_name + " " +temp_name+"/table.html"+";"+ \
438 "mv *.png " + temp_name +";"+ \
439 "tar cf "+ temp_name +".tar " + temp_name)
440 ;-------------------------------------------------------------------