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