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