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