1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/ameriflux/24.plot.ncl Mon Jan 26 22:08:20 2009 -0500
1.3 @@ -0,0 +1,847 @@
1.4 +;************************************************************
1.5 +; change data name to timeseries_L4_m.nc
1.6 +; move data
1.7 +; merge annual
1.8 +; add table
1.9 +; add time series plot
1.10 +; sort by latitude in decending order (N->S)
1.11 +; find year_ob >= 4
1.12 +; add year_ob_i and year_ob_f
1.13 +; change long_name
1.14 +;************************************************************
1.15 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
1.16 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
1.17 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
1.18 +;************************************************************
1.19 +procedure set_line(lines:string,nline:integer,newlines:string)
1.20 +begin
1.21 +; add line to ascci/html file
1.22 +
1.23 + nnewlines = dimsizes(newlines)
1.24 + if(nline+nnewlines-1.ge.dimsizes(lines))
1.25 + print("set_line: bad index, not setting anything.")
1.26 + return
1.27 + end if
1.28 + lines(nline:nline+nnewlines-1) = newlines
1.29 +; print ("lines = " + lines(nline:nline+nnewlines-1))
1.30 + nline = nline + nnewlines
1.31 + return
1.32 +end
1.33 +;*************************************************************
1.34 +begin
1.35 +
1.36 + plot_type = "ps"
1.37 + plot_type_new = "png"
1.38 +
1.39 +;************************************************
1.40 +; model data info
1.41 +;************************************************
1.42 + model = "cn"
1.43 +; model = "casa"
1.44 +
1.45 + model_name = "i01.10" + model
1.46 +
1.47 + ENERGY ="new"
1.48 +
1.49 + nmonth = 12
1.50 +
1.51 +;************************************************
1.52 +; observed data info
1.53 +;************************************************
1.54 +
1.55 + station = (/"ARM_Oklahoma" \
1.56 + ,"ARM_Oklahoma_burn" \
1.57 + ,"ARM_Oklahoma_control" \
1.58 + ,"Atqasuk" \
1.59 + ,"Audubon" \
1.60 + ,"AustinCary" \
1.61 + ,"Bartlett" \
1.62 + ,"Bondville" \
1.63 + ,"Brookings" \
1.64 + ,"Donaldson" \
1.65 + ,"Duke_Forest_Hardwoods" \
1.66 + ,"Duke_Forest_Open_Field" \
1.67 + ,"Duke_Forest_Pine" \
1.68 + ,"Fermi_Ag" \
1.69 + ,"Fermi_Prairie" \
1.70 + ,"Flagstaff_Managed" \
1.71 + ,"Flagstaff_Unmanaged" \
1.72 + ,"Flagstaff_Wildfire" \
1.73 + ,"FortPeck" \
1.74 + ,"FreemanRanch_mesquite" \
1.75 + ,"Goodwin_Creek" \
1.76 + ,"HarvardForest" \
1.77 + ,"HarvardForestHemlock" \
1.78 + ,"HowlandForestMain" \
1.79 + ,"HowlandForestWest" \
1.80 + ,"Ivotuk" \
1.81 + ,"KendallGrasslands" \
1.82 + ,"KennedySpaceCenterPine" \
1.83 + ,"KennedySpaceCenterScrub" \
1.84 + ,"LittleProspect" \
1.85 + ,"LostCreek" \
1.86 + ,"Mead-irrigated" \
1.87 + ,"Mead-irrigated-rotation" \
1.88 + ,"Mead-rainfed" \
1.89 + ,"Metolius_2nd_YoungPonderosaPine" \
1.90 + ,"MetoliusEyerly" \
1.91 + ,"MetoliusIntermediatePine" \
1.92 + ,"MetoliusOldPonderosaPine" \
1.93 + ,"MissouriOzark" \
1.94 + ,"Mize" \
1.95 + ,"MorganMonroe" \
1.96 + ,"NiwotRidge" \
1.97 + ,"NorthCarolina_cc" \
1.98 + ,"NorthCarolina_lp" \
1.99 + ,"ParkFalls" \
1.100 + ,"Rayonier" \
1.101 + ,"SantaRita" \
1.102 + ,"SkyOaks_Old" \
1.103 + ,"SkyOaks_PostFire" \
1.104 + ,"SkyOaks_Young" \
1.105 + ,"SylvaniaWilderness" \
1.106 + ,"Toledo" \
1.107 + ,"Tonzi" \
1.108 + ,"UCI_1850" \
1.109 + ,"UCI_1930" \
1.110 + ,"UCI_1964" \
1.111 + ,"UCI_1964wet" \
1.112 + ,"UCI_1981" \
1.113 + ,"UCI_1989" \
1.114 + ,"UCI_1998" \
1.115 + ,"UMBS" \
1.116 + ,"Vaira" \
1.117 + ,"WalkerBranch" \
1.118 + ,"WillowCreek" \
1.119 + ,"WindRiver" \
1.120 + ,"Wisconsin_ihw" \
1.121 + ,"Wisconsin_irp" \
1.122 + ,"Wisconsin_mrp" \
1.123 + ,"Wisconsin_myjp" \
1.124 + ,"Wisconsin_pb" \
1.125 + ,"Wisconsin_rpcc" \
1.126 + ,"Wisconsin_yhw" \
1.127 + ,"Wisconsin_yjp" \
1.128 + ,"Wisconsin_yrp" \
1.129 + /)
1.130 +
1.131 + field = (/"NEE Flux" \
1.132 + ,"Net Radiation" \
1.133 + ,"Latent Heat" \
1.134 + ,"Sensible Heat" \
1.135 + ,"GPP Flux" \
1.136 + ,"Respiration" \
1.137 + /)
1.138 +
1.139 + field_unit = (/"u mol/m2/s" \
1.140 + ,"W/m2" \
1.141 + ,"W/m2" \
1.142 + ,"W/m2" \
1.143 + ,"u mol/m2/s" \
1.144 + ,"u mol/m2/s" \
1.145 + /)
1.146 +
1.147 + nstation = dimsizes(station)
1.148 + nfield = dimsizes(field)
1.149 +
1.150 +;========================================================================
1.151 +; get observed info: number of year, first/last year, lat, lon
1.152 +; and annual data
1.153 +
1.154 + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/observed/ameriflux/"
1.155 +
1.156 + year_station = new ((/nstation/),integer) ; number of year
1.157 + year_ob = new ((/nstation/),string) ; observed year
1.158 + year_ob_i = new ((/nstation/),integer) ; first year
1.159 + year_ob_f = new ((/nstation/),integer) ; last year
1.160 + lat_ob = new ((/nstation/),float) ; latitude
1.161 + lon_ob = new ((/nstation/),float) ; longitude
1.162 +
1.163 + data_ob_ann = new ((/nfield, nmonth, nstation/),float)
1.164 +
1.165 + do n = 0, nstation-1
1.166 +
1.167 + diro = dir_root + station(n)+"/"
1.168 + filo = "timeseries_L4_m.nc"
1.169 + fo = addfile (diro+filo,"r")
1.170 +
1.171 + lat_ob(n) = fo->lat
1.172 + lon_ob(n) = fo->lon
1.173 +
1.174 + year = fo->year
1.175 +
1.176 + year_station(n) = dimsizes(year)
1.177 + year_ob_i(n) = year(0)
1.178 + year_ob_f(n) = year(year_station(n)-1)
1.179 + year_ob(n) = year_ob_i(n) + "-" + year_ob_f(n)
1.180 +
1.181 + delete (year)
1.182 +
1.183 + data = fo->NEE_or_fMDS
1.184 + data_ob_ann(0,:,n) = dim_avg(data(month|:,year|:))
1.185 +
1.186 + data = fo->Rg_f
1.187 + data_ob_ann(1,:,n) = dim_avg(data(month|:,year|:))
1.188 +
1.189 + data = fo->LE_f
1.190 + data_ob_ann(2,:,n) = dim_avg(data(month|:,year|:))
1.191 +
1.192 + data = fo->H_f
1.193 + data_ob_ann(3,:,n) = dim_avg(data(month|:,year|:))
1.194 +
1.195 + data = fo->GPP_or_MDS
1.196 + data_ob_ann(4,:,n) = dim_avg(data(month|:,year|:))
1.197 +
1.198 + data = fo->Reco_or
1.199 + data_ob_ann(5,:,n) = dim_avg(data(month|:,year|:))
1.200 +
1.201 + delete (data)
1.202 + delete (fo)
1.203 + end do
1.204 +
1.205 +;print (year_ob_i)
1.206 +;print (year_ob_f)
1.207 +
1.208 +;--------------------------------------------------------------
1.209 +; find (# of year observed) >=4 and year_ob_i <= 2001
1.210 +
1.211 + i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001)
1.212 +
1.213 + station_long = station(i_long_ob)
1.214 + lat_ob_long = lat_ob(i_long_ob)
1.215 + lon_ob_long = lat_ob(i_long_ob)
1.216 + year_ob_long = year_ob(i_long_ob)
1.217 + year_ob_i_long = year_ob_i(i_long_ob)
1.218 + year_ob_f_long = year_ob_f(i_long_ob)
1.219 + year_station_long = year_station(i_long_ob)
1.220 +
1.221 + nstation_long = dimsizes(station_long)
1.222 +
1.223 +; print (i_long_ob)
1.224 +; print (nstation_long)
1.225 +; print (station_long)
1.226 +; print (year_ob_i(i_long_ob))
1.227 +
1.228 +;=========================================================
1.229 +; get model data at observed lat-lon
1.230 +
1.231 + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
1.232 + film = model_name+"_ameriflux_1990-2004_monthly.nc"
1.233 + fm = addfile (dirm+film,"r")
1.234 +
1.235 + xm = fm->lon
1.236 + ym = fm->lat
1.237 + date = fm->date
1.238 +
1.239 + date_dim = dimsizes(date)
1.240 + nyear = date_dim(0)
1.241 +
1.242 + data_mod = new ((/nfield,nyear,nmonth,nstation/),float)
1.243 + data_mod_ann = new ((/nfield,nmonth,nstation/),float)
1.244 + data_mod_long = new ((/nfield,nyear,nmonth,nstation_long/),float)
1.245 +
1.246 +; change to unit of observed (u mol/m2/s)
1.247 +; Model_units [=] gC/m2/s
1.248 +; 12. = molecular weight of C
1.249 +; u mol = 1e-6 mol
1.250 +
1.251 + factor = 1.e6 /12.
1.252 +
1.253 +;------------------------------------------------------------
1.254 +; interpolate model data into observed station
1.255 +; note: model is 0-360E, 90S-90N
1.256 +
1.257 +; to be able to handle observation at (-89.98,-24.80)
1.258 + ym(0) = -90.
1.259 +;------------------------------------------------------------
1.260 +
1.261 +if (ENERGY .eq. "old") then
1.262 +
1.263 + data = fm->NEE
1.264 + data_mod(0,:,:,:) = data(:,:,:) * factor
1.265 +
1.266 +; data = fm->LATENT
1.267 + data1 = fm->FCEV
1.268 + data2 = fm->FCTR
1.269 + data3 = fm->FGEV
1.270 + data_mod(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:)
1.271 + delete (data1)
1.272 + delete (data2)
1.273 + delete (data3)
1.274 +
1.275 +; data = fm->SENSIBLE
1.276 + data = fm->FSH
1.277 + data_mod(3,:,:,:) = data(:,:,:)
1.278 +
1.279 +; data = fm->NETRAD
1.280 + data1 = fm->FSA
1.281 + data2 = fm->FIRA
1.282 + data_mod(1,:,:,:) = data1(:,:,:)-data2(:,:,:)
1.283 + delete (data1)
1.284 + delete (data2)
1.285 +
1.286 +else
1.287 +
1.288 + data = fm->NEE
1.289 + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
1.290 + data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
1.291 + data_mod(0,:,:,:) = yy(:,:,:) * factor
1.292 +
1.293 +; printVarSummary(yy)
1.294 +
1.295 + data = fm->NETRAD
1.296 + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
1.297 + data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:))
1.298 + data_mod(1,:,:,:) = yy(:,:,:)
1.299 +
1.300 + data = fm->LATENT
1.301 + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
1.302 + data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:))
1.303 + data_mod(2,:,:,:) = yy(:,:,:)
1.304 +
1.305 +; data = fm->SENSIBLE
1.306 + data = fm->FSH
1.307 + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
1.308 + data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:))
1.309 + data_mod(3,:,:,:) = yy(:,:,:)
1.310 +
1.311 +end if
1.312 +
1.313 + data = fm->GPP
1.314 + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
1.315 + data_mod_ann(4,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
1.316 + data_mod(4,:,:,:) = yy(:,:,:) * factor
1.317 +
1.318 + if (model .eq. "cn") then
1.319 + data = fm->ER
1.320 + else
1.321 + data1 = fm->AR
1.322 + data2 = fm->HR
1.323 + data = data1 + data2
1.324 +
1.325 + delete (data1)
1.326 + delete (data2)
1.327 + end if
1.328 +
1.329 + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
1.330 + data_mod_ann(5,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
1.331 + data_mod(5,:,:,:) = yy(:,:,:) * factor
1.332 +
1.333 + data_mod_long(:,:,:,:) = data_mod(:,:,:,i_long_ob)
1.334 +
1.335 + delete (data_mod)
1.336 + delete (fm)
1.337 + delete (data)
1.338 + delete (yy)
1.339 +
1.340 +;*******************************************************************
1.341 +; for station line plot
1.342 +;*******************************************************************
1.343 +
1.344 +; for x-axis in xyplot
1.345 + mon = ispan(1,12,1)
1.346 + mon@long_name = "month"
1.347 +
1.348 + res = True ; plot mods desired
1.349 + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker
1.350 + res@xyLineColors = (/"blue","red"/) ; line color (ob,model)
1.351 +
1.352 + res@tmXBFormat = "f" ; not to add trailing zeros
1.353 +
1.354 +;-------------------------------------------------------------------------
1.355 +; Add a boxed legend using the more simple method
1.356 +
1.357 + res@pmLegendDisplayMode = "Always"
1.358 +; res@pmLegendWidthF = 0.1
1.359 + res@pmLegendWidthF = 0.08
1.360 + res@pmLegendHeightF = 0.06
1.361 +; res@pmLegendOrthogonalPosF = -1.17
1.362 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward)
1.363 + res@pmLegendOrthogonalPosF = -0.30 ;(downward)
1.364 +
1.365 +; res@pmLegendParallelPosF = 0.18
1.366 + res@pmLegendParallelPosF = 0.23 ;(rightward)
1.367 +
1.368 +; res@lgPerimOn = False
1.369 + res@lgLabelFontHeightF = 0.015
1.370 + res@xyExplicitLegendLabels = (/"observed",model_name/)
1.371 +;-------------------------------------------------------------------
1.372 +; for panel plot
1.373 + res@gsnFrame = False ; Do not draw plot
1.374 + res@gsnDraw = False ; Do not advance frame
1.375 +
1.376 + pres = True ; panel plot mods desired
1.377 + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around
1.378 + ; indiv. plots in panel
1.379 + pres@gsnMaximize = True ; fill the page
1.380 +;-------------------------------------------------------------------
1.381 +
1.382 +;==============================================================
1.383 +; get ob data at each site with long observation
1.384 +
1.385 + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/"
1.386 +
1.387 + do n = 0,nstation_long-1
1.388 +; do n = 0,0
1.389 +
1.390 + year_setback = 0
1.391 +
1.392 + nyear = year_station_long(n)
1.393 +
1.394 + if (year_ob_f_long(n).eq. 2006) then
1.395 + year_setback = 2006 -2004
1.396 + end if
1.397 + if (year_ob_f_long(n).eq. 2005) then
1.398 + year_setback = 2005 -2004
1.399 + end if
1.400 +
1.401 + ntime = (nyear - year_setback) * nmonth
1.402 +
1.403 + data_ob = new ((/nfield, nyear, nmonth/),float)
1.404 +
1.405 + diro = dir_root + station_long(n)+"/"
1.406 + filo = year_ob_long(n)+"_L4_m.nc"
1.407 + fo = addfile (diro+filo,"r")
1.408 +
1.409 +; print (diro)
1.410 +; print (filo)
1.411 +
1.412 + data_ob(0,:,:) = fo->NEE_or_fMDS
1.413 + data_ob(1,:,:) = fo->Rg_f
1.414 + data_ob(2,:,:) = fo->LE_f
1.415 + data_ob(3,:,:) = fo->H_f
1.416 + data_ob(4,:,:) = fo->GPP_or_MDS
1.417 + data_ob(5,:,:) = fo->Reco_or
1.418 +
1.419 + delete (fo)
1.420 +
1.421 + timeI = new((/ntime/),integer)
1.422 + timeF = new((/ntime/),float)
1.423 + timeI = ispan(1,ntime,1)
1.424 + timeF = year_ob_i_long(n) + (timeI-1)/12.
1.425 + timeF@long_name = "year"
1.426 +
1.427 + plot_data = new((/2,ntime/),float)
1.428 +
1.429 +;----------------------------
1.430 +; for model_vs_ob
1.431 +
1.432 + plot_name = station_long(n)+"_tseries_vs_ob"
1.433 + title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")"
1.434 + res@tiMainString = title
1.435 +
1.436 + wks = gsn_open_wks (plot_type,plot_name)
1.437 + plot=new(nfield,graphic) ; create graphic array
1.438 +
1.439 + i_year_mod_i = year_ob_i_long(n) - 1990
1.440 + i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback
1.441 +
1.442 + i_year_ob_f = nyear - year_setback - 1
1.443 +
1.444 +; print (nyear)
1.445 +; print (i_year_ob_f)
1.446 +; print (i_year_mod_i)
1.447 +; print (i_year_mod_f)
1.448 +
1.449 + do i = 0,nfield-1
1.450 + plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:))
1.451 + plot_data(1,:) = ndtooned(data_mod_long(i,i_year_mod_i:i_year_mod_f,:,n))
1.452 + plot_data@long_name = field(i)+" ("+field_unit(i)+")"
1.453 + plot(i)=gsn_csm_xy(wks,timeF,plot_data,res) ; create plot
1.454 + end do
1.455 +
1.456 + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
1.457 +
1.458 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
1.459 + "rm "+plot_name+"."+plot_type)
1.460 +
1.461 + clear (wks)
1.462 + delete (plot)
1.463 +
1.464 + delete (data_ob)
1.465 + delete (timeI)
1.466 + delete (timeF)
1.467 + delete (plot_data)
1.468 +
1.469 + end do
1.470 +
1.471 +;###################################################################
1.472 +; for the following tables,
1.473 +; sort by latitude in decending order (N->S)
1.474 +
1.475 + isort = dim_pqsort(lat_ob_long,-1)
1.476 +
1.477 + station_sort = station_long(isort)
1.478 + year_ob_sort = year_ob_long(isort)
1.479 + lat_ob_sort = lat_ob_long(isort)
1.480 + lon_ob_sort = lon_ob_long(isort)
1.481 +
1.482 +; print(isort)
1.483 +; print(lat_ob_sort)
1.484 +
1.485 +;*******************************************************************
1.486 +; html table of site: observed
1.487 +;*******************************************************************
1.488 + output_html = "tseries_vs_ob.html"
1.489 +
1.490 + header = (/"<HTML>" \
1.491 + ,"<HEAD>" \
1.492 + ,"<TITLE>CLAMP metrics</TITLE>" \
1.493 + ,"</HEAD>" \
1.494 + ,"<H1>Timeseries at Site: "+model_name+" vs Observation</H1>" \
1.495 + /)
1.496 + footer = "</HTML>"
1.497 +
1.498 + table_header = (/ \
1.499 + "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
1.500 + ,"<tr>" \
1.501 + ," <th bgcolor=DDDDDD >Site Name</th>" \
1.502 + ," <th bgcolor=DDDDDD >Latitude</th>" \
1.503 + ," <th bgcolor=DDDDDD >Longitude</th>" \
1.504 + ," <th bgcolor=DDDDDD >Observed</th>" \
1.505 + ,"</tr>" \
1.506 + /)
1.507 + table_footer = "</table>"
1.508 + row_header = "<tr>"
1.509 + row_footer = "</tr>"
1.510 +
1.511 + lines = new(50000,string)
1.512 + nline = 0
1.513 +
1.514 + set_line(lines,nline,header)
1.515 + set_line(lines,nline,table_header)
1.516 +;-----------------------------------------------
1.517 +; row of table
1.518 +
1.519 + do n = 0,nstation_long-1
1.520 +
1.521 + set_line(lines,nline,row_header)
1.522 +
1.523 + txt0 = station_sort(n)
1.524 + txt1 = sprintf("%5.2f", lat_ob_sort(n))
1.525 + txt2 = sprintf("%5.2f", lon_ob_sort(n))
1.526 + txt3 = year_ob_sort(n)
1.527 +
1.528 + set_line(lines,nline,"<th><a href="+txt0+"_tseries_vs_ob.png>"+txt0+"</a></th>")
1.529 + set_line(lines,nline,"<th>"+txt1+"</th>")
1.530 + set_line(lines,nline,"<th>"+txt2+"</th>")
1.531 + set_line(lines,nline,"<th>"+txt3+"</th>")
1.532 +
1.533 + set_line(lines,nline,row_footer)
1.534 + end do
1.535 +;-----------------------------------------------
1.536 + set_line(lines,nline,table_footer)
1.537 + set_line(lines,nline,footer)
1.538 +
1.539 +; Now write to an HTML file.
1.540 + idx = ind(.not.ismissing(lines))
1.541 + if(.not.any(ismissing(idx))) then
1.542 + asciiwrite(output_html,lines(idx))
1.543 + else
1.544 + print ("error?")
1.545 + end if
1.546 + delete (idx)
1.547 +
1.548 + delete (isort)
1.549 + delete (station_sort)
1.550 + delete (year_ob_sort)
1.551 + delete (lat_ob_sort)
1.552 + delete (lon_ob_sort)
1.553 +
1.554 +;************************************************************
1.555 +; compute annual cycle correlation coef and M score
1.556 +;************************************************************
1.557 +
1.558 + score_max = 5.
1.559 +
1.560 + ccr = new ((/nstation, nfield/),float)
1.561 + M_score = new ((/nstation, nfield/),float)
1.562 +
1.563 + do n=0,nstation-1
1.564 + do m=0,nfield-1
1.565 + ccr(n,m) = esccr(data_ob_ann(m,:,n),data_mod_ann(m,:,n),0)
1.566 + bias = sum(abs(data_mod_ann(m,:,n)-data_ob_ann(m,:,n))/(abs(data_mod_ann(m,:,n))+abs(data_ob_ann(m,:,n))))
1.567 + M_score(n,m) = (1. -(bias/nmonth)) * score_max
1.568 + end do
1.569 + end do
1.570 +
1.571 + M_co2 = avg(M_score(:,0))
1.572 + M_rad = avg(M_score(:,1))
1.573 + M_lh = avg(M_score(:,2))
1.574 + M_sh = avg(M_score(:,3))
1.575 + M_gpp = avg(M_score(:,4))
1.576 + M_er = avg(M_score(:,5))
1.577 + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er
1.578 +
1.579 + M_energy_co2 = sprintf("%.2f", M_co2)
1.580 + M_energy_rad = sprintf("%.2f", M_rad)
1.581 + M_energy_lh = sprintf("%.2f", M_lh )
1.582 + M_energy_sh = sprintf("%.2f", M_sh )
1.583 + M_energy_gpp = sprintf("%.2f", M_gpp)
1.584 + M_energy_er = sprintf("%.2f", M_er )
1.585 + M_energy_all = sprintf("%.2f", M_all)
1.586 +
1.587 +;*******************************************************************
1.588 +; for station line plot
1.589 +;*******************************************************************
1.590 +
1.591 +; for x-axis in xyplot
1.592 + mon = ispan(1,12,1)
1.593 + mon@long_name = "month"
1.594 +
1.595 +;-------------------------------------------------------------------
1.596 +
1.597 + plot_data = new((/2,nmonth/),float)
1.598 + plot_data!0 = "case"
1.599 + plot_data!1 = "month"
1.600 +
1.601 + do n = 0,nstation-1
1.602 +;----------------------------
1.603 +; for observed
1.604 +
1.605 + plot_name = station(n)+"_ob"
1.606 + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
1.607 + res@tiMainString = title
1.608 +
1.609 + wks = gsn_open_wks (plot_type,plot_name)
1.610 + plot=new(nfield,graphic) ; create graphic array
1.611 +
1.612 + do i = 0,nfield-1
1.613 + plot_data(0,:) = (/data_ob_ann(i,:,n)/)
1.614 + plot_data@long_name = field(i)+" ("+field_unit(i)+")"
1.615 + plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot
1.616 + end do
1.617 +
1.618 + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
1.619 +
1.620 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
1.621 + "rm "+plot_name+"."+plot_type)
1.622 +
1.623 + clear (wks)
1.624 + delete (plot)
1.625 +;----------------------------
1.626 +; for model_vs_ob
1.627 +
1.628 + plot_name = station(n)+"_model_vs_ob"
1.629 + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
1.630 + res@tiMainString = title
1.631 +
1.632 + wks = gsn_open_wks (plot_type,plot_name)
1.633 + plot=new(nfield,graphic) ; create graphic array
1.634 +
1.635 + do i = 0,nfield-1
1.636 + plot_data(0,:) = (/data_ob_ann(i,:,n)/)
1.637 + plot_data(1,:) = (/data_mod_ann(i,:,n)/)
1.638 + plot_data@long_name = field(i)+" ("+field_unit(i)+")"
1.639 + plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot
1.640 + end do
1.641 +
1.642 + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot
1.643 +
1.644 + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
1.645 + "rm "+plot_name+"."+plot_type)
1.646 +
1.647 + clear (wks)
1.648 + delete (plot)
1.649 + end do
1.650 +
1.651 +;###################################################################
1.652 +; for the following tables,
1.653 +; sort by latitude in decending order (N->S)
1.654 +; sort by lat in decending order (N->S)
1.655 +
1.656 + isort = dim_pqsort(lat_ob,-1)
1.657 +
1.658 + station_sort = station(isort)
1.659 + year_ob_sort = year_ob(isort)
1.660 + lat_ob_sort = lat_ob(isort)
1.661 + lon_ob_sort = lon_ob(isort)
1.662 + M_score_sort = M_score(isort,:)
1.663 +
1.664 +; print(isort)
1.665 +; print(lat_ob_sort)
1.666 +;###################################################################
1.667 +;*******************************************************************
1.668 +; html table of site: observed
1.669 +;*******************************************************************
1.670 + output_html = "line_ob.html"
1.671 +
1.672 + header = (/"<HTML>" \
1.673 + ,"<HEAD>" \
1.674 + ,"<TITLE>CLAMP metrics</TITLE>" \
1.675 + ,"</HEAD>" \
1.676 + ,"<H1>Energy at Site: Observation</H1>" \
1.677 + /)
1.678 + footer = "</HTML>"
1.679 +
1.680 + table_header = (/ \
1.681 + "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
1.682 + ,"<tr>" \
1.683 + ," <th bgcolor=DDDDDD >Site Name</th>" \
1.684 + ," <th bgcolor=DDDDDD >Latitude</th>" \
1.685 + ," <th bgcolor=DDDDDD >Longitude</th>" \
1.686 + ," <th bgcolor=DDDDDD >Observed</th>" \
1.687 + ,"</tr>" \
1.688 + /)
1.689 + table_footer = "</table>"
1.690 + row_header = "<tr>"
1.691 + row_footer = "</tr>"
1.692 +
1.693 + lines = new(50000,string)
1.694 + nline = 0
1.695 +
1.696 + set_line(lines,nline,header)
1.697 + set_line(lines,nline,table_header)
1.698 +;-----------------------------------------------
1.699 +; row of table
1.700 +
1.701 + do n = 0,nstation-1
1.702 + set_line(lines,nline,row_header)
1.703 +
1.704 + txt0 = station_sort(n)
1.705 + txt1 = sprintf("%5.2f", lat_ob_sort(n))
1.706 + txt2 = sprintf("%5.2f", lon_ob_sort(n))
1.707 + txt3 = year_ob_sort(n)
1.708 +
1.709 + set_line(lines,nline,"<th><a href="+txt0+"_ob.png>"+txt0+"</a></th>")
1.710 + set_line(lines,nline,"<th>"+txt1+"</th>")
1.711 + set_line(lines,nline,"<th>"+txt2+"</th>")
1.712 + set_line(lines,nline,"<th>"+txt3+"</th>")
1.713 +
1.714 + set_line(lines,nline,row_footer)
1.715 + end do
1.716 +;-----------------------------------------------
1.717 + set_line(lines,nline,table_footer)
1.718 + set_line(lines,nline,footer)
1.719 +
1.720 +; Now write to an HTML file.
1.721 + idx = ind(.not.ismissing(lines))
1.722 + if(.not.any(ismissing(idx))) then
1.723 + asciiwrite(output_html,lines(idx))
1.724 + else
1.725 + print ("error?")
1.726 + end if
1.727 + delete (idx)
1.728 +
1.729 +;*******************************************************************
1.730 +; score and line table : model vs observed
1.731 +;*******************************************************************
1.732 + output_html = "score+line_vs_ob.html"
1.733 +
1.734 + header = (/"<HTML>" \
1.735 + ,"<HEAD>" \
1.736 + ,"<TITLE>CLAMP metrics</TITLE>" \
1.737 + ,"</HEAD>" \
1.738 + ,"<H1>Energy at Site: Model "+model_name+"</H1>" \
1.739 + /)
1.740 + footer = "</HTML>"
1.741 +
1.742 + delete (table_header)
1.743 + table_header = (/ \
1.744 + "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
1.745 + ,"<tr>" \
1.746 + ," <th bgcolor=DDDDDD >Site Name</th>" \
1.747 + ," <th bgcolor=DDDDDD >Latitude</th>" \
1.748 + ," <th bgcolor=DDDDDD >Longitude</th>" \
1.749 + ," <th bgcolor=DDDDDD >Observed</th>" \
1.750 + ," <th bgcolor=DDDDDD >CO2 Flux</th>" \
1.751 + ," <th bgcolor=DDDDDD >Net Radiation</th>" \
1.752 + ," <th bgcolor=DDDDDD >Latent Heat</th>" \
1.753 + ," <th bgcolor=DDDDDD >Sensible Heat</th>" \
1.754 + ," <th bgcolor=DDDDDD >GPP Glux</th>" \
1.755 + ," <th bgcolor=DDDDDD >Respiration</th>" \
1.756 + ," <th bgcolor=DDDDDD >Average</th>" \
1.757 + ,"</tr>" \
1.758 + /)
1.759 + table_footer = "</table>"
1.760 + row_header = "<tr>"
1.761 + row_footer = "</tr>"
1.762 +
1.763 + lines = new(50000,string)
1.764 + nline = 0
1.765 +
1.766 + set_line(lines,nline,header)
1.767 + set_line(lines,nline,table_header)
1.768 +;-----------------------------------------------
1.769 +; row of table
1.770 +
1.771 + do n = 0,nstation-1
1.772 + set_line(lines,nline,row_header)
1.773 +
1.774 + txt0 = station_sort(n)
1.775 + txt1 = sprintf("%5.2f", lat_ob_sort(n))
1.776 + txt2 = sprintf("%5.2f", lon_ob_sort(n))
1.777 + txt3 = year_ob_sort(n)
1.778 + txt4 = sprintf("%5.2f", M_score_sort(n,0))
1.779 + txt5 = sprintf("%5.2f", M_score_sort(n,1))
1.780 + txt6 = sprintf("%5.2f", M_score_sort(n,2))
1.781 + txt7 = sprintf("%5.2f", M_score_sort(n,3))
1.782 + txt8 = sprintf("%5.2f", M_score_sort(n,4))
1.783 + txt9 = sprintf("%5.2f", M_score_sort(n,5))
1.784 + txt10 = sprintf("%5.2f", avg(M_score_sort(n,:)))
1.785 +
1.786 + set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
1.787 + set_line(lines,nline,"<th>"+txt1+"</th>")
1.788 + set_line(lines,nline,"<th>"+txt2+"</th>")
1.789 + set_line(lines,nline,"<th>"+txt3+"</th>")
1.790 + set_line(lines,nline,"<th>"+txt4+"</th>")
1.791 + set_line(lines,nline,"<th>"+txt5+"</th>")
1.792 + set_line(lines,nline,"<th>"+txt6+"</th>")
1.793 + set_line(lines,nline,"<th>"+txt7+"</th>")
1.794 + set_line(lines,nline,"<th>"+txt8+"</th>")
1.795 + set_line(lines,nline,"<th>"+txt9+"</th>")
1.796 + set_line(lines,nline,"<th>"+txt10+"</th>")
1.797 +
1.798 + set_line(lines,nline,row_footer)
1.799 + end do
1.800 +
1.801 +; last row, summary
1.802 + set_line(lines,nline,row_header)
1.803 +
1.804 + txt0 = "All_"+sprintf("%.0f", nstation)
1.805 + txt1 = "-"
1.806 + txt2 = "-"
1.807 + txt3 = "-"
1.808 + txt4 = M_energy_co2
1.809 + txt5 = M_energy_rad
1.810 + txt6 = M_energy_lh
1.811 + txt7 = M_energy_sh
1.812 + txt8 = M_energy_gpp
1.813 + txt9 = M_energy_er
1.814 + txt10 = M_energy_all
1.815 +
1.816 + set_line(lines,nline,"<th>"+txt0+"</th>")
1.817 + set_line(lines,nline,"<th>"+txt1+"</th>")
1.818 + set_line(lines,nline,"<th>"+txt2+"</th>")
1.819 + set_line(lines,nline,"<th>"+txt3+"</th>")
1.820 + set_line(lines,nline,"<th>"+txt4+"</th>")
1.821 + set_line(lines,nline,"<th>"+txt5+"</th>")
1.822 + set_line(lines,nline,"<th>"+txt6+"</th>")
1.823 + set_line(lines,nline,"<th>"+txt7+"</th>")
1.824 + set_line(lines,nline,"<th>"+txt8+"</th>")
1.825 + set_line(lines,nline,"<th>"+txt9+"</th>")
1.826 + set_line(lines,nline,"<th>"+txt10+"</th>")
1.827 +
1.828 + set_line(lines,nline,row_footer)
1.829 +;-----------------------------------------------
1.830 + set_line(lines,nline,table_footer)
1.831 + set_line(lines,nline,footer)
1.832 +
1.833 +; Now write to an HTML file.
1.834 + idx = ind(.not.ismissing(lines))
1.835 + if(.not.any(ismissing(idx))) then
1.836 + asciiwrite(output_html,lines(idx))
1.837 + else
1.838 + print ("error?")
1.839 + end if
1.840 + delete (idx)
1.841 +
1.842 +;***************************************************************************
1.843 +; output plots
1.844 +;***************************************************************************
1.845 + output_dir = model_name+"/ameriflux"
1.846 +
1.847 + system("mv *.png *.html " + output_dir)
1.848 +;***************************************************************************
1.849 +end
1.850 +