# HG changeset patch # User Forrest Hoffman # Date 1233025700 18000 # Node ID 0c6405ab2ff4f69dd34fc64427ac869ee1ac0500 Initial commit of C-LAMP Diagnostics from Jeff Lee diff -r 000000000000 -r 0c6405ab2ff4 all/00.initial.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/00.initial.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,31 @@ +;***************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;**************************************************************************** +; Main code. +;**************************************************************************** +begin + +;-------------------------------------------------- +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + + system("sed -e '/"+modeln+"/s/"+modeln+"/"+model_name+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if +;------------------------------------- +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + +;--------------------------------------------------------------------------- + +end + diff -r 000000000000 -r 0c6405ab2ff4 all/01.npp.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/01.npp.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1370 @@ +;***************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;**************************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;**************************************************************************** +procedure get_bin(RAIN1_1D[*]:numeric, NPP1_1D[*]:numeric \ + ,RAIN2_1D[*]:numeric, NPP2_1D[*]:numeric \ + ,xvalues[*][*]:numeric, yvalues[*][*]:numeric \ + ,mn_yvalues[*][*]:numeric, mx_yvalues[*][*]:numeric \ + ,dx4[1]:numeric \ + ) +begin +; Calculaee "nice" bins for binning the data in equally spaced ranges. +; input : RAIN1_1D, RAIN2_1D, NPP1_1D, NPP2_1D +; output: xvalues, yvalues, mn_yvalues, mx_yvalues,dx4 + + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 +; print (nx) + +; xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. +; yvalues = new((/2,nx/),typeof(RAIN1_1D)) +; mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) +; mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; Print out information. +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data) + delete(npp_data) + end do +end +;**************************************************************************** +; Main code. +;**************************************************************************** +begin + + plot_type = "ps" + plot_type_new = "png" + +;----------------------------------------------------- +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if +;------------------------------------------------------ +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;------------------------------------------------------ +; read model data + + fm = addfile (dirm+film1,"r") + + nppmod0 = fm->NPP + rainmod0 = fm->RAIN + xm = fm->lon + ym = fm->lat + + delete (fm) + +;---------------------------------------------------- +; read ob data + +;(1) data at 81 sites + + dir81 = diro + "npp/" + fil81 = "data.81.nc" + f81 = addfile (dir81+fil81,"r") + + id81 = f81->SITE_ID + npp81 = f81->TNPP_C + rain81 = tofloat(f81->PREC_ANN) + x81 = f81->LONG_DD + y81 = f81->LAT_DD + + delete (f81) + + id81@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x81)-1 + if (x81(i) .lt. 0.) then + x81(i) = x81(i)+ 360. + end if + end do + +;------------------------------------- +;(2) data at 933 sites + + dir933 = diro + "npp/" + fil933 = "data.933.nc" + f933 = addfile (dir933+fil933,"r") + + id933 = f933->SITE_ID + npp933 = f933->TNPP_C + rain933 = f933->PREC + x933 = f933->LONG_DD + y933 = f933->LAT_DD + + delete (f933) + + id933@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x933)-1 + if (x933(i) .lt. 0.) then + x933(i) = x933(i)+ 360. + end if + end do + +;---------------------------------------- +;(3) global data, interpolated into model grid + + dirg = diro + "npp/" + filg = "Npp_"+model_grid+"_mean.nc" + fglobe = addfile (dirg+filg,"r") + + nppglobe0 = fglobe->NPP + nppglobe = nppglobe0 + + delete (fglobe) + +;*********************************************************************** +; interpolate model data into ob sites +;*********************************************************************** + + nppmod = nppmod0(0,:,:) + rainmod = rainmod0(0,:,:) + delete (nppmod0) + delete (rainmod0) + + nppmod81 =linint2_points(xm,ym,nppmod,True,x81,y81,0) + + nppmod933 =linint2_points(xm,ym,nppmod,True,x933,y933,0) + + rainmod81 =linint2_points(xm,ym,rainmod,True,x81,y81,0) + + rainmod933=linint2_points(xm,ym,rainmod,True,x933,y933,0) + +;********************************************************** +; unified units +;********************************************************** +; Units for these variables are: +; +; rain81 : mm/year +; rainmod : mm/s +; npp81 : g C/m^2/year +; nppmod81: g C/m^2/s +; nppglobe: g C/m^2/year +; +; We want to convert these to "m/year" and "g C/m^2/year". + + nsec_per_year = 60*60*24*365 + + rain81 = rain81 / 1000. + rainmod81 = (rainmod81/ 1000.) * nsec_per_year + nppmod81 = nppmod81 * nsec_per_year + + rain933 = rain933 / 1000. + rainmod933 = (rainmod933/ 1000.) * nsec_per_year + nppmod933 = nppmod933 * nsec_per_year + + nppmod = nppmod * nsec_per_year + + npp81@units = "gC/m^2/yr" + nppmod81@units = "gC/m^2/yr" + npp933@units = "gC/m^2/yr" + nppmod933@units = "gC/m^2/yr" + nppmod@units = "gC/m^2/yr" + nppglobe@units = "gC/m^2/yr" + rain81@units = "m/yr" + rainmod81@units = "m/yr" + rain933@units = "m/yr" + rainmod933@units = "m/yr" + + npp81@long_name = "Obs. NPP (gC/m2/year)" + npp933@long_name = "Obs. NPP (gC/m2/year)" + nppmod81@long_name = "Model NPP (gC/m2/year)" + nppmod933@long_name = "Model NPP (gC/m2/year)" + nppmod@long_name = "Model NPP (gC/m2/year)" + nppglobe@long_name = "NPP (gC/m2/year)" + rain81@long_name = "PREC (m/year)" + rain933@long_name = "PREC (m/year)" + rainmod81@long_name = "PREC (m/year)" + rainmod933@long_name = "PREC (m/year)" + +; change longitude from 0-360 to -180-180 + x81 = where(x81 .gt. 180., x81 -360., x81 ) + x933 = where(x933 .gt. 180., x933-360., x933) + +;******************************************************************* +;(A)-1 html table of site81 -- observed +;******************************************************************* + + output_html = "table_site81_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

EMDI Observations Class A (81 sites)

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site IDLatitudeLongitudeNPP(gC/m2/year)PPT(m/year)
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + nrow = dimsizes(id81) + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = sprintf("%5.0f", id81(n)) + txt2 = sprintf("%5.2f", y81(n)) + txt3 = sprintf("%5.2f", x81(n)) + txt4 = sprintf("%5.2f", npp81(n)) + txt5 = sprintf("%5.2f", rain81(n)) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +;******************************************************************* +;(A)-2 html table of site933 -- observed +;******************************************************************* + output_html = "table_site933_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

EMDI Observations Class B (933 sites)

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site IDLatitudeLongitudeNPP(gC/m2/year)PPT(m/year)
" + row_header = "" + row_footer = "" + + delete (lines) + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + nrow = dimsizes(id933) + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = sprintf("%5.0f", id933(n)) + txt2 = sprintf("%5.2f", y933(n)) + txt3 = sprintf("%5.2f", x933(n)) + txt4 = sprintf("%5.2f", npp933(n)) + txt5 = sprintf("%5.2f", rain933(n)) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + delete (idx) + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +;******************************************************************* +;(A)-3 html table of site81 -- model vs ob +;******************************************************************* + output_html = "table_site81_model_vs_ob.html" + + header_text = "

Model "+model_name+" vs Class A Observations (81 sites)

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + delete (table_header) + table_header_text = " "+model_name+"" + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + ,"" \ + ," " \ + , table_header_text \ + ," " \ + , table_header_text \ + ,"" \ + /) + table_footer = "
Site IDLatitudeLongitudeNPP(gC/m2.year)RAIN(m/year)
observedobserved
" + row_header = "" + row_footer = "" + + delete (lines) + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + nrow = dimsizes(id81) + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = sprintf("%5.0f", id81(n)) + txt2 = sprintf("%5.2f", y81(n)) + txt3 = sprintf("%5.2f", x81(n)) + txt4 = sprintf("%5.2f", npp81(n)) + txt5 = sprintf("%5.2f", nppmod81(n)) + txt6 = sprintf("%5.2f", rain81(n)) + txt7 = sprintf("%5.2f", rainmod81(n)) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + delete (idx) + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +;******************************************************************* +;(A)-4 html table of site933 -- model vs ob +;******************************************************************* + output_html = "table_site933_model_vs_ob.html" + + header_text = "

Model "+model_name+" vs Class B Observations (933 sites)

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + delete (table_header) + table_header_text = " "+model_name+"" + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + ,"" \ + ," " \ + , table_header_text \ + ," " \ + , table_header_text \ + ,"" \ + /) + table_footer = "
Site IDLatitudeLongitudeNPP(gC/m2.year)RAIN(m/year)
observedobserved
" + row_header = "" + row_footer = "" + + delete (lines) + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + nrow = dimsizes(id933) + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = sprintf("%5.0f", id933(n)) + txt2 = sprintf("%5.2f", y933(n)) + txt3 = sprintf("%5.2f", x933(n)) + txt4 = sprintf("%5.2f", npp933(n)) + txt5 = sprintf("%5.2f", nppmod933(n)) + txt6 = sprintf("%5.2f", rain933(n)) + txt7 = sprintf("%5.2f", rainmod933(n)) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + delete (idx) + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +;*************************************************************************** +;(A)-5 scatter plot, model vs ob 81 +;*************************************************************************** + + plot_name = "scatter_model_vs_ob_81" + title = model_name +" vs Class A observations (81 sites)" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + res@gsnDraw = False + res@gsnFrame = False ; don't advance frame yet +;------------------------------- +;compute correlation coef. and M + ccr81 = esccr(nppmod81,npp81,0) +;print (ccr81) + + score_max = 2.5 + + bias = sum(abs(nppmod81-npp81)/(abs(nppmod81)+abs(npp81))) + M81s = (1. - (bias/dimsizes(y81)))*score_max + M_npp_S81 = sprintf("%.2f", M81s) + + if (isvar("compare")) then + system("sed -e '1,/M_npp_S81/s/M_npp_S81/"+M_npp_S81+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_npp_S81#"+M_npp_S81+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp81,nppmod81,res) ; create plot +;------------------------------- +; add polyline + + dum=gsn_add_polyline(wks,plot,(/0,1200/),(/0,1200/),False) +;------------------------------- + draw (plot) + delete (wks) + delete (dum) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;*************************************************************************** +;(A)-6 scatter plot, model vs ob 933 +;*************************************************************************** + + plot_name = "scatter_model_vs_ob_933" + title = model_name +" vs Class B Observations (933 sites)" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + res@gsnDraw = False + res@gsnFrame = False ; don't advance frame yet +;------------------------------- +;compute correlation coef. and M + + ccr933 = esccr(nppmod933,npp933,0) + + score_max = 2.5 + + bias = sum(abs(nppmod933-npp933)/(abs(nppmod933)+abs(npp933))) + M933s = (1. - (bias/dimsizes(y933)))*score_max + M_npp_S933 = sprintf("%.2f", M933s) + + if (isvar("compare")) then + system("sed -e '1,/M_npp_S933/s/M_npp_S933/"+M_npp_S933+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_npp_S933#"+M_npp_S933+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp933,nppmod933,res) ; create plot +;------------------------------- +; add polyline + + dum=gsn_add_polyline(wks,plot,(/0,1500/),(/0,1500/),False) +;------------------------------- + draw (plot) + delete (wks) + delete (dum) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;************************************************************************** +;(B) histogram 81 +;************************************************************************** +;get data + RAIN1_1D = ndtooned(rain81) + RAIN2_1D = ndtooned(rainmod81) + NPP1_1D = ndtooned(npp81) + NPP2_1D = ndtooned(nppmod81) + +; number of bin + nx = 8 + + xvalues = new((/2,nx/),float) + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + dx4 = new((/1/),float) + + get_bin(RAIN1_1D, NPP1_1D, RAIN2_1D, NPP2_1D \ + ,xvalues,yvalues,mn_yvalues,mx_yvalues,dx4) + +;---------------------------------------- +;compute correlation coeff and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr81h = esccr(uu,vv,0) + + score_max = 2.5 + + bias = sum(abs(vv-uu)/(abs(vv)+abs(uu))) + M81h = (1.- (bias/dimsizes(uu)))*score_max + M_npp_H81 = sprintf("%.2f", M81h) + + if (isvar("compare")) then + system("sed -e '1,/M_npp_H81/s/M_npp_H81/"+M_npp_H81+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_npp_H81#"+M_npp_H81+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + resh = True + resh@gsnMaximize = True + resh@gsnDraw = False + resh@gsnFrame = False + resh@xyMarkLineMode = "Markers" + resh@xyMarkerSizeF = 0.014 + resh@xyMarker = 16 + resh@xyMarkerColors = (/"Brown","Blue"/) + resh@trYMinF = min(mn_yvalues) - 10. + resh@trYMaxF = max(mx_yvalues) + 10. + + resh@tiYAxisString = "NPP (g C/m2/year)" + resh@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) + +;************************************************************************** +;(B)-1 histogram plot, ob 81 site +;************************************************************************** + + plot_name = "histogram_ob_81" + title = "Class A Observations (81 sites)" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + plx = (/x1,x1/) + ply = (/y1,y2/) + min_bar(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + + y2 = mx_yvalues(nd,i) + plx = (/x1,x1/) + ply = (/y1,y2/) + max_bar(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + plx = (/x1,x2/) + ply = (/y1,y1/) + min_cap(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + + y1 = mx_yvalues(nd,i) + plx = (/x1,x2/) + ply = (/y1,y1/) + max_cap(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + end if + end do + end do + + draw(xy) + delete (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(B)-2 histogram plot, model vs ob 81 site +;**************************************************************************** + + plot_name = "histogram_model_vs_ob_81" + title = model_name+ " vs Class A Observations (81 sites)" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + resh@pmLegendDisplayMode = "Always" +; resh@pmLegendWidthF = 0.1 + resh@pmLegendWidthF = 0.08 + resh@pmLegendHeightF = 0.05 + resh@pmLegendOrthogonalPosF = -1.17 +; resh@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resh@pmLegendParallelPosF = 0.18 + resh@pmLegendParallelPosF = 0.88 ;(rightward) + +; resh@lgPerimOn = False + resh@lgLabelFontHeightF = 0.015 + resh@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81h)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resh) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + delete(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + delete (RAIN1_1D) + delete (RAIN2_1D) + delete (NPP1_1D) + delete (NPP2_1D) +;delete (range) + delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) + +;************************************************************************** +;(B) histogram 933 +;************************************************************************** + +; get data + RAIN1_1D = ndtooned(rain933) + RAIN2_1D = ndtooned(rainmod933) + NPP1_1D = ndtooned(npp933) + NPP2_1D = ndtooned(nppmod933) + +; number of bin + nx = 10 + + xvalues = new((/2,nx/),float) + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + dx4 = new((/1/),float) + + get_bin(RAIN1_1D, NPP1_1D, RAIN2_1D, NPP2_1D \ + ,xvalues,yvalues,mn_yvalues,mx_yvalues,dx4) + +;---------------------------------------- +;compute correlation coeff and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr933h = esccr(uu,vv,0) + + score_max = 2.5 + + bias = sum(abs(vv-uu)/(abs(vv)+abs(uu))) + M933h = (1.- (bias/dimsizes(uu)))*score_max + M_npp_H933 = sprintf("%.2f", M933h) + + if (isvar("compare")) then + system("sed -e '1,/M_npp_H933/s/M_npp_H933/"+M_npp_H933+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_npp_H933#"+M_npp_H933+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + delete (resh) + resh = True + resh@gsnMaximize = True + resh@gsnDraw = False + resh@gsnFrame = False + resh@xyMarkLineMode = "Markers" + resh@xyMarkerSizeF = 0.014 + resh@xyMarker = 16 + resh@xyMarkerColors = (/"Brown","Blue"/) + resh@trYMinF = min(mn_yvalues) - 10. + resh@trYMaxF = max(mx_yvalues) + 10. + + resh@tiYAxisString = "NPP (g C/m2/year)" + resh@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) + +;************************************************************************** +;(B)-3 histogram plot, ob 933 site +;************************************************************************** + + plot_name = "histogram_ob_933" + title = "Class B Observations (933 sites)" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + delete (xy) + delete (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(B)-4 histogram plot, model vs ob 933 site +;**************************************************************************** + + plot_name = "histogram_model_vs_ob_933" + title = model_name+ " vs Class B Observations (933 sites)" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + resh@pmLegendDisplayMode = "Always" +; resh@pmLegendWidthF = 0.1 + resh@pmLegendWidthF = 0.08 + resh@pmLegendHeightF = 0.05 + resh@pmLegendOrthogonalPosF = -1.17 +; resh@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resh@pmLegendParallelPosF = 0.18 + resh@pmLegendParallelPosF = 0.88 ;(rightward) + +; resh@lgPerimOn = False + resh@lgLabelFontHeightF = 0.015 + resh@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933h)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resh) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + delete(xy) + delete(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;*************************************************************************** +;(C) global contour +;*************************************************************************** + +;res + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@gsnSpreadColors = True ; use full colormap + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 2200. ; Max level + resg@cnLevelSpacingF = 200. ; interval + +;**************************************************************************** +;(C)-1 global contour plot, ob +;**************************************************************************** + + delta = 0.00000000001 + nppglobe = where(ismissing(nppglobe).and.(ismissing(nppmod).or.(nppmod.lt.delta)),0.,nppglobe) + + plot_name = "global_ob" + title = "Observed MODIS MOD 17" + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppglobe,resg) + + delete (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;**************************************************************************** +;(C)-2 global contour plot, model +;**************************************************************************** + + plot_name = "global_model" + title = "Model "+ model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppmod,resg) + + delete (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(C)-3 global contour plot, model vs ob +;**************************************************************************** + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; compute correlation coef and M score + + uu1 = ndtooned(nppmod) + vv1 = ndtooned(nppglobe) + + delete (good) + good = ind(.not.ismissing(uu1) .and. .not.ismissing(vv1)) + + ug = uu1(good) + vg = vv1(good) + + ccrG = esccr(ug,vg,0) + + score_max = 5.0 + + MG = (ccrG*ccrG)* score_max + M_npp_G = sprintf("%.2f", MG) + + if (isvar("compare")) then + system("sed -e '1,/M_npp_G/s/M_npp_G/"+M_npp_G+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_npp_G#"+M_npp_G+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrG)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = "Observed MODIS MOD 17" + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,nppglobe,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,nppmod,resg) + +;(c) model-ob + + zz = nppmod + zz = nppmod - nppglobe + title = "Model_"+model_name+" - Observed" + + resg@cnMinLevelValF = -500 ; Min level + resg@cnMaxLevelValF = 500. ; Max level + resg@cnLevelSpacingF = 50. ; interval + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;*************************************************************************** +;(D)-1 zonal line plot, ob +;*************************************************************************** + + vv = zonalAve(nppglobe) + vv@long_name = nppglobe@long_name + + plot_name = "zonal_ob" + title = "Observed MODIS MOD 17" + + resz = True + resz@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + plot = gsn_csm_xy (wks,ym,vv,resz) + + delete (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(D)-2 zonal line plot, model vs ob +;**************************************************************************** + + s = new ((/2,dimsizes(ym)/), float) + + s(0,:) = zonalAve(nppglobe) + s(1,:) = zonalAve(nppmod) + + s@long_name = nppglobe@long_name +;------------------------------------------- +; compute correlation coef and M score + + score_max = 5.0 + + ccrZ = esccr(s(1,:), s(0,:),0) + MZ = (ccrZ*ccrZ)* score_max + M_npp_Z = sprintf("%.2f", MZ) + + if (isvar("compare")) then + system("sed -e '1,/M_npp_Z/s/M_npp_Z/"+M_npp_Z+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_npp_Z#"+M_npp_Z+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) +;------------------------------------------- + plot_name = "zonal_model_vs_ob" + title = "Zonal Average" + resz@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + +; resz@vpHeightF = 0.4 ; change aspect ratio of plot +; resz@vpWidthF = 0.7 + + resz@xyMonoLineColor = "False" ; want colored lines + resz@xyLineColors = (/"black","red"/) ; colors chosen +; resz@xyLineThicknesses = (/3.,3./) ; line thicknesses + resz@xyLineThicknesses = (/2.,2./) ; line thicknesses + resz@xyDashPatterns = (/0.,0./) ; make all lines solid + + resz@tiYAxisString = s@long_name ; add a axis title + resz@txFontHeightF = 0.0195 ; change title font heights + +; Legent + resz@pmLegendDisplayMode = "Always" ; turn on legend + resz@pmLegendSide = "Top" ; Change location of +; resz@pmLegendParallelPosF = .45 ; move units right + resz@pmLegendParallelPosF = .82 ; move units right + resz@pmLegendOrthogonalPosF = -0.4 ; move units down + + resz@pmLegendWidthF = 0.10 ; Change width and + resz@pmLegendHeightF = 0.10 ; height of legend. + resz@lgLabelFontHeightF = .02 ; change font height +; resz@lgTitleOn = True ; turn on legend title +; resz@lgTitleString = "Example" ; create legend title +; resz@lgTitleFontHeightF = .025 ; font of legend title + resz@xyExplicitLegendLabels = (/"Observed",model_name/) ; explicit labels +;-------------------------------------------------------------------- + zRes = True + zRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrZ)+")" + + gsn_text_ndc(wks,correlation_text,0.50,0.77,zRes) +;-------------------------------------------------------------------- + + plot = gsn_csm_xy (wks,ym,s,resz) + + delete (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;*************************************************************************** +; add total score and write to file +;*************************************************************************** + M_total = M81s + M81h + M933s + M933h + MG + MZ + + asciiwrite("M_save.npp", M_total) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/npp" + + system("mv table_*.html " + output_dir +";"+ \ + "mv *.png " + output_dir) + +;*************************************************************************** +end + diff -r 000000000000 -r 0c6405ab2ff4 all/02.lai.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/02.lai.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,879 @@ +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;----------------------------------------------------- +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if + +;------------------------------------------------------ +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;------------------------------------------------------ +; read data: model + + fm = addfile(dirm+film10,"r") + laimod = fm->TLAI + + delete (fm) + + dsizes = dimsizes(laimod) + ntime = dsizes(0) + nlat = dsizes(1) + nlon = dsizes(2) + +;----------------------------------- +; get landfrac data + + film_l = "lnd_"+ model_grid + ".nc" + fm_l = addfile (dirs+film_l,"r") + landfrac = fm_l->landfrac + + delete (fm_l) +;---------------------------------- +; read biome data: model + + biome_name_mod = "Model PFT Class" + + film_c = "class_pft_"+model_grid+".nc" + fm_c = addfile(dirs+film_c,"r") + classmod = fm_c->CLASS_PFT + + delete (fm_c) + +; model data has 17 land-type classes + nclass_mod = 17 + +;---------------------------------------------------------- +; read data: ob + +;---------------------------------- +; read biome data: observed + + biome_name_ob = "MODIS LandCover" + + dir_c = diro + "lai/" + filo_c = "land_class_"+model_grid+".nc" + fo = addfile(dir_c+filo_c,"r") + classob = tofloat(fo->LAND_CLASS) + + delete (fo) + +; input observed data has 20 land-type classes + nclass_ob = 20 + +;--------------------------------- +; read lai data: observed + + ;ob_name = "MODIS MOD 15A2 2000-2005" + ob_name = "MODIS MOD 15A2 2000-2004" + + dir_l = diro + "lai/" + ;filo = "LAI_2000-2005_MONS_"+model_grid+".nc" + filo = "LAI_2000-2004_MONS_"+model_grid+".nc" + fo = addfile(dir_l+filo,"r") + laiob = fo->LAI + + delete (fo) + +;------------------------------------------------- +; take into account landfrac + + laimod = laimod * conform(laimod,landfrac,(/1,2/)) + laiob = laiob * conform(laiob ,landfrac,(/1,2/)) + + delete (landfrac) + +;************************************************ +; global res +;************************************************ + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + +;************************************************ +; plot global biome class: (1) observed +;************************************************ + + resg@cnMinLevelValF = 1. ; Min level + resg@cnMaxLevelValF = 19. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + classob@_FillValue = 1.e+36 + classob = where(classob.eq.0,classob@_FillValue,classob) + + plot_name = "global_class_ob" + title = biome_name_ob + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,classob,resg) + + delete (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;************************************************ +; plot global biome class: (2) model +;************************************************ + + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 16. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + plot_name = "global_class_model" + title = biome_name_mod + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,classmod,resg) + + delete (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;******************************************************************* +; for html table : all 3 components (Mean, Max, Phase) +;******************************************************************* + +; column (not including header column) + + component = (/"Mean","Max","Phase"/) + + col_head = (/"observed",model_name,"M_score" \ + ,"observed",model_name,"M_score" \ + ,"observed",model_name,"M_score" \ + /) + + n_comp = dimsizes(component) + ncol = dimsizes(col_head ) + +; row (not including header row) + +;---------------------------------------------------- +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biomes" \ + /) + + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + +; total M_score + M_total = 0. + +;******************************************************************** +; use land-type class to bin the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +; for 2 data: model and observed + data_n = 2 + +; using model biome class + + base = ndtooned(classmod) + +; output + + yvalues = new((/data_n,nx/),float) + count = new((/data_n,nx/),float) + +;************************************************************************ +; go through all components +;************************************************************************ + + do m = 0,n_comp-1 + +;=================== +; get data: +;=================== +; (A) Mean + + if (m .eq. 0) then + data_ob = dim_avg_Wrap(laiob (lat|:,lon|:,time|:)) + data_mod = dim_avg_Wrap(laimod(lat|:,lon|:,time|:)) + end if + +; (B) Max + + if (m .eq. 1) then + +; observed + data_ob = laiob(0,:,:) + data_ob@long_name = "Leaf Area Index Max" + + do j = 0,nlat-1 + do i = 0,nlon-1 + data_ob(j,i) = max(laiob(:,j,i)) + end do + end do + +; model + data_mod = laimod(0,:,:) + data_mod@long_name = "Leaf Area Index Max" + + do j = 0,nlat-1 + do i = 0,nlon-1 + data_mod(j,i) = max(laimod(:,j,i)) + end do + end do + + end if + +; (C) phase + + if (m .eq. 2) then + +; observed + data_ob = laiob(0,:,:) + data_ob@long_name = "Leaf Area Index Max Month" + + do j = 0,nlat-1 + do i = 0,nlon-1 + data_ob(j,i) = maxind(laiob(:,j,i)) + 1 + end do + end do + +; model + data_mod = laimod(0,:,:) + data_mod@long_name = "Leaf Area Index Max Month" + + do j = 0,nlat-1 + do i = 0,nlon-1 + data_mod(j,i) = maxind(laimod(:,j,i)) + 1 + end do + end do + + end if + +;============================== +; put data into bins +;============================== + +; Loop through each range, using base + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if + +; loop through each dataset + + do n = 0,data_n-1 + + if (n .eq. 0) then + data = ndtooned(data_ob) + end if + + if (n .eq. 1) then + data = ndtooned(data_mod) + end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(n,i) = avg(data(idx)) + count(n,i) = dimsizes(idx) + else + yvalues(n,i) = yvalues@_FillValue + count(n,i) = 0 + end if + +;############################################################# +; using model biome class: +; +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(n,i) = yvalues@_FillValue + count(n,i) = 0 + end if +;############################################################# + + delete(data) + end do ; n-loop + + delete(idx) + end do ; i-loop + +;===================================== +; compute correlation coef and M score +;===================================== + + score_max = 5.0 + + u = yvalues(0,:) + v = yvalues(1,:) + u_count = count(0,:) + v_count = count(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + + uu = u(good) + vv = v(good) + uu_count = u_count(good) + vv_count = v_count(good) + +; compute correlation coef + cc = esccr(uu,vv,0) + + if (n .eq. 2) then + bias = avg(abs(vv-uu)) + bias = where((bias.gt. 6.),12.-bias,bias) + Mscore = ((6. - bias)/6.)*score_max + else + bias = sum(abs(vv-uu)/abs(vv+uu)) + Mscore = (1.- (bias/dimsizes(uu)))*score_max + end if + + M_score = sprintf("%.2f", Mscore) + +; compute M_total + + M_total = M_total + Mscore + +;================================ +; output M_score to score sheet +;=============================== + + if (isvar("compare")) then + system("sed -e '1,/M_lai_"+component(m)+"/s/M_lai_"+component(m)+"/"+M_score+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_lai_"+component(m)+"#"+M_score+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + +;============================== +; output M_score to html table +;============================== + + n = m*3 + + do i=0,nrow-2 + text(i,n) = sprintf("%.1f",uu(i)) + text(i,n+1) = sprintf("%.1f",vv(i)) + text(i,n+2) = "-" + end do + text(nrow-1,n) = sprintf("%.1f",sum(uu*uu_count)/sum(uu_count)) + text(nrow-1,n+1) = sprintf("%.1f",sum(vv*vv_count)/sum(vv_count)) + text(nrow-1,n+2) = M_score + + delete (u) + delete (v) + delete (uu) + delete (vv) + delete (u_count) + delete (v_count) + delete (uu_count) + delete (vv_count) + delete (good) + +;======================================== +; global res changes for each component +;======================================== + delta = 0.00001 + + if (m .eq. 0) then + resg@cnMinLevelValF = 0. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob) + end if + + if (m .eq. 1) then + resg@cnMinLevelValF = 0. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob) + end if + + if (m .eq. 2) then + resg@cnMinLevelValF = 1. + resg@cnMaxLevelValF = 12. + resg@cnLevelSpacingF = 1. + + data_mod = where(ismissing(data_ob).or.(data_mod.lt.delta),data_mod@_FillValue,data_mod) + data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob) + + end if + +;========================= +; global contour : ob +;========================= + + plot_name = "global_"+component(m)+"_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,data_ob,resg) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;============================ +; global contour : model +;============================ + + plot_name = "global_"+component(m)+"_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") + + plot = gsn_csm_contour_map_ce(wks,data_mod,resg) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;================================ +; global contour: model vs ob +;================================ + + plot_name = "global_"+component(m)+"_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") + + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%.2f", cc)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) + +; plot ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,data_ob,resg) + +; plot model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,data_mod,resg) + +; plot model-ob + + if (m .eq. 0) then + resg@cnMinLevelValF = -2. + resg@cnMaxLevelValF = 2. + resg@cnLevelSpacingF = 0.4 + end if + + if (m .eq. 1) then + resg@cnMinLevelValF = -6. + resg@cnMaxLevelValF = 6. + resg@cnLevelSpacingF = 1. + end if + + if (m .eq. 2) then + resg@cnMinLevelValF = -6. + resg@cnMaxLevelValF = 6. + resg@cnLevelSpacingF = 1. + end if + + zz = data_mod + zz = data_mod - data_ob + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + +; plot panel + + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + delete (data_ob) + delete (data_mod) + + resg@gsnFrame = True ; Do advance frame + resg@gsnDraw = True ; Do draw plot + + end do ; m-loop + +;************************************************** +; html table +;************************************************** + output_html = "table_model_vs_ob.html" + + header_text = "

LAI: Model "+model_name+" vs. MODIS observations

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Class"+component(0)+" (m2/m2)"+component(1)+" (m2/m2)"+component(2)+" (months)Annual Plot
observed"+model_name+"M_scoreobserved"+model_name+"M_scoreobserved"+model_name+"M_score
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text(n,0) + txt3 = text(n,1) + txt4 = text(n,2) + txt5 = text(n,3) + txt6 = text(n,4) + txt7 = text(n,5) + txt8 = text(n,6) + txt9 = text(n,7) + txt10 = text(n,8) + txt11 = "model_vs_ob" + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + set_line(lines,nline,""+txt11+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (yvalues) + delete (count) + delete (idx) + +;************************************************************************ +; go through all ntime +;************************************************************************ + +; for 2 data: model and observed + data_n = 2 + +; using model biome class + + base = ndtooned(classmod) + +; output + + yvalues = new((/data_n,nx,ntime/),float) + +;============================== +; put data into bins +;============================== + +; Loop through each range, using base + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if + +; loop through each dataset + + do n = 0,data_n-1 + + do m = 0,ntime-1 + + if (n .eq. 0) then + data = ndtooned(laiob (m,:,:)) + end if + + if (n .eq. 1) then + data = ndtooned(laimod(m,:,:)) + end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(n,i,m) = avg(data(idx)) + else + yvalues(n,i,m) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(n,i,m) = yvalues@_FillValue + end if +;############################################################# + + end do ; m-loop + + delete(data) + end do ; n-loop + + delete(idx) + end do ; i-loop + + good = ind(.not.ismissing(yvalues(0,:,0))) + + n_biome = dimsizes(good) + +;---------------------------------------------------------------- +; data for tseries plot + + yvalues_g = new((/data_n,n_biome,ntime/),float) + + yvalues_g@units = "" + + yvalues_g = yvalues(:,good,:) + + delete (good) + +;******************************************************************* +; res for line plot +;******************************************************************* +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; change line color + +; res@tiMainFontHeightF = 0.025 ; size of title + +; Add a boxed legend using the more simple method + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) + +;************************************************************ + + plot_data = new((/2,ntime/),float) + plot_data@long_name = "Leaf Area Index" + +;---------------------------------------------- +; time series plot : per biome + + do m = 0, n_biome-1 + + plot_name = "annual_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = "LAI : "+ row_head(m) + res@tiMainString = title + + plot_data(0,:) = yvalues_g(0,m,:) + plot_data(1,:) = yvalues_g(1,m,:) + + plot = gsn_csm_xy(wks,mon,plot_data,res) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + end do + +;-------------------------------------------- +; time series plot: all biome + + plot_name = "annual_biome_"+ n_biome + + wks = gsn_open_wks (plot_type,plot_name) + + title = "LAI : "+ row_head(n_biome) + res@tiMainString = title + + do k = 0,ntime-1 + plot_data(0,k) = avg(yvalues_g(0,:,k)) + plot_data(1,k) = avg(yvalues_g(1,:,k)) + end do + + plot = gsn_csm_xy(wks,mon,plot_data,res) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + delete (plot_data) + +;*************************************************************************** +; write total score to file +;*************************************************************************** + + asciiwrite("M_save.lai", M_total) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/lai" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end + diff -r 000000000000 -r 0c6405ab2ff4 all/03.co2.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/03.co2.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,593 @@ +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +load dirscript + "taylor_diagram.ncl" +;************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;**************************************************************************** + +begin + + plot_type = "ps" + plot_type_new = "png" + +;----------------------------------------------------- +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if + +;------------------------------------------------------ +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;------------------------------------------------------ +; read model data + + fm = addfile(dirm+film3,"r") + + x = fm->CO2 + xi = fm->lon + yi = fm->lat + + delete (fm) + + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) + +; get co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" + +;************************************************ +; read data: observed +;************************************************ + diri = diro + "co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + + delete (g) + + ncase = dimsizes(lat) +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ +; to be able to handle observation at (-89.98,-24.80) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) + val_model_0 = val_model +;************************************************************ +; remove annual mean +;************************************************************ + val_model = val_model - conform(val_model,dim_avg(val_model),0) + +;******************************************************************* +; res for station line plot +;******************************************************************* +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"red","blue"/) ; change line color + +; Add a boxed legend using the more simple method + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/model_name,"observed"/) +;************************************************************ +; number of latitude zone +;************************************************************ + nzone = 4 + +; saving data for zone +; number of rows for zone table (with data) + nrow_zone = nzone + +; number of columns for zone table + ncol_zone = 7 + + text = new((/nrow_zone,ncol_zone/),string) + +do z = 0,nzone-1 + + if (z .eq. 0) then + zone = "60N-90N" + score_max = 5.0 + ind_z = ind(lat_ob .ge. 60.) + end if + + if (z .eq. 1) then + zone = "30N-60N" + score_max = 5.0 + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) + end if + + if (z .eq. 2) then + zone = "EQ-30N" + score_max = 5.0 + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) + end if + + if (z .eq. 3) then + zone = "90S-EQ" + score_max = 5.0 + ind_z = ind(lat_ob .lt. 0. ) + end if + + npts = dimsizes(ind_z) + +;------------------------------------------------------ +; for metric table computation + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) + + var_sta = new((/npts/),float) +;----------------------------------------------------- +; for station line plot + npts_str = "" + npts_str = npts + + plot_data = new((/2,12,npts/),float) + plot_data_0 = new((/12,npts/),float) + + plot_data!0 = "case" + plot_data!1 = "month" + plot_data!2 = "pts" + plot_data@long_name = "CO2 Annual Cycle (ppm)" + + plot_data_0!0 = "month" + plot_data_0!1 = "pts" + plot_data_0@long_name = "CO2 (ppm)" +;-------------------------------------------------------------------------- + do n=0,npts-1 + + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + + var_model = stddev(val_model(ind_z(n),:)) + var_ob = stddev(val_ob(ind_z(n),:)) + var_sta(n)= var_model/var_ob +;---------------------------------------------------------------------- +; for station line plot + + plot_data(0,:,n) = (/val_model(ind_z(n),:)/) + plot_data(1,:,n) = (/val_ob(ind_z(n),:)/) + + plot_data_0(:,n) = (/val_model_0(ind_z(n),:)/) + + plot_name = sta(ind_z(n)) + title = plot_name+" ("+lat(ind_z(n))+","+lon(ind_z(n))+")" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;------------------------------------------ +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------ + res@tiMainString = title ; add title + + plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1 + + plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,n),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;--------------------------------------------------------------------------- + end do + +;------------------------------------------------------------------------- +; for Taylor plot in a zone + +; Cases [Model] + case = (/ model_name /) + nCase = dimsizes(case ) ; # of Cases [Cases] + +; station compared + var = sta(ind_z) + nVar = dimsizes(var) ; # of stations + +; arrays to be passed to taylor plot + ratio = new ((/nCase, nVar/),typeof(var_sta) ) + cc = new ((/nCase, nVar/),typeof(ccr_sta) ) + + ratio(0,:) = var_sta + cc(0,:) = ccr_sta + +;--------------------------------- +; create plot + + rest = True ; default taylor diagram + + rest@Markers = (/16/) ; make all solid fill + rest@Colors = (/"red" /) +; rest@varLabels = var + rest@caseLabels = case + + rOpts = True + rOpts@caseLabels = True +; rOpts@caseLabelsFontHeightF = 0.05 + rOpts@caseLabelsFontHeightF = 0.15 + + plot_name = "taylor_diagram_"+ zone + title = "CO2 Annual Cycle: "+ zone + rest@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + plot = taylor_diagram(wks,ratio,cc,rest) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + delete (ratio) + delete (cc) + delete (var_sta) + delete (var) + +;------------------------------------------------------------------------- +; for line plot in a zone + + plot_name = "All_"+npts_str + title = plot_name + " in "+ zone + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;----------------------------------------- +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;----------------------------------------- + res@tiMainString = title ; add title + + plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1 + + plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + delete (plot_data) + delete (plot_data_0) +;--------------------------------------------------------------------------- +; values saved for zone table + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + text(z,0) = zone + text(z,1) = sprintf("%.0f", npts) + text(z,2) = sprintf("%.2f", amp_ratio_zone) + text(z,3) = sprintf("%.2f", ccr_zone) + text(z,4) = sprintf("%.2f", M_zone) + text(z,5) = sprintf("%.2f", score_zone) + text(z,6) = zone + +;******************************************************************* +; html table -- station +;******************************************************************* + output_html = "score+line_"+zone+".html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Latitude Zone "+zone+": Model "+model_name+"

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudemodel vs obs.
amplitude ratio
Correlation Coef.M ScoreCombined Score
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,npts-1 + set_line(lines,nline,row_header) + + txt0 = sta(ind_z(n)) + txt1 = sprintf("%5.2f", (/lat(ind_z(n))/)) + txt2 = sprintf("%5.2f", (/lon(ind_z(n))/)) + txt3 = sprintf("%5.2f", (/amp_ratio_sta(n)/)) + txt4 = sprintf("%5.2f", (/ccr_sta(n)/)) + txt5 = sprintf("%5.2f", (/M_sta(n)/)) + txt6 = sprintf("%5.2f", (/score_sta(n)/)) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", (/npts/)) + txt1 = "-" + txt2 = "-" + txt3 = sprintf("%5.2f", (/amp_ratio_zone/)) + txt4 = sprintf("%5.2f", (/ccr_zone/)) + txt5 = sprintf("%5.2f", (/M_zone/)) + txt6 = sprintf("%5.2f", (/score_zone/)) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) +;----------------------------------------------------------------- + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) +end do + +;******************************************************************* +; html table -- zone +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

CO2 Seasonal Cycle Comparisons by Latitude Zone: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
ZoneNumber of Sitemodel vs obs.
amplitide ratio
Correlation Coef.M ScoreCombined ScoreTaylor diagram
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow_zone-1 + set_line(lines,nline,row_header) + + set_line(lines,nline,""+text(n,0)+"") + set_line(lines,nline,""+text(n,1)+"") + set_line(lines,nline,""+text(n,2)+"") + set_line(lines,nline,""+text(n,3)+"") + set_line(lines,nline,""+text(n,4)+"") + set_line(lines,nline,""+text(n,5)+"") + set_line(lines,nline,"Taylor_diagram") + + set_line(lines,nline,row_footer) + end do + +; for the last row + + txt0 = "All" + txt1 = sum(stringtofloat(text(0:3,1))) + txt2 = "-" + txt3 = "-" + txt4 = "-" + txt5 = sum(stringtofloat(text(0:3,5))) + txt6 = "-" + + set_line(lines,nline,row_header) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) +;-------------------------------------------------------------------------- + + M_co2 = txt5 + + if (isvar("compare")) then + + system("sed -e '1,/M_co2/s/M_co2/"+M_co2+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_co2#"+M_co2+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + +;*************************************************************************** +; add total score and write to file +;*************************************************************************** + M_total = M_co2 + + asciiwrite("M_save.co2", M_total) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/co2" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 all/04.biomass.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/04.biomass.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,536 @@ +; **************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + plot_type = "ps" + plot_type_new = "png" + +;------------------------------------------------------ +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if + +;------------------------------------------------------ +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;--------------------------------- +; get model data: landfrac and area + + film_l = "lnd_"+ model_grid + ".nc" + fm_l = addfile (dirs+film_l,"r") + + landfrac = fm_l->landfrac + area0 = fm_l->area + + delete (fm_l) + +; change area from km**2 to m**2 + area0 = area0 * 1.e6 + +;----------------------------- +; take into account landfrac + + area0 = area0 * landfrac + +;-------------------------------------------- +; read model data + + fm = addfile (dirm+film1,"r") + + if (BGC .eq. "cn") then + data1 = fm->LIVESTEMC + data2 = fm->DEADSTEMC + data3 = fm->LEAFC + datamod0 = data1(0,:,:) + datamod0 = data1(0,:,:) + data2(0,:,:) + data3(0,:,:) + end if + + if (BGC .eq. "casa") then + factor_WOODC = 0.7 + data1 = fm->WOODC + data2 = fm->LEAFC + datamod0 = data1(0,:,:) + datamod0 = data1(0,:,:)*factor_WOODC + data2(0,:,:) + end if + +; unit: gC/m2 + + xm = fm->lon + ym = fm->lat + + delete (fm) + +;------------------------------------------------ +; read amazon mask data + + dir_m = diro + "biomass/" + fil_m = "amazon_mask_"+ model_grid + ".nc" + fm = addfile (dir_m+fil_m,"r") + + mask_amazon0 = fm->mask_amazon + + delete (fm) + +;------------------------------------------------ +; read ob data + + ob_name = "LC15_Amazon_Biomass" + + dir_b = diro + "biomass/" + fil_b = "amazon_biomass_"+model_grid+".nc" + fo = addfile (dir_b+fil_b,"r") + + dataob = fo->BIOMASS + xo = fo->lon + yo = fo->lat + + delete (fo) + +;************************************************ +; Units for these variables are: +; dataob : MgC/ha +; datamod0 : gC/m2 +; We want to convert these to KgC/m2 +; ha = 100m*100m = 10,000 m2 +; MgC/ha*1000/10,000 = KgC/m2 + + factor_aboveground = 0.5 + factor_unit_ob = 0.1 + factor_unit_mod = 0.001 + + dataob = dataob * factor_aboveground * factor_unit_ob + datamod0 = datamod0 * factor_unit_mod + + dataob@units = "KgC/m2" + datamod0@units = "KgC/m2" + + dataob@long_name = "Amazon Biomass" + datamod0@long_name = "Amazon Biomass" +;******************************************************** +; get subset of datamod0 that match dataob + + nlon = dimsizes(xo) + nlat = dimsizes(yo) + + ind_lonL = ind(xm .eq. xo(0)) + ind_lonR = ind(xm .eq. xo(nlon-1)) + ind_latS = ind(ym .eq. yo(0)) + ind_latN = ind(ym .eq. yo(nlat-1)) + + datamod = dataob + datamod(:,:) = datamod0(ind_latS:ind_latN,ind_lonL:ind_lonR) + + area = dataob + area(:,:) = area0(ind_latS:ind_latN,ind_lonL:ind_lonR) + + mask_amazon = dataob + mask_amazon(:,:) = mask_amazon0(ind_latS:ind_latN,ind_lonL:ind_lonR) + + mask_amazon@units = "" +;******************************************************** +; sum over amazom_mask area: + +; Peta g = 1.e15 g = 1.e12 Kg + factor_unit = 1.e-12 + +; mask_amazon = where(mask_amazon .ge. 0.5, mask_amazon ,0.) + + Sum_area = sum(area*mask_amazon)*factor_unit + + Sum_ob = sum(dataob*area*mask_amazon)*factor_unit + Sum_mod = sum(datamod*area*mask_amazon)*factor_unit + + avg_ob = Sum_ob /Sum_area + avg_mod = Sum_mod/Sum_area + + Sum_biomass_ob = sprintf("%.2f",Sum_ob ) + Sum_biomass_mod = sprintf("%.2f",Sum_mod) + +;---------------------------------------------------------------------- +; contour plot res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@gsnAddCyclic = False + + resg@gsnSpreadColors = True ; use full colormap + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + + resg@mpMinLatF = -21.1 ; range to zoom in on + resg@mpMaxLatF = 13.8 + resg@mpMinLonF = 277.28 + resg@mpMaxLonF = 326.43 +;------------------------------------------------------------------------ +; mask plot + + plot_name = "mask_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + +;----------------------------------------- +; plot area sum + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + area_sum_text = "(mask area = "+sprintf("%.2f", Sum_area)+"e12 m2)" + + gsn_text_ndc(wks,area_sum_text,0.50,0.80,gRes) +;----------------------------------------- + + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 1. ; Max level + resg@cnLevelSpacingF = 0.1 ; interval + + resg@tiMainString = "Amazon Mask: grid = "+ model_grid + + plot = gsn_csm_contour_map_ce(wks,mask_amazon,resg) + + delete (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;------------------------------------------------------------------------ +; contour ob + + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 30. ; Max level + resg@cnLevelSpacingF = 2. ; interval + + plot_name = "global_ob" + title = ob_name+" "+ model_grid + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,dataob,resg) + + delete (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;------------------------------------------------------------------------ +; contour model + + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 30. ; Max level + resg@cnLevelSpacingF = 2. ; interval + + plot_name = "global_model" + title = "Model "+ model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,datamod,resg) + + delete (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;------------------------------------------------------------------------ +; contour model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;(d) compute correlation coef and M score + + uu = ndtooned(datamod) + vv = ndtooned(dataob) + + good = ind(.not.ismissing(uu) .and. .not.ismissing(vv)) + + ug = uu(good) + vg = vv(good) + + ccrG = esccr(ug,vg,0) + + score_max = 5.0 + +; Miomass = (ccrG*ccrG)* score_max +; new eq + bias = sum(abs(ug-vg)/(abs(ug)+abs(vg))) + Mbiomass = (1. - (bias/dimsizes(ug)))*score_max + M_biomass = sprintf("%.2f", Mbiomass) + + if (isvar("compare")) then + system("sed -e '1,/M_biomass/s/M_biomass/"+M_biomass+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_biomass#"+M_biomass+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrG)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = ob_name+" "+ model_grid + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,dataob,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,datamod,resg) + +;(c) model-ob + + zz = datamod + zz = datamod - dataob + title = "Model_"+model_name+" - Observed" + + resg@cnMinLevelValF = -10. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 2. ; interval + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + delete (wks) + delete (plot) + delete (zz) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + resg@gsnFrame = True ; draw plot + resg@gsnDraw = True ; advance frame +;------------------------------------------------------------------------ +; contour ob : masked + + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 30. ; Max level + resg@cnLevelSpacingF = 2. ; interval + + plot_name = "global_mask_ob" + title = ob_name+" "+ model_grid + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap +;----------------------------------------- +; plot average over mask region + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 0 + + area_avg_text = "(average over mask area = "+sprintf("%.2f", avg_ob)+" Kg C/m2)" + + gsn_text_ndc(wks,area_avg_text,0.50,0.81,gRes) +;----------------------------------------- + zo = dataob + zo = dataob*mask_amazon + zo = where((mask_amazon .le. 0.01), zo@_FillValue, zo) + plot = gsn_csm_contour_map_ce(wks,zo,resg) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;------------------------------------------------------------------------ +; contour model: masked + + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 30. ; Max level + resg@cnLevelSpacingF = 2. ; interval + + plot_name = "global_mask_model" + title = "Model "+ model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap +;----------------------------------------- +; plot average over mask region + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 0 + + area_avg_text = "(average over mask area = "+sprintf("%.2f", avg_mod)+" Kg C/m2)" + + gsn_text_ndc(wks,area_avg_text,0.50,0.81,gRes) +;----------------------------------------- + zm = datamod + zm = datamod*mask_amazon + zm = where((mask_amazon .le. 0.01), zm@_FillValue, zm) + plot = gsn_csm_contour_map_ce(wks,zm,resg) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;------------------------------------------------------------------------ +; contour model vs ob: masked + + plot_name = "global_mask_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;(d) compute correlation coef and M score + + delete (good) + delete (uu) + delete (vv) + delete (ug) + delete (vg) + + score_max = 5. + + uu = ndtooned(zm) + vv = ndtooned(zo) + + good = ind((uu .gt. 0.) .and. (vv .gt. 0.)) + + ug = uu(good) + vg = vv(good) + + ccrG = esccr(ug,vg,0) + +; Miomass = (ccrG*ccrG)*score_max +; new eq + bias = sum(abs(ug-vg)/(abs(ug)+abs(vg))) + Mbiomass2 = (1. - (bias/dimsizes(ug)))*score_max + M_biomask = sprintf("%.2f", Mbiomass2) + + if (isvar("compare")) then + system("sed -e '1,/M_biomask/s/M_biomask/"+M_biomask+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + system("sed -e '1,/Sum_biomass_ob/s/Sum_biomass_ob/"+Sum_biomass_ob+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + system("sed -e '1,/Sum_biomass_mod/s/Sum_biomass_mod/"+Sum_biomass_mod+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_biomask#"+M_biomask+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + system("sed s#Sum_biomass_ob#"+Sum_biomass_ob+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + system("sed s#Sum_biomass_mod#"+Sum_biomass_mod+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) +;-------------------------------------------------------------------- +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%.2f", ccrG)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = ob_name+" "+ model_grid + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,zo,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,zm,resg) + +;(c) model-ob + + zz = zo + zz = zm - zo + title = "Model_"+model_name+" - Observed" + + resg@cnMinLevelValF = -10. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 2. ; interval + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;*************************************************************************** +; add total score and write to file +;*************************************************************************** + M_total = Mbiomass + Mbiomass2 + + asciiwrite("M_save.biomass", M_total) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/biomass" + + system("mv *.png " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 all/06.fluxnet.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/06.fluxnet.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,544 @@ +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +;------------------------------------------------------ +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if + +;------------------------------------------------------ +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;------------------------------------------------------ +; read model data + + fm = addfile(dirm+film2,"r") + + xm = fm->lon + ym = fm->lat + + nlat = dimsizes(ym) + nlon = dimsizes(xm) + +; for 4 fields, 12-monthly + nmon = 12 + nfield = 4 + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) +end if + + delete (fm) + +;************************************************ +; read data: observed +;************************************************ + + station = (/"BOREAS_NSA_OBS" \ + ,"CastelPorziano" \ + ,"Hyytiala" \ + ,"Kaamanen" \ + ,"LBA_Tapajos_KM67" \ + ,"Lethbridge" \ + ,"Tharandt" \ + ,"Vielsalm" \ + /) + + year_ob = (/"1994-2004" \ + ,"1997-2003" \ + ,"1996-2003" \ + ,"2000-2003" \ + ,"2002-2005" \ + ,"1999-2004" \ + ,"1996-2003" \ + ,"1998-2003" \ + /) + + field = (/"NEE" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + /) + + nstation = dimsizes(station) + nmon = 12 + nfield = dimsizes(field) + + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + + diri_root = diro + "fluxnet/" + + do n = 0,nstation-1 + diri = diri_root + station(n)+"/" + fili = station(n)+"_"+year_ob(n)+"_monthly.nc" + g = addfile (diri+fili,"r") + + lon_ob(n) = g->lon + lat_ob(n) = g->lat + + data = g->CO2_FLUX + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->RAD_FLUX + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->LH_FLUX + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->SH_FLUX + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (g) + end do + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0) + + delete (data_mod0) + yy!0 = "field" + data_mod = yy(pts|:,field|:,time|:) + +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + + M_nee = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_all = M_nee+ M_rad +M_lh + M_sh + + M_fluxnet_nee = sprintf("%.2f", M_nee) + M_fluxnet_rad = sprintf("%.2f", M_rad) + M_fluxnet_lh = sprintf("%.2f", M_lh ) + M_fluxnet_sh = sprintf("%.2f", M_sh ) + M_fluxnet_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + +; change longitude from 0-360 to -180-180 + lon_ob = where(lon_ob .gt. 180.,lon_ob-360., lon_ob) + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data(1,:) = (/data_mod(n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data(1,:) = (/data_mod(n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data(1,:) = (/data_mod(n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data(1,:) = (/data_mod(n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + end do + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Fluxnet at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + + set_line(lines,nline,"
"+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Fluxnet at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedNEENet RadiationLatent HeatSensible HeatAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + txt4 = sprintf("%5.2f", M_score(n,0)) + txt5 = sprintf("%5.2f", M_score(n,1)) + txt6 = sprintf("%5.2f", M_score(n,2)) + txt7 = sprintf("%5.2f", M_score(n,3)) + txt8 = sprintf("%5.2f", avg(M_score(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_fluxnet_nee + txt5 = M_fluxnet_rad + txt6 = M_fluxnet_lh + txt7 = M_fluxnet_sh + txt8 = M_fluxnet_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;************************************************************************************** +; update score +;************************************************************************************** + + if (isvar("compare")) then + system("sed -e '1,/M_fluxnet_nee/s/M_fluxnet_nee/"+M_fluxnet_nee+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed -e '1,/M_fluxnet_rad/s/M_fluxnet_rad/"+M_fluxnet_rad+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed -e '1,/M_fluxnet_lh/s/M_fluxnet_lh/"+M_fluxnet_lh+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed -e '1,/M_fluxnet_sh/s/M_fluxnet_sh/"+M_fluxnet_sh+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_fluxnet_nee#"+M_fluxnet_nee+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_fluxnet_rad#"+M_fluxnet_rad+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_fluxnet_lh#"+M_fluxnet_lh+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_fluxnet_sh#"+M_fluxnet_sh+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + +;*************************************************************************** +; add total score and write to file +;*************************************************************************** + M_total = M_fluxnet_all + + asciiwrite("M_save.fluxnet", M_total) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/fluxnet" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 all/07.beta.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/07.beta.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,541 @@ +;******************************************************** +; hardwired: co2_i = 283.1878 +; co2_f = 364.1252 +; +; beta_4_ob = 0.6 +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;------------------------------------------------------ +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if + +;------------------------------------------------------- +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;------------------------------------------------------- +; read model data + +;############################################################### +; hardwired for model data + +; these values correspond to the start and the end of model data + co2_i = 283.1878 + co2_f = 364.1252 + + film_i = film6 + film_f = film5 +;############################################################### + + fm_i = addfile (dirm+film_i,"r") + fm_f = addfile (dirm+film_f,"r") + + xm = fm_f->lon + ym = fm_f->lat + + npp_i = fm_i->NPP + npp_f = fm_f->NPP + + delete (fm_i) + delete (fm_f) + +;Units for these variables are: +;npp_i: g C/m^2/s + + nsec_per_year = 60*60*24*365 + + npp_i = npp_i * nsec_per_year + npp_f = npp_f * nsec_per_year + + unit = "gC/m2/year" + +;------------------------------ +; get landfrac data + + film_l = "lnd_" + model_grid + ".nc" + fm_l = addfile (dirs+film_l,"r") + landfrac = fm_l->landfrac + + npp_i(0,:,:) = npp_i(0,:,:) * landfrac(:,:) + npp_f(0,:,:) = npp_f(0,:,:) * landfrac(:,:) + + delete (fm_l) + delete (landfrac) + +;----------------------------- +; read biome data: model + + biome_name_mod = "Model PFT Class" + + film_c = "class_pft_"+model_grid+".nc" + fm_c = addfile (dirs+film_c,"r") + classmod = fm_c->CLASS_PFT + + delete (fm_c) + +; model data has 17 land-type classes + nclass_mod = 17 + +;--------------------------------------------------- +; read data: observed at stations + + station = (/"DukeFACE" \ + ,"AspenFACE" \ + ,"ORNL-FACE" \ + ,"POP-EUROFACE" \ + /) + + lat_ob = (/ 35.58, 45.40, 35.54, 42.22/) + lon_ob = (/-79.05, -89.37, -84.20, 11.48/) + lon_obx = where(lon_ob.lt.0.,lon_ob+360.,lon_ob) + + n_sta = dimsizes(station) + beta_4_ob = new((/n_sta/),float) + +;################################################### +; this is a hardwired value + beta_4_ob = 0.60 +;################################################### +;--------------------------------------------------- +; get model data at station + + npp_i_4 =linint2_points(xm,ym,npp_i,True,lon_obx,lat_ob,0) + + npp_f_4 =linint2_points(xm,ym,npp_f,True,lon_obx,lat_ob,0) + +;--------------------------------------------------- +;compute beta_4 + + score_max = 3. + + beta_4 = new((/n_sta/),float) + + beta_4 = ((npp_f_4/npp_i_4) - 1.)/log(co2_f/co2_i) + + beta_4_avg = avg(beta_4) + + bias = sum(abs(beta_4-beta_4_ob)/(abs(beta_4)+abs(beta_4_ob))) + Mbeta = (1. - (bias/n_sta))*score_max + M_beta = sprintf("%.2f", Mbeta) + +;========================= +; for html table - station +;========================= + + output_html = "table_station.html" + +; column (not including header column) + + col_head = (/"Latitude","Longitude","CO2_i","CO2_f","NPP_i","NPP_f","Beta_model","Beta_ob"/) + + ncol = dimsizes(col_head) + +; row (not including header row) + row_head = (/"DukeFACE" \ + ,"AspenFACE" \ + ,"ORNL-FACE" \ + ,"POP-EUROFACE" \ + ,"All Station" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text(i,0) = sprintf("%.1f",lat_ob(i)) + text(i,1) = sprintf("%.1f",lon_ob(i)) + text(i,2) = sprintf("%.1f",co2_i) + text(i,3) = sprintf("%.1f",co2_f) + text(i,4) = sprintf("%.1f",npp_i_4(0,i)) + text(i,5) = sprintf("%.1f",npp_f_4(0,i)) + text(i,6) = sprintf("%.2f",beta_4(i)) + text(i,7) = "-" + end do + text(nrow-1,0) = "-" + text(nrow-1,1) = "-" + text(nrow-1,2) = "-" + text(nrow-1,3) = "-" + text(nrow-1,4) = "-" + text(nrow-1,5) = "-" + text(nrow-1,6) = sprintf("%.2f",beta_4_avg) + text(nrow-1,7) = sprintf("%.2f",avg(beta_4_ob)) + +;----------- +; html table +;----------- + + header_text = "

Beta Factor: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Station"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+"
("+unit+")
"+col_head(5)+"
("+unit+")
"+col_head(6)+""+col_head(7)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text(n,0) + txt3 = text(n,1) + txt4 = text(n,2) + txt5 = text(n,3) + txt6 = text(n,4) + txt7 = text(n,5) + txt8 = text(n,6) + txt9 = text(n,7) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (col_head) + delete (row_head) + delete (text) + delete (table_header) + delete (idx) + +;******************************************************************** +; use land-type class to bin the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;============================== +; put data into bins +;============================== + +; for model data and observed + data_n = 2 + +; using model biome class + + base = ndtooned(classmod) + +; output + + yvalues = new((/data_n,nx/),float) + count = new((/data_n,nx/),float) + +; Loop through each range, using base + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if + +; loop through each dataset + + do n = 0,data_n-1 + + if (n .eq. 0) then + data = ndtooned(npp_i) + end if + + if (n .eq. 1) then + data = ndtooned(npp_f) + end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(n,i) = avg(data(idx)) + count(n,i) = dimsizes(idx) + else + yvalues(n,i) = yvalues@_FillValue + count(n,i) = 0 + end if + +;############################################################# +; using model biome class: +; +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(n,i) = yvalues@_FillValue + count(n,i) = 0 + end if +;############################################################# + + delete(data) + end do ; n-loop + + delete(idx) + end do ; i-loop + + delete (base) + delete (npp_i) + delete (npp_f) + +;============================ +;compute beta +;============================ + + u = yvalues(0,:) + v = yvalues(1,:) + u_count = count(0,:) + v_count = count(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + + uu = u(good) + vv = v(good) + uu_count = u_count(good) + vv_count = v_count(good) + + n_biome = dimsizes(uu) + beta_biome = new((/n_biome/),float) + + beta_biome = ((vv/uu) - 1.)/log(co2_f/co2_i) + + beta_biome_avg = (sum(vv*vv_count)/sum(uu*uu_count) - 1.)/log(co2_f/co2_i) + +;=========================== +; for html table - biome +;=========================== + + output_html = "table_biome.html" + +; column (not including header column) + + col_head = (/"CO2_i","CO2_f","NPP_i","NPP_f","Beta_model"/) + + ncol = dimsizes(col_head) + +; row (not including header row) + +;---------------------------------------------------- +; using model biome class: +; + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text(i,0) = sprintf("%.1f",co2_i) + text(i,1) = sprintf("%.1f",co2_f) + text(i,2) = sprintf("%.1f",uu(i)) + text(i,3) = sprintf("%.1f",vv(i)) + text(i,4) = sprintf("%.2f",beta_biome(i)) + end do + text(nrow-1,0) = "-" + text(nrow-1,1) = "-" + text(nrow-1,2) = "-" + text(nrow-1,3) = "-" + text(nrow-1,4) = sprintf("%.2f",beta_biome_avg) + +;************************************************** +; html table +;************************************************** + + header_text = "

Beta Factor: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Class"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text(n,0) + txt3 = text(n,1) + txt4 = text(n,2) + txt5 = text(n,3) + txt6 = text(n,4) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;************************************************************************************** +; update score +;************************************************************************************** + if (isvar("compare")) then + system("sed -e '1,/M_beta/s/M_beta/"+M_beta+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_beta#"+M_beta+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + +;*************************************************************************** +; get total score and write to file +;*************************************************************************** + M_total = Mbeta + + asciiwrite("M_save.beta", M_total) + + delete (M_total) + +;*************************************************************************** +; output plot and html +;*************************************************************************** + output_dir = model_name+"/beta" + + system("mv *.html " + output_dir) +;*************************************************************************** + +end + diff -r 000000000000 -r 0c6405ab2ff4 all/08.turnover.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/08.turnover.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,351 @@ +;******************************************************** +; hardwire: flux = flux/1200. (for casa only) +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;------------------------------------------------------ +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if + +;------------------------------------------------------ +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;--------------------------------------------------------------- +;components + + component = (/"Leaf","Wood","Fine_Root","Litter","Coarse_Woody_Debris","Soil"/) + n_comp = dimsizes(component) + + field_pool = (/"LEAFC","WOODC","FROOTC","LITTERC","CWDC","SOILC"/) + field_flux = (/"LEAFC_ALLOC","WOODC_ALLOC","FROOTC_ALLOC","LITTERC_LOSS","CWDC_LOSS","SOILC_HR"/) + +;-------------------------------------------------- +; get landfrac data + + film_l = "lnd_"+ model_grid +".nc" + fm_l = addfile (dirs+film_l,"r") + landfrac = fm_l->landfrac + + delete (fm_l) +;--------------------------------------------------- +; read biome data: model + + biome_name_mod = "Model PFT Class" + + film_c = "class_pft_"+ model_grid +".nc" + fm_c = addfile (dirs+film_c,"r") + classmod = fm_c->CLASS_PFT + + delete (fm_c) + +; model data has 17 land-type classes + nclass_mod = 17 + +;******************************************************************** +; use land-type class to bin the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +; for 2 data: pool and flux + data_n = 2 + +; using model biome class + + base = ndtooned(classmod) + +; output + + yvalues = new((/data_n,nx/),float) + count = new((/data_n,nx/),float) + +;-------------------------------------------------- +; read model data, each component: + + fm = addfile (dirm+film4,"r") + + do k = 0,n_comp-1 + + pool = fm->$field_pool(k)$ + flux = fm->$field_flux(k)$ + +; Units for these variables are: +; pool: g C/m^2 +; flux: g C/m^2/s + + nsec_per_year = 60*60*24*365 + + flux = flux * nsec_per_year + + unit_p = "gC/m2" + unit_f = "gC/m2/year" + unit_t = "year" + +;############################################################# +; casa only +; all the plant pools (leaf, wood, and fine root) and +; coarse woody debris (cwd) and litter pools for +; CASA need to be divided by 1200. The soil flux +; and turnover time are fine and do not need to be adjusted. + + if (BGC .eq. "casa") then + if (k .ne. n_comp-1) then + flux = flux/1200. + end if + end if +;############################################################## + +; take into account landfrac + + pool = pool * conform(pool,landfrac,(/1,2/)) + flux = flux * conform(flux,landfrac,(/1,2/)) + +; Loop through each range, using base + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if + +; loop through each dataset + + do n = 0,data_n-1 + + if (n .eq. 0) then + data = ndtooned(pool) + end if + + if (n .eq. 1) then + data = ndtooned(flux) + end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(n,i) = avg(data(idx)) + count(n,i) = dimsizes(idx) + else + yvalues(n,i) = yvalues@_FillValue + count(n,i) = 0 + end if + +;############################################################# +; using model biome class: +; +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(n,i) = yvalues@_FillValue + count(n,i) = 0 + end if +;############################################################# + + delete(data) + end do ; n-loop + + delete(idx) + end do ; i-loop + + delete (pool) + delete (flux) + +;============================ +;compute turnover time +;============================ + + u = yvalues(0,:) + v = yvalues(1,:) + u_count = count(0,:) + v_count = count(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + + uu = u(good) + vv = v(good) + uu_count = u_count(good) + vv_count = v_count(good) + + n_biome = dimsizes(uu) + t_biome = new((/n_biome/),float) + + t_biome = uu/vv + + t_biome_avg = sum(uu*uu_count)/sum(vv*vv_count) + +;=========================== +; for html table - biome +;=========================== + + output_html = "table_"+component(k)+".html" + +; column (not including header column) + + col_head = (/component(k)+" Flux",component(k)+" Pool",component(k)+" Turnover Time"/) + + ncol = dimsizes(col_head) + +; row (not including header row) + +;---------------------------------------------------- +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text(i,0) = sprintf("%.1f",vv(i)) + text(i,1) = sprintf("%.1f",uu(i)) + text(i,2) = sprintf("%.2f",t_biome(i)) + end do + text(nrow-1,0) = "-" + text(nrow-1,1) = "-" + text(nrow-1,2) = sprintf("%.2f",t_biome_avg) + +;************************************************** +; html table +;************************************************** + + header_text = "

"+component(k)+" Turnover Time: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Class"+col_head(0)+"
("+unit_f+")
"+col_head(1)+"
("+unit_p+")
"+col_head(2)+"
("+unit_t+")
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text(n,0) + txt3 = text(n,1) + txt4 = text(n,2) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + + delete (good) + delete (t_biome) + delete (text) + + end do ; k-loop + + delete (fm) + +;*************************************************************************** +; output plot and html +;*************************************************************************** + output_dir = model_name+"/turnover" + + system("mv *.html " + output_dir) +;****************************** + +end + diff -r 000000000000 -r 0c6405ab2ff4 all/09.carbon_sink.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/09.carbon_sink.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,888 @@ +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;---------------------------------------------------------- +; edit current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if + +;---------------------------------------------------------- +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;---------------------------------------------------------- +; get biome data: model + + biome_name_mod = "Model PFT Class" + + film_c = "class_pft_"+ model_grid +".nc" + fm_c = addfile (dirs+film_c,"r") + classmod = fm_c->CLASS_PFT + + delete (fm_c) + +; model data has 17 land-type classes + nclass_mod = 17 + +;------------------------------------ +; get model landfrac and area + + film_l = "lnd_"+ model_grid +".nc" + fm_l = addfile (dirs+film_l,"r") + landfrac = fm_l->landfrac + area = fm_l->area + + delete (fm_l) + +; change area from km**2 to m**2 + area = area * 1.e6 + +;------------------------------------- +; take into account landfrac + +; area = area * landfrac + +; delete (landfrac) + +;--------------------------------------------------- +; read data: model, group 1 + + fm = addfile (dirm+film4,"r") + + NPP1 = fm->NPP + + leafc = fm->LEAFC + woodc = fm->WOODC + frootc = fm->FROOTC + VegC = leafc + VegC = leafc + woodc + frootc + + litterc = fm->LITTERC + cwdc = fm->CWDC + LiCwC = litterc + LiCwC = litterc + cwdc + + SoilC = fm->SOILC + + delete (fm) +;--------------------------------------------------- +; read data: model, group 2 + + fm = addfile (dirm+film5,"r") + + NPP2 = fm->NPP + NEE2 = fm->NEE + GPP2 = fm->GPP + + delete (fm) +;--------------------------------------------------- +; Units for these variables are: + +;NPP1: g C/m^2/s +;NPP2: g C/m^2/s +;NEE2: g C/m^2/s +;GPP2: g C/m^2/s + +;VegC: g C/m^2 +;LiCwC: g C/m^2 +;SoilC: g C/m^2 + + nsec_per_year = 60*60*24*365 + +; change unit to g C/m^2/year + + NPP1 = NPP1 * nsec_per_year * conform(NPP1,landfrac,(/1,2/)) + NPP2 = NPP2 * nsec_per_year * conform(NPP2,landfrac,(/1,2/)) + NEE2 = NEE2 * nsec_per_year * conform(NEE2,landfrac,(/1,2/)) + GPP2 = GPP2 * nsec_per_year * conform(GPP2,landfrac,(/1,2/)) + + VegC = VegC * conform(VegC,landfrac,(/1,2/)) + LiCwC = LiCwC * conform(LiCwC,landfrac,(/1,2/)) + SoilC = SoilC * conform(SoilC,landfrac,(/1,2/)) + + data_n = 8 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; print (range) +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + + area_1d = ndtooned(area) + +; output + + yvalues = new((/data_n,nx/),float) ; (per m2) + yvalues_t = new((/data_n,nx/),float) ; (per biome) + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if + + do n = 0,data_n-1 + + if (n.eq.0) then + data = ndtooned(area) + end if + + if (n.eq.1) then + data = ndtooned(NPP1) + end if + + if (n.eq.2) then + data = ndtooned(VegC) + end if + + if (n.eq.3) then + data = ndtooned(LiCwC) + end if + + if (n.eq.4) then + data = ndtooned(SoilC) + end if + + if (n.eq.5) then + data = ndtooned(NPP2) + end if + + if (n.eq.6) then + data = ndtooned(NEE2) + end if + + if (n.eq.7) then + data = ndtooned(GPP2) + end if + +; Calculate sum and average + + if (.not.any(ismissing(idx))) then + if (n.eq.0) then + yvalues(n,i) = sum(data(idx)) + yvalues_t(n,i) = sum(data(idx)) + else + yvalues(n,i) = avg(data(idx)) + yvalues_t(n,i) = sum(data(idx)*area_1d(idx)) + end if + else + yvalues(n,i) = yvalues@_FillValue + yvalues_t(n,i) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(n,i) = yvalues@_FillValue + yvalues_t(n,i) = yvalues@_FillValue + end if +;############################################################# + + delete (data) + end do + + delete (idx) + end do + + delete (base) + delete (area) + delete (NPP1) + delete (VegC) + delete (LiCwC) + delete (SoilC) + delete (NPP2) + delete (NEE2) + delete (GPP2) + +;---------------------------------------------------------------- +; data for table1 + + good = ind(.not.ismissing(yvalues(5,:)) .and. .not.ismissing(yvalues(1,:))) +;print (good) + + area_g = yvalues(0,good) + NPP1_g = yvalues(1,good) + VegC_g = yvalues(2,good) + LiCwC_g = yvalues(3,good) + SoilC_g = yvalues(4,good) + NPP2_g = yvalues(5,good) + NEE2_g = yvalues(6,good) + GPP2_g = yvalues(7,good) + + NPP_ratio = NPP2_g/NPP1_g + + n_biome = dimsizes(NPP1_g) + +;----------------------------------------------------------------- +; data for table2 + +; change unit from g to Pg (Peta gram) + factor_unit = 1.e-15 + + NPP1_t = yvalues_t(1,good) * factor_unit + VegC_t = yvalues_t(2,good) * factor_unit + LiCwC_t = yvalues_t(3,good) * factor_unit + SoilC_t = yvalues_t(4,good) * factor_unit + NEE2_t = yvalues_t(6,good) * factor_unit + GPP2_t = yvalues_t(7,good) * factor_unit + + delete (yvalues) + delete (yvalues_t) + +;------------------------------------------------------------- +; html table1 data + +; column (not including header column) + + col_head = (/"Area (1.e12m2)" \ + ,"NPP (gC/m2/yr)" \ + ,"VegC (gC/m2)" \ + ,"Litter+CWD (gC/m2)" \ + ,"SoilC (gC/m2)" \ + ,"NPP_ratio" \ + ,"NEE (gC/m2/yr)" \ + ,"GPP (gC/m2/yr)" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text(i,0) = sprintf("%.1f",area_g(i)*1.e-12) + text(i,1) = sprintf("%.1f",NPP1_g(i)) + text(i,2) = sprintf("%.1f",VegC_g(i)) + text(i,3) = sprintf("%.1f",LiCwC_g(i)) + text(i,4) = sprintf("%.1f",SoilC_g(i)) + text(i,5) = sprintf("%.2f",NPP_ratio(i)) + text(i,6) = sprintf("%.1f",NEE2_g(i)) + text(i,7) = sprintf("%.1f",GPP2_g(i)) + end do + +;------------------------------------------------------- +; create html table1 + + header_text = "

NEE and Carbon Stocks and Fluxes: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+""+col_head(7)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) + +;---------------------------- +;row of table + + do n = 0,nrow-2 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text(n,0) + txt2 = text(n,1) + txt3 = text(n,2) + txt4 = text(n,3) + txt5 = text(n,4) + txt6 = text(n,5) + txt7 = text(n,6) + txt8 = text(n,7) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + + set_line(lines,nline,row_footer) + end do +;---------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_per_m2.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + + delete (col_head) + delete (row_head) + delete (text) + delete (table_header) + +;----------------------------------------------------------------- +; html table2 data + +; column (not including header column) + + col_head = (/"NPP (PgC/yr)" \ + ,"VegC (PgC)" \ + ,"Litter+CWD (PgC)" \ + ,"SoilC (PgC)" \ + ,"NEE (PgC/yr)" \ + ,"GPP (PgC/yr)" \ + ,"NPP timeseries" \ + ,"NEE timeseries" \ + ,"Fire timeseries" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text(i,0) = sprintf("%.1f",NPP1_t(i)) + text(i,1) = sprintf("%.1f",VegC_t(i)) + text(i,2) = sprintf("%.1f",LiCwC_t(i)) + text(i,3) = sprintf("%.1f",SoilC_t(i)) + text(i,4) = sprintf("%.1f",NEE2_t(i)) + text(i,5) = sprintf("%.1f",GPP2_t(i)) + text(i,6) = "monthly_plot
annual_plot" + text(i,7) = "monthly_plot
annual_plot" + text(i,8) = "monthly_plot
annual_plot" + end do + + text(nrow-1,0) = sprintf("%.1f",sum(NPP1_t)) + text(nrow-1,1) = sprintf("%.1f",sum(VegC_t)) + text(nrow-1,2) = sprintf("%.1f",sum(LiCwC_t)) + text(nrow-1,3) = sprintf("%.1f",sum(SoilC_t)) + text(nrow-1,4) = sprintf("%.1f",sum(NEE2_t)) + text(nrow-1,5) = sprintf("%.1f",sum(GPP2_t)) + text(nrow-1,6) = "monthly_plot
annual_plot" + text(nrow-1,7) = "monthly_plot
annual_plot" + text(nrow-1,8) = "monthly_plot
annual_plot" + +;************************************************** +; create html table2 +;************************************************** + + header_text = "

NEE and Carbon Stocks and Fluxes (per biome): Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+""+col_head(7)+""+col_head(8)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text(n,0) + txt2 = text(n,1) + txt3 = text(n,2) + txt4 = text(n,3) + txt5 = text(n,4) + txt6 = text(n,5) + txt7 = text(n,6) + txt8 = text(n,7) + txt9 = text(n,8) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_per_biome.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + +;--------------------------------------------------- +; read model data, time series: + + fm = addfile (dirm+film7,"r") + + NPP3 = fm->NPP + NEE3 = fm->NEE + Fire = fm->COL_FIRE_CLOSS + + delete (fm) + +; Units for these variables are: + +;NPP3: g C/m^2/s +;NEE3: g C/m^2/s +;Fire: g C/m^2/s + + nsec_per_month = 60*60*24*30 + +; change unit to g C/m^2/month + + NPP3 = NPP3 * nsec_per_month * conform(NPP3,landfrac,(/2,3/)) + NEE3 = NEE3 * nsec_per_month * conform(NEE3,landfrac,(/2,3/)) + Fire = Fire * nsec_per_month * conform(Fire,landfrac,(/2,3/)) + + data_n = 3 + + dsizes = dimsizes(NPP3) + nyear = dsizes(0) + nmonth = dsizes(1) + ntime = nyear * nmonth + + year_start = 1979 + year_end = 2004 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; print (range) +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + +; output + + yvalues = new((/ntime,data_n,nx/),float) + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if + + do n = 0,data_n-1 + + t = -1 + do m = 0,nyear-1 + do k = 0,nmonth-1 + + t = t + 1 + + if (n.eq.0) then + data = ndtooned(NPP3(m,k,:,:)) + end if + + if (n.eq.1) then + data = ndtooned(NEE3(m,k,:,:)) + end if + + if (n.eq.2) then + data = ndtooned(Fire(m,k,:,:)) + end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(t,n,i) = sum(data(idx)*area_1d(idx)) + else + yvalues(t,n,i) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(t,n,i) = yvalues@_FillValue + end if +;############################################################# + + end do + end do + + delete(data) + end do + + delete(idx) + end do + + delete (base) + delete (NPP3) + delete (NEE3) + delete (Fire) + +;---------------------------------------------------------------- +; data for tseries plot + + yvalues_g = new((/ntime,data_n,n_biome/),float) + + yvalues_g@units = "TgC/month" + +; change unit to Tg C/month +; change unit from g to Tg (Tera gram) + factor_unit = 1.e-12 + + yvalues_g = yvalues(:,:,good) * factor_unit + +;******************************************************************* +; general settings for line plot +;******************************************************************* + +; res + res = True + res@xyDashPatterns = (/0/) ; make lines solid + res@xyLineThicknesses = (/2.0/) ; make lines thicker + res@xyLineColors = (/"blue"/) ; line color + + res@trXMinF = year_start + res@trXMaxF = year_end + 1 + + res@vpHeightF = 0.4 ; change aspect ratio of plot +; res@vpWidthF = 0.8 + res@vpWidthF = 0.75 + +; res@gsnMaximize = True + +;******************************************************************* +; (A) 1 component in each biome: monthly +;******************************************************************* + + component = (/"NPP","NEE","Fire"/) + +; for x-axis in xyplot + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_start + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/ntime/),float) + plot_data@long_name = "TgC/month" + + do n = 0, data_n-1 + do m = 0, n_biome-1 + + plot_name = component(n)+"_monthly_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": "+ row_head(m) + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + plot_data(:) = yvalues_g(:,n,m) + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + end do + end do + + do n = 0, data_n-1 + + plot_name = component(n)+"_monthly_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": Global" + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + do k = 0,ntime-1 + plot_data(k) = sum(yvalues_g(k,n,:)) + end do + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + end do + + delete (plot_data) + delete (timeI) + delete (timeF) + +;******************************************************************* +; (B) 1 component in each biome: annually +;******************************************************************* + + yvalues_a = new((/nyear,data_n,n_biome/),float) + yvalues_g!0 = "time" + yvalues_g!1 = "case" + yvalues_g!2 = "record" + + yvalues_a = month_to_annual(yvalues_g,0) + + delete (yvalues_g) + +; for x-axis in xyplot + + timeI = new((/nyear/),integer) + timeF = new((/nyear/),float) + timeI = ispan(1,nyear,1) + timeF = year_start + (timeI-1) + timeF@long_name = "year" + + plot_data = new((/nyear/),float) + plot_data@long_name = "TgC/year" + + do n = 0, data_n-1 + do m = 0, n_biome-1 + + plot_name = component(n)+"_annual_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": "+ row_head(m) + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + plot_data(:) = yvalues_a(:,n,m) + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + end do + end do + + do n = 0, data_n-1 + + plot_name = component(n)+"_annual_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": Global" + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + do k = 0,nyear-1 + plot_data(k) = sum(yvalues_a(k,n,:)) + end do + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + end do + +;**************************************** +; output plot and html +;**************************************** + output_dir = model_name+"/carbon_sink" + + system("mv *.png *.html " + output_dir) +;**************************************** + +end + diff -r 000000000000 -r 0c6405ab2ff4 all/09x.carbon_sink.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/09x.carbon_sink.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,890 @@ +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;---------------------------------------------------------- +; edit current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if + +;---------------------------------------------------------- +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;---------------------------------------------------------- +; get biome data: model + + biome_name_mod = "Model PFT Class" + + film_c = "class_pft_"+ model_grid +".nc" + fm_c = addfile (dirs+film_c,"r") + classmod = fm_c->CLASS_PFT + + delete (fm_c) + +; model data has 17 land-type classes + nclass_mod = 17 + +;------------------------------------ +; get model landfrac and area + + film_l = "lnd_"+ model_grid +".nc" + fm_l = addfile (dirs+film_l,"r") + landfrac = fm_l->landfrac + area = fm_l->area + + delete (fm_l) + +; change area from km**2 to m**2 + area = area * 1.e6 + +;------------------------------------- +; take into account landfrac + +; area = area * landfrac + +; delete (landfrac) + +;--------------------------------------------------- +; read data: model, group 1 + + fm = addfile (dirm+film4,"r") + + NPP1 = fm->NPP + + leafc = fm->LEAFC + woodc = fm->WOODC + frootc = fm->FROOTC + VegC = leafc + VegC = leafc + woodc + frootc + + litterc = fm->LITTERC + cwdc = fm->CWDC + LiCwC = litterc + LiCwC = litterc + cwdc + + SoilC = fm->SOILC + + delete (fm) +;--------------------------------------------------- +; read data: model, group 2 + + fm = addfile (dirm+film5,"r") + + NPP2 = fm->NPP + NEE2 = fm->NEE + GPP2 = fm->GPP + + delete (fm) +;--------------------------------------------------- +; Units for these variables are: + +;NPP1: g C/m^2/s +;NPP2: g C/m^2/s +;NEE2: g C/m^2/s +;GPP2: g C/m^2/s + +;VegC: g C/m^2 +;LiCwC: g C/m^2 +;SoilC: g C/m^2 + + nsec_per_year = 60*60*24*365 + +; change unit to g C/m^2/year + + NPP1 = NPP1 * nsec_per_year * conform(NPP1,landfrac,(/1,2/)) + NPP2 = NPP2 * nsec_per_year * conform(NPP2,landfrac,(/1,2/)) + NEE2 = NEE2 * nsec_per_year * conform(NEE2,landfrac,(/1,2/)) + GPP2 = GPP2 * nsec_per_year * conform(GPP2,landfrac,(/1,2/)) + + VegC = VegC * conform(VegC,landfrac,(/1,2/)) + LiCwC = LiCwC * conform(LiCwC,landfrac,(/1,2/)) + SoilC = SoilC * conform(SoilC,landfrac,(/1,2/)) + + data_n = 8 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; print (range) +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + + area_1d = ndtooned(area) + +; output + + yvalues = new((/data_n,nx/),float) ; (per m2) + yvalues_t = new((/data_n,nx/),float) ; (per biome) + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if + + do n = 0,data_n-1 + + if (n.eq.0) then + data = ndtooned(area) + end if + + if (n.eq.1) then + data = ndtooned(NPP1) + end if + + if (n.eq.2) then + data = ndtooned(VegC) + end if + + if (n.eq.3) then + data = ndtooned(LiCwC) + end if + + if (n.eq.4) then + data = ndtooned(SoilC) + end if + + if (n.eq.5) then + data = ndtooned(NPP2) + end if + + if (n.eq.6) then + data = ndtooned(NEE2) + end if + + if (n.eq.7) then + data = ndtooned(GPP2) + end if + +; Calculate sum and average + + if (.not.any(ismissing(idx))) then + if (n.eq.0) then + yvalues(n,i) = sum(data(idx)) + yvalues_t(n,i) = sum(data(idx)) + else + yvalues(n,i) = avg(data(idx)) + yvalues_t(n,i) = sum(data(idx)*area_1d(idx)) + end if + else + yvalues(n,i) = yvalues@_FillValue + yvalues_t(n,i) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(n,i) = yvalues@_FillValue + yvalues_t(n,i) = yvalues@_FillValue + end if +;############################################################# + + delete (data) + end do + + delete (idx) + end do + + delete (base) + delete (area) + delete (NPP1) + delete (VegC) + delete (LiCwC) + delete (SoilC) + delete (NPP2) + delete (NEE2) + delete (GPP2) + +;---------------------------------------------------------------- +; data for table1 + + good = ind(.not.ismissing(yvalues(5,:)) .and. .not.ismissing(yvalues(1,:))) +;print (good) + + area_g = yvalues(0,good) + NPP1_g = yvalues(1,good) + VegC_g = yvalues(2,good) + LiCwC_g = yvalues(3,good) + SoilC_g = yvalues(4,good) + NPP2_g = yvalues(5,good) + NEE2_g = yvalues(6,good) + GPP2_g = yvalues(7,good) + + NPP_ratio = NPP2_g/NPP1_g + + n_biome = dimsizes(NPP1_g) + +;----------------------------------------------------------------- +; data for table2 + +; change unit from g to Pg (Peta gram) + factor_unit = 1.e-15 + + NPP1_t = yvalues_t(1,good) * factor_unit + VegC_t = yvalues_t(2,good) * factor_unit + LiCwC_t = yvalues_t(3,good) * factor_unit + SoilC_t = yvalues_t(4,good) * factor_unit + NEE2_t = yvalues_t(6,good) * factor_unit + GPP2_t = yvalues_t(7,good) * factor_unit + + delete (yvalues) + delete (yvalues_t) + +;------------------------------------------------------------- +; html table1 data + +; column (not including header column) + + col_head = (/"Area (1.e12m2)" \ + ,"NPP (gC/m2/yr)" \ + ,"VegC (gC/m2)" \ + ,"Litter+CWD (gC/m2)" \ + ,"SoilC (gC/m2)" \ + ,"NPP_ratio" \ + ,"NEE (gC/m2/yr)" \ + ,"GPP (gC/m2/yr)" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text(i,0) = sprintf("%.1f",area_g(i)*1.e-12) + text(i,1) = sprintf("%.1f",NPP1_g(i)) + text(i,2) = sprintf("%.1f",VegC_g(i)) + text(i,3) = sprintf("%.1f",LiCwC_g(i)) + text(i,4) = sprintf("%.1f",SoilC_g(i)) + text(i,5) = sprintf("%.2f",NPP_ratio(i)) + text(i,6) = sprintf("%.1f",NEE2_g(i)) + text(i,7) = sprintf("%.1f",GPP2_g(i)) + end do + +;------------------------------------------------------- +; create html table1 + + header_text = "

NEE and Carbon Stocks and Fluxes: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+""+col_head(7)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) + +;---------------------------- +;row of table + + do n = 0,nrow-2 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text(n,0) + txt2 = text(n,1) + txt3 = text(n,2) + txt4 = text(n,3) + txt5 = text(n,4) + txt6 = text(n,5) + txt7 = text(n,6) + txt8 = text(n,7) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + + set_line(lines,nline,row_footer) + end do +;---------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_per_m2.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + + delete (col_head) + delete (row_head) + delete (text) + delete (table_header) + +;----------------------------------------------------------------- +; html table2 data + +; column (not including header column) + + col_head = (/"NPP (PgC/yr)" \ + ,"VegC (PgC)" \ + ,"Litter+CWD (PgC)" \ + ,"SoilC (PgC)" \ + ,"NEE (PgC/yr)" \ + ,"GPP (PgC/yr)" \ + ,"NPP timeseries" \ + ,"NEE timeseries" \ + ,"Fire timeseries" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text(i,0) = sprintf("%.1f",NPP1_t(i)) + text(i,1) = sprintf("%.1f",VegC_t(i)) + text(i,2) = sprintf("%.1f",LiCwC_t(i)) + text(i,3) = sprintf("%.1f",SoilC_t(i)) + text(i,4) = sprintf("%.1f",NEE2_t(i)) + text(i,5) = sprintf("%.1f",GPP2_t(i)) + text(i,6) = "monthly_plot
annual_plot" + text(i,7) = "monthly_plot
annual_plot" + text(i,8) = "--" + end do + + text(nrow-1,0) = sprintf("%.1f",sum(NPP1_t)) + text(nrow-1,1) = sprintf("%.1f",sum(VegC_t)) + text(nrow-1,2) = sprintf("%.1f",sum(LiCwC_t)) + text(nrow-1,3) = sprintf("%.1f",sum(SoilC_t)) + text(nrow-1,4) = sprintf("%.1f",sum(NEE2_t)) + text(nrow-1,5) = sprintf("%.1f",sum(GPP2_t)) + text(nrow-1,6) = "monthly_plot
annual_plot" + text(nrow-1,7) = "monthly_plot
annual_plot" + text(nrow-1,8) = "--" + +;************************************************** +; create html table2 +;************************************************** + + header_text = "

NEE and Carbon Stocks and Fluxes (per biome): Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+""+col_head(7)+""+col_head(8)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text(n,0) + txt2 = text(n,1) + txt3 = text(n,2) + txt4 = text(n,3) + txt5 = text(n,4) + txt6 = text(n,5) + txt7 = text(n,6) + txt8 = text(n,7) + txt9 = text(n,8) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_per_biome.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + +;--------------------------------------------------- +; read model data, time series: + + fm = addfile (dirm+film7,"r") + + NPP3 = fm->NPP + NEE3 = fm->NEE +;Fire = fm->COL_FIRE_CLOSS + + delete (fm) + +; Units for these variables are: + +;NPP3: g C/m^2/s +;NEE3: g C/m^2/s +;Fire: g C/m^2/s + + nsec_per_month = 60*60*24*30 + +; change unit to g C/m^2/month + + NPP3 = NPP3 * nsec_per_month * conform(NPP3,landfrac,(/2,3/)) + NEE3 = NEE3 * nsec_per_month * conform(NEE3,landfrac,(/2,3/)) +;Fire = Fire * nsec_per_month * conform(Fire,landfrac,(/2,3/)) + +;data_n = 3 + data_n = 2 + + dsizes = dimsizes(NPP3) + nyear = dsizes(0) + nmonth = dsizes(1) + ntime = nyear * nmonth + + year_start = 1979 + year_end = 2004 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; print (range) +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + +; output + + yvalues = new((/ntime,data_n,nx/),float) + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if + + do n = 0,data_n-1 + + t = -1 + do m = 0,nyear-1 + do k = 0,nmonth-1 + + t = t + 1 + + if (n.eq.0) then + data = ndtooned(NPP3(m,k,:,:)) + end if + + if (n.eq.1) then + data = ndtooned(NEE3(m,k,:,:)) + end if + +; if (n.eq.2) then +; data = ndtooned(Fire(m,k,:,:)) +; end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(t,n,i) = sum(data(idx)*area_1d(idx)) + else + yvalues(t,n,i) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(t,n,i) = yvalues@_FillValue + end if +;############################################################# + + end do + end do + + delete(data) + end do + + delete(idx) + end do + + delete (base) + delete (NPP3) + delete (NEE3) +; delete (Fire) + +;---------------------------------------------------------------- +; data for tseries plot + + yvalues_g = new((/ntime,data_n,n_biome/),float) + + yvalues_g@units = "TgC/month" + +; change unit to Tg C/month +; change unit from g to Tg (Tera gram) + factor_unit = 1.e-12 + + yvalues_g = yvalues(:,:,good) * factor_unit + +;******************************************************************* +; general settings for line plot +;******************************************************************* + +; res + res = True + res@xyDashPatterns = (/0/) ; make lines solid + res@xyLineThicknesses = (/2.0/) ; make lines thicker + res@xyLineColors = (/"blue"/) ; line color + + res@trXMinF = year_start + res@trXMaxF = year_end + 1 + + res@vpHeightF = 0.4 ; change aspect ratio of plot +; res@vpWidthF = 0.8 + res@vpWidthF = 0.75 + +; res@gsnMaximize = True + +;******************************************************************* +; (A) 1 component in each biome: monthly +;******************************************************************* + +; component = (/"NPP","NEE","Fire"/) + component = (/"NPP","NEE"/) + +; for x-axis in xyplot + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_start + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/ntime/),float) + plot_data@long_name = "TgC/month" + + do n = 0, data_n-1 + do m = 0, n_biome-1 + + plot_name = component(n)+"_monthly_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": "+ row_head(m) + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + plot_data(:) = yvalues_g(:,n,m) + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + end do + end do + + do n = 0, data_n-1 + + plot_name = component(n)+"_monthly_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": Global" + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + do k = 0,ntime-1 + plot_data(k) = sum(yvalues_g(k,n,:)) + end do + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + end do + + delete (plot_data) + delete (timeI) + delete (timeF) + +;******************************************************************* +; (B) 1 component in each biome: annually +;******************************************************************* + + yvalues_a = new((/nyear,data_n,n_biome/),float) + yvalues_g!0 = "time" + yvalues_g!1 = "case" + yvalues_g!2 = "record" + + yvalues_a = month_to_annual(yvalues_g,0) + + delete (yvalues_g) + +; for x-axis in xyplot + + timeI = new((/nyear/),integer) + timeF = new((/nyear/),float) + timeI = ispan(1,nyear,1) + timeF = year_start + (timeI-1) + timeF@long_name = "year" + + plot_data = new((/nyear/),float) + plot_data@long_name = "TgC/year" + + do n = 0, data_n-1 + do m = 0, n_biome-1 + + plot_name = component(n)+"_annual_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": "+ row_head(m) + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + plot_data(:) = yvalues_a(:,n,m) + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + end do + end do + + do n = 0, data_n-1 + + plot_name = component(n)+"_annual_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": Global" + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + do k = 0,nyear-1 + plot_data(k) = sum(yvalues_a(k,n,:)) + end do + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + end do + +;**************************************** +; output plot and html +;**************************************** + output_dir = model_name+"/carbon_sink" + + system("mv *.png *.html " + output_dir) +;**************************************** + +end + diff -r 000000000000 -r 0c6405ab2ff4 all/10.fire.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/10.fire.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,744 @@ +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;------------------------------------------------------ +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if + +;------------------------------------------------------ +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;------------------------------------------------------ +; get biome data: model + + biome_name_mod = "Model PFT Class" + + film_c = "class_pft_"+ model_grid +".nc" + fm_c = addfile (dirs+film_c,"r") + classmod = fm_c->CLASS_PFT + + delete (fm_c) + +; model data has 17 land-type classes + nclass_mod = 17 + +;-------------------------------- +; get model data: landmask, landfrac and area + + film_l = "lnd_"+ model_grid +".nc" + fm_l = addfile (dirs+film_l,"r") + landmask = fm_l->landmask + landfrac = fm_l->landfrac + area = fm_l->area + + delete (fm_l) + +; change area from km**2 to m**2 + area = area * 1.e6 + +; take into account landfrac + area = area * landfrac + +;-------------------------------- +; read data: time series, model + + fm = addfile (dirm+film7,"r") + + data_mod = fm->COL_FIRE_CLOSS(18:25,:,:,:) + + delete (fm) + +; Units for these variables are: +; g C/m^2/s + +; change unit to gC/m2/month + + nsec_per_month = 60*60*24*30 + + data_mod = data_mod * nsec_per_month + + data_mod@units = "gC/m2/month" + +;---------------------------------------------------- +; read data: time series, observed + + dir_f = diro + "fire/" + fil_f = "Fire_C_1997-2006_monthly_"+ model_grid+".nc" + fm = addfile (dir_f+fil_f,"r") + data_ob = fm->FIRE_C(0:7,:,:,:) + + delete (fm) + + ob_name = "GFEDv2" + +; Units for these variables are: gC/m2/month + + data_ob@units = "gC/m2/month" + +;------------------------------------------------------------- +; html table1 data + +; column (not including header column) + + col_head = (/"Observed Fire_Flux (PgC/yr)" \ + ,"Model Fire_Flux (PgC/yr)" \ + ,"Correlation Coefficient" \ + ,"Ratio model/observed" \ + ,"M_score" \ + ,"Timeseries plot" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biomes" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + +;***************************************************************** +; (A) get time-mean +;***************************************************************** + + x = dim_avg_Wrap(data_mod(lat|:,lon|:,month|:,year|:)) + data_mod_m = dim_avg_Wrap( x(lat|:,lon|:,month|:)) + delete (x) + + x = dim_avg_Wrap( data_ob(lat|:,lon|:,month|:,year|:)) + data_ob_m = dim_avg_Wrap( x(lat|:,lon|:,month|:)) + delete (x) + +;---------------------------------------------------- +; compute correlation coef: space + + landmask_1d = ndtooned(landmask) + data_mod_1d = ndtooned(data_mod_m) + data_ob_1d = ndtooned(data_ob_m ) + area_1d = ndtooned(area) + landfrac_1d = ndtooned(landfrac) + + good = ind(landmask_1d .gt. 0.) + + global_mod = sum(data_mod_1d(good)*area_1d(good)) * 1.e-15 * 12. + global_ob = sum(data_ob_1d(good) *area_1d(good)) * 1.e-15 * 12. +; print (global_mod) +; print (global_ob) + + global_area= sum(area_1d) + global_land= sum(area_1d(good)) +; print (global_area) +; print (global_land) + + cc_space = esccr(data_mod_1d(good)*landfrac_1d(good),data_ob_1d(good)*landfrac_1d(good),0) + + delete (landmask_1d) + delete (landfrac_1d) +; delete (area_1d) + delete (data_mod_1d) + delete (data_ob_1d) + delete (good) + +;---------------------------------------------------- +; compute M_global + + score_max = 1. + + Mscore1 = cc_space * cc_space * score_max + + M_global = sprintf("%.2f", Mscore1) + +;---------------------------------------------------- +; global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + +;---------------------------------------------------- +; global contour: model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") + + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;---------------------- +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%.2f", cc_space)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) + +;----------------------- +; plot ob +; change from gC/m2/month to gC/m2/yr + month_to_year = 12. + + data_ob_m@units = "gC/m2/yr" + data_mod_m@units = "gC/m2/yr" + + data_ob_m = data_ob_m * month_to_year + data_ob_m = where(landmask .gt. 0., data_ob_m, data_ob_m@_FillValue) + + title = ob_name + resg@tiMainString = title + + resg@cnMinLevelValF = 10. + resg@cnMaxLevelValF = 100. + resg@cnLevelSpacingF = 10. + + plot(0) = gsn_csm_contour_map_ce(wks,data_ob_m,resg) + +;----------------------- +; plot model + + data_mod_m = data_mod_m * month_to_year + + data_mod_m = where(landmask .gt. 0., data_mod_m, data_mod_m@_FillValue) + + title = "Model "+ model_name + resg@tiMainString = title + + resg@cnMinLevelValF = 10. + resg@cnMaxLevelValF = 100. + resg@cnLevelSpacingF = 10. + + plot(1) = gsn_csm_contour_map_ce(wks,data_mod_m,resg) + +;----------------------- +; plot model-ob + + resg@cnMinLevelValF = -80. + resg@cnMaxLevelValF = 20. + resg@cnLevelSpacingF = 10. + + zz = data_ob_m + zz = data_mod_m - data_ob_m + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + +; plot panel + + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + delete (data_ob_m) + delete (data_mod_m) + delete (zz) + + resg@gsnFrame = True ; Do advance frame + resg@gsnDraw = True ; Do draw plot + +;******************************************************************* +; (B) Time series : per biome +;******************************************************************* + + data_n = 2 + + dsizes = dimsizes(data_mod) + nyear = dsizes(0) + nmonth = dsizes(1) + ntime = nyear * nmonth + + year_start = 1997 + year_end = 2004 + +;------------------------------------------- +; Calculate "nice" bins for binning the data + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;------------------------------------------- +; put data into bins + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + +; output + + area_bin = new((/nx/),float) + yvalues = new((/ntime,data_n,nx/),float) + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if +;--------------------- +; for area + + if (.not.any(ismissing(idx))) then + area_bin(i) = sum(area_1d(idx)) + else + area_bin(i) = area_bin@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + area_bin(i) = area_bin@_FillValue + end if +;############################################################# + +;--------------------- +; for data_mod and data_ob + + do n = 0,data_n-1 + + t = -1 + do m = 0,nyear-1 + do k = 0,nmonth-1 + + t = t + 1 + + if (n.eq.0) then + data = ndtooned(data_ob(m,k,:,:)) + end if + + if (n.eq.1) then + data = ndtooned(data_mod(m,k,:,:)) + end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(t,n,i) = sum(data(idx)*area_1d(idx)) + else + yvalues(t,n,i) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(t,n,i) = yvalues@_FillValue + end if +;############################################################# + + end do + end do + + delete(data) + end do + + delete(idx) + end do + + delete (base) + delete (data_mod) + delete (data_ob) + + global_bin = sum(area_bin) +; print (global_bin) + +;---------------------------------------------------------------- +; get area_good + + good = ind(.not.ismissing(area_bin)) + + area_g = area_bin(good) + + n_biome = dimsizes(good) + + global_good = sum(area_g) +; print (global_good) + +;---------------------------------------------------------------- +; data for tseries plot + + yvalues_g = new((/ntime,data_n,n_biome/),float) + + yvalues_g@units = "TgC/month" + +; change unit to Tg C/month +; change unit from g to Tg (Tera gram) + factor_unit = 1.e-12 + + yvalues_g = yvalues(:,:,good) * factor_unit + + delete (good) + +;------------------------------------------------------------------- +; general settings for line plot + + res = True + res@xyDashPatterns = (/0,0/) ; make lines solid + res@xyLineThicknesses = (/2.0,2.0/) ; make lines thicker + res@xyLineColors = (/"blue","red"/) ; line color + + res@trXMinF = year_start + res@trXMaxF = year_end + 1 + + res@vpHeightF = 0.4 ; change aspect ratio of plot +; res@vpWidthF = 0.8 + res@vpWidthF = 0.75 + + res@tiMainFontHeightF = 0.025 ; size of title + + res@tmXBFormat = "f" ; not to add trailing zeros + +; res@gsnMaximize = True + +;---------------------------------------------- +; Add a boxed legend using the simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + res@pmLegendParallelPosF = 0.73 ;(rightward) + res@pmLegendParallelPosF = 0.83 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) + +;******************************************************************* +; (A) time series plot: monthly ( 2 lines per plot) +;******************************************************************* + +; x-axis in time series plot + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_start + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + plot_data@long_name = "TgC/month" + +;---------------------------------------------- +; time series plot : per biome + + do m = 0, n_biome-1 + + plot_name = "monthly_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = "Fire : "+ row_head(m) + res@tiMainString = title + + plot_data(0,:) = yvalues_g(:,0,m) + plot_data(1,:) = yvalues_g(:,1,m) + + plot = gsn_csm_xy(wks,timeF,plot_data,res) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + end do + +;------------------------------------------ +; data for table : per biome + +; unit change from TgC/month to PgC/month + unit_factor = 1.e-3 + + score_max = 1. + + tmp_ob = new((/ntime/),float) + tmp_mod = new((/ntime/),float) + + total_ob = new((/n_biome/),float) + total_mod = new((/n_biome/),float) + Mscore2 = new((/n_biome/),float) + + do m = 0, n_biome-1 + + tmp_ob = yvalues_g(:,0,m) + tmp_mod = yvalues_g(:,1,m) + + total_ob(m) = avg(month_to_annual(tmp_ob, 0)) * unit_factor + total_mod(m) = avg(month_to_annual(tmp_mod,0)) * unit_factor + + cc_time = esccr(tmp_mod,tmp_ob,0) + + ratio = total_mod(m)/total_ob(m) + + good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.) + + bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) ) + Mscore2(m) = (1.- (bias/dimsizes(good)))*score_max + + delete (good) + + text(m,0) = sprintf("%.2f",total_ob(m)) + text(m,1) = sprintf("%.2f",total_mod(m)) + text(m,2) = sprintf("%.2f",cc_time) + text(m,3) = sprintf("%.2f",ratio) + text(m,4) = sprintf("%.2f",Mscore2(m)) + text(m,5) = "model_vs_ob" + end do + + delete (tmp_ob) + delete (tmp_mod) + +;-------------------------------------------- +; time series plot: all biome + + plot_name = "monthly_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = "Fire : "+ row_head(n_biome) + res@tiMainString = title + + do k = 0,ntime-1 + plot_data(0,k) = sum(yvalues_g(k,0,:)) + plot_data(1,k) = sum(yvalues_g(k,1,:)) + end do + + plot = gsn_csm_xy(wks,timeF,plot_data,res) + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;------------------------------------------ +; data for table : global + + score_max = 1. + + tmp_ob = ndtooned(yvalues_g(:,0,:)) + tmp_mod = ndtooned(yvalues_g(:,1,:)) + + cc_time = esccr(tmp_mod,tmp_ob,0) + + ratio = sum(total_mod)/sum(total_ob) + + good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.) + + bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) ) + Mscore3 = (1.- (bias/dimsizes(good)))*score_max + +; print (Mscore3) + + delete (good) + + text(nrow-1,0) = sprintf("%.2f",sum(total_ob)) + text(nrow-1,1) = sprintf("%.2f",sum(total_mod)) + text(nrow-1,2) = sprintf("%.2f",cc_time) + text(nrow-1,3) = sprintf("%.2f",ratio) +; text(nrow-1,4) = sprintf("%.2f",avg(Mscore2)) + text(nrow-1,4) = sprintf("%.2f", Mscore3) + text(nrow-1,5) = "model_vs_ob" + +;************************************************** +; create html table +;************************************************** + + header_text = "

Fire Emissions from GFEDv2 (1997-2004) vs "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text(n,0) + txt2 = text(n,1) + txt3 = text(n,2) + txt4 = text(n,3) + txt5 = text(n,4) + txt6 = text(n,5) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_fire.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + +;************************************************************************************** +; update score +;************************************************************************************** + + M_all = Mscore1 + Mscore3 + M_fire = sprintf("%.2f", M_all) + + if (isvar("compare")) then + system("sed -e '1,/M_fire/s/M_fire/"+M_fire+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_fire#"+M_fire+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + +;*************************************************************************** +; get total score and write to file +;*************************************************************************** + + asciiwrite("M_save.fire", M_fire) + + delete (M_fire) + +;*************************************************************************** +; output plot and html +;*************************************************************************** + output_dir = model_name+"/fire" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** + +end + diff -r 000000000000 -r 0c6405ab2ff4 all/11.ameriflux.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/11.ameriflux.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,893 @@ +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +;------------------------------------------------------ +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if + +;------------------------------------------------------ +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;------------------------------------------------------ + + nmonth = 12 + +; for nee, gpp, and ar +; observed unit is gC/m2/day +; model unit is gC/m2/s +; to change to observed unit, + + factor_flux = 86400. + +; for incident solar radiation, +; observed Rg_f unit is MJ/m2/day +; model (FSDS) unit is W/m2 +; to change to model unit, + + factor_rad = 1.e6/86400. + +;************************************************ +; observed data info +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + field = (/"NEE Flux" \ + ,"Shortwave Incoming" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"gC/m2/day" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"gC/m2/day" \ + ,"gC/m2/day" \ + /) + + nstation = dimsizes(station) + nfield = dimsizes(field) + +;======================================================================== +; get observed info: number of year, first/last year, lat, lon +; and annual data + + dir_root = diro + "ameriflux/" + + year_station = new ((/nstation/),integer) ; number of year + year_ob = new ((/nstation/),string) ; observed year + year_ob_i = new ((/nstation/),integer) ; first year + year_ob_f = new ((/nstation/),integer) ; last year + lat_ob = new ((/nstation/),float) ; latitude + lon_ob = new ((/nstation/),float) ; longitude + + data_ob_ann = new ((/nfield, nmonth, nstation/),float) + + do n = 0, nstation-1 + + dir_f = dir_root + station(n)+"/" + fil_f = "timeseries_L4_m.nc" + fo = addfile (dir_f+fil_f,"r") + + lat_ob(n) = fo->lat + lon_ob(n) = fo->lon + + year = fo->year + + year_station(n) = dimsizes(year) + year_ob_i(n) = year(0) + year_ob_f(n) = year(year_station(n)-1) + year_ob(n) = year_ob_i(n) + "-" + year_ob_f(n) + + delete (year) + + data = fo->NEE_or_fMDS + data_ob_ann(0,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->Rg_f + data_ob_ann(1,:,n) = dim_avg(data(month|:,year|:)) * factor_rad + + data = fo->LE_f + data_ob_ann(2,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->H_f + data_ob_ann(3,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->GPP_or_MDS + data_ob_ann(4,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->Reco_or + data_ob_ann(5,:,n) = dim_avg(data(month|:,year|:)) + + delete (data) + delete (fo) + end do + +;-------------------------------------------------------------- +; find (# of year observed) >=4 and year_ob_i <= 2001 + + i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001) + + station_long = station(i_long_ob) + lat_ob_long = lat_ob(i_long_ob) + lon_ob_long = lat_ob(i_long_ob) + year_ob_long = year_ob(i_long_ob) + year_ob_i_long = year_ob_i(i_long_ob) + year_ob_f_long = year_ob_f(i_long_ob) + year_station_long = year_station(i_long_ob) + + nstation_long = dimsizes(station_long) + +;========================================================= +; get model data at observed lat-lon + + fm = addfile (dirm+film8,"r") + + xm = fm->lon + ym = fm->lat + date = fm->date + + date_dim = dimsizes(date) + nyear = date_dim(0) + + data_mod = new ((/nfield,nyear,nmonth,nstation/),float) + data_mod_ann = new ((/nfield,nmonth,nstation/),float) + data_mod_long = new ((/nfield,nyear,nmonth,nstation_long/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + + factor = 1.e6 /12. + +;------------------------------------------------------------ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. +;------------------------------------------------------------ + +if (ENERGY .eq. "old") then + + data = fm->NEE + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor_flux + data_mod(0,:,:,:) = yy(:,:,:) * factor_flux + +;;data = fm->NETRAD +; data = fm->FSA +; data1 = fm->FIRA +; data = data - data1 +; delete (data1) + + data = fm->FSDS + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(1,:,:,:) = yy(:,:,:) + + +; data = fm->LATENT + data = fm->FCEV + data1 = fm->FCTR + data2 = fm->FGEV + data = data + data1 + data2 + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(2,:,:,:) = yy(:,:,:) + delete (data1) + delete (data2) + +; data = fm->SENSIBLE + data = fm->FSH + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(3,:,:,:) = yy(:,:,:) + +else + + data = fm->NEE + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor_flux + data_mod(0,:,:,:) = yy(:,:,:) * factor_flux + +; data = fm->NETRAD + data = fm->FSDS + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(1,:,:,:) = yy(:,:,:) + + data = fm->LATENT + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(2,:,:,:) = yy(:,:,:) + +; data = fm->SENSIBLE + data = fm->FSH + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(3,:,:,:) = yy(:,:,:) + +end if + + data = fm->GPP + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(4,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor_flux + data_mod(4,:,:,:) = yy(:,:,:) * factor_flux + + data = fm->ER + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(5,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor_flux + data_mod(5,:,:,:) = yy(:,:,:) * factor_flux + + data_mod_long(:,:,:,:) = data_mod(:,:,:,i_long_ob) + + delete (data_mod) + delete (fm) + delete (data) + delete (yy) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) + + res@tmXBFormat = "f" ; not to add trailing zeros + +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + +; change longitude from 0-360 to -180-180 + lon_ob = where(lon_ob .gt. 180.,lon_ob-360., lon_ob) + lon_ob_long = where(lon_ob_long .gt. 180.,lon_ob_long-360., lon_ob_long) + +;============================================================== +; get ob data at each site with long observation + + do n = 0,nstation_long-1 + +;################################################################## +; hardwired: model up to year 2004 +; observed up to year 2006 + + year_setback = 0 + + nyear = year_station_long(n) + + if (year_ob_f_long(n).eq. 2006) then + year_setback = 2006 -2004 + end if + if (year_ob_f_long(n).eq. 2005) then + year_setback = 2005 -2004 + end if +;################################################################## + + ntime = (nyear - year_setback) * nmonth + + data_ob = new ((/nfield, nyear, nmonth/),float) + + dir_f = dir_root + station_long(n)+"/" + fil_f = "timeseries_L4_m.nc" + fo = addfile (dir_f+fil_f,"r") + + data_ob(0,:,:) = fo->NEE_or_fMDS + data_ob(1,:,:) = fo->Rg_f + data_ob(2,:,:) = fo->LE_f + data_ob(3,:,:) = fo->H_f + data_ob(4,:,:) = fo->GPP_or_MDS + data_ob(5,:,:) = fo->Reco_or + + data_ob(1,:,:) = data_ob(1,:,:) * factor_rad + + delete (fo) + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_ob_i_long(n) + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + +;---------------------------- +; for model_vs_ob + + plot_name = station_long(n)+"_tseries_vs_ob" + title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + i_year_mod_i = year_ob_i_long(n) - 1990 + i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback + + i_year_ob_f = nyear - year_setback - 1 + +; print (nyear) +; print (i_year_ob_f) +; print (i_year_mod_i) +; print (i_year_mod_f) + + do i = 0,nfield-1 + plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:)) + plot_data(1,:) = ndtooned(data_mod_long(i,i_year_mod_i:i_year_mod_f,:,n)) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,timeF,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + delete (data_ob) + delete (timeI) + delete (timeF) + delete (plot_data) + + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) + + isort = dim_pqsort(lat_ob_long,-1) + + station_sort = station_long(isort) + year_ob_sort = year_ob_long(isort) + lat_ob_sort = lat_ob_long(isort) + lon_ob_sort = lon_ob_long(isort) + +; print(isort) +; print(lat_ob_sort) + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "tseries_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Timeseries at Site: "+model_name+" vs Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation_long-1 + + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + + delete (isort) + delete (station_sort) + delete (year_ob_sort) + delete (lat_ob_sort) + delete (lon_ob_sort) + +;************************************************************ +; compute annual cycle correlation coef and M score +;************************************************************ + + score_max = 1. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob_ann(m,:,n),data_mod_ann(m,:,n),0) + 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)))) + M_score(n,m) = (1. -(bias/nmonth)) * score_max + end do + end do + + M_nee = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_nee+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_ameriflux_nee = sprintf("%.2f", M_nee) + M_ameriflux_rad = sprintf("%.2f", M_rad) + M_ameriflux_lh = sprintf("%.2f", M_lh ) + M_ameriflux_sh = sprintf("%.2f", M_sh ) + M_ameriflux_gpp = sprintf("%.2f", M_gpp) + M_ameriflux_er = sprintf("%.2f", M_er ) + M_ameriflux_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + +;------------------------------------------------------------------- + + plot_data = new((/2,nmonth/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob_ann(i,:,n)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob_ann(i,:,n)/) + plot_data(1,:) = (/data_mod_ann(i,:,n)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + delete (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) +; sort by lat in decending order (N->S) + + isort = dim_pqsort(lat_ob,-1) + + station_sort = station(isort) + year_ob_sort = year_ob(isort) + lat_ob_sort = lat_ob(isort) + lon_ob_sort = lon_ob(isort) + M_score_sort = M_score(isort,:) + +; print(isort) +; print(lat_ob_sort) +;################################################################### +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedNEE FluxShortwave
Incoming
Latent HeatSensible HeatGPP FluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + txt4 = sprintf("%5.2f", M_score_sort(n,0)) + txt5 = sprintf("%5.2f", M_score_sort(n,1)) + txt6 = sprintf("%5.2f", M_score_sort(n,2)) + txt7 = sprintf("%5.2f", M_score_sort(n,3)) + txt8 = sprintf("%5.2f", M_score_sort(n,4)) + txt9 = sprintf("%5.2f", M_score_sort(n,5)) + txt10 = sprintf("%5.2f", avg(M_score_sort(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_ameriflux_nee + txt5 = M_ameriflux_rad + txt6 = M_ameriflux_lh + txt7 = M_ameriflux_sh + txt8 = M_ameriflux_gpp + txt9 = M_ameriflux_er + txt10 = M_ameriflux_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;************************************************************************************** +; update score +;************************************************************************************** + + if (isvar("compare")) then + system("sed -e '1,/M_ameriflux_nee/s/M_ameriflux_nee/"+M_ameriflux_nee+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed -e '1,/M_ameriflux_rad/s/M_ameriflux_rad/"+M_ameriflux_rad+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed -e '1,/M_ameriflux_lh/s/M_ameriflux_lh/"+M_ameriflux_lh+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed -e '1,/M_ameriflux_sh/s/M_ameriflux_sh/"+M_ameriflux_sh+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed -e '1,/M_ameriflux_gpp/s/M_ameriflux_gpp/"+M_ameriflux_gpp+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed -e '1,/M_ameriflux_er/s/M_ameriflux_er/"+M_ameriflux_er+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_ameriflux_nee#"+M_ameriflux_nee+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_ameriflux_rad#"+M_ameriflux_rad+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_ameriflux_lh#"+M_ameriflux_lh+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_ameriflux_sh#"+M_ameriflux_sh+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_ameriflux_gpp#"+M_ameriflux_gpp+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_ameriflux_er#"+M_ameriflux_er+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + +;*************************************************************************** +; add total score and write to file +;*************************************************************************** + M_total = M_ameriflux_all + + asciiwrite("M_save.ameriflux", M_total) + +;*************************************************************************** +; output plot and html +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** + +end + diff -r 000000000000 -r 0c6405ab2ff4 all/99.final.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/99.final.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,95 @@ +;******************************************************** +; landfrac applied to area only. +; using model biome class +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin +;-------------------------------------------------- +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if + +;------------------------------------- +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;--------------------------------------------------- +; add total score and update metric table + + M_save = 0. + + if (isfilepresent("M_save.npp")) then + M_save = M_save + asciiread("M_save.npp",(/1/),"float") + end if + + if (isfilepresent("M_save.lai")) then + M_save = M_save + asciiread("M_save.lai",(/1/),"float") + end if + + if (film3 .ne. "") then + if (isfilepresent("M_save.co2")) then + M_save = M_save + asciiread("M_save.co2",(/1/),"float") + end if + end if + + if (isfilepresent("M_save.biomass")) then + M_save = M_save + asciiread("M_save.biomass",(/1/),"float") + end if + + if (isfilepresent("M_save.fluxnet")) then + M_save = M_save + asciiread("M_save.fluxnet",(/1/),"float") + end if + + if (isfilepresent("M_save.beta")) then + M_save = M_save + asciiread("M_save.beta",(/1/),"float") + end if + + if (isfilepresent("M_save.fire")) then + M_save = M_save + asciiread("M_save.fire",(/1/),"float") + end if + + if (isfilepresent("M_save.ameriflux")) then + M_save = M_save + asciiread("M_save.ameriflux",(/1/),"float") + end if + + M_total = sprintf("%.2f", M_save) + + if (isvar("compare")) then + system("sed -e '1,/M_total/s/M_total/"+M_total+"/' "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_total#"+M_total+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "rm M_save.*") +end + diff -r 000000000000 -r 0c6405ab2ff4 all/note.data --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/note.data Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,93 @@ +model data used : + + FILE1 = i01.10cn_1948-2004_ANN_climo.nc + FILE2 = i01.10cn_1948-2004_MONS_climo.nc + FILE3 = f02.03cn_1901-1925_MONS_climo_atm.nc + FILE4 = i01.06cn_1980-2004_ANN_climo.nc + FILE5 = i01.10cn_1990-2004_ANN_climo.nc + FILE6 = i01.07cn_1990-2004_ANN_climo.nc + FILE7 = i01.10cn_Fire_C_1979-2004_monthly.nc + FILE8 = i01.10cn_ameriflux_1990-2004_monthly.nc + +model data compared with observed data: + +1. NPP: + + model: i01.10cn_1948-2004_ANN_climo.nc : NPP, RAIN + + ob : data.81.nc : TNPP_C, PREC_ANN + data.933.nc : TNPP_C, PREC + Npp_T42_mean.nc : NPP + +2. LAI: + + model: i01.10cn_1948-2004_MONS_climo.nc : TLAI + + ob : LAI_2000-2005_MONS_T42.nc : LAI + +3. CO2 Seasonal Cycle: + + model: f02.03cn_1901-1925_MONS_climo_atm.nc : CO2 + + ob : co2_globalView_98.nc : CO2_SEAS + +4. Carbon Stocks: + + model: i01.10cn_1948-2004_ANN_climo.nc : LIVESTEMC, DEADSTEMC, LEAFC + WOODC, LEAFC + + ob : amazon_biomass_T42.nc : BIOMASS + +6. Fluxnet: + + model: i01.10cn_1948-2004_MONS_climo.nc : NEE, NETRAD, LATENT, FSH + + ob : station_name_year_ob_monthly.nc : CO2_FLUX, RAD_FLUX, + LH_FLUX, SH_FLUX +7. Ameriflux: + + model: i01.10cn_ameriflux_1990-2004_monthly.nc : NEE, NETRAD, LATENT, FSH, + NPP, ER + ob : station_name/timeseries_L4_m.nc : NEE_or_fMDS, Rg_f, LE_f, + H_f, GPP_or_MDS, Reco_or + +8. Beta factor: + + model: i01.07cn_1990-2004_ANN_climo.nc (initial) : NPP + i01.10cn_1990-2004_ANN_climo.nc (final) : NPP + + ob : beta =0.6 + +9. Turnover time: + + model: i01.06cn_1980-2004_ANN_climo.nc : + + pool: LEAFC, WOODC, FROOTC, LITTERC, CWDC, SOILC + flux: LEAFC_ALLOC, WOODC_ALLOC, FROOTC_ALLOC, + LITTERC_LOSS, CWDC_LOSS, SOILC_HR + + ob : none + +10. Carbon sink: + + model: i01.06cn_1980-2004_ANN_climo.nc : + + NPP, SOILC + VegC = LEAFC + WOODC + FROOTC + LiCwC = LITTERC + CWDC + + i01.10cn_1990-2004_ANN_climo.nc + + NPP, NEE, GPP + + i01.10cn_Fire_C_1979-2004_monthly.nc + + NPP, NEE, COL_FIRE_CLOSS + + ob : none + +11. Fire: + + model: i01.10cn_Fire_C_1979-2004_monthly.nc : COL_FIRE_CLOSS + + ob : Fire_C_1997-2006_monthly_T42.nc : FIRE_C \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 all/note.message --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/note.message Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,6 @@ + +The following warning types are normal: + +warning:avg: Entire input array contains missing values, can't compute average +warning:esccr: Non-fatal conditions encountered: all missing or constant values +warning:["CoordArrays.c":590]:No Valid values in Array, unable to compute Min or Max \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 all/readme --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/readme Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,29 @@ +====================================== +To process CLAMP metric diagnostics: +====================================== + +1. get script: + + ( run_1-model.csh : if comparing 1 model with observation ) + ( run_2-model.csh : if comparing 2 models with observation ) + + /fis/cgd/cseg/people/jeff/clamp/all/run_1-model.csh + or + /fis/cgd/cseg/people/jeff/clamp/all/run_2-model.csh + +2. edit script: (change ONLY the "user modeification" section) + +3. run script: + + run_1-model.csh > out.1 + run_2-model.csh > out.1 + + => final ouptput in 1 directory (if comparing 1 model) + or + final ouptput in 3 directories (if comparing 2 models) + + (if need to copy output to a web directory: + - copy the (one) file *.tar to a web directory + - untar *.tar at the web directory ) + + see note.message for normal messages in out.1 \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 all/run_1-model.csh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/run_1-model.csh Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,112 @@ +#!/bin/csh -f +#------------------------------------------------------------------- +# note: user modifies ONLY the "user modification" section +# +# MODEL : model name +# DIR_M : directory of model data +# DIR_O : directory of observed data +# DIR_S : directory of model surface data +# DIR_SCRIPTS : directory of run scripts +# FILE1 : time_mean climatology from CLM diagnostic package +# FILE2 : 12-monthly climatology from CLM diagnostic package +# FILE3 : 12-monthly climatology from ATM diagnostic package +# leave it blank, if no ATM file: +# set FILE3 = +# FILE7 : timeseries file generated from .... +# FILE8 : timeseries file generated from .... +# GRID : T31, T42, or 1.9 +# BGC : cn or casa +# ENERGY: new or old (model data fields) +#******************************************************************** +# user modification: + +# model data (no ATM file) +set MODEL = CN +set DIR_M = /fis/cgd/cseg/people/jeff/clamp_data/model/ +set FILE1 = i01.10cn_1948-2004_ANN_climo.nc +set FILE2 = i01.10cn_1948-2004_MONS_climo.nc +set FILE3 = +set FILE4 = i01.06cn_1980-2004_ANN_climo.nc +set FILE5 = i01.10cn_1990-2004_ANN_climo.nc +set FILE6 = i01.07cn_1990-2004_ANN_climo.nc +set FILE7 = i01.10cn_Fire_C_1979-2004_monthly.nc +set FILE8 = i01.10cn_ameriflux_1990-2004_monthly.nc +set GRID = T42 +set BGC = cn +set ENERGY = new + +# in the "CLAMP metric processing" section: +# only 00.initial.ncl and 99.final.ncl are required, +# user can comment out any one or more of the other ncl scripts, +# e.g. +# #ncl $INPUT_TEXT $DIR_SCRIPTS/10.fire.ncl + +# model surface data +set DIR_S = /fis/cgd/cseg/people/jeff/clamp_data/surface_model/ + +# observed data +set DIR_O = /fis/cgd/cseg/people/jeff/clamp_data/observed/ + +# directory for scripts, templates and ncl files +set DIR_SCRIPTS = /fis/cgd/cseg/people/jeff/clamp/all/ + +#******************************************************************** + +# create a directory for the model by copying from a template +if ($FILE3 != "") then + set TEMPLATE = template_1-model +else + set TEMPLATE = template_1-model_noCO2 +endif +cp -r $DIR_SCRIPTS/$TEMPLATE $MODEL + +# add quote, to be usesd in INPUT_TEXT +set MODELQ = \"$MODEL\" +set DIRMQ = \"$DIR_M\" +set F1 = \"$FILE1\" +set F2 = \"$FILE2\" +set F3 = \"$FILE3\" +set F4 = \"$FILE4\" +set F5 = \"$FILE5\" +set F6 = \"$FILE6\" +set F7 = \"$FILE7\" +set F8 = \"$FILE8\" +set GRIDQ = \"$GRID\" +set BGCQ = \"$BGC\" +set ENERGYQ = \"$ENERGY\" +set DIRSQ = \"$DIR_S\" +set DIROQ = \"$DIR_O\" + +set INPUT_TEXT = "model_name=$MODELQ model_grid=$GRIDQ dirm=$DIRMQ film1=$F1 film2=$F2 film3=$F3 film4=$F4 film5=$F5 film6=$F6 film7=$F7 film8=$F8 BGC=$BGCQ ENERGY=$ENERGYQ dirs=$DIRSQ diro=$DIROQ" + +# CLAMP metric processing +ncl $INPUT_TEXT $DIR_SCRIPTS/00.initial.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/01.npp.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/02.lai.ncl + +if ($FILE3 != "") then +ncl $INPUT_TEXT $DIR_SCRIPTS/03.co2.ncl +endif + +ncl $INPUT_TEXT $DIR_SCRIPTS/04.biomass.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/06.fluxnet.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/07.beta.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/08.turnover.ncl + +if ($BGC != "casa") then +ncl $INPUT_TEXT $DIR_SCRIPTS/09.carbon_sink.ncl +else +ncl $INPUT_TEXT $DIR_SCRIPTS/09x.carbon_sink.ncl +endif + +if ($BGC != "casa") then +ncl $INPUT_TEXT $DIR_SCRIPTS/10.fire.ncl +endif + +ncl $INPUT_TEXT $DIR_SCRIPTS/11.ameriflux.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/99.final.ncl + +# create a tar file from the final output +tar cf $MODEL.tar $MODEL + + diff -r 000000000000 -r 0c6405ab2ff4 all/run_2-model.csh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/run_2-model.csh Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,201 @@ +#!/bin/csh -f +#------------------------------------------------------------------- +# note: user modifies ONLY the "user modification" section +# +# COMPARE: model1 vs model2 +# MODELn : model name +# DIR_M : directory of model data +# DIR_O : directory of observed data +# DIR_S : directory of model surface data +# DIR_SCRIPTS : directory of run scripts +# FILE1 : time_mean climatology from CLM diagnostic package +# FILE2 : 12-monthly climatology from CLM diagnostic package +# FILE3 : 12-monthly climatology from ATM diagnostic package +# leave it blank, if no ATM file: +# set FILE3 = +# FILE7 : timeseries file generated from .... +# FILE8 : timeseries file generated from .... +# GRID : T31, T42, or 1.9 +# BGC : cn or casa +# ENERGY : new or old (fields in model data) +#------------------------------------------------------------------- + +#******************************************************* +# user modification-(1) + +# directory name of model comparison +#et COMPARE = b30.061n_vs_b30.061m +set COMPARE = CN_vs_CASA + +#******************************************************* +# user modification-(2) + +# model1 +set MODEL1 = CN +set DIR_M = /lustre/wolf-ddn/scratch/hof/clamp_data/model/ +set FILE1 = i01.10cn_1948-2004_ANN_climo.nc +set FILE2 = i01.10cn_1948-2004_MONS_climo.nc +set FILE3 = f02.03cn_1901-1925_MONS_climo_atm.nc +set FILE4 = i01.06cn_1980-2004_ANN_climo.nc +set FILE5 = i01.10cn_1990-2004_ANN_climo.nc +set FILE6 = i01.07cn_1990-2004_ANN_climo.nc +set FILE7 = i01.10cn_Fire_C_1979-2004_monthly.nc +set FILE8 = i01.10cn_ameriflux_1990-2004_monthly.nc +set GRID = T42 +set BGC = cn +set ENERGY = new + +# in the "CLAMP metric processing" section: +# only 00.initial.ncl and 99.final.ncl are required, +# user can comment out any one or more of the other ncl scripts, +# e.g. +# #ncl $INPUT_TEXT $DIR_SCRIPTS/10.fire.ncl + +# model surface data +set DIR_S = /lustre/wolf-ddn/scratch/hof/clamp_data/surface_model/ + +# observed data +set DIR_O = /lustre/wolf-ddn/scratch/hof/clamp_data/observed/ + +# directory for scripts, templates and ncl files +set DIR_SCRIPTS = /lustre/wolf-ddn/scratch/hof/clamp/all/ + +#******************************************************** + +# create model1 and model1_vs_model2 directory by copying templates +if ($FILE3 != "") then + set TEMPLATE1 = template_1-model + set TEMPLATE2 = template_2-model +else + set TEMPLATE1 = template_1-model_noCO2 + set TEMPLATE2 = template_2-model_noCO2 +endif +cp -r $DIR_SCRIPTS/$TEMPLATE1 $MODEL1 +cp -r $DIR_SCRIPTS/$TEMPLATE2 $COMPARE + +# add quote, to be usesd in INPUT_TEXT +set MODELQ = \"$MODEL1\" +set DIRMQ = \"$DIR_M\" +set F1 = \"$FILE1\" +set F2 = \"$FILE2\" +set F3 = \"$FILE3\" +set F4 = \"$FILE4\" +set F5 = \"$FILE5\" +set F6 = \"$FILE6\" +set F7 = \"$FILE7\" +set F8 = \"$FILE8\" +set GRIDQ = \"$GRID\" +set BGCQ = \"$BGC\" +set ENERGYQ = \"$ENERGY\" +set DIRSQ = \"$DIR_S\" +set DIROQ = \"$DIR_O\" +set DIRCQ = \"$DIR_SCRIPTS\" + +set COMPAREQ = \"$COMPARE\" +set MODELN = \"model1\" + +set INPUT_TEXT = "model_name=$MODELQ model_grid=$GRIDQ dirm=$DIRMQ film1=$F1 film2=$F2 film3=$F3 film4=$F4 film5=$F5 film6=$F6 film7=$F7 film8=$F8 BGC=$BGCQ ENERGY=$ENERGYQ dirs=$DIRSQ diro=$DIROQ dirscript=$DIRCQ modeln=$MODELN compare=$COMPAREQ" + +# CLAMP metric processing of model1 +ncl $INPUT_TEXT $DIR_SCRIPTS/00.initial.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/01.npp.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/02.lai.ncl + +if ($FILE3 != "") then +ncl $INPUT_TEXT $DIR_SCRIPTS/03.co2.ncl +endif + +ncl $INPUT_TEXT $DIR_SCRIPTS/04.biomass.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/06.fluxnet.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/07.beta.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/08.turnover.ncl + +if ($BGC != "casa") then +ncl $INPUT_TEXT $DIR_SCRIPTS/09.carbon_sink.ncl +else +ncl $INPUT_TEXT $DIR_SCRIPTS/09x.carbon_sink.ncl +endif + +if ($BGC != "casa") then +ncl $INPUT_TEXT $DIR_SCRIPTS/10.fire.ncl +endif + +ncl $INPUT_TEXT $DIR_SCRIPTS/11.ameriflux.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/99.final.ncl + +#******************************************************* +# user modification-(3) + +# model2 +set MODEL2 = CASA +set DIR_M = /lustre/wolf-ddn/scratch/hof/clamp_data/model/ +set FILE1 = i01.10casa_1948-2004_ANN_climo.nc +set FILE2 = i01.10casa_1948-2004_MONS_climo.nc +set FILE3 = f02.03casa_1876-1900_MONS_climo_atm.nc +set FILE4 = i01.06casa_1980-2004_ANN_climo.nc +set FILE5 = i01.10casa_1990-2004_ANN_climo.nc +set FILE6 = i01.07casa_1990-2004_ANN_climo.nc +set FILE7 = i01.10casa_Fire_C_1979-2004_monthly.nc +set FILE8 = i01.10casa_ameriflux_1990-2004_monthly.nc +set GRID = T42 +set BGC = casa +set ENERGY = new +#******************************************************* +# create model2 directory by copying templates +if ($FILE3 != "") then + set TEMPLATE1 = template_1-model +else + set TEMPLATE1 = template_1-model_noCO2 +endif +cp -r $DIR_SCRIPTS/$TEMPLATE1 $MODEL2 + +# add quote, to be usesd in INPUT_TEXT +set MODELQ = \"$MODEL2\" +set DIRMQ = \"$DIR_M\" +set F1 = \"$FILE1\" +set F2 = \"$FILE2\" +set F3 = \"$FILE3\" +set F4 = \"$FILE4\" +set F5 = \"$FILE5\" +set F6 = \"$FILE6\" +set F7 = \"$FILE7\" +set F8 = \"$FILE8\" +set GRIDQ = \"$GRID\" +set BGCQ = \"$BGC\" +set ENERGYQ = \"$ENERGY\" + +set COMPAREQ = \"$COMPARE\" +set MODELN = \"model2\" + +set INPUT_TEXT = "model_name=$MODELQ model_grid=$GRIDQ dirm=$DIRMQ film1=$F1 film2=$F2 film3=$F3 film4=$F4 film5=$F5 film6=$F6 film7=$F7 film8=$F8 BGC=$BGCQ ENERGY=$ENERGYQ dirs=$DIRSQ diro=$DIROQ dirscript=$DIRCQ modeln=$MODELN compare=$COMPAREQ" + +# CLAMP metric processing of model2 +ncl $INPUT_TEXT $DIR_SCRIPTS/00.initial.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/01.npp.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/02.lai.ncl + +if ($FILE3 != "") then +ncl $INPUT_TEXT $DIR_SCRIPTS/03.co2.ncl +endif + +ncl $INPUT_TEXT $DIR_SCRIPTS/04.biomass.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/06.fluxnet.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/07.beta.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/08.turnover.ncl + +if ($BGC != "casa") then +ncl $INPUT_TEXT $DIR_SCRIPTS/09.carbon_sink.ncl +else +ncl $INPUT_TEXT $DIR_SCRIPTS/09x.carbon_sink.ncl +endif + +if ($BGC != "casa") then +ncl $INPUT_TEXT $DIR_SCRIPTS/10.fire.ncl +endif + +ncl $INPUT_TEXT $DIR_SCRIPTS/11.ameriflux.ncl +ncl $INPUT_TEXT $DIR_SCRIPTS/99.final.ncl + +# create a tar file from the final output +tar cf - $MODEL1 $MODEL2 $COMPARE > all.tar + diff -r 000000000000 -r 0c6405ab2ff4 all/taylor_diagram.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/taylor_diagram.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,479 @@ +function taylor_diagram (wks:graphic ,RATIO[*][*]:numeric, CC[*][*]:numeric \ + ,rOpts:logical) +;-------------------------------------------------------------------- +; This version of taylor_diagram supports "paneling" +; It requires NCL version 4.2.0.a034 because it uses "gsn_create_legend" +;-------------------------------------------------------------------- + +; +; Generate a Taylor Diagram: +; Generate Multiple Aspects of Model Performance in a Single Diagram +; Taylor, K. E., J. Geophys. Res., 106, D7, 7183-7192, 2001 +; +; An example: +; http://www.grida.no/climate/ipcc_tar/wg1/fig8-4.htm +; +; This expects one or more datasets. The left dimension +; is the number of datasets. The rightmost is the number of pts. +; +; Markers are at: +; http://www.ncl.ucar.edu/Document/Graphics/Resources/gs.shtml +; +; By default, the function can handle up to 10 variable comparisons.. +; To expand ... modify the 'Colors' and 'Markers' attributes. +; The user can change / add some default settings. +; +; The defaults that the user can modify: +; +; rOpts = True +; ; 'made-up' resources +; rOpts@Colors = (/ "blue" , "red", "green", "cyan", "black" \ +; , "torquoise", "brown", "yellow"/) +; rOpts@Markers = (/ 2, 3, 6, 14, 9, 12, 7, 4/) ; Marker Indices +; rOpts@markerTxOffset = 0.0175 ; offset for text above marker +; rOpts@stnRad = (/ 1. /) ; (/ 0.50, 0.75, 1.5 /) +; rOpts@centerDiffRMS = False ; True mean draw additional radii from REF +; rOpts@caseLabelsFontHeightF = 0.05 +; rOpts@varLabelsFontHeightF = 0.013 +; rOpts@varLabelsYloc = 0.65 +; rOpts@legendWidth = 0.015 +; rOpts@legendHeight = 0.030*nCase +; rOpts@taylorDraw = True +; rOpts@taylorFrame = True +; +; ; standard NCL resources +; rOpts@tiMainString = "Taylor" ; not using title makes plot bigger +; rOpts@gsMarkerSizeF = 0.0085 ; marker size +; rOpts@gsMarkerThicknessF = 1.0 +; rOpts@txFontHeightF = 0.0125 ; text size +; rOpts@tiMainFontHeightF = 0.0225 ; tiMainString size +; +; It returns to the user a graphic object containing the +; Taylor background and plotted x/y pts. +; This graphic object contains a simple Taylor background appropriate +; for standardized data and the markers for the datasets. +; ================================================================== +; This version allows paneling: +; The 'cumbersome' "dum" variables were added by +; Adam Phillips to allow paneling via "gsn_add_?". +; ================================================================== +begin + dimR = dimsizes(RATIO) + nCase = dimR(0) ; # of cases [models] + nVar = dimR(1) ; # of variables + + ; x/y coordinates for plotting + X = new ( (/nCase,nVar/) , typeof(RATIO) ) + Y = new ( (/nCase,nVar/) , typeof(RATIO) ) + + do nc=0,nCase-1 + angle = acos( CC(nc,:) ) ; array operation + X(nc,:) = RATIO(nc,:)*cos( angle ) + Y(nc,:) = RATIO(nc,:)*sin( angle ) + end do + + xyMin = 0. + xyOne = 1.00 + xyMax = 1.65 + xyMax_Panel = xyMax+ 0.10 ; paneling purposes + + if (rOpts .and. isatt(rOpts,"txFontHeightF")) then + FontHeightF = rOpts@txFontHeightF ; user wants to specify size + else + FontHeightF = 0.0175 + end if + +; ---------------------------------------------------------------- +; Part 1: +; base plot: Based upon request of Mark Stevens +; basic x-y and draw the 1.0 observed and the outer curve at 1.65 +; ---------------------------------------------------------------- + + rxy = True + rxy@gsnDraw = False + rxy@gsnFrame = False + rxy@vpHeightF = 0.65 + rxy@vpWidthF = 0.65 + rxy@tmYLBorderOn = False + rxy@tmXBBorderOn = False + + rxy@tiYAxisString = "Standardized Deviation (Normalized)" + rxy@tiYAxisFontHeightF= FontHeightF ; default=0.025 + + rxy@tmXBMode = "Explicit" + rxy@tmXBValues = (/0.0,0.25,0.50,0.75,1.00,1.25,1.5/) ; major tm + ; default "OBS" or "REF" + ;rxy@tmXBLabels = (/"0.00","0.25","0.50","0.75","REF" ,"1.25","1.50"/) + rxy@tmXBLabels = (/" ","0.25","0.50","0.75","REF" ,"1.25","1.50"/) + if (rOpts .and. isatt(rOpts,"OneX") ) then ; eg: rOpts@OneX="1.00" + ;rxy@tmXBLabels = (/"0.00","0.25","0.50","0.75",rOpts@OneX,"1.25","1.50"/) + rxy@tmXBLabels = (/" ","0.25","0.50","0.75",rOpts@OneX,"1.25","1.50"/) + end if + + rxy@tmXBMajorLengthF = 0.015 ; default=0.02 for a vpHeightF=0.6 + rxy@tmXBLabelFontHeightF = FontHeightF + rxy@tmXBMinorOn = False + rxy@trXMaxF = xyMax_Panel + + rxy@tmYLMode = "Manual" + rxy@tmYLMinorOn = False + rxy@tmYLMajorLengthF = rxy@tmXBMajorLengthF + rxy@tmYLLabelFontHeightF = FontHeightF + rxy@tmYLMode = "Explicit" + rxy@tmYLValues = (/0.0, .25,0.50, 0.75, 1.00, 1.25, 1.5/) ; major tm + rxy@tmYLLabels = (/"0.00","0.25","0.50","0.75","1.00","1.25","1.50"/) + ;rxy@tmYLLabels = (/" ","0.25","0.50","0.75","1.00","1.25","1.50"/) + rxy@trYMaxF = xyMax_Panel + + rxy@tmYRBorderOn = False + rxy@tmYROn = False ; Turn off right tick marks. + + rxy@tmXTBorderOn = False + rxy@tmXTOn = False ; Turn off right tick marks. + + rxy@xyDashPatterns = (/ 0 /) ; line characteristics (dash,solid) + rxy@xyLineThicknesses = (/ 2./) ; choose line thickness + + rxy@gsnFrame = False ; Don't advance the frame. + + ; create outer 'correlation axis' + npts = 200 ; arbitrary + xx = fspan(xyMin,xyMax,npts) + yy = sqrt(xyMax^2 - xx^2 ) ; outer correlation line (xyMax) + + sLabels = (/"0.0","0.1","0.2","0.3","0.4","0.5","0.6" \ ; correlation labels + ,"0.7","0.8","0.9","0.95","0.99","1.0" /); also, major tm + cLabels = stringtofloat(sLabels) + rad = 4.*atan(1.0)/180. + angC = acos(cLabels)/rad ; angles: correlation labels + + if (rOpts .and. isatt(rOpts,"tiMainString")) then + rxy@tiMainString = rOpts@tiMainString + ;rxy@tiMainOffsetYF = 0.015 ; default 0.0 + if (isatt(rOpts,"tiMainFontHeightF")) then + rxy@tiMainFontHeightF = rOpts@tiMainFontHeightF + else + rxy@tiMainFontHeightF = 0.0225 ; default 0.025 + end if + end if +;;if (rOpts .and. isatt(rOpts,"gsnCenterString")) then +;; rxy@gsnCenterString = rOpts@gsnCenterString ; only gsn_csm_xy +;;end if + + taylor = gsn_xy(wks,xx,yy,rxy) ; Create and draw XY plot. + + rsrRes = True + rsrRes@gsLineThicknessF = rxy@xyLineThicknesses(0) ; line thickness + rsrRes@gsLineDashPattern = 0 ; solid line pattern + ; draw x and y to xyMax + dum0 = gsn_add_polyline(wks,taylor,(/0., 0. /),(/0.,xyMax/), rsrRes) + dum1 = gsn_add_polyline(wks,taylor,(/0.,xyMax/),(/0., 0. /), rsrRes) + + xx = fspan(xyMin, xyOne ,npts) ; draw 1.0 standard radius + yy = sqrt(xyOne - xx^2) + rsrRes@gsLineDashPattern = 1 ; dashed line pattern + rsrRes@gsLineThicknessF = rxy@xyLineThicknesses(0) ; line thickness + dum2 = gsn_add_polyline(wks,taylor,xx,yy, rsrRes) + delete(xx) + delete(yy) + + if (rOpts .and. isatt(rOpts,"stnRad") ) then + rsrRes@gsLineThicknessF = 1 ; rxy@xyLineThicknesses(0) + nStnRad = dimsizes(rOpts@stnRad) + + dum3 = new(nStnRad,graphic) + do n=0,nStnRad-1 + rr = rOpts@stnRad(n) + xx = fspan(xyMin, rr ,npts) + yy = sqrt(rr^2 - xx^2) + dum3(n) = gsn_add_polyline(wks,taylor,xx,yy, rsrRes) + end do + taylor@$unique_string("dum")$ = dum3 + + delete(xx) + delete(yy) + end if + + getvalues taylor ; get style info from taylor + "tmYLLabelFont" : tmYLLabelFont ; use for correlation axis + "tmYLLabelFontHeightF" : tmYLLabelFontHeightF + end getvalues + +; ---------------------------------------------------------------- +; Part 2: +; Correlation labels +; ---------------------------------------------------------------- + radC = xyMax ; for correlation labels + xC = radC*cos(angC*rad) + yC = radC*sin(angC*rad) +; added to get some separation + xC = xC + 0.020*cos(rad*angC) + yC = yC + 0.060*sin(rad*angC) + + txRes = True ; text mods desired + txRes@txFontHeightF = FontHeightF ; match YL + txRes@tmYLLabelFont = tmYLLabelFont ; match YL + txRes@txAngleF = -45. + if (.not.isatt(rOpts,"drawCorLabel") .or. rOpts@drawCorLabel) then + dum4 = gsn_add_text(wks,taylor,"Correlation",1.30,1.30,txRes) + taylor@$unique_string("dum")$ = dum4 + end if + txRes@txAngleF = 0.0 + txRes@txFontHeightF = FontHeightF*0.50 ; bit smaller + +;;dum0 = gsn_add_text(wks,taylor,"OBSERVED",1.00,0.075,txRes) + + plRes = True + plRes@gsLineThicknessF = 2. + + txRes@txJust = "CenterLeft" ; Default="CenterCenter". + txRes@txFontHeightF = FontHeightF ; match YL + ;txRes@txBackgroundFillColor = "white" + + tmEnd = 0.975 + radTM = xyMax*tmEnd ; radius end: major TM + xTM = new( 2 , "float") + yTM = new( 2 , "float") + + dum5 = new(dimsizes(sLabels),graphic) + dum6 = dum5 + + do i=0,dimsizes(sLabels)-1 ; Loop to draw strings + txRes@txAngleF = angC(i) + dum5(i) = gsn_add_text(wks, taylor, sLabels(i),xC(i),yC(i),txRes) ; cor label + xTM(0) = xyMax*cos(angC(i)*rad) ; major tickmarks at + yTM(0) = xyMax*sin(angC(i)*rad) ; correlation labels + xTM(1) = radTM*cos(angC(i)*rad) + yTM(1) = radTM*sin(angC(i)*rad) + dum6(i) = gsn_add_polyline(wks,taylor,xTM,yTM,plRes) + end do + ; minor tm locations + mTM = (/0.05,0.15,0.25,0.35,0.45,0.55,0.65 \ + ,0.75,0.85,0.91,0.92,0.93,0.94,0.96,0.97,0.98 /) + angmTM = acos(mTM)/rad ; angles: correlation labels + radmTM = xyMax*(1.-(1.-tmEnd)*0.5) ; radius end: minor TM + + dum7 = new(dimsizes(mTM),graphic) + + do i=0,dimsizes(mTM)-1 ; manually add tm + xTM(0) = xyMax*cos(angmTM(i)*rad) ; minor tickmarks + yTM(0) = xyMax*sin(angmTM(i)*rad) + xTM(1) = radmTM*cos(angmTM(i)*rad) + yTM(1) = radmTM*sin(angmTM(i)*rad) + dum7(i) = gsn_add_polyline(wks,taylor,xTM,yTM,plRes) + end do + ; added for Wanli + if (rOpts .and. isatt(rOpts,"ccRays") ) then + angRL = acos(rOpts@ccRays)/rad ; angles: radial lines + + rlRes = True + rlRes@xyDashPattern = 4 ; line pattern + rlRes@xyLineThicknessF = 1 ; choose line thickness + + dum8 = new(dimsizes(angRL),graphic) + do i=0,dimsizes(angRL)-1 + xRL = xyMax*cos(angRL(i)*rad) + yRL = xyMax*sin(angRL(i)*rad) + dum8(i) = gsn_add_polyline(wks,taylor,(/0, xRL /),(/0, yRL /),rlRes) + end do + taylor@$unique_string("dum")$ = dum8 + end if + +; ---------------------------------------------------------------- +; Part 3: +; Concentric about 1.0 on XB axis +; I think this is correct. Still test mode. +; ---------------------------------------------------------------- + if (rOpts .and. isatt(rOpts,"centerDiffRMS") \ + .and. rOpts@centerDiffRMS) then + respl = True ; polyline mods desired + respl@gsLineThicknessF = 1.0 ; line thickness + respl@gsLineColor = "Black" ; line color + respl@gsLineDashPattern = 2 ; short dash lines + + dx = 0.25 + ncon = 4 ; 0.75, 0.50, 0.25, 0.0 + npts = 100 ; arbitrary + ang = fspan(180,360,npts)*rad + + dum9 = new(ncon,graphic) + + do n=1,ncon + rr = n*dx ; radius from 1.0 [OBS] abscissa + xx = 1. + rr*cos(ang) + yy = fabs( rr*sin(ang) ) + if (n.le.2) then + dum9(n-1) = gsn_add_polyline(wks,taylor,xx,yy,respl) + end if + if (n.eq.3) then + n3 = floattointeger( 0.77*npts ) + dum9(n-1) = gsn_add_polyline(wks,taylor,xx(0:n3),yy(0:n3),respl) + end if + if (n.eq.4) then + n4 = floattointeger( 0.61*npts ) + dum9(n-1) = gsn_add_polyline(wks,taylor,xx(0:n4),yy(0:n4),respl) + end if + end do + delete(ang) + delete(xx) + delete(yy) + taylor@$unique_string("dum")$ = dum9 + + end if +; --------------------------------------------------------------- +; Part 4: +; generic resources that will be applied to all users data points +; of course, these can be changed +; http://www.ncl.ucar.edu/Document/Graphics/Resources/gs.shtml +; --------------------------------------------------------------- + if (rOpts .and. isatt(rOpts,"Markers")) then + Markers = rOpts@Markers + else + Markers = (/ 4, 6, 8, 0, 9, 12, 7, 2, 11, 16/) ; Marker Indices + end if + + if (rOpts .and. isatt(rOpts,"Colors")) then + Colors = rOpts@Colors + else + Colors = (/ "red", "blue", "green", "cyan", "orange" \ + , "torquoise", "brown", "yellow", "purple", "black"/) + end if + + if (rOpts .and. isatt(rOpts,"gsMarkerThicknessF")) then + gsMarkerThicknessF = rOpts@gsMarkerThicknessF + else + gsMarkerThicknessF = 1.0 + end if + + if (rOpts .and. isatt(rOpts,"gsMarkerSizeF")) then + gsMarkerSizeF = rOpts@gsMarkerSizeF + else + gsMarkerSizeF = 0.0085 ; Default: 0.007 + end if + + gsRes = True + gsRes@gsMarkerThicknessF = gsMarkerThicknessF ; default=1.0 + gsRes@gsMarkerSizeF = gsMarkerSizeF ; Default: 0.007 + + ptRes = True ; text options for points + ptRes@txJust = "BottomCenter"; Default="CenterCenter". + ptRes@txFontThicknessF = 1.2 ; default=1.00 + ptRes@txFontHeightF = 0.0125 ; default=0.05 + if (rOpts .and. isatt(rOpts,"txFontHeightF")) then + ptRes@txFontHeightF = rOpts@txFontHeightF + end if + + markerTxYOffset = 0.0175 ; default + if (rOpts .and. isatt(rOpts,"markerTxYOffset")) then + markerTxYOffset = rOpts@markerTxYOffset ; user defined offset + end if + + dum10 = new((nCase*nVar),graphic) + dum11 = dum10 + + do n=0,nCase-1 + gsRes@gsMarkerIndex = Markers(n) ; marker style (+) + gsRes@gsMarkerColor = Colors(n) ; marker color + ptRes@txFontColor = gsRes@gsMarkerColor + do i=0,nVar-1 + dum10(n*nVar+i) = gsn_add_polymarker(wks,taylor,X(n,i),Y(n,i),gsRes) +; dum11(n*nVar+i) = gsn_add_text(wks,taylor,(i+1),X(n,i),Y(n,i)+markerTxYOffset,ptRes) + end do + end do + +; --------------------------------------------------------------- +; Part 5: ; add case legend and variable labels +; --------------------------------------------------------------- + + if (rOpts .and. isatt(rOpts,"caseLabels")) then + + if (isatt(rOpts,"caseLabelsFontHeightF")) then + caseLabelsFontHeightF = rOpts@caseLabelsFontHeightF + else +; caseLabelsFontHeightF = 0.05 + caseLabelsFontHeightF = 0.15 + end if + + lgres = True + lgres@lgMarkerColors = Colors ; colors of markers + lgres@lgMarkerIndexes = Markers ; Markers + lgres@lgMarkerSizeF = gsMarkerSizeF ; Marker size + lgres@lgItemType = "Markers" ; draw markers only + lgres@lgLabelFontHeightF = caseLabelsFontHeightF ; font height of legend case labels + + if (isatt(rOpts,"legendWidth")) then + lgres@vpWidthF = rOpts@legendWidth + else + lgres@vpWidthF = 0.15 ; width of legend (NDC) + end if + + if (isatt(rOpts,"legendHeight")) then + lgres@vpHeightF = rOpts@legendHeight + else + lgres@vpHeightF = 0.030*nCase ; height of legend (NDC) + end if + + lgres@lgPerimOn = False ; turn off perimeter + nModel = dimsizes( rOpts@caseLabels ) + lbid = gsn_create_legend(wks,nModel,rOpts@caseLabels,lgres) + + amres = True + amres@amParallelPosF = 0.35 + amres@amOrthogonalPosF = -0.35 + annoid1 = gsn_add_annotation(taylor,lbid,amres) ; add legend to plot + end if + + if (rOpts .and. isatt(rOpts,"varLabels")) then + nVar = dimsizes(rOpts@varLabels) + + if (isatt(rOpts,"varLabelsFontHeightF")) then + varLabelsFontHeightF = rOpts@varLabelsFontHeightF + else + varLabelsFontHeightF = 0.013 + end if + + txres = True + txres@txFontHeightF = varLabelsFontHeightF + txres@txJust = "CenterLeft" ; justify to the center left + + ;delta_y = 0.02 + delta_y = 0.06 + if (rOpts .and. isatt(rOpts,"varLabelsYloc")) then + ys = rOpts@varLabelsYloc ; user specified + else + ys = max( (/nVar*delta_y , 0.30/) ) + end if + + + do i = 1,nVar + if (i.eq.1) then + dum12 = new(nVar,graphic) + end if + + dum12(i-1) = gsn_add_text(wks,taylor,i+" - "+rOpts@varLabels(i-1), .125,ys,txres) + ys = ys- delta_y + end do + + taylor@$unique_string("dum")$ = dum12 + end if + + taylor@$unique_string("dum")$ = dum0 ; x-axis + taylor@$unique_string("dum")$ = dum1 ; y-axis + taylor@$unique_string("dum")$ = dum2 ; 1.0 std curve + taylor@$unique_string("dum")$ = dum5 ; labels [COR] + taylor@$unique_string("dum")$ = dum6 ; major tm [COR] + taylor@$unique_string("dum")$ = dum7 ; minor tm + taylor@$unique_string("dum")$ = dum10 ; markers + taylor@$unique_string("dum")$ = dum11 ; text + + if (.not.isatt(rOpts,"taylorDraw") .or. \ + (isatt(rOpts,"taylorDraw") .and. rOpts@taylorDraw)) then + draw(taylor) + end if + if (.not.isatt(rOpts,"taylorFrame") .or. \ + (isatt(rOpts,"taylorFrame") .and. rOpts@taylorFrame)) then + frame(wks) + end if + return(taylor) +end + diff -r 000000000000 -r 0c6405ab2ff4 all/template_1-model/index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/template_1-model/index.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,16 @@ + + + Score Sheet for CLAMP + + + + + + +

    CLAMP Score Sheet for Biogeochemical Model Evaluation

+ + + + + + diff -r 000000000000 -r 0c6405ab2ff4 all/template_1-model/table.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/template_1-model/table.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,407 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Metric Metric
components
Observations &
comparison protocol
Model
model_name
Score (points)
Full model_name
NPPEMDI NPP
observations
+ + Class_A_table + + + table
+ + scatter_plot +
2.5M_npp_S81
+ + Class_B_table + + + table
+ + scatter_plot +
2.5M_npp_S933
EMDI NPP
normalized by PPT
+ + Class_A_histogram + + + Class_A_histogram + 2.5M_npp_H81
+ + Class_B_histogram + + + Class_B_histogram + 2.5M_npp_H933
Correlation with MODIS obs. + + global_map + + + model_map
+ + model_vs_obs +
5M_npp_G
Correlation with MODIS-zonal mean + + zonal_mean_obs + + + zonal_mean
model_vs_obs_plot
+
5M_npp_Z
LAIMODIS Mean + + land_class_obs
+ + land_class_model
+ + global_map +
+ + model_vs_obs_table
+ + global_map
+ + model_vs_obs +
5M_lai_Mean
MODIS Maximum + + global_map + + + global_map
+ + model_vs_obs +
5M_lai_Max
MODIS Phase + + global_map + + + global_map
+ + model_vs_obs +
5M_lai_Phase
CO2
Seasonal
Cycle
Comparison with NOAA observations
phase and amplitude
-- + + model_vs_obs + 20M_co2
Carbon
Stocks
Aboveground live biomass
in South America
+ + obs_amazon + + + model_amazon
+ + model_vs_obs +
5M_biomass
Aboveground live
biomass
within Amazon Basin
(sum within Legal Amazon)
+ + mask
+ + obs_masked
+ Sum_biomass_ob (Pg C) +
+ + model_masked
+ + model_vs_obs
+ Sum_biomass_mod (Pg C) +
5M_biomask
Energy and
C Fluxes
from Fluxnet
NEE + + line_plot + + + model_vs_obs + 5M_fluxnet_nee
Net radiation5M_fluxnet_rad
Latent heat5M_fluxnet_lh
Sensible heat5M_fluxnet_sh
Energy and
C Fluxes
from Ameriflux
NEE + + line_plot + + + model_vs_obs
+ + timeseries_plot +
1M_ameriflux_nee
Shortwave Incoming1M_ameriflux_rad
Latent heat1M_ameriflux_lh
Sensible heat1M_ameriflux_sh
GPP1M_ameriflux_gpp
ER1M_ameriflux_er
Transient DynamicsBeta factor for NPP Stimulation from elevated CO2-- + + FACE_Site_comparison
+ + biome_table +
3M_beta
Turnover times and pool sizes-- + + Leaf
+ + Wood
+ + Fine_Root
+ + Litter
+ + Coarse_Woody_Debris
+ + Soil +
3--
Carbon Sinks
(1990-2004)
-- + + biome_mean
+ + biome_total +
2--
Fire Variability-- + + global_spatial_comparison
+ + temporal_dynamics_(1997-2004) +
2M_fire
Total 100M_total
+ diff -r 000000000000 -r 0c6405ab2ff4 all/template_1-model/tablerows.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/template_1-model/tablerows.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,13 @@ + + + NPP +Site observationn1 + + + + + +Site observationn2 +Site observationn3 +Site observationn4 + diff -r 000000000000 -r 0c6405ab2ff4 all/template_1-model_noCO2/index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/template_1-model_noCO2/index.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,16 @@ + + + Score Sheet for CLAMP + + + + + + +

    CLAMP Score Sheet for Biogeochemical Model Evaluation

+ + + + + + diff -r 000000000000 -r 0c6405ab2ff4 all/template_1-model_noCO2/table.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/template_1-model_noCO2/table.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,404 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Metric Metric
components
Observations &
comparison protocol
Model
model_name
Score (points)
Full model_name
NPPEMDI NPP
observations
+ + Class_A_table + + + table
+ + scatter_plot +
2.5M_npp_S81
+ + Class_B_table + + + table
+ + scatter_plot +
2.5M_npp_S933
EMDI NPP
normalized by PPT
+ + Class_A_histogram + + + Class_A_histogram + 2.5M_npp_H81
+ + Class_B_histogram + + + Class_B_histogram + 2.5M_npp_H933
Correlation with MODIS obs. + + global_map + + + model_map
+ + model_vs_obs +
5M_npp_G
Correlation with MODIS-zonal mean + + zonal_mean_obs + + + zonal_mean
model_vs_obs_plot
+
5M_npp_Z
LAIMODIS Mean + + land_class_obs
+ + land_class_model
+ + global_map +
+ + model_vs_obs_table
+ + global_map
+ + model_vs_obs +
5M_lai_Mean
MODIS Maximum + + global_map + + + global_map
+ + model_vs_obs +
5M_lai_Max
MODIS Phase + + global_map + + + global_map
+ + model_vs_obs +
5M_lai_Phase
CO2
Seasonal
Cycle
Comparison with NOAA observations
phase and amplitude
----20--
Carbon
Stocks
Aboveground live biomass
in South America
+ + obs_amazon + + + model_amazon
+ + model_vs_obs +
5M_biomass
Aboveground live
biomass
within Amazon Basin
(sum within Legal Amazon)
+ + mask
+ + obs_masked
+ Sum_biomass_ob (Pg C) +
+ + model_masked
+ + model_vs_obs
+ Sum_biomass_mod (Pg C) +
5M_biomask
Energy and
C Fluxes
from Fluxnet
NEE + + line_plot + + + model_vs_obs + 5M_fluxnet_nee
Net radiation5M_fluxnet_rad
Latent heat5M_fluxnet_lh
Sensible heat5M_fluxnet_sh
Energy and
C Fluxes
from Ameriflux
NEE + + line_plot + + + model_vs_obs
+ + timeseries_plot +
1M_ameriflux_nee
Shortwave Incoming1M_ameriflux_rad
Latent heat1M_ameriflux_lh
Sensible heat1M_ameriflux_sh
GPP1M_ameriflux_gpp
ER1M_ameriflux_er
Transient DynamicsBeta factor for NPP Stimulation from elevated CO2-- + + FACE_Site_comparison
+ + biome_table +
3M_beta
Turnover times and pool sizes-- + + Leaf
+ + Wood
+ + Fine_Root
+ + Litter
+ + Coarse_Woody_Debris
+ + Soil +
3--
Carbon Sinks
(1990-2004)
-- + + biome_mean
+ + biome_total +
2--
Fire Variability-- + + global_spatial_comparison
+ + temporal_dynamics_(1997-2004) +
2M_fire
Total 100M_total
+ diff -r 000000000000 -r 0c6405ab2ff4 all/template_1-model_noCO2/tablerows.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/template_1-model_noCO2/tablerows.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,13 @@ + + + NPP +Site observationn1 + + + + + +Site observationn2 +Site observationn3 +Site observationn4 + diff -r 000000000000 -r 0c6405ab2ff4 all/template_2-model/index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/template_2-model/index.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,16 @@ + + + Score Sheet for CLAMP + + + + + + +

    CLAMP Score Sheet for Biogeochemical Model Evaluation

+ + + + + + diff -r 000000000000 -r 0c6405ab2ff4 all/template_2-model/table.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/template_2-model/table.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,559 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Metric Metric
components
Observations &
comparison protocol
Model
model1
Model
model2
Score (points)
Full model1 model2
NPPEMDI NPP
observations
+ + Class_A_table + + + table
+ + scatter_plot +
+ + table
+ + scatter_plot +
2.5M_npp_S81M_npp_S81
+ + Class_B_table + + + table
+ + scatter_plot +
+ + table
+ + scatter_plot +
2.5M_npp_S933M_npp_S933
EMDI NPP
normalized by PPT
+ + Class_A_histogram + + + Class_A_histogram + + + Class_A_histogram + 2.5M_npp_H81M_npp_H81
+ + Class_B_histogram + + + Class_B_histogram + + + Class_B_histogram + 2.5M_npp_H933M_npp_H933
Correlation with MODIS obs. + + global_map + + + model_map
+ + model_vs_obs +
+ + model_map
+ + model_vs_obs +
5M_npp_GM_npp_G
Correlation with MODIS-zonal mean + + zonal_mean_obs + + + zonal_mean
model_vs_obs_plot
+
+ + zonal_mean
model_vs_obs_plot
+
5M_npp_ZM_npp_Z
LAIMODIS Mean + + land_class_obs
+ + land_class_model
+ + global_map +
+ + model_vs_obs_table
+ + global_map
+ + model_vs_obs +
+ + model_vs_obs_table
+ + global_map
+ + model_vs_obs +
5M_lai_MeanM_lai_Mean
MODIS Maximum + + global_map + + + global_map
+ + model_vs_obs +
+ + global_map
+ + model_vs_obs +
5M_lai_MaxM_lai_Max
MODIS Phase + + global_map + + + global_map
+ + model_vs_obs +
+ + global_map
+ + model_vs_obs +
5M_lai_PhaseM_lai_Phase
CO2
Seasonal
Cycle
Comparison with NOAA observations
phase and amplitude
-- + + model_vs_obs + + + model_vs_obs + 20M_co2M_co2
Carbon
Stocks
Aboveground live biomass
in South America
+ + obs_amazon + + + model_amazon
+ + model_vs_obs +
+ + amazon_map
+ + model_vs_obs +
5M_biomassM_biomass
Aboveground live
biomass
within Amazon Basin
(sum within Legal Amazon)
+ + mask
+ + obs_masked
+ Sum_biomass_ob (Pg C) +
+ + model_masked
+ + model_vs_obs
+ Sum_biomass_mod (Pg C) +
+ + model_masked
+ + model_vs_obs
+ Sum_biomass_mod (Pg C) +
5M_biomaskM_biomask
Energy and
C Fluxes
from Fluxnet
NEE + + line_plot + + + model_vs_obs + + + model_vs_obs + 5M_fluxnet_neeM_fluxnet_nee
Net radiation5M_fluxnet_radM_fluxnet_rad
Latent heat5M_fluxnet_lhM_fluxnet_lh
Sensible heat5M_fluxnet_shM_fluxnet_sh
Energy and
C Fluxes
from Ameriflux
NEE + + line_plot + + + model_vs_obs
+ + timeseries_plot +
+ + model_vs_obs
+ + timeseries_plot +
1M_ameriflux_neeM_ameriflux_nee
Shortwave Incoming1M_ameriflux_radM_ameriflux_rad
Latent heat1M_ameriflux_lhM_ameriflux_lh
Sensible heat1M_ameriflux_shM_ameriflux_sh
GPP1M_ameriflux_gppM_ameriflux_gpp
ER1M_ameriflux_erM_ameriflux_er
Transient DynamicsBeta factor for NPP Stimulation from elevated CO2-- + + FACE_Site_comparison
+ + biome_table +
+ + FACE_Site_comparison
+ + biome_table +
3M_betaM_beta
Turnover times and pool sizes-- + + Leaf
+ + Wood
+ + Fine_Root
+ + Litter
+ + Coarse_Woody_Debris
+ + Soil +
+ + Leaf
+ + Wood
+ + Fine_Root
+ + Litter
+ + Coarse_Woody_Debris
+ + Soil +
3----
Carbon Sinks
(1990-2004)
-- + + biome_mean
+ + biome_total +
+ + biome_mean
+ + biome_total +
2----
Fire Variability-- + + global_spatial_comparison
+ + temporal_dynamics_(1997-2004) +
--2M_fire--
Total 100M_totalM_total
+ diff -r 000000000000 -r 0c6405ab2ff4 all/template_2-model/tablerows.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/template_2-model/tablerows.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,13 @@ + + + NPP +Site observationn1 + + + + + +Site observationn2 +Site observationn3 +Site observationn4 + diff -r 000000000000 -r 0c6405ab2ff4 all/template_2-model_noCO2/index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/template_2-model_noCO2/index.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,16 @@ + + + Score Sheet for CLAMP + + + + + + +

    CLAMP Score Sheet for Biogeochemical Model Evaluation

+ + + + + + diff -r 000000000000 -r 0c6405ab2ff4 all/template_2-model_noCO2/table.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/template_2-model_noCO2/table.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,552 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Metric Metric
components
Observations &
comparison protocol
Model
model1
Model
model2
Score (points)
Full model1 model2
NPPEMDI NPP
observations
+ + Class_A_table + + + table
+ + scatter_plot +
+ + table
+ + scatter_plot +
2.5M_npp_S81M_npp_S81
+ + Class_B_table + + + table
+ + scatter_plot +
+ + table
+ + scatter_plot +
2.5M_npp_S933M_npp_S933
EMDI NPP
normalized by PPT
+ + Class_A_histogram + + + Class_A_histogram + + + Class_A_histogram + 2.5M_npp_H81M_npp_H81
+ + Class_B_histogram + + + Class_B_histogram + + + Class_B_histogram + 2.5M_npp_H933M_npp_H933
Correlation with MODIS obs. + + global_map + + + model_map
+ + model_vs_obs +
+ + model_map
+ + model_vs_obs +
5M_npp_GM_npp_G
Correlation with MODIS-zonal mean + + zonal_mean_obs + + + zonal_mean
model_vs_obs_plot
+
+ + zonal_mean
model_vs_obs_plot
+
5M_npp_ZM_npp_Z
LAIMODIS Mean + + land_class_obs
+ + land_class_model
+ + global_map +
+ + model_vs_obs_table
+ + global_map
+ + model_vs_obs +
+ + model_vs_obs_table
+ + global_map
+ + model_vs_obs +
5M_lai_MeanM_lai_Mean
MODIS Maximum + + global_map + + + global_map
+ + model_vs_obs +
+ + global_map
+ + model_vs_obs +
5M_lai_MaxM_lai_Max
MODIS Phase + + global_map + + + global_map
+ + model_vs_obs +
+ + global_map
+ + model_vs_obs +
5M_lai_PhaseM_lai_Phase
CO2
Seasonal
Cycle
Comparison with NOAA observations
phase and amplitude
------20----
Carbon
Stocks
Aboveground live biomass
in South America
+ + obs_amazon + + + model_amazon
+ + model_vs_obs +
+ + amazon_map
+ + model_vs_obs +
5M_biomassM_biomass
Aboveground live
biomass
within Amazon Basin
(sum within Legal Amazon)
+ + mask
+ + obs_masked
+ Sum_biomass_ob (Pg C) +
+ + model_masked
+ + model_vs_obs
+ Sum_biomass_mod (Pg C) +
+ + model_masked
+ + model_vs_obs
+ Sum_biomass_mod (Pg C) +
5M_biomaskM_biomask
Energy and
C Fluxes
from Fluxnet
NEE + + line_plot + + + model_vs_obs + + + model_vs_obs + 5M_fluxnet_neeM_fluxnet_nee
Net radiation5M_fluxnet_radM_fluxnet_rad
Latent heat5M_fluxnet_lhM_fluxnet_lh
Sensible heat5M_fluxnet_shM_fluxnet_sh
Energy and
C Fluxes
from Ameriflux
NEE + + line_plot + + + model_vs_obs
+ + timeseries_plot +
+ + model_vs_obs
+ + timeseries_plot +
1M_ameriflux_neeM_ameriflux_nee
Shortwave Incoming1M_ameriflux_radM_ameriflux_rad
Latent heat1M_ameriflux_lhM_ameriflux_lh
Sensible heat1M_ameriflux_shM_ameriflux_sh
GPP1M_ameriflux_gppM_ameriflux_gpp
ER1M_ameriflux_erM_ameriflux_er
Transient DynamicsBeta factor for NPP Stimulation from elevated CO2-- + + FACE_Site_comparison
+ + biome_table +
+ + FACE_Site_comparison
+ + biome_table +
3M_betaM_beta
Turnover times and pool sizes-- + + Leaf
+ + Wood
+ + Fine_Root
+ + Litter
+ + Coarse_Woody_Debris
+ + Soil +
+ + Leaf
+ + Wood
+ + Fine_Root
+ + Litter
+ + Coarse_Woody_Debris
+ + Soil +
3----
Carbon Sinks
(1990-2004)
-- + + biome_mean
+ + biome_total +
+ + biome_mean
+ + biome_total +
2----
Fire Variability-- + + global_spatial_comparison
+ + temporal_dynamics_(1997-2004) +
--2M_fire--
Total 100M_totalM_total
+ diff -r 000000000000 -r 0c6405ab2ff4 all/template_2-model_noCO2/tablerows.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/all/template_2-model_noCO2/tablerows.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,13 @@ + + + NPP +Site observationn1 + + + + + +Site observationn2 +Site observationn3 +Site observationn4 + diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/01.read_ascii.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/01.read_ascii.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,371 @@ +;---------------------------------------------------------------------- +; This example reads an ASCII file that is formatted a specific way, and +; writes out the results to a netCDF file. +; +; The first line in the ASCII file must be a header, with each field +; separated by a single character delimiter (like a ","). The rest of +; the file must be such that each row contains all fields, each +; separated by the designated delimiter. +; +; The fields can be integer, float, double, character, or string. +; String fields cannot be written to a netCDF file. They have to +; be read in as character arrays and written out that way. +;---------------------------------------------------------------------- + +;---------------------------------------------------------------------- +; This function returns the index locations of the given delimiter +; in a row or several rows of strings. +;---------------------------------------------------------------------- +function delim_indices(strings,nfields,delimiter) +local cstrings, cdelim +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) ; Convert to characters. + cdelim = stringtochar(delimiter) ; Convert delimiter to character. +; +; Som error checking here. Make sure delimiter is one character. +; + nc = dimsizes(cdelim) + rank = dimsizes(nc) + if(rank.ne.1.or.(rank.eq.1.and.nc.ne.2)) then + print("delim_indices: fatal: the delimiter you've selected") + print("must be a single character. Can't continue.") + exit + end if + +; +; Create array to hold indices of delimiter locations, and then loop +; through each row and find all the delimiters. Make sure each row has +; the correct number of delimiters. +; + ndelims = nfields-1 + cindices = new((/nrows,ndelims/),integer) + do i = 0, nrows-1 + ii = ind(cstrings(i,:).eq.cdelim(0)) +; +; Make sure there were delimiters on this row. If not, we just quit. +; This could probably be modified to do this more gracefully. +; + if(any(ismissing(ii))) then + print("delim_indices: fatal: I didn't find any delimiters") + print("('" + delimiter + "') on row " + i + ". Can't continue.") + exit + end if + if(dimsizes(ii).ne.ndelims) then + print("delim_indices: fatal: I expected to find " + ndelims) + print("delimiters on row " + i + ". Instead, I found " + dimsizes(ii) + ".") + print("Can't continue.") + exit + end if + + cindices(i,:) = ii + + delete(ii) ; For next time through loop + end do + + return(cindices) +end + +;---------------------------------------------------------------------- +; This function reads in a particular field from a string array, +; given the field number to read (fields start at #1 and go to #nfield), +; and the indices of the delimiters. +; +; It returns either an integer, float, double, character, or a string, +; depending on the input flag "return_type". +;---------------------------------------------------------------------- +function read_field(strings,ifield,indices,return_type) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if + +; +; Set up array to return. For string, int, float, or double arrays, +; we don't have to do anything special. For character arrays, +; however, we do. +; + if(return_type.ne."character") then + return_array = new(nrows,return_type) + else +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + end if + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if +; +; Here's the code that pulls off the correct string, and converts it +; to float if desired. +; + if(return_type.eq."integer") then + return_array(i) = stringtointeger(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."float") then + return_array(i) = stringtofloat(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."double") then + return_array(i) = stringtodouble(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."string") then + return_array(i) = chartostring(cstrings(i,ibeg:iend)) + end if + if(return_type.eq."character") then + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + tmp_return_array(i,0:iend-ibeg) = cstrings(i,ibeg:iend) + end if + end do + + if(return_type.eq."character") then + return_array = new((/nrows,max_len/),"character") + return_array = tmp_return_array(:,0:max_len-1) + end if + + return(return_array) +end + + +;---------------------------------------------------------------------- +; This function reads in string fields only to get the maximum string +; length. +;---------------------------------------------------------------------- +function get_maxlen(strings,ifield,indices) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + end do + + return(max_len) +end + +;---------------------------------------------------------------------- +; Main code. +;---------------------------------------------------------------------- +begin + +; Set up defaults here. We are hard-coding the field types here. +; You can set up this script to try to determine the field types +; automatically, but this is a bit tedious. Maybe later. + + station = "USHa1" + year = 1991 + nfields = 30 ; # of fields + delimiter = "," ; field delimiter + + filename = station+year+"_L4_m.txt" ; ASCII" file to read. + cdf_file = station+year+"_L4_m.nc" ; netCDF file to write. + +; In this case, fields #2-#2 are integers, +; and the rest of the fields are floats. + + var_types = new(nfields,string) + var_strlens = new(nfields,integer) ; var to hold strlens, just in case. + + var_types = "float" ; Most are floats. + var_types(0:1) = "integer" + + if(isfilepresent(cdf_file)) + print("Warning: '" + cdf_file + "' exists. Will remove it.") + system("/bin/rm " + cdf_file) + end if + +; Read in data as strings. This will create a string array that has the +; same number of strings as there are rows in the file. We will then need +; to parse each string later. + + read_data = asciiread(filename,-1,"string") + header = read_data(0) ; Header. Use for variable names. + data = read_data(1:) ; Get rid of first line which is a header. + nrows = dimsizes(data) ; Number of rows. + +; Read in locations of delimiters in each string row. + + hindices = delim_indices(header,nfields,delimiter) ; header row + dindices = delim_indices(data,nfields,delimiter) ; rest of file + + print (hindices) + print (dindices) + +; Read in the field names which will become variable names on +; the netCDF file. + + var_names = new(nfields,string) + + do i=0,nfields-1 + var_names(i) = read_field(header,i+1,hindices,"string") + end do + +; Write out this netCDF file efficiently so it will be faster. +; Try to predefine everything before you write to it. + + f = addfile(cdf_file,"c") + setfileoption(f,"DefineMode",True) ; Enter predefine phase. + +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. + + fAtt = True + fAtt@description = "Data read in from " + filename + " ASCII file." + fAtt@creation_date = systemfunc ("date") + fileattdef( f, fAtt ) + +; Write dimension names to file. If there are no character variables, +; then there's only one dimension name ("nvalues"). + + nyear = -1 + nmonth = 12 + + dim_names = (/ "year", "month" /) + dim_sizes = (/ nyear , nmonth /) + dimUnlim = (/ True , False /) + + filedimdef( f, dim_names, dim_sizes, dimUnlim ) + +; Define each variable on the file. +; +; Don't deal with variable Month (i=0). + + do i=1,nfields-1 + filevardef(f, var_names(i), var_types(i), dim_names) + end do + +; Loop through each field, read the values for that field, print +; information about the variable, and then write it to the netCDF +; file. + + do i=1,nfields-1 + ifield = i+1 ; Fields start at #1, not #0. + +; Note: you can't write strings to a netCDF file, so these have +; to be written out as character arrays. + + tmp_data = new((/1,nmonth/),var_types(i)) + + out_data = read_field(data,ifield,dindices,var_types(i)) + + tmp_data(0,:) = out_data(:) + +; Print some info about the variable. + + print("") + print("Writing variable '" + var_names(i) + "' (field #" + ifield + ").") + print("Type is " + var_types(i) + ".") + print("min/max = " + min(tmp_data) + "/" + max(tmp_data)) + + if(any(ismissing(tmp_data))) then + print("This variable does contain missing values.") + else + print("This variable doesn't contain missing values.") + end if + + f->$var_names(i)$ = tmp_data ; Write to netCDF file. + + delete(tmp_data) ; Delete for next round. + delete(out_data) + end do +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/02.read_ascii.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/02.read_ascii.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,377 @@ +;---------------------------------------------------------------------- +; add year to output +; +; This example reads an ASCII file that is formatted a specific way, and +; writes out the results to a netCDF file. +; +; The first line in the ASCII file must be a header, with each field +; separated by a single character delimiter (like a ","). The rest of +; the file must be such that each row contains all fields, each +; separated by the designated delimiter. +; +; The fields can be integer, float, double, character, or string. +; String fields cannot be written to a netCDF file. They have to +; be read in as character arrays and written out that way. +;---------------------------------------------------------------------- + +;---------------------------------------------------------------------- +; This function returns the index locations of the given delimiter +; in a row or several rows of strings. +;---------------------------------------------------------------------- +function delim_indices(strings,nfields,delimiter) +local cstrings, cdelim +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) ; Convert to characters. + cdelim = stringtochar(delimiter) ; Convert delimiter to character. +; +; Som error checking here. Make sure delimiter is one character. +; + nc = dimsizes(cdelim) + rank = dimsizes(nc) + if(rank.ne.1.or.(rank.eq.1.and.nc.ne.2)) then + print("delim_indices: fatal: the delimiter you've selected") + print("must be a single character. Can't continue.") + exit + end if + +; +; Create array to hold indices of delimiter locations, and then loop +; through each row and find all the delimiters. Make sure each row has +; the correct number of delimiters. +; + ndelims = nfields-1 + cindices = new((/nrows,ndelims/),integer) + do i = 0, nrows-1 + ii = ind(cstrings(i,:).eq.cdelim(0)) +; +; Make sure there were delimiters on this row. If not, we just quit. +; This could probably be modified to do this more gracefully. +; + if(any(ismissing(ii))) then + print("delim_indices: fatal: I didn't find any delimiters") + print("('" + delimiter + "') on row " + i + ". Can't continue.") + exit + end if + if(dimsizes(ii).ne.ndelims) then + print("delim_indices: fatal: I expected to find " + ndelims) + print("delimiters on row " + i + ". Instead, I found " + dimsizes(ii) + ".") + print("Can't continue.") + exit + end if + + cindices(i,:) = ii + + delete(ii) ; For next time through loop + end do + + return(cindices) +end + +;---------------------------------------------------------------------- +; This function reads in a particular field from a string array, +; given the field number to read (fields start at #1 and go to #nfield), +; and the indices of the delimiters. +; +; It returns either an integer, float, double, character, or a string, +; depending on the input flag "return_type". +;---------------------------------------------------------------------- +function read_field(strings,ifield,indices,return_type) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if + +; +; Set up array to return. For string, int, float, or double arrays, +; we don't have to do anything special. For character arrays, +; however, we do. +; + if(return_type.ne."character") then + return_array = new(nrows,return_type) + else +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + end if + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if +; +; Here's the code that pulls off the correct string, and converts it +; to float if desired. +; + if(return_type.eq."integer") then + return_array(i) = stringtointeger(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."float") then + return_array(i) = stringtofloat(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."double") then + return_array(i) = stringtodouble(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."string") then + return_array(i) = chartostring(cstrings(i,ibeg:iend)) + end if + if(return_type.eq."character") then + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + tmp_return_array(i,0:iend-ibeg) = cstrings(i,ibeg:iend) + end if + end do + + if(return_type.eq."character") then + return_array = new((/nrows,max_len/),"character") + return_array = tmp_return_array(:,0:max_len-1) + end if + + return(return_array) +end + + +;---------------------------------------------------------------------- +; This function reads in string fields only to get the maximum string +; length. +;---------------------------------------------------------------------- +function get_maxlen(strings,ifield,indices) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + end do + + return(max_len) +end + +;---------------------------------------------------------------------- +; Main code. +;---------------------------------------------------------------------- +begin + +; Set up defaults here. We are hard-coding the field types here. +; You can set up this script to try to determine the field types +; automatically, but this is a bit tedious. Maybe later. + + station = "USHa1" + year = 1991 + nfields = 30 ; # of fields + delimiter = "," ; field delimiter + + filename = station+year+"_L4_m.txt" ; ASCII" file to read. + cdf_file = station+year+"_L4_m.nc" ; netCDF file to write. + +; In this case, fields #2-#2 are integers, +; and the rest of the fields are floats. + + var_types = new(nfields,string) + var_strlens = new(nfields,integer) ; var to hold strlens, just in case. + + var_types = "float" ; Most are floats. + var_types(0:1) = "integer" + + if(isfilepresent(cdf_file)) + print("Warning: '" + cdf_file + "' exists. Will remove it.") + system("/bin/rm " + cdf_file) + end if + +; Read in data as strings. This will create a string array that has the +; same number of strings as there are rows in the file. We will then need +; to parse each string later. + + read_data = asciiread(filename,-1,"string") + header = read_data(0) ; Header. Use for variable names. + data = read_data(1:) ; Get rid of first line which is a header. + nrows = dimsizes(data) ; Number of rows. + +; Read in locations of delimiters in each string row. + + hindices = delim_indices(header,nfields,delimiter) ; header row + dindices = delim_indices(data,nfields,delimiter) ; rest of file + + print (hindices) + print (dindices) + +; Read in the field names which will become variable names on +; the netCDF file. + + var_names = new(nfields,string) + + do i=0,nfields-1 + var_names(i) = read_field(header,i+1,hindices,"string") + end do + +; Write out this netCDF file efficiently so it will be faster. +; Try to predefine everything before you write to it. + + f = addfile(cdf_file,"c") + setfileoption(f,"DefineMode",True) ; Enter predefine phase. + +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. + + fAtt = True + fAtt@description = "Data read in from " + filename + " ASCII file." + fAtt@creation_date = systemfunc ("date") + fileattdef( f, fAtt ) + +; Write dimension names to file. If there are no character variables, +; then there's only one dimension name ("nvalues"). + + nyear = -1 + nmonth = 12 + + dim_names = (/ "year", "month" /) + dim_sizes = (/ nyear , nmonth /) + dimUnlim = (/ True , False /) + + filedimdef( f, dim_names, dim_sizes, dimUnlim ) + +; Define each variable on the file. + + filevardef( f, "year", "integer", "year" ) + +; Don't deal with variable Month (i=0). + + do i=1,nfields-1 + filevardef(f, var_names(i), var_types(i), dim_names) + end do + +; Loop through each field, read the values for that field, print +; information about the variable, and then write it to the netCDF +; file. + + do i=1,nfields-1 + ifield = i+1 ; Fields start at #1, not #0. + +; Note: you can't write strings to a netCDF file, so these have +; to be written out as character arrays. + + tmp_data = new((/1,nmonth/),var_types(i)) + + out_data = read_field(data,ifield,dindices,var_types(i)) + + tmp_data(0,:) = out_data(:) + +; Print some info about the variable. + + print("") + print("Writing variable '" + var_names(i) + "' (field #" + ifield + ").") + print("Type is " + var_types(i) + ".") + print("min/max = " + min(tmp_data) + "/" + max(tmp_data)) + + if(any(ismissing(tmp_data))) then + print("This variable does contain missing values.") + else + print("This variable doesn't contain missing values.") + end if + + f->$var_names(i)$ = tmp_data ; Write to netCDF file. + + delete(tmp_data) ; Delete for next round. + delete(out_data) + end do + + f->year = year +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/03.read_ascii.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/03.read_ascii.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,387 @@ +;---------------------------------------------------------------------- +; add Month to output +; add lat, lon to output +; add year to output +; +; This example reads an ASCII file that is formatted a specific way, and +; writes out the results to a netCDF file. +; +; The first line in the ASCII file must be a header, with each field +; separated by a single character delimiter (like a ","). The rest of +; the file must be such that each row contains all fields, each +; separated by the designated delimiter. +; +; The fields can be integer, float, double, character, or string. +; String fields cannot be written to a netCDF file. They have to +; be read in as character arrays and written out that way. +;---------------------------------------------------------------------- + +;---------------------------------------------------------------------- +; This function returns the index locations of the given delimiter +; in a row or several rows of strings. +;---------------------------------------------------------------------- +function delim_indices(strings,nfields,delimiter) +local cstrings, cdelim +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) ; Convert to characters. + cdelim = stringtochar(delimiter) ; Convert delimiter to character. +; +; Som error checking here. Make sure delimiter is one character. +; + nc = dimsizes(cdelim) + rank = dimsizes(nc) + if(rank.ne.1.or.(rank.eq.1.and.nc.ne.2)) then + print("delim_indices: fatal: the delimiter you've selected") + print("must be a single character. Can't continue.") + exit + end if + +; +; Create array to hold indices of delimiter locations, and then loop +; through each row and find all the delimiters. Make sure each row has +; the correct number of delimiters. +; + ndelims = nfields-1 + cindices = new((/nrows,ndelims/),integer) + do i = 0, nrows-1 + ii = ind(cstrings(i,:).eq.cdelim(0)) +; +; Make sure there were delimiters on this row. If not, we just quit. +; This could probably be modified to do this more gracefully. +; + if(any(ismissing(ii))) then + print("delim_indices: fatal: I didn't find any delimiters") + print("('" + delimiter + "') on row " + i + ". Can't continue.") + exit + end if + if(dimsizes(ii).ne.ndelims) then + print("delim_indices: fatal: I expected to find " + ndelims) + print("delimiters on row " + i + ". Instead, I found " + dimsizes(ii) + ".") + print("Can't continue.") + exit + end if + + cindices(i,:) = ii + + delete(ii) ; For next time through loop + end do + + return(cindices) +end + +;---------------------------------------------------------------------- +; This function reads in a particular field from a string array, +; given the field number to read (fields start at #1 and go to #nfield), +; and the indices of the delimiters. +; +; It returns either an integer, float, double, character, or a string, +; depending on the input flag "return_type". +;---------------------------------------------------------------------- +function read_field(strings,ifield,indices,return_type) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if + +; +; Set up array to return. For string, int, float, or double arrays, +; we don't have to do anything special. For character arrays, +; however, we do. +; + if(return_type.ne."character") then + return_array = new(nrows,return_type) + else +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + end if + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if +; +; Here's the code that pulls off the correct string, and converts it +; to float if desired. +; + if(return_type.eq."integer") then + return_array(i) = stringtointeger(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."float") then + return_array(i) = stringtofloat(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."double") then + return_array(i) = stringtodouble(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."string") then + return_array(i) = chartostring(cstrings(i,ibeg:iend)) + end if + if(return_type.eq."character") then + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + tmp_return_array(i,0:iend-ibeg) = cstrings(i,ibeg:iend) + end if + end do + + if(return_type.eq."character") then + return_array = new((/nrows,max_len/),"character") + return_array = tmp_return_array(:,0:max_len-1) + end if + + return(return_array) +end + + +;---------------------------------------------------------------------- +; This function reads in string fields only to get the maximum string +; length. +;---------------------------------------------------------------------- +function get_maxlen(strings,ifield,indices) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + end do + + return(max_len) +end + +;---------------------------------------------------------------------- +; Main code. +;---------------------------------------------------------------------- +begin + +; Set up defaults here. We are hard-coding the field types here. +; You can set up this script to try to determine the field types +; automatically, but this is a bit tedious. Maybe later. + + station = "USHa1" + lat = 42.5378 + lon = -72.1715 + 360. + year = 1991 + nfields = 30 ; # of fields + delimiter = "," ; field delimiter + + filename = station+year+"_L4_m.txt" ; ASCII" file to read. + cdf_file = station+year+"_L4_m.nc" ; netCDF file to write. + +; In this case, fields #2-#2 are integers, +; and the rest of the fields are floats. + + var_types = new(nfields,string) + var_strlens = new(nfields,integer) ; var to hold strlens, just in case. + + var_types = "float" ; Most are floats. + var_types(0:1) = "integer" + + if(isfilepresent(cdf_file)) + print("Warning: '" + cdf_file + "' exists. Will remove it.") + system("/bin/rm " + cdf_file) + end if + +; Read in data as strings. This will create a string array that has the +; same number of strings as there are rows in the file. We will then need +; to parse each string later. + + read_data = asciiread(filename,-1,"string") + header = read_data(0) ; Header. Use for variable names. + data = read_data(1:) ; Get rid of first line which is a header. + nrows = dimsizes(data) ; Number of rows. + +; Read in locations of delimiters in each string row. + + hindices = delim_indices(header,nfields,delimiter) ; header row + dindices = delim_indices(data,nfields,delimiter) ; rest of file + +; print (hindices) +; print (dindices) + +; Read in the field names which will become variable names on +; the netCDF file. + + var_names = new(nfields,string) + + do i=0,nfields-1 + var_names(i) = read_field(header,i+1,hindices,"string") + end do + +; Write out this netCDF file efficiently so it will be faster. +; Try to predefine everything before you write to it. + + f = addfile(cdf_file,"c") + setfileoption(f,"DefineMode",True) ; Enter predefine phase. + +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. + + fAtt = True + fAtt@description = "Data read in from " + filename + " ASCII file." + fAtt@creation_date = systemfunc ("date") + fileattdef( f, fAtt ) + +; Write dimension names to file. If there are no character variables, +; then there's only one dimension name ("nvalues"). + + nyear = -1 + nmonth = 12 + + dim_names = (/ "year", "month" /) + dim_sizes = (/ nyear , nmonth /) + dimUnlim = (/ True , False /) + + filedimdef( f, dim_names, dim_sizes, dimUnlim ) + filedimdef( f, "lat", 1, False ) + filedimdef( f, "lon", 1, False ) + +; Define each variable on the file. + + filevardef( f, "year", "integer", "year" ) + filevardef( f, "lat" , "float" , "lat" ) + filevardef( f, "lon" , "float" , "lon" ) + +; Don't deal with variable Month (i=0). + + do i=0,nfields-1 + filevardef(f, var_names(i), var_types(i), dim_names) + end do + +; Loop through each field, read the values for that field, print +; information about the variable, and then write it to the netCDF +; file. + + do i=0,nfields-1 + ifield = i+1 ; Fields start at #1, not #0. + +; Note: you can't write strings to a netCDF file, so these have +; to be written out as character arrays. + + tmp_data = new((/1,nmonth/),var_types(i)) + + tmp_data(0,:) = read_field(data,ifield,dindices,var_types(i)) + +; tmp_data(0,:) = out_data(:) + +; Print some info about the variable. + + print("") + print("Writing variable '" + var_names(i) + "' (field #" + ifield + ").") + print("Type is " + var_types(i) + ".") + print("min/max = " + min(tmp_data) + "/" + max(tmp_data)) + + if(any(ismissing(tmp_data))) then + print("This variable does contain missing values.") + else + print("This variable doesn't contain missing values.") + end if + + f->$var_names(i)$ = tmp_data ; Write to netCDF file. + + delete(tmp_data) ; Delete for next round. +; delete(out_data) + end do + + f->year = year + f->lat = lat + f->lon = lon +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/04.read_ascii.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/04.read_ascii.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,391 @@ +;---------------------------------------------------------------------- +; change Month to yyyymm +; add Month to output +; add lat, lon to output +; add year to output +; +; This example reads an ASCII file that is formatted a specific way, and +; writes out the results to a netCDF file. +; +; The first line in the ASCII file must be a header, with each field +; separated by a single character delimiter (like a ","). The rest of +; the file must be such that each row contains all fields, each +; separated by the designated delimiter. +; +; The fields can be integer, float, double, character, or string. +; String fields cannot be written to a netCDF file. They have to +; be read in as character arrays and written out that way. +;---------------------------------------------------------------------- + +;---------------------------------------------------------------------- +; This function returns the index locations of the given delimiter +; in a row or several rows of strings. +;---------------------------------------------------------------------- +function delim_indices(strings,nfields,delimiter) +local cstrings, cdelim +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) ; Convert to characters. + cdelim = stringtochar(delimiter) ; Convert delimiter to character. +; +; Som error checking here. Make sure delimiter is one character. +; + nc = dimsizes(cdelim) + rank = dimsizes(nc) + if(rank.ne.1.or.(rank.eq.1.and.nc.ne.2)) then + print("delim_indices: fatal: the delimiter you've selected") + print("must be a single character. Can't continue.") + exit + end if + +; +; Create array to hold indices of delimiter locations, and then loop +; through each row and find all the delimiters. Make sure each row has +; the correct number of delimiters. +; + ndelims = nfields-1 + cindices = new((/nrows,ndelims/),integer) + do i = 0, nrows-1 + ii = ind(cstrings(i,:).eq.cdelim(0)) +; +; Make sure there were delimiters on this row. If not, we just quit. +; This could probably be modified to do this more gracefully. +; + if(any(ismissing(ii))) then + print("delim_indices: fatal: I didn't find any delimiters") + print("('" + delimiter + "') on row " + i + ". Can't continue.") + exit + end if + if(dimsizes(ii).ne.ndelims) then + print("delim_indices: fatal: I expected to find " + ndelims) + print("delimiters on row " + i + ". Instead, I found " + dimsizes(ii) + ".") + print("Can't continue.") + exit + end if + + cindices(i,:) = ii + + delete(ii) ; For next time through loop + end do + + return(cindices) +end + +;---------------------------------------------------------------------- +; This function reads in a particular field from a string array, +; given the field number to read (fields start at #1 and go to #nfield), +; and the indices of the delimiters. +; +; It returns either an integer, float, double, character, or a string, +; depending on the input flag "return_type". +;---------------------------------------------------------------------- +function read_field(strings,ifield,indices,return_type) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if + +; +; Set up array to return. For string, int, float, or double arrays, +; we don't have to do anything special. For character arrays, +; however, we do. +; + if(return_type.ne."character") then + return_array = new(nrows,return_type) + else +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + end if + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if +; +; Here's the code that pulls off the correct string, and converts it +; to float if desired. +; + if(return_type.eq."integer") then + return_array(i) = stringtointeger(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."float") then + return_array(i) = stringtofloat(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."double") then + return_array(i) = stringtodouble(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."string") then + return_array(i) = chartostring(cstrings(i,ibeg:iend)) + end if + if(return_type.eq."character") then + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + tmp_return_array(i,0:iend-ibeg) = cstrings(i,ibeg:iend) + end if + end do + + if(return_type.eq."character") then + return_array = new((/nrows,max_len/),"character") + return_array = tmp_return_array(:,0:max_len-1) + end if + + return(return_array) +end + + +;---------------------------------------------------------------------- +; This function reads in string fields only to get the maximum string +; length. +;---------------------------------------------------------------------- +function get_maxlen(strings,ifield,indices) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + end do + + return(max_len) +end + +;---------------------------------------------------------------------- +; Main code. +;---------------------------------------------------------------------- +begin + +;############################################################### +; Set up defaults. We are hard-coding here.. + + year = 1991 + station = "USHa1" + lat = 42.5378 + lon = -72.1715 + 360. + + nfields = 30 ; # of fields + delimiter = "," ; field delimiter + + filename = station+year+"_L4_m.txt" ; ASCII" file to read. + cdf_file = station+year+"_L4_m.nc" ; netCDF file to write. + + if(isfilepresent(cdf_file)) + print("Warning: '" + cdf_file + "' exists. Will remove it.") + system("/bin/rm " + cdf_file) + end if + +; In this case, fields #1-#2 are integers, +; and the rest of the fields are floats. + + var_types = new(nfields,string) + var_types = "float" ; Most are floats. + var_types(0:1) = "integer" + +;##################################################################### + +; Read in data as strings. This will create a string array that has the +; same number of strings as there are rows in the file. We will then need +; to parse each string later. + + read_data = asciiread(filename,-1,"string") + + header = read_data(0) ; Header. Use for variable names. + data = read_data(1:) ; Get rid of first line which is a header. + nmonth = dimsizes(data) ; Number of rows == number of month. + +; Read in locations of delimiters in each string row. + + hindices = delim_indices(header,nfields,delimiter) ; header row + dindices = delim_indices(data,nfields,delimiter) ; rest of file + +; Read in the field names which will become variable names on +; the netCDF file. + + var_names = new(nfields,string) + + do i=0,nfields-1 + var_names(i) = read_field(header,i+1,hindices,"string") + end do + +;------------------------------------------------------------------- +; Write out this netCDF file efficiently so it will be faster. +; Try to predefine everything before you write to it. + + f = addfile(cdf_file,"c") + setfileoption(f,"DefineMode",True) ; Enter predefine phase. + +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. + + fAtt = True + fAtt@description = "Data read in from " + filename + " ASCII file." + fAtt@creation_date = systemfunc ("date") + fileattdef( f, fAtt ) + +; Write dimension names to file. + + dim_names = (/ "year", "month" /) + dim_sizes = (/ -1 , nmonth /) + dimUnlim = (/ True , False /) + filedimdef( f, dim_names, dim_sizes, dimUnlim ) + + filedimdef( f, "lat", 1, False ) + filedimdef( f, "lon", 1, False ) + +; Define each variable on the file. + + filevardef( f, "year", "integer", "year" ) + filevardef( f, "lat" , "float" , "lat" ) + filevardef( f, "lon" , "float" , "lon" ) + + do i=0,nfields-1 + filevardef(f, var_names(i), var_types(i), dim_names) + end do +;----------------------------------------------------------------- + +; Loop through each field, read the values for that field, print +; information about the variable, and then write it to the netCDF file. + + do i=0,nfields-1 + ifield = i+1 ; Fields start at #1, not #0. + + tmp_data = new((/1,nmonth/),var_types(i)) + + if (i.le.1) then + tmp_data@_FillValue = -999 + else + tmp_data@_FillValue = -9999.00 + end if + + tmp_data(0,:) = read_field(data,ifield,dindices,var_types(i)) + +; change Month to yyyymm + + if (i.eq.0) then + tmp_data(0,:) = tmp_data(0,:) + year*100 + end if + +; Print some info about the variable. + +; print("") +; print("Writing variable '" + var_names(i) + "' (field #" + ifield + ").") +; print("Type is " + var_types(i) + ".") +; print("min/max = " + min(tmp_data) + "/" + max(tmp_data)) + +; if(any(ismissing(tmp_data))) then +; print("This variable does contain missing values.") +; else +; print("This variable doesn't contain missing values.") +; end if + +; write variable to file + + f->$var_names(i)$ = tmp_data ; Write to netCDF file. + + delete(tmp_data) ; Delete for next round. + end do + +; write variable to file + + f->year = year + f->lat = lat + f->lon = lon +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/05.read_ascii.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/05.read_ascii.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,413 @@ +;---------------------------------------------------------------------- +; set _FillValue +; change Month to yyyymm +; add Month to output +; add lat, lon to output +; add year to output +; +; This example reads an ASCII file that is formatted a specific way, and +; writes out the results to a netCDF file. +; +; The first line in the ASCII file must be a header, with each field +; separated by a single character delimiter (like a ","). The rest of +; the file must be such that each row contains all fields, each +; separated by the designated delimiter. +; +; The fields can be integer, float, double, character, or string. +; String fields cannot be written to a netCDF file. They have to +; be read in as character arrays and written out that way. +;---------------------------------------------------------------------- + +;---------------------------------------------------------------------- +; This function returns the index locations of the given delimiter +; in a row or several rows of strings. +;---------------------------------------------------------------------- +function delim_indices(strings,nfields,delimiter) +local cstrings, cdelim +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) ; Convert to characters. + cdelim = stringtochar(delimiter) ; Convert delimiter to character. +; +; Som error checking here. Make sure delimiter is one character. +; + nc = dimsizes(cdelim) + rank = dimsizes(nc) + if(rank.ne.1.or.(rank.eq.1.and.nc.ne.2)) then + print("delim_indices: fatal: the delimiter you've selected") + print("must be a single character. Can't continue.") + exit + end if + +; +; Create array to hold indices of delimiter locations, and then loop +; through each row and find all the delimiters. Make sure each row has +; the correct number of delimiters. +; + ndelims = nfields-1 + cindices = new((/nrows,ndelims/),integer) + do i = 0, nrows-1 + ii = ind(cstrings(i,:).eq.cdelim(0)) +; +; Make sure there were delimiters on this row. If not, we just quit. +; This could probably be modified to do this more gracefully. +; + if(any(ismissing(ii))) then + print("delim_indices: fatal: I didn't find any delimiters") + print("('" + delimiter + "') on row " + i + ". Can't continue.") + exit + end if + if(dimsizes(ii).ne.ndelims) then + print("delim_indices: fatal: I expected to find " + ndelims) + print("delimiters on row " + i + ". Instead, I found " + dimsizes(ii) + ".") + print("Can't continue.") + exit + end if + + cindices(i,:) = ii + + delete(ii) ; For next time through loop + end do + + return(cindices) +end + +;---------------------------------------------------------------------- +; This function reads in a particular field from a string array, +; given the field number to read (fields start at #1 and go to #nfield), +; and the indices of the delimiters. +; +; It returns either an integer, float, double, character, or a string, +; depending on the input flag "return_type". +;---------------------------------------------------------------------- +function read_field(strings,ifield,indices,return_type) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if + +; +; Set up array to return. For string, int, float, or double arrays, +; we don't have to do anything special. For character arrays, +; however, we do. +; + if(return_type.ne."character") then + return_array = new(nrows,return_type) + else +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + end if + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if +; +; Here's the code that pulls off the correct string, and converts it +; to float if desired. +; + if(return_type.eq."integer") then + return_array(i) = stringtointeger(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."float") then + return_array(i) = stringtofloat(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."double") then + return_array(i) = stringtodouble(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."string") then + return_array(i) = chartostring(cstrings(i,ibeg:iend)) + end if + if(return_type.eq."character") then + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + tmp_return_array(i,0:iend-ibeg) = cstrings(i,ibeg:iend) + end if + end do + + if(return_type.eq."character") then + return_array = new((/nrows,max_len/),"character") + return_array = tmp_return_array(:,0:max_len-1) + end if + + return(return_array) +end + + +;---------------------------------------------------------------------- +; This function reads in string fields only to get the maximum string +; length. +;---------------------------------------------------------------------- +function get_maxlen(strings,ifield,indices) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + end do + + return(max_len) +end + +;---------------------------------------------------------------------- +; Main code. +;---------------------------------------------------------------------- +begin + +;############################################################### +; Set up defaults. We are hard-coding here.. + + year = 1991 + station = "USHa1" + lat = 42.5378 + lon = -72.1715 + 360. + + nfields = 30 ; # of fields + delimiter = "," ; field delimiter + + filename = station+year+"_L4_m.txt" ; ASCII" file to read. + cdf_file = station+year+"_L4_m.nc" ; netCDF file to write. + + if(isfilepresent(cdf_file)) + print("Warning: '" + cdf_file + "' exists. Will remove it.") + system("/bin/rm " + cdf_file) + end if + +; In this case, fields #1-#2 are integers, +; and the rest of the fields are floats. + + var_types = new(nfields,string) + var_types = "float" ; Most are floats. + var_types(0:1) = "integer" + +;##################################################################### + +; Read in data as strings. This will create a string array that has the +; same number of strings as there are rows in the file. We will then need +; to parse each string later. + + read_data = asciiread(filename,-1,"string") + + header = read_data(0) ; Header. Use for variable names. + data = read_data(1:) ; Get rid of first line which is a header. + nmonth = dimsizes(data) ; Number of rows == number of month. + +; Read in locations of delimiters in each string row. + + hindices = delim_indices(header,nfields,delimiter) ; header row + dindices = delim_indices(data,nfields,delimiter) ; rest of file + +; Read in the field names which will become variable names on +; the netCDF file. + + var_names = new(nfields,string) + + do i=0,nfields-1 + var_names(i) = read_field(header,i+1,hindices,"string") + end do + +;------------------------------------------------------------------- +; Write out this netCDF file efficiently so it will be faster. +; Try to predefine everything before you write to it. + + f = addfile(cdf_file,"c") + setfileoption(f,"DefineMode",True) ; Enter predefine phase. + +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. + + fAtt = True + fAtt@description = "Data read in from " + filename + " ASCII file." + fAtt@creation_date = systemfunc ("date") + fileattdef( f, fAtt ) + +; Write dimension names to file. + + dim_names = (/ "year", "month" /) + dim_sizes = (/ -1 , nmonth /) + dimUnlim = (/ True , False /) + filedimdef( f, dim_names, dim_sizes, dimUnlim ) + + filedimdef( f, "lat", 1, False ) + filedimdef( f, "lon", 1, False ) + +; Define each variable on the file. + + filevardef( f, "year", "integer", "year" ) + filevardef( f, "lat" , "float" , "lat" ) + filevardef( f, "lon" , "float" , "lon" ) + + do i=0,nfields-1 + +; define variable + + filevardef(f, var_names(i), var_types(i), dim_names) + +; define variable attributes + + if (i.le.1) then + varAtt = 0 +; varAtt@_FillValue = -999 + else + varAtt = 0. +; varAtt@_FillValue = 1.e36 + end if + + varAtt@long_name = var_names(i) + + filevarattdef( f, var_names(i) , varAtt ) + + delete (varAtt) + end do +;----------------------------------------------------------------- + +; Loop through each field, read the values for that field, print +; information about the variable, and then write it to the netCDF file. + + do i=0,nfields-1 + ifield = i+1 ; Fields start at #1, not #0. + + tmp_data = new((/1,nmonth/),var_types(i)) + + if (i.le.1) then + tmp_data@_FillValue = -999 + else + tmp_data@_FillValue = 1.e36 + end if + + tmp_data(0,:) = read_field(data,ifield,dindices,var_types(i)) + + tmp_data = where(tmp_data .le. -9000.,tmp_data@_FillValue,tmp_data) + +; change Month to yyyymm + + if (i.eq.0) then + tmp_data(0,:) = tmp_data(0,:) + year*100 + end if + +; Print some info about the variable. + +; print("") +; print("Writing variable '" + var_names(i) + "' (field #" + ifield + ").") +; print("Type is " + var_types(i) + ".") +; print("min/max = " + min(tmp_data) + "/" + max(tmp_data)) + +; if(any(ismissing(tmp_data))) then +; print("This variable does contain missing values.") +; else +; print("This variable doesn't contain missing values.") +; end if + +; write variable to file + + f->$var_names(i)$ = tmp_data ; Write to netCDF file. + + delete(tmp_data) ; Delete for next round. + end do + +; write variable to file + + f->year = year + f->lat = lat + f->lon = lon +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/06.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/06.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,412 @@ +;---------------------------------------------------------------------- +; set _FillValue +; change Month to yyyymm +; add Month to output +; add lat, lon to output +; add year to output +; +; This example reads an ASCII file that is formatted a specific way, and +; writes out the results to a netCDF file. +; +; The first line in the ASCII file must be a header, with each field +; separated by a single character delimiter (like a ","). The rest of +; the file must be such that each row contains all fields, each +; separated by the designated delimiter. +; +; The fields can be integer, float, double, character, or string. +; String fields cannot be written to a netCDF file. They have to +; be read in as character arrays and written out that way. +;---------------------------------------------------------------------- + +;---------------------------------------------------------------------- +; This function returns the index locations of the given delimiter +; in a row or several rows of strings. +;---------------------------------------------------------------------- +function delim_indices(strings,nfields,delimiter) +local cstrings, cdelim +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) ; Convert to characters. + cdelim = stringtochar(delimiter) ; Convert delimiter to character. +; +; Som error checking here. Make sure delimiter is one character. +; + nc = dimsizes(cdelim) + rank = dimsizes(nc) + if(rank.ne.1.or.(rank.eq.1.and.nc.ne.2)) then + print("delim_indices: fatal: the delimiter you've selected") + print("must be a single character. Can't continue.") + exit + end if + +; +; Create array to hold indices of delimiter locations, and then loop +; through each row and find all the delimiters. Make sure each row has +; the correct number of delimiters. +; + ndelims = nfields-1 + cindices = new((/nrows,ndelims/),integer) + do i = 0, nrows-1 + ii = ind(cstrings(i,:).eq.cdelim(0)) +; +; Make sure there were delimiters on this row. If not, we just quit. +; This could probably be modified to do this more gracefully. +; + if(any(ismissing(ii))) then + print("delim_indices: fatal: I didn't find any delimiters") + print("('" + delimiter + "') on row " + i + ". Can't continue.") + exit + end if + if(dimsizes(ii).ne.ndelims) then + print("delim_indices: fatal: I expected to find " + ndelims) + print("delimiters on row " + i + ". Instead, I found " + dimsizes(ii) + ".") + print("Can't continue.") + exit + end if + + cindices(i,:) = ii + + delete(ii) ; For next time through loop + end do + + return(cindices) +end + +;---------------------------------------------------------------------- +; This function reads in a particular field from a string array, +; given the field number to read (fields start at #1 and go to #nfield), +; and the indices of the delimiters. +; +; It returns either an integer, float, double, character, or a string, +; depending on the input flag "return_type". +;---------------------------------------------------------------------- +function read_field(strings,ifield,indices,return_type) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if + +; +; Set up array to return. For string, int, float, or double arrays, +; we don't have to do anything special. For character arrays, +; however, we do. +; + if(return_type.ne."character") then + return_array = new(nrows,return_type) + else +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + end if + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if +; +; Here's the code that pulls off the correct string, and converts it +; to float if desired. +; + if(return_type.eq."integer") then + return_array(i) = stringtointeger(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."float") then + return_array(i) = stringtofloat(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."double") then + return_array(i) = stringtodouble(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."string") then + return_array(i) = chartostring(cstrings(i,ibeg:iend)) + end if + if(return_type.eq."character") then + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + tmp_return_array(i,0:iend-ibeg) = cstrings(i,ibeg:iend) + end if + end do + + if(return_type.eq."character") then + return_array = new((/nrows,max_len/),"character") + return_array = tmp_return_array(:,0:max_len-1) + end if + + return(return_array) +end + + +;---------------------------------------------------------------------- +; This function reads in string fields only to get the maximum string +; length. +;---------------------------------------------------------------------- +function get_maxlen(strings,ifield,indices) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + end do + + return(max_len) +end + +;---------------------------------------------------------------------- +; Main code. +;---------------------------------------------------------------------- +begin + +;############################################################### +; Set up defaults. We are hard-coding here.. + + year = 2002 + lat = 46.61878 + lon = -91.08144 + 360. + + nfields = 30 ; # of fields + delimiter = "," ; field delimiter + + filename = year+".txt" ; ASCII" file to read. + cdf_file = year+"_L4_m.nc" ; netCDF file to write. + + if(isfilepresent(cdf_file)) + print("Warning: '" + cdf_file + "' exists. Will remove it.") + system("/bin/rm " + cdf_file) + end if + +; In this case, fields #1-#2 are integers, +; and the rest of the fields are floats. + + var_types = new(nfields,string) + var_types = "float" ; Most are floats. + var_types(0:1) = "integer" + +;##################################################################### + +; Read in data as strings. This will create a string array that has the +; same number of strings as there are rows in the file. We will then need +; to parse each string later. + + read_data = asciiread(filename,-1,"string") + + header = read_data(0) ; Header. Use for variable names. + data = read_data(1:) ; Get rid of first line which is a header. + nmonth = dimsizes(data) ; Number of rows == number of month. + +; Read in locations of delimiters in each string row. + + hindices = delim_indices(header,nfields,delimiter) ; header row + dindices = delim_indices(data,nfields,delimiter) ; rest of file + +; Read in the field names which will become variable names on +; the netCDF file. + + var_names = new(nfields,string) + + do i=0,nfields-1 + var_names(i) = read_field(header,i+1,hindices,"string") + end do + +;------------------------------------------------------------------- +; Write out this netCDF file efficiently so it will be faster. +; Try to predefine everything before you write to it. + + f = addfile(cdf_file,"c") + setfileoption(f,"DefineMode",True) ; Enter predefine phase. + +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. + + fAtt = True + fAtt@description = "Data read in from " + filename + " ASCII file." + fAtt@creation_date = systemfunc ("date") + fileattdef( f, fAtt ) + +; Write dimension names to file. + + dim_names = (/ "year", "month" /) + dim_sizes = (/ -1 , nmonth /) + dimUnlim = (/ True , False /) + filedimdef( f, dim_names, dim_sizes, dimUnlim ) + + filedimdef( f, "lat", 1, False ) + filedimdef( f, "lon", 1, False ) + +; Define each variable on the file. + + filevardef( f, "year", "integer", "year" ) + filevardef( f, "lat" , "float" , "lat" ) + filevardef( f, "lon" , "float" , "lon" ) + + do i=0,nfields-1 + +; define variable + + filevardef(f, var_names(i), var_types(i), dim_names) + +; define variable attributes + + if (i.le.1) then + varAtt = 0 +; varAtt@_FillValue = -999 + else + varAtt = 0. +; varAtt@_FillValue = 1.e36 + end if + + varAtt@long_name = var_names(i) + + filevarattdef( f, var_names(i) , varAtt ) + + delete (varAtt) + end do +;----------------------------------------------------------------- + +; Loop through each field, read the values for that field, print +; information about the variable, and then write it to the netCDF file. + + do i=0,nfields-1 + ifield = i+1 ; Fields start at #1, not #0. + + tmp_data = new((/1,nmonth/),var_types(i)) + + if (i.le.1) then + tmp_data@_FillValue = -999 + else + tmp_data@_FillValue = 1.e36 + end if + + tmp_data(0,:) = read_field(data,ifield,dindices,var_types(i)) + + tmp_data = where(tmp_data .le. -9000.,tmp_data@_FillValue,tmp_data) + +; change Month to yyyymm + + if (i.eq.0) then + tmp_data(0,:) = tmp_data(0,:) + year*100 + end if + +; Print some info about the variable. + +; print("") +; print("Writing variable '" + var_names(i) + "' (field #" + ifield + ").") +; print("Type is " + var_types(i) + ".") +; print("min/max = " + min(tmp_data) + "/" + max(tmp_data)) + +; if(any(ismissing(tmp_data))) then +; print("This variable does contain missing values.") +; else +; print("This variable doesn't contain missing values.") +; end if + +; write variable to file + + f->$var_names(i)$ = tmp_data ; Write to netCDF file. + + delete(tmp_data) ; Delete for next round. + end do + +; write variable to file + + f->year = year + f->lat = lat + f->lon = lon +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/06.read_ascii.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/06.read_ascii.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,412 @@ +;---------------------------------------------------------------------- +; set _FillValue +; change Month to yyyymm +; add Month to output +; add lat, lon to output +; add year to output +; +; This example reads an ASCII file that is formatted a specific way, and +; writes out the results to a netCDF file. +; +; The first line in the ASCII file must be a header, with each field +; separated by a single character delimiter (like a ","). The rest of +; the file must be such that each row contains all fields, each +; separated by the designated delimiter. +; +; The fields can be integer, float, double, character, or string. +; String fields cannot be written to a netCDF file. They have to +; be read in as character arrays and written out that way. +;---------------------------------------------------------------------- + +;---------------------------------------------------------------------- +; This function returns the index locations of the given delimiter +; in a row or several rows of strings. +;---------------------------------------------------------------------- +function delim_indices(strings,nfields,delimiter) +local cstrings, cdelim +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) ; Convert to characters. + cdelim = stringtochar(delimiter) ; Convert delimiter to character. +; +; Som error checking here. Make sure delimiter is one character. +; + nc = dimsizes(cdelim) + rank = dimsizes(nc) + if(rank.ne.1.or.(rank.eq.1.and.nc.ne.2)) then + print("delim_indices: fatal: the delimiter you've selected") + print("must be a single character. Can't continue.") + exit + end if + +; +; Create array to hold indices of delimiter locations, and then loop +; through each row and find all the delimiters. Make sure each row has +; the correct number of delimiters. +; + ndelims = nfields-1 + cindices = new((/nrows,ndelims/),integer) + do i = 0, nrows-1 + ii = ind(cstrings(i,:).eq.cdelim(0)) +; +; Make sure there were delimiters on this row. If not, we just quit. +; This could probably be modified to do this more gracefully. +; + if(any(ismissing(ii))) then + print("delim_indices: fatal: I didn't find any delimiters") + print("('" + delimiter + "') on row " + i + ". Can't continue.") + exit + end if + if(dimsizes(ii).ne.ndelims) then + print("delim_indices: fatal: I expected to find " + ndelims) + print("delimiters on row " + i + ". Instead, I found " + dimsizes(ii) + ".") + print("Can't continue.") + exit + end if + + cindices(i,:) = ii + + delete(ii) ; For next time through loop + end do + + return(cindices) +end + +;---------------------------------------------------------------------- +; This function reads in a particular field from a string array, +; given the field number to read (fields start at #1 and go to #nfield), +; and the indices of the delimiters. +; +; It returns either an integer, float, double, character, or a string, +; depending on the input flag "return_type". +;---------------------------------------------------------------------- +function read_field(strings,ifield,indices,return_type) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if + +; +; Set up array to return. For string, int, float, or double arrays, +; we don't have to do anything special. For character arrays, +; however, we do. +; + if(return_type.ne."character") then + return_array = new(nrows,return_type) + else +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + end if + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if +; +; Here's the code that pulls off the correct string, and converts it +; to float if desired. +; + if(return_type.eq."integer") then + return_array(i) = stringtointeger(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."float") then + return_array(i) = stringtofloat(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."double") then + return_array(i) = stringtodouble(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."string") then + return_array(i) = chartostring(cstrings(i,ibeg:iend)) + end if + if(return_type.eq."character") then + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + tmp_return_array(i,0:iend-ibeg) = cstrings(i,ibeg:iend) + end if + end do + + if(return_type.eq."character") then + return_array = new((/nrows,max_len/),"character") + return_array = tmp_return_array(:,0:max_len-1) + end if + + return(return_array) +end + + +;---------------------------------------------------------------------- +; This function reads in string fields only to get the maximum string +; length. +;---------------------------------------------------------------------- +function get_maxlen(strings,ifield,indices) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + end do + + return(max_len) +end + +;---------------------------------------------------------------------- +; Main code. +;---------------------------------------------------------------------- +begin + +;############################################################### +; Set up defaults. We are hard-coding here.. + + year = 2005 + lat = 35.9735823 + lon = -79.1004304 + 360. + + nfields = 30 ; # of fields + delimiter = "," ; field delimiter + + filename = year+".txt" ; ASCII" file to read. + cdf_file = year+"_L4_m.nc" ; netCDF file to write. + + if(isfilepresent(cdf_file)) + print("Warning: '" + cdf_file + "' exists. Will remove it.") + system("/bin/rm " + cdf_file) + end if + +; In this case, fields #1-#2 are integers, +; and the rest of the fields are floats. + + var_types = new(nfields,string) + var_types = "float" ; Most are floats. + var_types(0:1) = "integer" + +;##################################################################### + +; Read in data as strings. This will create a string array that has the +; same number of strings as there are rows in the file. We will then need +; to parse each string later. + + read_data = asciiread(filename,-1,"string") + + header = read_data(0) ; Header. Use for variable names. + data = read_data(1:) ; Get rid of first line which is a header. + nmonth = dimsizes(data) ; Number of rows == number of month. + +; Read in locations of delimiters in each string row. + + hindices = delim_indices(header,nfields,delimiter) ; header row + dindices = delim_indices(data,nfields,delimiter) ; rest of file + +; Read in the field names which will become variable names on +; the netCDF file. + + var_names = new(nfields,string) + + do i=0,nfields-1 + var_names(i) = read_field(header,i+1,hindices,"string") + end do + +;------------------------------------------------------------------- +; Write out this netCDF file efficiently so it will be faster. +; Try to predefine everything before you write to it. + + f = addfile(cdf_file,"c") + setfileoption(f,"DefineMode",True) ; Enter predefine phase. + +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. + + fAtt = True + fAtt@description = "Data read in from " + filename + " ASCII file." + fAtt@creation_date = systemfunc ("date") + fileattdef( f, fAtt ) + +; Write dimension names to file. + + dim_names = (/ "year", "month" /) + dim_sizes = (/ -1 , nmonth /) + dimUnlim = (/ True , False /) + filedimdef( f, dim_names, dim_sizes, dimUnlim ) + + filedimdef( f, "lat", 1, False ) + filedimdef( f, "lon", 1, False ) + +; Define each variable on the file. + + filevardef( f, "year", "integer", "year" ) + filevardef( f, "lat" , "float" , "lat" ) + filevardef( f, "lon" , "float" , "lon" ) + + do i=0,nfields-1 + +; define variable + + filevardef(f, var_names(i), var_types(i), dim_names) + +; define variable attributes + + if (i.le.1) then + varAtt = 0 +; varAtt@_FillValue = -999 + else + varAtt = 0. +; varAtt@_FillValue = 1.e36 + end if + + varAtt@long_name = var_names(i) + + filevarattdef( f, var_names(i) , varAtt ) + + delete (varAtt) + end do +;----------------------------------------------------------------- + +; Loop through each field, read the values for that field, print +; information about the variable, and then write it to the netCDF file. + + do i=0,nfields-1 + ifield = i+1 ; Fields start at #1, not #0. + + tmp_data = new((/1,nmonth/),var_types(i)) + + if (i.le.1) then + tmp_data@_FillValue = -999 + else + tmp_data@_FillValue = 1.e36 + end if + + tmp_data(0,:) = read_field(data,ifield,dindices,var_types(i)) + + tmp_data = where(tmp_data .le. -9000.,tmp_data@_FillValue,tmp_data) + +; change Month to yyyymm + + if (i.eq.0) then + tmp_data(0,:) = tmp_data(0,:) + year*100 + end if + +; Print some info about the variable. + +; print("") +; print("Writing variable '" + var_names(i) + "' (field #" + ifield + ").") +; print("Type is " + var_types(i) + ".") +; print("min/max = " + min(tmp_data) + "/" + max(tmp_data)) + +; if(any(ismissing(tmp_data))) then +; print("This variable does contain missing values.") +; else +; print("This variable doesn't contain missing values.") +; end if + +; write variable to file + + f->$var_names(i)$ = tmp_data ; Write to netCDF file. + + delete(tmp_data) ; Delete for next round. + end do + +; write variable to file + + f->year = year + f->lat = lat + f->lon = lon +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/07.missing_year.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/07.missing_year.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,63 @@ +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ + +begin + + year_new = 2000 + file_input = "1999_L4_m.nc" + file_output = year_new+"_L4_m.nc" + + a = addfile(file_input,"r") + b = addfile(file_output,"c") +;------------------------------------------------------------------- +; Enter predefine phase. + +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. + + fAtt = True + fAtt@description = "Data read in from " + file_input + fAtt@creation_date = systemfunc ("date") + fileattdef( b, fAtt ) + + filedimdef( b,"year",-1,True) +;------------------------------------------------------------------- + month_of_year = (/1,2,3,4,5,6,7,8,9,10,11,12/) + + Var = getfilevarnames(a) + nVar= dimsizes(Var) + +; do n = 0,nVar-1 +; print( (/Var(n)/)) +; end do + + do n = 0,nVar-1 + + if (Var(n).ne."year" .and. Var(n).ne."Month" .and. Var(n).ne."n_days" .and. Var(n).ne."lat" .and. Var(n).ne."lon" ) then + + temp = a->$Var(n)$ + temp(0,:) = -999. + b->$Var(n)$ = temp + else + + if (Var(n).eq."year") then + b->$Var(n)$ = year_new + end if + + if (Var(n).eq."Month") then + Month = a->$Var(n)$ + Month(0,:)= month_of_year + year_new * 100 + b->$Var(n)$ = Month + end if + + if (Var(n).eq."n_days" .or. Var(n).eq."lat" .or. Var(n).eq."lon") then + b->$Var(n)$ = a->$Var(n)$ + end if + + end if + end do + +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/07.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/07.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,63 @@ +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ + +begin + + year_new = 2000 + file_input = "1999_L4_m.nc" + file_output = year_new+"_L4_m.nc" + + a = addfile(file_input,"r") + b = addfile(file_output,"c") +;------------------------------------------------------------------- +; Enter predefine phase. + +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. + + fAtt = True + fAtt@description = "Data read in from " + file_input + fAtt@creation_date = systemfunc ("date") + fileattdef( b, fAtt ) + + filedimdef( b,"year",-1,True) +;------------------------------------------------------------------- + month_of_year = (/1,2,3,4,5,6,7,8,9,10,11,12/) + + Var = getfilevarnames(a) + nVar= dimsizes(Var) + +; do n = 0,nVar-1 +; print( (/Var(n)/)) +; end do + + do n = 0,nVar-1 + + if (Var(n).ne."year" .and. Var(n).ne."Month" .and. Var(n).ne."n_days" .and. Var(n).ne."lat" .and. Var(n).ne."lon" ) then + + temp = a->$Var(n)$ + temp(0,:) = -999. + b->$Var(n)$ = temp + else + + if (Var(n).eq."year") then + b->$Var(n)$ = year_new + end if + + if (Var(n).eq."Month") then + Month = a->$Var(n)$ + Month(0,:)= month_of_year + year_new * 100 + b->$Var(n)$ = Month + end if + + if (Var(n).eq."n_days" .or. Var(n).eq."lat" .or. Var(n).eq."lon") then + b->$Var(n)$ = a->$Var(n)$ + end if + + end if + end do + +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/10.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/10.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,575 @@ +;************************************************************ +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; using gsn_table for all +; output: line plot for each site (4 fields) +; table for M_score +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +; for 6 fields, 12-monthly + nmon = 12 + nfield = 6 + +;************************************************ +; read model data +;************************************************ +; model = "cn" + model = "casa" + + model_name = "i01.10" + model + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile(dirm+film,"r") + + xm = fm->lon + ym = fm->lat +;------------------------------------------------ + nlat = dimsizes(ym) + nlon = dimsizes(xm) + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + + ENERGY ="new" + +;************************************************ +; read data: observed +;************************************************ + + station = (/"HarvardForest" \ + /) + + year_ob = (/"1991-2004" \ + /) + + field = (/"CO2 Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + nstation = dimsizes(station) + + data_mod = new ((/nstation, nfield, nmon/),float) + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + + diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/" + dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + + do n = 0,nstation-1 + +;------------------------------------------------- +; get ob data + + diro = diro_root + station(n)+"/" + filo = station(n)+"_"+year_ob(n)+"_monthly.nc" + fo = addfile (diro+filo,"r") + + print (filo) + + lon_ob(n) = fo->lon + lat_ob(n) = fo->lat + + data = fo->NEE_or_fMDS + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Rg_f + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->LE_f + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->H_f + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->GPP_or_MDS + data_ob(n,4,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Reco_or + data_ob(n,5,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (fo) +;--------------------------------------------------- +; get model data + + film = model_name+"_"+year_ob(n)+"_MONS_climo.nc" + fm = addfile (dirm_root+film,"r") + + print (film) + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) +end if + + data = fm->GPP + data_mod0(4,:,:,:) = data(:,:,:) * factor + delete (data) + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + data_mod0(5,:,:,:) = data(:,:,:) * factor + delete (data) + + delete (fm) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0) + +; print (yy) + + data_mod(n,:,:) = yy(:,:,0) + + delete (yy) + + end do +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_gpp = sprintf("%.2f", M_gpp) + M_energy_er = sprintf("%.2f", M_er ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4 + + plot_data(0,:) = (/data_ob (n,4,:)/) + plot_data@long_name = field(4) + plot(4)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 5 + + plot_data(0,:) = (/data_ob (n,5,:)/) + plot_data@long_name = field(5) + plot(5)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 6 + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data(1,:) = (/data_mod(n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data(1,:) = (/data_mod(n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data(1,:) = (/data_mod(n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data(1,:) = (/data_mod(n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4 + + + plot_data(0,:) = (/data_ob (n,4,:)/) + plot_data(1,:) = (/data_mod(n,4,:)/) + plot_data@long_name = field(4) + plot(4)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 5 + + + plot_data(0,:) = (/data_ob (n,5,:)/) + plot_data(1,:) = (/data_mod(n,5,:)/) + plot_data@long_name = field(5) + plot(5)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 6 + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + + set_line(lines,nline,"
"+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + txt4 = sprintf("%5.2f", M_score(n,0)) + txt5 = sprintf("%5.2f", M_score(n,1)) + txt6 = sprintf("%5.2f", M_score(n,2)) + txt7 = sprintf("%5.2f", M_score(n,3)) + txt8 = sprintf("%5.2f", M_score(n,4)) + txt9 = sprintf("%5.2f", M_score(n,5)) + txt10 = sprintf("%5.2f", avg(M_score(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/11.ameriflux.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/11.ameriflux.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,910 @@ +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +;------------------------------------------------------ +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + end if + +;------------------------------------------------------ +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +;------------------------------------------------------ + + nmonth = 12 + +; for nee, gpp, and ar +; observed unit is gC/m2/day +; model unit is gC/m2/s +; to change to observed unit, + + factor_flux = 86400. + +; for incident solar radiation, +; observed Rg_f unit is MJ/m2/day +; model (FSDS) unit is W/m2 +; to change to model unit, + + factor_rad = 1.e6/86400. + +;************************************************ +; observed data info +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + field = (/"NEE Flux" \ + ,"Shortwave Incoming" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"gC/m2/day" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"gC/m2/day" \ + ,"gC/m2/day" \ + /) + + nstation = dimsizes(station) + nfield = dimsizes(field) + +;======================================================================== +; get observed info: number of year, first/last year, lat, lon +; and annual data + + dir_root = diro + "ameriflux/" + + year_station = new ((/nstation/),integer) ; number of year + year_ob = new ((/nstation/),string) ; observed year + year_ob_i = new ((/nstation/),integer) ; first year + year_ob_f = new ((/nstation/),integer) ; last year + lat_ob = new ((/nstation/),float) ; latitude + lon_ob = new ((/nstation/),float) ; longitude + + data_ob_ann = new ((/nfield, nmonth, nstation/),float) + + do n = 0, nstation-1 + + dir_f = dir_root + station(n)+"/" + fil_f = "timeseries_L4_m.nc" + fo = addfile (dir_f+fil_f,"r") + + lat_ob(n) = fo->lat + lon_ob(n) = fo->lon + + year = fo->year + + year_station(n) = dimsizes(year) + year_ob_i(n) = year(0) + year_ob_f(n) = year(year_station(n)-1) + year_ob(n) = year_ob_i(n) + "-" + year_ob_f(n) + + delete (year) + + data = fo->NEE_or_fMDS + data_ob_ann(0,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->Rg_f + data_ob_ann(1,:,n) = dim_avg(data(month|:,year|:)) * factor_rad + + data = fo->LE_f + data_ob_ann(2,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->H_f + data_ob_ann(3,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->GPP_or_MDS + data_ob_ann(4,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->Reco_or + data_ob_ann(5,:,n) = dim_avg(data(month|:,year|:)) + + delete (data) + delete (fo) + end do + +;-------------------------------------------------------------- +; find (# of year observed) >=4 and year_ob_i <= 2001 + + i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001) + + station_long = station(i_long_ob) + lat_ob_long = lat_ob(i_long_ob) + lon_ob_long = lat_ob(i_long_ob) + year_ob_long = year_ob(i_long_ob) + year_ob_i_long = year_ob_i(i_long_ob) + year_ob_f_long = year_ob_f(i_long_ob) + year_station_long = year_station(i_long_ob) + + nstation_long = dimsizes(station_long) + +;========================================================= +; get model data at observed lat-lon + + fm = addfile (dirm+film8,"r") + + xm = fm->lon + ym = fm->lat + date = fm->date + + date_dim = dimsizes(date) + nyear = date_dim(0) + + data_mod = new ((/nfield,nyear,nmonth,nstation/),float) + data_mod_ann = new ((/nfield,nmonth,nstation/),float) + data_mod_long = new ((/nfield,nyear,nmonth,nstation_long/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + + factor = 1.e6 /12. + +;------------------------------------------------------------ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. +;------------------------------------------------------------ + +if (ENERGY .eq. "old") then + + data = fm->NEE + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor_flux + data_mod(0,:,:,:) = yy(:,:,:) * factor_flux + +;;data = fm->NETRAD +; data = fm->FSA +; data1 = fm->FIRA +; data = data - data1 +; delete (data1) + + data = fm->FSDS + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(1,:,:,:) = yy(:,:,:) + + +; data = fm->LATENT + data = fm->FCEV + data1 = fm->FCTR + data2 = fm->FGEV + data = data + data1 + data2 + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(2,:,:,:) = yy(:,:,:) + delete (data1) + delete (data2) + +; data = fm->SENSIBLE + data = fm->FSH + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(3,:,:,:) = yy(:,:,:) + +else + + data = fm->NEE + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor_flux + data_mod(0,:,:,:) = yy(:,:,:) * factor_flux + +; data = fm->NETRAD + data = fm->FSDS + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(1,:,:,:) = yy(:,:,:) + + data = fm->LATENT + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(2,:,:,:) = yy(:,:,:) + +; data = fm->SENSIBLE + data = fm->FSH + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(3,:,:,:) = yy(:,:,:) + +end if + + data = fm->GPP + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(4,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor_flux + data_mod(4,:,:,:) = yy(:,:,:) * factor_flux + + data = fm->ER + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(5,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor_flux + data_mod(5,:,:,:) = yy(:,:,:) * factor_flux + + data_mod_long(:,:,:,:) = data_mod(:,:,:,i_long_ob) + + delete (data_mod) + delete (fm) + delete (data) + delete (yy) + + asciiwrite(station(0)+"_ob.txt", data_ob_ann(:,:,0)) + asciiwrite(station(0)+"_"+model_name+".txt", data_mod_ann(:,:,0)) + + asciiwrite(station(7)+"_ob.txt", data_ob_ann(:,:,7)) + asciiwrite(station(7)+"_"+model_name+".txt", data_mod_ann(:,:,7)) + + asciiwrite(station(21)+"_ob.txt", data_ob_ann(:,:,21)) + asciiwrite(station(21)+"_"+model_name+".txt", data_mod_ann(:,:,21)) + + asciiwrite(station(44)+"_ob.txt", data_ob_ann(:,:,44)) + asciiwrite(station(44)+"_"+model_name+".txt", data_mod_ann(:,:,44)) + + asciiwrite(station(50)+"_ob.txt", data_ob_ann(:,:,50)) + asciiwrite(station(50)+"_"+model_name+".txt", data_mod_ann(:,:,50)) + + asciiwrite(station(54)+"_ob.txt", data_ob_ann(:,:,54)) + asciiwrite(station(54)+"_"+model_name+".txt", data_mod_ann(:,:,54)) + + asciiwrite(station(62)+"_ob.txt", data_ob_ann(:,:,62)) + asciiwrite(station(62)+"_"+model_name+".txt", data_mod_ann(:,:,62)) +exit + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) + + res@tmXBFormat = "f" ; not to add trailing zeros + +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + +;============================================================== +; get ob data at each site with long observation + + do n = 0,nstation_long-1 + +;################################################################## +; hardwired: model up to year 2004 +; observed up to year 2006 + + year_setback = 0 + + nyear = year_station_long(n) + + if (year_ob_f_long(n).eq. 2006) then + year_setback = 2006 -2004 + end if + if (year_ob_f_long(n).eq. 2005) then + year_setback = 2005 -2004 + end if +;################################################################## + + ntime = (nyear - year_setback) * nmonth + + data_ob = new ((/nfield, nyear, nmonth/),float) + + dir_f = dir_root + station_long(n)+"/" + fil_f = "timeseries_L4_m.nc" + fo = addfile (dir_f+fil_f,"r") + + data_ob(0,:,:) = fo->NEE_or_fMDS + data_ob(1,:,:) = fo->Rg_f + data_ob(2,:,:) = fo->LE_f + data_ob(3,:,:) = fo->H_f + data_ob(4,:,:) = fo->GPP_or_MDS + data_ob(5,:,:) = fo->Reco_or + + data_ob(1,:,:) = data_ob(1,:,:) * factor_rad + + delete (fo) + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_ob_i_long(n) + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + +;---------------------------- +; for model_vs_ob + + plot_name = station_long(n)+"_tseries_vs_ob" + title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + i_year_mod_i = year_ob_i_long(n) - 1990 + i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback + + i_year_ob_f = nyear - year_setback - 1 + +; print (nyear) +; print (i_year_ob_f) +; print (i_year_mod_i) +; print (i_year_mod_f) + + do i = 0,nfield-1 + plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:)) + plot_data(1,:) = ndtooned(data_mod_long(i,i_year_mod_i:i_year_mod_f,:,n)) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,timeF,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + delete (data_ob) + delete (timeI) + delete (timeF) + delete (plot_data) + + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) + + isort = dim_pqsort(lat_ob_long,-1) + + station_sort = station_long(isort) + year_ob_sort = year_ob_long(isort) + lat_ob_sort = lat_ob_long(isort) + lon_ob_sort = lon_ob_long(isort) + +; print(isort) +; print(lat_ob_sort) + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "tseries_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Timeseries at Site: "+model_name+" vs Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation_long-1 + + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + + delete (isort) + delete (station_sort) + delete (year_ob_sort) + delete (lat_ob_sort) + delete (lon_ob_sort) + +;************************************************************ +; compute annual cycle correlation coef and M score +;************************************************************ + + score_max = 1. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob_ann(m,:,n),data_mod_ann(m,:,n),0) + 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)))) + M_score(n,m) = (1. -(bias/nmonth)) * score_max + end do + end do + + M_nee = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_nee+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_ameriflux_nee = sprintf("%.2f", M_nee) + M_ameriflux_rad = sprintf("%.2f", M_rad) + M_ameriflux_lh = sprintf("%.2f", M_lh ) + M_ameriflux_sh = sprintf("%.2f", M_sh ) + M_ameriflux_gpp = sprintf("%.2f", M_gpp) + M_ameriflux_er = sprintf("%.2f", M_er ) + M_ameriflux_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + +;------------------------------------------------------------------- + + plot_data = new((/2,nmonth/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob_ann(i,:,n)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob_ann(i,:,n)/) + plot_data(1,:) = (/data_mod_ann(i,:,n)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) +; sort by lat in decending order (N->S) + + isort = dim_pqsort(lat_ob,-1) + + station_sort = station(isort) + year_ob_sort = year_ob(isort) + lat_ob_sort = lat_ob(isort) + lon_ob_sort = lon_ob(isort) + M_score_sort = M_score(isort,:) + +; print(isort) +; print(lat_ob_sort) +;################################################################### +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedNEE FluxShortwave
Incoming
Latent HeatSensible HeatGPP FluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + txt4 = sprintf("%5.2f", M_score_sort(n,0)) + txt5 = sprintf("%5.2f", M_score_sort(n,1)) + txt6 = sprintf("%5.2f", M_score_sort(n,2)) + txt7 = sprintf("%5.2f", M_score_sort(n,3)) + txt8 = sprintf("%5.2f", M_score_sort(n,4)) + txt9 = sprintf("%5.2f", M_score_sort(n,5)) + txt10 = sprintf("%5.2f", avg(M_score_sort(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_ameriflux_nee + txt5 = M_ameriflux_rad + txt6 = M_ameriflux_lh + txt7 = M_ameriflux_sh + txt8 = M_ameriflux_gpp + txt9 = M_ameriflux_er + txt10 = M_ameriflux_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;************************************************************************************** +; update score +;************************************************************************************** + + if (isvar("compare")) then + system("sed 1,/M_ameriflux_nee/s//"+M_ameriflux_nee+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed 1,/M_ameriflux_rad/s//"+M_ameriflux_rad+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed 1,/M_ameriflux_lh/s//"+M_ameriflux_lh+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed 1,/M_ameriflux_sh/s//"+M_ameriflux_sh+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed 1,/M_ameriflux_gpp/s//"+M_ameriflux_gpp+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed 1,/M_ameriflux_er/s//"+M_ameriflux_er+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_ameriflux_nee#"+M_ameriflux_nee+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_ameriflux_rad#"+M_ameriflux_rad+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_ameriflux_lh#"+M_ameriflux_lh+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_ameriflux_sh#"+M_ameriflux_sh+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_ameriflux_gpp#"+M_ameriflux_gpp+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_ameriflux_er#"+M_ameriflux_er+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + +;*************************************************************************** +; add total score and write to file +;*************************************************************************** + M_total = M_ameriflux_all + + asciiwrite("M_save.ameriflux", M_total) + +;*************************************************************************** +; output plot and html +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** + +end + diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/11.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/11.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,581 @@ +;************************************************************ +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; using gsn_table for all +; output: line plot for each site (4 fields) +; table for M_score +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +; for 6 fields, 12-monthly + nmon = 12 + nfield = 6 + +;************************************************ +; read model data +;************************************************ +; model = "cn" + model = "casa" + + model_name = "i01.10" + model + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile(dirm+film,"r") + + xm = fm->lon + ym = fm->lat +;------------------------------------------------ + nlat = dimsizes(ym) + nlon = dimsizes(xm) + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + + ENERGY ="new" + +;************************************************ +; read data: observed +;************************************************ + + station = (/"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"HarvardForest" \ + /) + + year_ob = (/"2003-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"1991-2004" \ + /) + + field = (/"CO2 Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + nstation = dimsizes(station) + + data_mod = new ((/nstation, nfield, nmon/),float) + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + + diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/" + dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + + do n = 0,nstation-1 + +;------------------------------------------------- +; get ob data + + diro = diro_root + station(n)+"/" + filo = year_ob(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + print (filo) + + lon_ob(n) = fo->lon + lat_ob(n) = fo->lat + + data = fo->NEE_or_fMDS + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Rg_f + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->LE_f + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->H_f + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->GPP_or_MDS + data_ob(n,4,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Reco_or + data_ob(n,5,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (fo) +;--------------------------------------------------- +; get model data + + film = model_name+"_"+year_ob(n)+"_MONS_climo.nc" + fm = addfile (dirm_root+film,"r") + + print (film) + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) +end if + + data = fm->GPP + data_mod0(4,:,:,:) = data(:,:,:) * factor + delete (data) + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + data_mod0(5,:,:,:) = data(:,:,:) * factor + delete (data) + + delete (fm) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0) + +; print (yy) + + data_mod(n,:,:) = yy(:,:,0) + + delete (yy) + + end do +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_gpp = sprintf("%.2f", M_gpp) + M_energy_er = sprintf("%.2f", M_er ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4 + + plot_data(0,:) = (/data_ob (n,4,:)/) + plot_data@long_name = field(4) + plot(4)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 5 + + plot_data(0,:) = (/data_ob (n,5,:)/) + plot_data@long_name = field(5) + plot(5)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 6 + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data(1,:) = (/data_mod(n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data(1,:) = (/data_mod(n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data(1,:) = (/data_mod(n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data(1,:) = (/data_mod(n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4 + + + plot_data(0,:) = (/data_ob (n,4,:)/) + plot_data(1,:) = (/data_mod(n,4,:)/) + plot_data@long_name = field(4) + plot(4)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 5 + + + plot_data(0,:) = (/data_ob (n,5,:)/) + plot_data(1,:) = (/data_mod(n,5,:)/) + plot_data@long_name = field(5) + plot(5)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 6 + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + txt4 = sprintf("%5.2f", M_score(n,0)) + txt5 = sprintf("%5.2f", M_score(n,1)) + txt6 = sprintf("%5.2f", M_score(n,2)) + txt7 = sprintf("%5.2f", M_score(n,3)) + txt8 = sprintf("%5.2f", M_score(n,4)) + txt9 = sprintf("%5.2f", M_score(n,5)) + txt10 = sprintf("%5.2f", avg(M_score(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/12.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/12.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,722 @@ +;************************************************************ +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; using gsn_table for all +; output: line plot for each site (4 fields) +; table for M_score +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +; for 6 fields, 12-monthly + nmon = 12 + nfield = 6 + +;************************************************ +; read model data +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile(dirm+film,"r") + + xm = fm->lon + ym = fm->lat +;------------------------------------------------ + nlat = dimsizes(ym) + nlon = dimsizes(xm) + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + + ENERGY ="new" + +;************************************************ +; read data: observed +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + year_ob = (/"2003-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1999-2006" \ + ,"2002-2006" \ + ,"2000-2005" \ + ,"2004-2005" \ + ,"1996-2006" \ + ,"2004-2006" \ + ,"1999-2004" \ + ,"2003-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2005-2006" \ + ,"2004-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2000-2006" \ + ,"2004-2006" \ + ,"2002-2006" \ + ,"1991-2004" \ + ,"2004-2004" \ + ,"1996-2004" \ + ,"1999-2004" \ + ,"2003-2006" \ + ,"2004-2006" \ + ,"2002-2002" \ + ,"2000-2006" \ + ,"2002-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2004-2005" \ + ,"2004-2005" \ + ,"2003-2005" \ + ,"1996-2000" \ + ,"2004-2006" \ + ,"1998-2004" \ + ,"1999-2005" \ + ,"1999-2003" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1996-2003" \ + ,"1998-1998" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2002-2006" \ + ,"2004-2005" \ + ,"2001-2006" \ + ,"2004-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2004" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2005" \ + ,"1999-2003" \ + ,"2001-2006" \ + ,"1995-1999" \ + ,"1999-2005" \ + ,"1999-2004" \ + ,"2003-2003" \ + ,"2003-2003" \ + ,"2002-2005" \ + ,"2004-2004" \ + ,"2002-2002" \ + ,"2005-2005" \ + ,"2002-2002" \ + ,"2004-2005" \ + ,"2002-2002" \ + /) + + field = (/"CO2 Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + nstation = dimsizes(station) + + data_mod = new ((/nstation, nfield, nmon/),float) + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + + diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + + do n = 0,nstation-1 + +;------------------------------------------------- +; get ob data + + diro = diro_root + station(n)+"/" + filo = year_ob(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + print (filo) + + lon_ob(n) = fo->lon + lat_ob(n) = fo->lat + + data = fo->NEE_or_fMDS + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Rg_f + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->LE_f + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->H_f + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->GPP_or_MDS + data_ob(n,4,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Reco_or + data_ob(n,5,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (fo) +;--------------------------------------------------- +; get model data + +; film = model_name+"_"+ year_ob(n)+"_MONS_climo.nc" + film = model_name+"_"+"1990-2004"+"_MONS_climo.nc" + fm = addfile (dirm_root+film,"r") + + print (film) + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) +end if + + data = fm->GPP + data_mod0(4,:,:,:) = data(:,:,:) * factor + delete (data) + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + data_mod0(5,:,:,:) = data(:,:,:) * factor + delete (data) + + delete (fm) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0) + +; print (yy) + + data_mod(n,:,:) = yy(:,:,0) + + delete (yy) + + end do +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_gpp = sprintf("%.2f", M_gpp) + M_energy_er = sprintf("%.2f", M_er ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4 + + plot_data(0,:) = (/data_ob (n,4,:)/) + plot_data@long_name = field(4) + plot(4)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 5 + + plot_data(0,:) = (/data_ob (n,5,:)/) + plot_data@long_name = field(5) + plot(5)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 6 + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data(1,:) = (/data_mod(n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data(1,:) = (/data_mod(n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data(1,:) = (/data_mod(n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data(1,:) = (/data_mod(n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4 + + + plot_data(0,:) = (/data_ob (n,4,:)/) + plot_data(1,:) = (/data_mod(n,4,:)/) + plot_data@long_name = field(4) + plot(4)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 5 + + + plot_data(0,:) = (/data_ob (n,5,:)/) + plot_data(1,:) = (/data_mod(n,5,:)/) + plot_data@long_name = field(5) + plot(5)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 6 + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + txt4 = sprintf("%5.2f", M_score(n,0)) + txt5 = sprintf("%5.2f", M_score(n,1)) + txt6 = sprintf("%5.2f", M_score(n,2)) + txt7 = sprintf("%5.2f", M_score(n,3)) + txt8 = sprintf("%5.2f", M_score(n,4)) + txt9 = sprintf("%5.2f", M_score(n,5)) + txt10 = sprintf("%5.2f", avg(M_score(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/13.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/13.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,683 @@ +;************************************************************ +; change long_name +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +; for 6 fields, 12-monthly + nmon = 12 + nfield = 6 + +;************************************************ +; read model data +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile(dirm+film,"r") + + xm = fm->lon + ym = fm->lat +;------------------------------------------------ + nlat = dimsizes(ym) + nlon = dimsizes(xm) + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + + ENERGY ="new" + +;************************************************ +; read data: observed +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + year_ob = (/"2003-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1999-2006" \ + ,"2002-2006" \ + ,"2000-2005" \ + ,"2004-2005" \ + ,"1996-2006" \ + ,"2004-2006" \ + ,"1999-2004" \ + ,"2003-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2005-2006" \ + ,"2004-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2000-2006" \ + ,"2004-2006" \ + ,"2002-2006" \ + ,"1991-2004" \ + ,"2004-2004" \ + ,"1996-2004" \ + ,"1999-2004" \ + ,"2003-2006" \ + ,"2004-2006" \ + ,"2002-2002" \ + ,"2000-2006" \ + ,"2002-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2004-2005" \ + ,"2004-2005" \ + ,"2003-2005" \ + ,"1996-2000" \ + ,"2004-2006" \ + ,"1998-2004" \ + ,"1999-2005" \ + ,"1999-2003" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1996-2003" \ + ,"1998-1998" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2002-2006" \ + ,"2004-2005" \ + ,"2001-2006" \ + ,"2004-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2004" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2005" \ + ,"1999-2003" \ + ,"2001-2006" \ + ,"1995-1999" \ + ,"1999-2005" \ + ,"1999-2004" \ + ,"2003-2003" \ + ,"2003-2003" \ + ,"2002-2005" \ + ,"2004-2004" \ + ,"2002-2002" \ + ,"2005-2005" \ + ,"2002-2002" \ + ,"2004-2005" \ + ,"2002-2002" \ + /) + + field = (/"NEE Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"u mol/m2/s" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"u mol/m2/s" \ + ,"u mol/m2/s" \ + /) + + nstation = dimsizes(station) + + data_mod = new ((/nstation, nfield, nmon/),float) + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + unit_ob = new ((/nfield/),string) + + diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + + do n = 0,nstation-1 + +;------------------------------------------------- +; get ob data + + diro = diro_root + station(n)+"/" + filo = year_ob(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + print (filo) + + lon_ob(n) = fo->lon + lat_ob(n) = fo->lat + + data = fo->NEE_or_fMDS + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Rg_f + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->LE_f + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->H_f + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->GPP_or_MDS + data_ob(n,4,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Reco_or + data_ob(n,5,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (fo) +;--------------------------------------------------- +; get model data + +; film = model_name+"_"+ year_ob(n)+"_MONS_climo.nc" + film = model_name+"_"+"1990-2004"+"_MONS_climo.nc" + fm = addfile (dirm_root+film,"r") + + print (film) + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) +end if + + data = fm->GPP + data_mod0(4,:,:,:) = data(:,:,:) * factor + delete (data) + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + data_mod0(5,:,:,:) = data(:,:,:) * factor + delete (data) + + delete (fm) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0) + +; print (yy) + + data_mod(n,:,:) = yy(:,:,0) + + delete (yy) + + end do +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_gpp = sprintf("%.2f", M_gpp) + M_energy_er = sprintf("%.2f", M_er ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob (n,i,:)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob (n,i,:)/) + plot_data(1,:) = (/data_mod(n,i,:)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + txt4 = sprintf("%5.2f", M_score(n,0)) + txt5 = sprintf("%5.2f", M_score(n,1)) + txt6 = sprintf("%5.2f", M_score(n,2)) + txt7 = sprintf("%5.2f", M_score(n,3)) + txt8 = sprintf("%5.2f", M_score(n,4)) + txt9 = sprintf("%5.2f", M_score(n,5)) + txt10 = sprintf("%5.2f", avg(M_score(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/14.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/14.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,854 @@ +;************************************************************ +; sort by latitude in decending order (N->S) +; add year_ob_i and year_ob_f +; change long_name +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +; for 6 fields, 12-monthly + nmon = 12 + nfield = 6 + +;************************************************ +; read model data +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile(dirm+film,"r") + + xm = fm->lon + ym = fm->lat +;------------------------------------------------ + nlat = dimsizes(ym) + nlon = dimsizes(xm) + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + + ENERGY ="new" + +;************************************************ +; read data: observed +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + year_ob = (/"2003-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1999-2006" \ + ,"2002-2006" \ + ,"2000-2005" \ + ,"2004-2005" \ + ,"1996-2006" \ + ,"2004-2006" \ + ,"1999-2004" \ + ,"2003-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2005-2006" \ + ,"2004-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2000-2006" \ + ,"2004-2006" \ + ,"2002-2006" \ + ,"1991-2004" \ + ,"2004-2004" \ + ,"1996-2004" \ + ,"1999-2004" \ + ,"2003-2006" \ + ,"2004-2006" \ + ,"2002-2002" \ + ,"2000-2006" \ + ,"2002-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2004-2005" \ + ,"2004-2005" \ + ,"2003-2005" \ + ,"1996-2000" \ + ,"2004-2006" \ + ,"1998-2004" \ + ,"1999-2005" \ + ,"1999-2003" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1996-2003" \ + ,"1998-1998" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2002-2006" \ + ,"2004-2005" \ + ,"2001-2006" \ + ,"2004-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2004" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2005" \ + ,"1999-2003" \ + ,"2001-2006" \ + ,"1995-1999" \ + ,"1999-2005" \ + ,"1999-2004" \ + ,"2003-2003" \ + ,"2003-2003" \ + ,"2002-2005" \ + ,"2004-2004" \ + ,"2002-2002" \ + ,"2005-2005" \ + ,"2002-2002" \ + ,"2004-2005" \ + ,"2002-2002" \ + /) + + year_ob_i = (/2003 \ + ,2005 \ + ,2005 \ + ,1999 \ + ,2002 \ + ,2000 \ + ,2004 \ + ,1996 \ + ,2004 \ + ,1999 \ + ,2003 \ + ,2001 \ + ,2001 \ + ,2005 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2000 \ + ,2004 \ + ,2002 \ + ,1991 \ + ,2004 \ + ,1996 \ + ,1999 \ + ,2003 \ + ,2004 \ + ,2002 \ + ,2000 \ + ,2002 \ + ,2001 \ + ,2001 \ + ,2001 \ + ,2001 \ + ,2004 \ + ,2004 \ + ,2003 \ + ,1996 \ + ,2004 \ + ,1998 \ + ,1999 \ + ,1999 \ + ,2005 \ + ,2005 \ + ,1996 \ + ,1998 \ + ,2004 \ + ,1997 \ + ,2004 \ + ,1997 \ + ,2002 \ + ,2004 \ + ,2001 \ + ,2004 \ + ,2001 \ + ,2001 \ + ,2002 \ + ,2001 \ + ,2001 \ + ,2002 \ + ,1999 \ + ,2001 \ + ,1995 \ + ,1999 \ + ,1999 \ + ,2003 \ + ,2003 \ + ,2002 \ + ,2004 \ + ,2002 \ + ,2005 \ + ,2002 \ + ,2004 \ + ,2002 \ + /) + + year_ob_f = (/2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2006 \ + ,2006 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2004 \ + ,2004 \ + ,2004 \ + ,2004 \ + ,2006 \ + ,2006 \ + ,2002 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2000 \ + ,2006 \ + ,2004 \ + ,2005 \ + ,2003 \ + ,2006 \ + ,2006 \ + ,2003 \ + ,1998 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2005 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2003 \ + ,2006 \ + ,1999 \ + ,2005 \ + ,2004 \ + ,2003 \ + ,2003 \ + ,2005 \ + ,2004 \ + ,2002 \ + ,2005 \ + ,2002 \ + ,2005 \ + ,2002 \ + /) + + field = (/"NEE Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"u mol/m2/s" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"u mol/m2/s" \ + ,"u mol/m2/s" \ + /) + + nstation = dimsizes(station) + + data_mod = new ((/nstation, nfield, nmon/),float) + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + unit_ob = new ((/nfield/),string) + + diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + + do n = 0,nstation-1 + +;------------------------------------------------- +; get ob data + + diro = diro_root + station(n)+"/" + filo = year_ob_i(n)+"-"+year_ob_f(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + print (filo) + + lon_ob(n) = fo->lon + lat_ob(n) = fo->lat + + data = fo->NEE_or_fMDS + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Rg_f + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->LE_f + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->H_f + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->GPP_or_MDS + data_ob(n,4,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Reco_or + data_ob(n,5,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (fo) +;--------------------------------------------------- +; get model data + +; film = model_name+"_"+ year_ob(n)+"_MONS_climo.nc" + film = model_name+"_"+"1990-2004"+"_MONS_climo.nc" + fm = addfile (dirm_root+film,"r") + +; print (film) + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) +end if + + data = fm->GPP + data_mod0(4,:,:,:) = data(:,:,:) * factor + delete (data) + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + data_mod0(5,:,:,:) = data(:,:,:) * factor + delete (data) + + delete (fm) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0) + +; print (yy) + + data_mod(n,:,:) = yy(:,:,0) + + delete (yy) + + end do + +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_gpp = sprintf("%.2f", M_gpp) + M_energy_er = sprintf("%.2f", M_er ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob (n,i,:)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob (n,i,:)/) + plot_data(1,:) = (/data_mod(n,i,:)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) +; sort by lat in decending order (N->S) + + isort = dim_pqsort(lat_ob,-1) + + station_sort = station(isort) + lat_ob_sort = lat_ob(isort) + lon_ob_sort = lon_ob(isort) + year_ob_sort = year_ob(isort) + M_score_sort = M_score(isort,:) + + print(isort) + print(lat_ob_sort) +;################################################################### +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + txt4 = sprintf("%5.2f", M_score_sort(n,0)) + txt5 = sprintf("%5.2f", M_score_sort(n,1)) + txt6 = sprintf("%5.2f", M_score_sort(n,2)) + txt7 = sprintf("%5.2f", M_score_sort(n,3)) + txt8 = sprintf("%5.2f", M_score_sort(n,4)) + txt9 = sprintf("%5.2f", M_score_sort(n,5)) + txt10 = sprintf("%5.2f", avg(M_score_sort(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/15.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/15.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,858 @@ +;************************************************************ +; find year_ob >= 4 +; add year_ob_i and year_ob_f +; change long_name +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +; for 6 fields, 12-monthly + nmon = 12 + nfield = 6 + +;************************************************ +; read model data +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile(dirm+film,"r") + + xm = fm->lon + ym = fm->lat +;------------------------------------------------ + nlat = dimsizes(ym) + nlon = dimsizes(xm) + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + + ENERGY ="new" + +;************************************************ +; read data: observed +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + year_ob = (/"2003-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1999-2006" \ + ,"2002-2006" \ + ,"2000-2005" \ + ,"2004-2005" \ + ,"1996-2006" \ + ,"2004-2006" \ + ,"1999-2004" \ + ,"2003-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2005-2006" \ + ,"2004-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2000-2006" \ + ,"2004-2006" \ + ,"2002-2006" \ + ,"1991-2004" \ + ,"2004-2004" \ + ,"1996-2004" \ + ,"1999-2004" \ + ,"2003-2006" \ + ,"2004-2006" \ + ,"2002-2002" \ + ,"2000-2006" \ + ,"2002-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2004-2005" \ + ,"2004-2005" \ + ,"2003-2005" \ + ,"1996-2000" \ + ,"2004-2006" \ + ,"1998-2004" \ + ,"1999-2005" \ + ,"1999-2003" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1996-2003" \ + ,"1998-1998" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2002-2006" \ + ,"2004-2005" \ + ,"2001-2006" \ + ,"2004-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2004" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2005" \ + ,"1999-2003" \ + ,"2001-2006" \ + ,"1995-1999" \ + ,"1999-2005" \ + ,"1999-2004" \ + ,"2003-2003" \ + ,"2003-2003" \ + ,"2002-2005" \ + ,"2004-2004" \ + ,"2002-2002" \ + ,"2005-2005" \ + ,"2002-2002" \ + ,"2004-2005" \ + ,"2002-2002" \ + /) + + year_ob_i = (/2003 \ + ,2005 \ + ,2005 \ + ,1999 \ + ,2002 \ + ,2000 \ + ,2004 \ + ,1996 \ + ,2004 \ + ,1999 \ + ,2003 \ + ,2001 \ + ,2001 \ + ,2005 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2000 \ + ,2004 \ + ,2002 \ + ,1991 \ + ,2004 \ + ,1996 \ + ,1999 \ + ,2003 \ + ,2004 \ + ,2002 \ + ,2000 \ + ,2002 \ + ,2001 \ + ,2001 \ + ,2001 \ + ,2001 \ + ,2004 \ + ,2004 \ + ,2003 \ + ,1996 \ + ,2004 \ + ,1998 \ + ,1999 \ + ,1999 \ + ,2005 \ + ,2005 \ + ,1996 \ + ,1998 \ + ,2004 \ + ,1997 \ + ,2004 \ + ,1997 \ + ,2002 \ + ,2004 \ + ,2001 \ + ,2004 \ + ,2001 \ + ,2001 \ + ,2002 \ + ,2001 \ + ,2001 \ + ,2002 \ + ,1999 \ + ,2001 \ + ,1995 \ + ,1999 \ + ,1999 \ + ,2003 \ + ,2003 \ + ,2002 \ + ,2004 \ + ,2002 \ + ,2005 \ + ,2002 \ + ,2004 \ + ,2002 \ + /) + + year_ob_f = (/2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2006 \ + ,2006 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2004 \ + ,2004 \ + ,2004 \ + ,2004 \ + ,2006 \ + ,2006 \ + ,2002 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2000 \ + ,2006 \ + ,2004 \ + ,2005 \ + ,2003 \ + ,2006 \ + ,2006 \ + ,2003 \ + ,1998 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2005 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2003 \ + ,2006 \ + ,1999 \ + ,2005 \ + ,2004 \ + ,2003 \ + ,2003 \ + ,2005 \ + ,2004 \ + ,2002 \ + ,2005 \ + ,2002 \ + ,2005 \ + ,2002 \ + /) + + year_ob_long = ind((year_ob_f - year_ob_i) .ge. 4 .and. year_ob_i .le. 2001) + print (year_ob_long) + print (year_ob_i(year_ob_long)) + + + field = (/"NEE Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"u mol/m2/s" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"u mol/m2/s" \ + ,"u mol/m2/s" \ + /) + +;nstation = dimsizes(station) + nstation = dimsizes(year_ob_long) + + data_mod = new ((/nstation, nfield, nmon/),float) + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + unit_ob = new ((/nfield/),string) + + diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + + do n = 0,nstation-1 + +;------------------------------------------------- +; get ob data + +; nn = n + nn = year_ob_long(n) + + diro = diro_root + station(nn)+"/" + filo = year_ob_i(nn)+"-"+year_ob_f(nn)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + print (filo) + + lon_ob(n) = fo->lon + lat_ob(n) = fo->lat + + data = fo->NEE_or_fMDS + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Rg_f + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->LE_f + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->H_f + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->GPP_or_MDS + data_ob(n,4,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Reco_or + data_ob(n,5,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (fo) +;--------------------------------------------------- +; get model data + +; film = model_name+"_"+ year_ob(n)+"_MONS_climo.nc" + film = model_name+"_"+"1990-2004"+"_MONS_climo.nc" + fm = addfile (dirm_root+film,"r") + +; print (film) + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) +end if + + data = fm->GPP + data_mod0(4,:,:,:) = data(:,:,:) * factor + delete (data) + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + data_mod0(5,:,:,:) = data(:,:,:) * factor + delete (data) + + delete (fm) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0) + +; print (yy) + + data_mod(n,:,:) = yy(:,:,0) + + delete (yy) + + end do +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_gpp = sprintf("%.2f", M_gpp) + M_energy_er = sprintf("%.2f", M_er ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 + +; nn = n + nn = year_ob_long(n) + +;---------------------------- +; for observed + + plot_name = station(nn)+"_ob" + title = station(nn)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob (n,i,:)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(nn)+"_model_vs_ob" + title = station(nn)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob (n,i,:)/) + plot_data(1,:) = (/data_mod(n,i,:)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + +; nn = n + nn = year_ob_long(n) + + set_line(lines,nline,row_header) + + txt0 = station(nn) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(nn) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + +; nn = n + nn = year_ob_long(n) + + set_line(lines,nline,row_header) + + txt0 = station(nn) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(nn) + txt4 = sprintf("%5.2f", M_score(n,0)) + txt5 = sprintf("%5.2f", M_score(n,1)) + txt6 = sprintf("%5.2f", M_score(n,2)) + txt7 = sprintf("%5.2f", M_score(n,3)) + txt8 = sprintf("%5.2f", M_score(n,4)) + txt9 = sprintf("%5.2f", M_score(n,5)) + txt10 = sprintf("%5.2f", avg(M_score(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/16.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/16.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,872 @@ +;************************************************************ +; sort by latitude in decending order (N->S) +; find year_ob >= 4 +; add year_ob_i and year_ob_f +; change long_name +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +; for 6 fields, 12-monthly + nmon = 12 + nfield = 6 + +;************************************************ +; read model data +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile(dirm+film,"r") + + xm = fm->lon + ym = fm->lat +;------------------------------------------------ + nlat = dimsizes(ym) + nlon = dimsizes(xm) + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + + ENERGY ="new" + +;************************************************ +; read data: observed +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + year_ob = (/"2003-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1999-2006" \ + ,"2002-2006" \ + ,"2000-2005" \ + ,"2004-2005" \ + ,"1996-2006" \ + ,"2004-2006" \ + ,"1999-2004" \ + ,"2003-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2005-2006" \ + ,"2004-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2000-2006" \ + ,"2004-2006" \ + ,"2002-2006" \ + ,"1991-2004" \ + ,"2004-2004" \ + ,"1996-2004" \ + ,"1999-2004" \ + ,"2003-2006" \ + ,"2004-2006" \ + ,"2002-2002" \ + ,"2000-2006" \ + ,"2002-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2004-2005" \ + ,"2004-2005" \ + ,"2003-2005" \ + ,"1996-2000" \ + ,"2004-2006" \ + ,"1998-2004" \ + ,"1999-2005" \ + ,"1999-2003" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1996-2003" \ + ,"1998-1998" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2002-2006" \ + ,"2004-2005" \ + ,"2001-2006" \ + ,"2004-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2004" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2005" \ + ,"1999-2003" \ + ,"2001-2006" \ + ,"1995-1999" \ + ,"1999-2005" \ + ,"1999-2004" \ + ,"2003-2003" \ + ,"2003-2003" \ + ,"2002-2005" \ + ,"2004-2004" \ + ,"2002-2002" \ + ,"2005-2005" \ + ,"2002-2002" \ + ,"2004-2005" \ + ,"2002-2002" \ + /) + + year_ob_i = (/2003 \ + ,2005 \ + ,2005 \ + ,1999 \ + ,2002 \ + ,2000 \ + ,2004 \ + ,1996 \ + ,2004 \ + ,1999 \ + ,2003 \ + ,2001 \ + ,2001 \ + ,2005 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2000 \ + ,2004 \ + ,2002 \ + ,1991 \ + ,2004 \ + ,1996 \ + ,1999 \ + ,2003 \ + ,2004 \ + ,2002 \ + ,2000 \ + ,2002 \ + ,2001 \ + ,2001 \ + ,2001 \ + ,2001 \ + ,2004 \ + ,2004 \ + ,2003 \ + ,1996 \ + ,2004 \ + ,1998 \ + ,1999 \ + ,1999 \ + ,2005 \ + ,2005 \ + ,1996 \ + ,1998 \ + ,2004 \ + ,1997 \ + ,2004 \ + ,1997 \ + ,2002 \ + ,2004 \ + ,2001 \ + ,2004 \ + ,2001 \ + ,2001 \ + ,2002 \ + ,2001 \ + ,2001 \ + ,2002 \ + ,1999 \ + ,2001 \ + ,1995 \ + ,1999 \ + ,1999 \ + ,2003 \ + ,2003 \ + ,2002 \ + ,2004 \ + ,2002 \ + ,2005 \ + ,2002 \ + ,2004 \ + ,2002 \ + /) + + year_ob_f = (/2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2006 \ + ,2006 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2004 \ + ,2004 \ + ,2004 \ + ,2004 \ + ,2006 \ + ,2006 \ + ,2002 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2000 \ + ,2006 \ + ,2004 \ + ,2005 \ + ,2003 \ + ,2006 \ + ,2006 \ + ,2003 \ + ,1998 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2005 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2003 \ + ,2006 \ + ,1999 \ + ,2005 \ + ,2004 \ + ,2003 \ + ,2003 \ + ,2005 \ + ,2004 \ + ,2002 \ + ,2005 \ + ,2002 \ + ,2005 \ + ,2002 \ + /) + + field = (/"NEE Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"u mol/m2/s" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"u mol/m2/s" \ + ,"u mol/m2/s" \ + /) + +;======================================================================== +; find # year observed >=4 and year_ob_i <= 2001 + + i_long_ob = ind((year_ob_f - year_ob_i) .ge. 4 .and. year_ob_i .le. 2001) + + station_long = station(i_long_ob) + year_ob_long = year_ob(i_long_ob) + year_ob_i_long = year_ob_i(i_long_ob) + year_ob_f_long = year_ob_f(i_long_ob) + +;print (i_long_ob) +;print (year_ob_i(i_long_ob)) +;print (station_long) +;======================================================================== + + nstation = dimsizes(station_long) + + data_mod = new ((/nstation, nfield, nmon/),float) + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + unit_ob = new ((/nfield/),string) + + diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + + do n = 0,nstation-1 + +;------------------------------------------------- +; get ob data + + diro = diro_root + station_long(n)+"/" + filo = year_ob_i_long(n)+"-"+year_ob_f_long(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + print (filo) + + lon_ob(n) = fo->lon + lat_ob(n) = fo->lat + + data = fo->NEE_or_fMDS + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Rg_f + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->LE_f + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->H_f + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->GPP_or_MDS + data_ob(n,4,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->Reco_or + data_ob(n,5,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (fo) +;--------------------------------------------------- +; get model data + +; film = model_name+"_"+ year_ob(n)+"_MONS_climo.nc" + film = model_name+"_"+"1990-2004"+"_MONS_climo.nc" + fm = addfile (dirm_root+film,"r") + +; print (film) + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) +end if + + data = fm->GPP + data_mod0(4,:,:,:) = data(:,:,:) * factor + delete (data) + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + data_mod0(5,:,:,:) = data(:,:,:) * factor + delete (data) + + delete (fm) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0) + +; print (yy) + + data_mod(n,:,:) = yy(:,:,0) + + delete (yy) + + end do + +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_gpp = sprintf("%.2f", M_gpp) + M_energy_er = sprintf("%.2f", M_er ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 + +;---------------------------- +; for observed + + plot_name = station_long(n)+"_ob" + title = station_long(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob (n,i,:)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station_long(n)+"_model_vs_ob" + title = station_long(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob (n,i,:)/) + plot_data(1,:) = (/data_mod(n,i,:)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) + + isort = dim_pqsort(lat_ob,-1) + + station_sort = station_long(isort) + year_ob_sort = year_ob_long(isort) + lat_ob_sort = lat_ob(isort) + lon_ob_sort = lon_ob(isort) + M_score_sort = M_score(isort,:) + + print(isort) + print(lat_ob_sort) + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + txt4 = sprintf("%5.2f", M_score_sort(n,0)) + txt5 = sprintf("%5.2f", M_score_sort(n,1)) + txt6 = sprintf("%5.2f", M_score_sort(n,2)) + txt7 = sprintf("%5.2f", M_score_sort(n,3)) + txt8 = sprintf("%5.2f", M_score_sort(n,4)) + txt9 = sprintf("%5.2f", M_score_sort(n,5)) + txt10 = sprintf("%5.2f", avg(M_score_sort(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/17.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/17.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,879 @@ +;************************************************************ +; add time series plot +; sort by latitude in decending order (N->S) +; find year_ob >= 4 +; add year_ob_i and year_ob_f +; change long_name +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + + ENERGY ="new" + +;************************************************ +; read data: observed +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + year_ob = (/"2003-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1999-2006" \ + ,"2002-2006" \ + ,"2000-2005" \ + ,"2004-2005" \ + ,"1996-2006" \ + ,"2004-2006" \ + ,"1999-2004" \ + ,"2003-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2005-2006" \ + ,"2004-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2000-2006" \ + ,"2004-2006" \ + ,"2002-2006" \ + ,"1991-2004" \ + ,"2004-2004" \ + ,"1996-2004" \ + ,"1999-2004" \ + ,"2003-2006" \ + ,"2004-2006" \ + ,"2002-2002" \ + ,"2000-2006" \ + ,"2002-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2004-2005" \ + ,"2004-2005" \ + ,"2003-2005" \ + ,"1996-2000" \ + ,"2004-2006" \ + ,"1998-2004" \ + ,"1999-2005" \ + ,"1999-2003" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1996-2003" \ + ,"1998-1998" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2002-2006" \ + ,"2004-2005" \ + ,"2001-2006" \ + ,"2004-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2004" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2005" \ + ,"1999-2003" \ + ,"2001-2006" \ + ,"1995-1999" \ + ,"1999-2005" \ + ,"1999-2004" \ + ,"2003-2003" \ + ,"2003-2003" \ + ,"2002-2005" \ + ,"2004-2004" \ + ,"2002-2002" \ + ,"2005-2005" \ + ,"2002-2002" \ + ,"2004-2005" \ + ,"2002-2002" \ + /) + + year_ob_i = (/2003 \ + ,2005 \ + ,2005 \ + ,1999 \ + ,2002 \ + ,2000 \ + ,2004 \ + ,1996 \ + ,2004 \ + ,1999 \ + ,2003 \ + ,2001 \ + ,2001 \ + ,2005 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2000 \ + ,2004 \ + ,2002 \ + ,1991 \ + ,2004 \ + ,1996 \ + ,1999 \ + ,2003 \ + ,2004 \ + ,2002 \ + ,2000 \ + ,2002 \ + ,2001 \ + ,2001 \ + ,2001 \ + ,2001 \ + ,2004 \ + ,2004 \ + ,2003 \ + ,1996 \ + ,2004 \ + ,1998 \ + ,1999 \ + ,1999 \ + ,2005 \ + ,2005 \ + ,1996 \ + ,1998 \ + ,2004 \ + ,1997 \ + ,2004 \ + ,1997 \ + ,2002 \ + ,2004 \ + ,2001 \ + ,2004 \ + ,2001 \ + ,2001 \ + ,2002 \ + ,2001 \ + ,2001 \ + ,2002 \ + ,1999 \ + ,2001 \ + ,1995 \ + ,1999 \ + ,1999 \ + ,2003 \ + ,2003 \ + ,2002 \ + ,2004 \ + ,2002 \ + ,2005 \ + ,2002 \ + ,2004 \ + ,2002 \ + /) + + year_ob_f = (/2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2006 \ + ,2006 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2004 \ + ,2004 \ + ,2004 \ + ,2004 \ + ,2006 \ + ,2006 \ + ,2002 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2000 \ + ,2006 \ + ,2004 \ + ,2005 \ + ,2003 \ + ,2006 \ + ,2006 \ + ,2003 \ + ,1998 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2005 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2003 \ + ,2006 \ + ,1999 \ + ,2005 \ + ,2004 \ + ,2003 \ + ,2003 \ + ,2005 \ + ,2004 \ + ,2002 \ + ,2005 \ + ,2002 \ + ,2005 \ + ,2002 \ + /) + + field = (/"NEE Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"u mol/m2/s" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"u mol/m2/s" \ + ,"u mol/m2/s" \ + /) + + nfield = dimsizes(field) + +;======================================================================== +; find (# of year observed) >=4 and year_ob_i <= 2001 + + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + nstation = dimsizes(station) + + year_station = new ((/nstation/),integer) + + do n = 0,nstation-1 + + diro = dir_root + station(n)+"/" + filo = year_ob_i(n)+"-"+year_ob_f(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + year = fo->year + year_station(n) = dimsizes(year) + delete (year) + + end do + + delete (fo) + + i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001) + + station_long = station(i_long_ob) + year_ob_long = year_ob(i_long_ob) + year_ob_i_long = year_ob_i(i_long_ob) + year_ob_f_long = year_ob_f(i_long_ob) + year_station_long = year_station(i_long_ob) + + nstation = dimsizes(station_long) +; print (nstation) +; print (i_long_ob) +; print (year_ob_i(i_long_ob)) +; print (station_long) + +;======================================================================== +; get observed lat and lon + + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + + do n = 0,nstation-1 + + diro = dir_root + station_long(n)+"/" + filo = year_ob_i_long(n)+"-"+year_ob_f_long(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + +; print (diro) +; print (filo) + + lon_ob(n) = fo->lon + lat_ob(n) = fo->lat + + delete (fo) + + end do + +;========================================================= +; get model data at observed lat-lon + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name+"_ameriflux_1990-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + xm = fm->lon + ym = fm->lat + date = fm->date + + date_dim = dimsizes(date) + nyear = date_dim(0) + + nmonth =12 + + data_mod = new ((/nfield,nyear,nmonth,nstation/),float) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod(0,:,:,:) = data(:,:,:) * factor + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod(3,:,:,:) = data(:,:,:) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod(1,:,:,:) = data1(:,:,:)-data2(:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod(0,:,:,:) = yy(:,:,:) * factor + + data = fm->NETRAD + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod(1,:,:,:) = yy(:,:,:) + + data = fm->LATENT + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod(2,:,:,:) = yy(:,:,:) + +; data = fm->SENSIBLE + data = fm->FSH + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod(3,:,:,:) = yy(:,:,:) + +end if + + data = fm->GPP + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod(4,:,:,:) = yy(:,:,:) * factor + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod(5,:,:,:) = yy(:,:,:) * factor + + delete (fm) + delete (data) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) + + res@tmXBFormat = "f" ; not to add trailing zeros + +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + +;============================================================== +; get ob data at each site + + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + do n = 0,nstation-1 +; do n = 2,6 + + year_setback = 0 + + nyear = year_station_long(n) + + if (year_ob_f_long(n).eq. 2006) then + year_setback = 2006 -2004 + end if + if (year_ob_f_long(n).eq. 2005) then + year_setback = 2005 -2004 + end if + + ntime = (nyear - year_setback) * nmonth + print (nyear) + + data_ob = new ((/nfield, nyear, nmonth/),float) + + diro = dir_root + station_long(n)+"/" + filo = year_ob_i_long(n)+"-"+year_ob_f_long(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + print (diro) + print (filo) + + lon_ob(n) = fo->lon + lat_ob(n) = fo->lat + + data = fo->NEE_or_fMDS + data_ob(0,:,:) = data(:,:) + delete (data) + + data = fo->Rg_f + data_ob(1,:,:) = data(:,:) + delete (data) + + data = fo->LE_f + data_ob(2,:,:) = data(:,:) + delete (data) + + data = fo->H_f + data_ob(3,:,:) = data(:,:) + delete (data) + + data = fo->GPP_or_MDS + data_ob(4,:,:) = data(:,:) + delete (data) + + data = fo->Reco_or + data_ob(5,:,:) = data(:,:) + delete (data) + + delete (fo) + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_ob_i_long(n) + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + +;---------------------------- +; for model_vs_ob + + plot_name = station_long(n)+"_model_vs_ob" + title = station_long(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + i_year_mod_i = year_ob_i_long(n) - 1990 + i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback + + i_year_ob_f = nyear - year_setback - 1 + + print (nyear) + print (i_year_ob_f) + print (i_year_mod_i) + print (i_year_mod_f) + + do i = 0,nfield-1 + plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:)) + plot_data(1,:) = ndtooned(data_mod(i,i_year_mod_i:i_year_mod_f,:,n)) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,timeF,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + delete (data_ob) + delete (timeI) + delete (timeF) + delete (plot_data) + + end do +exit +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) + + isort = dim_pqsort(lat_ob,-1) + + station_sort = station_long(isort) + year_ob_sort = year_ob_long(isort) + lat_ob_sort = lat_ob(isort) + lon_ob_sort = lon_ob(isort) + M_score_sort = M_score(isort,:) + + print(isort) + print(lat_ob_sort) + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + txt4 = sprintf("%5.2f", M_score_sort(n,0)) + txt5 = sprintf("%5.2f", M_score_sort(n,1)) + txt6 = sprintf("%5.2f", M_score_sort(n,2)) + txt7 = sprintf("%5.2f", M_score_sort(n,3)) + txt8 = sprintf("%5.2f", M_score_sort(n,4)) + txt9 = sprintf("%5.2f", M_score_sort(n,5)) + txt10 = sprintf("%5.2f", avg(M_score_sort(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/18.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/18.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,745 @@ +;************************************************************ +; add table +; add time series plot +; sort by latitude in decending order (N->S) +; find year_ob >= 4 +; add year_ob_i and year_ob_f +; change long_name +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + + ENERGY ="new" + +;************************************************ +; read data: observed +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + year_ob = (/"2003-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1999-2006" \ + ,"2002-2006" \ + ,"2000-2005" \ + ,"2004-2005" \ + ,"1996-2006" \ + ,"2004-2006" \ + ,"1999-2004" \ + ,"2003-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2005-2006" \ + ,"2004-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2000-2006" \ + ,"2004-2006" \ + ,"2002-2006" \ + ,"1991-2004" \ + ,"2004-2004" \ + ,"1996-2004" \ + ,"1999-2004" \ + ,"2003-2006" \ + ,"2004-2006" \ + ,"2002-2002" \ + ,"2000-2006" \ + ,"2002-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2004-2005" \ + ,"2004-2005" \ + ,"2003-2005" \ + ,"1996-2000" \ + ,"2004-2006" \ + ,"1998-2004" \ + ,"1999-2005" \ + ,"1999-2003" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1996-2003" \ + ,"1998-1998" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2002-2006" \ + ,"2004-2005" \ + ,"2001-2006" \ + ,"2004-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2004" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2005" \ + ,"1999-2003" \ + ,"2001-2006" \ + ,"1995-1999" \ + ,"1999-2005" \ + ,"1999-2004" \ + ,"2003-2003" \ + ,"2003-2003" \ + ,"2002-2005" \ + ,"2004-2004" \ + ,"2002-2002" \ + ,"2005-2005" \ + ,"2002-2002" \ + ,"2004-2005" \ + ,"2002-2002" \ + /) + + year_ob_i = (/2003 \ + ,2005 \ + ,2005 \ + ,1999 \ + ,2002 \ + ,2000 \ + ,2004 \ + ,1996 \ + ,2004 \ + ,1999 \ + ,2003 \ + ,2001 \ + ,2001 \ + ,2005 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2000 \ + ,2004 \ + ,2002 \ + ,1991 \ + ,2004 \ + ,1996 \ + ,1999 \ + ,2003 \ + ,2004 \ + ,2002 \ + ,2000 \ + ,2002 \ + ,2001 \ + ,2001 \ + ,2001 \ + ,2001 \ + ,2004 \ + ,2004 \ + ,2003 \ + ,1996 \ + ,2004 \ + ,1998 \ + ,1999 \ + ,1999 \ + ,2005 \ + ,2005 \ + ,1996 \ + ,1998 \ + ,2004 \ + ,1997 \ + ,2004 \ + ,1997 \ + ,2002 \ + ,2004 \ + ,2001 \ + ,2004 \ + ,2001 \ + ,2001 \ + ,2002 \ + ,2001 \ + ,2001 \ + ,2002 \ + ,1999 \ + ,2001 \ + ,1995 \ + ,1999 \ + ,1999 \ + ,2003 \ + ,2003 \ + ,2002 \ + ,2004 \ + ,2002 \ + ,2005 \ + ,2002 \ + ,2004 \ + ,2002 \ + /) + + year_ob_f = (/2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2006 \ + ,2006 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2004 \ + ,2004 \ + ,2004 \ + ,2004 \ + ,2006 \ + ,2006 \ + ,2002 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2000 \ + ,2006 \ + ,2004 \ + ,2005 \ + ,2003 \ + ,2006 \ + ,2006 \ + ,2003 \ + ,1998 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2005 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2003 \ + ,2006 \ + ,1999 \ + ,2005 \ + ,2004 \ + ,2003 \ + ,2003 \ + ,2005 \ + ,2004 \ + ,2002 \ + ,2005 \ + ,2002 \ + ,2005 \ + ,2002 \ + /) + + field = (/"NEE Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"u mol/m2/s" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"u mol/m2/s" \ + ,"u mol/m2/s" \ + /) + + nfield = dimsizes(field) + +;======================================================================== +; find (# of year observed) >=4 and year_ob_i <= 2001 + + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + nstation = dimsizes(station) + + year_station = new ((/nstation/),integer) + + do n = 0,nstation-1 + + diro = dir_root + station(n)+"/" + filo = year_ob_i(n)+"-"+year_ob_f(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + year = fo->year + year_station(n) = dimsizes(year) + delete (year) + + end do + + delete (fo) + + i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001) + + station_long = station(i_long_ob) + year_ob_long = year_ob(i_long_ob) + year_ob_i_long = year_ob_i(i_long_ob) + year_ob_f_long = year_ob_f(i_long_ob) + year_station_long = year_station(i_long_ob) + + nstation_long = dimsizes(station_long) +; print (nstation_long) +; print (i_long_ob) +; print (year_ob_i(i_long_ob)) +; print (station_long) + +;======================================================================== +; get long observed lat and lon + + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + lat_ob_long = new ((/nstation_long/),float) + lon_ob_long = new ((/nstation_long/),float) + + do n = 0,nstation_long-1 + + diro = dir_root + station_long(n)+"/" + filo = year_ob_i_long(n)+"-"+year_ob_f_long(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + +; print (diro) +; print (filo) + + lon_ob_long(n) = fo->lon + lat_ob_long(n) = fo->lat + + delete (fo) + + end do + +;========================================================= +; get model data at observed lat-lon + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name+"_ameriflux_1990-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + xm = fm->lon + ym = fm->lat + date = fm->date + + date_dim = dimsizes(date) + nyear = date_dim(0) + + nmonth =12 + + data_mod = new ((/nfield,nyear,nmonth,nstation_long/),float) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod(0,:,:,:) = data(:,:,:) * factor + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod(3,:,:,:) = data(:,:,:) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod(1,:,:,:) = data1(:,:,:)-data2(:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob_long,lat_ob_long,0) + data_mod(0,:,:,:) = yy(:,:,:) * factor + + data = fm->NETRAD + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob_long,lat_ob_long,0) + data_mod(1,:,:,:) = yy(:,:,:) + + data = fm->LATENT + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob_long,lat_ob_long,0) + data_mod(2,:,:,:) = yy(:,:,:) + +; data = fm->SENSIBLE + data = fm->FSH + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob_long,lat_ob_long,0) + data_mod(3,:,:,:) = yy(:,:,:) + +end if + + data = fm->GPP + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob_long,lat_ob_long,0) + data_mod(4,:,:,:) = yy(:,:,:) * factor + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob_long,lat_ob_long,0) + data_mod(5,:,:,:) = yy(:,:,:) * factor + + delete (fm) + delete (data) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) + + res@tmXBFormat = "f" ; not to add trailing zeros + +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + +;============================================================== +; get ob data at each site + + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + do n = 0,nstation_long-1 +; do n = 2,6 + + year_setback = 0 + + nyear = year_station_long(n) + + if (year_ob_f_long(n).eq. 2006) then + year_setback = 2006 -2004 + end if + if (year_ob_f_long(n).eq. 2005) then + year_setback = 2005 -2004 + end if + + ntime = (nyear - year_setback) * nmonth + print (nyear) + + data_ob = new ((/nfield, nyear, nmonth/),float) + + diro = dir_root + station_long(n)+"/" + filo = year_ob_i_long(n)+"-"+year_ob_f_long(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + +; print (diro) +; print (filo) + + data_ob(0,:,:) = fo->NEE_or_fMDS + data_ob(1,:,:) = fo->Rg_f + data_ob(2,:,:) = fo->LE_f + data_ob(3,:,:) = fo->H_f + data_ob(4,:,:) = fo->GPP_or_MDS + data_ob(5,:,:) = fo->Reco_or + + delete (fo) + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_ob_i_long(n) + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + +;---------------------------- +; for model_vs_ob + + plot_name = station_long(n)+"_tseries_vs_ob" + title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + i_year_mod_i = year_ob_i_long(n) - 1990 + i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback + + i_year_ob_f = nyear - year_setback - 1 + +; print (nyear) +; print (i_year_ob_f) +; print (i_year_mod_i) +; print (i_year_mod_f) + + do i = 0,nfield-1 + plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:)) + plot_data(1,:) = ndtooned(data_mod(i,i_year_mod_i:i_year_mod_f,:,n)) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,timeF,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + delete (data_ob) + delete (timeI) + delete (timeF) + delete (plot_data) + + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) + + isort = dim_pqsort(lat_ob_long,-1) + + station_sort = station_long(isort) + year_ob_sort = year_ob_long(isort) + lat_ob_sort = lat_ob_long(isort) + lon_ob_sort = lon_ob_long(isort) + +; print(isort) +; print(lat_ob_sort) + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "tseries_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Timeseries at Site: "+model_name+" vs Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation_long-1 + + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/20.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/20.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,842 @@ +;************************************************************ +; merge 14 and 18 +; sort by latitude in decending order (N->S) +; add year_ob_i and year_ob_f +; change long_name +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +; for 6 fields, 12-monthly + nmon = 12 + +;************************************************ +; read model +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + +;************************************************ +; read data: observed +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + year_ob = (/"2003-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1999-2006" \ + ,"2002-2006" \ + ,"2000-2005" \ + ,"2004-2005" \ + ,"1996-2006" \ + ,"2004-2006" \ + ,"1999-2004" \ + ,"2003-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2005-2006" \ + ,"2004-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2000-2006" \ + ,"2004-2006" \ + ,"2002-2006" \ + ,"1991-2004" \ + ,"2004-2004" \ + ,"1996-2004" \ + ,"1999-2004" \ + ,"2003-2006" \ + ,"2004-2006" \ + ,"2002-2002" \ + ,"2000-2006" \ + ,"2002-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2004-2005" \ + ,"2004-2005" \ + ,"2003-2005" \ + ,"1996-2000" \ + ,"2004-2006" \ + ,"1998-2004" \ + ,"1999-2005" \ + ,"1999-2003" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1996-2003" \ + ,"1998-1998" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2002-2006" \ + ,"2004-2005" \ + ,"2001-2006" \ + ,"2004-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2004" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2005" \ + ,"1999-2003" \ + ,"2001-2006" \ + ,"1995-1999" \ + ,"1999-2005" \ + ,"1999-2004" \ + ,"2003-2003" \ + ,"2003-2003" \ + ,"2002-2005" \ + ,"2004-2004" \ + ,"2002-2002" \ + ,"2005-2005" \ + ,"2002-2002" \ + ,"2004-2005" \ + ,"2002-2002" \ + /) + + year_ob_i = (/2003 \ + ,2005 \ + ,2005 \ + ,1999 \ + ,2002 \ + ,2000 \ + ,2004 \ + ,1996 \ + ,2004 \ + ,1999 \ + ,2003 \ + ,2001 \ + ,2001 \ + ,2005 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2000 \ + ,2004 \ + ,2002 \ + ,1991 \ + ,2004 \ + ,1996 \ + ,1999 \ + ,2003 \ + ,2004 \ + ,2002 \ + ,2000 \ + ,2002 \ + ,2001 \ + ,2001 \ + ,2001 \ + ,2001 \ + ,2004 \ + ,2004 \ + ,2003 \ + ,1996 \ + ,2004 \ + ,1998 \ + ,1999 \ + ,1999 \ + ,2005 \ + ,2005 \ + ,1996 \ + ,1998 \ + ,2004 \ + ,1997 \ + ,2004 \ + ,1997 \ + ,2002 \ + ,2004 \ + ,2001 \ + ,2004 \ + ,2001 \ + ,2001 \ + ,2002 \ + ,2001 \ + ,2001 \ + ,2002 \ + ,1999 \ + ,2001 \ + ,1995 \ + ,1999 \ + ,1999 \ + ,2003 \ + ,2003 \ + ,2002 \ + ,2004 \ + ,2002 \ + ,2005 \ + ,2002 \ + ,2004 \ + ,2002 \ + /) + + year_ob_f = (/2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2006 \ + ,2006 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2004 \ + ,2004 \ + ,2004 \ + ,2004 \ + ,2006 \ + ,2006 \ + ,2002 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2000 \ + ,2006 \ + ,2004 \ + ,2005 \ + ,2003 \ + ,2006 \ + ,2006 \ + ,2003 \ + ,1998 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2006 \ + ,2005 \ + ,2006 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2004 \ + ,2005 \ + ,2005 \ + ,2005 \ + ,2003 \ + ,2006 \ + ,1999 \ + ,2005 \ + ,2004 \ + ,2003 \ + ,2003 \ + ,2005 \ + ,2004 \ + ,2002 \ + ,2005 \ + ,2002 \ + ,2005 \ + ,2002 \ + /) + + field = (/"NEE Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"u mol/m2/s" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"u mol/m2/s" \ + ,"u mol/m2/s" \ + /) + + nstation = dimsizes(station) + nfield = dimsizes(field) +;------------------------------------------------- +; get ob data + + nmon = 12 + + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + + diro_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + do n = 0,nstation-1 + + diro = diro_root + station(n)+"/" + filo = year_ob_i(n)+"-"+year_ob_f(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + print (filo) + + lon_ob(n) = fo->lon + lat_ob(n) = fo->lat + + data = fo->NEE_or_fMDS + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + + data = fo->Rg_f + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + + data = fo->LE_f + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + + data = fo->H_f + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + + data = fo->GPP_or_MDS + data_ob(n,4,:) = dim_avg(data(month|:,year|:)) + + data = fo->Reco_or + data_ob(n,5,:) = dim_avg(data(month|:,year|:)) + + delete (data) + delete (fo) + + end do + +;--------------------------------------------------- +; get model data + + dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name+"_"+"1990-2004"+"_MONS_climo.nc" + fm = addfile (dirm_root+film,"r") + +; print (film) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + + ENERGY ="new" + + xm = fm->lon + ym = fm->lat + + nlat = dimsizes(ym) + nlon = dimsizes(xm) + + data_mod0 = new ((/nfield, nmon, nlat, nlon/),float) + data_mod = new ((/nstation, nfield, nmon/),float) + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) +end if + + data = fm->GPP + data_mod0(4,:,:,:) = data(:,:,:) * factor + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + data_mod0(5,:,:,:) = data(:,:,:) * factor + + delete (data) + delete (fm) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0) + +; print (yy) + + do n = 0, nstation-1 + data_mod(n,:,:) = yy(:,:,n) + end do + + delete (data_mod0) + delete (yy) + +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_gpp = sprintf("%.2f", M_gpp) + M_energy_er = sprintf("%.2f", M_er ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob (n,i,:)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob (n,i,:)/) + plot_data(1,:) = (/data_mod(n,i,:)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) +; sort by lat in decending order (N->S) + + isort = dim_pqsort(lat_ob,-1) + + station_sort = station(isort) + lat_ob_sort = lat_ob(isort) + lon_ob_sort = lon_ob(isort) + year_ob_sort = year_ob(isort) + M_score_sort = M_score(isort,:) + + print(isort) + print(lat_ob_sort) +;################################################################### +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + txt4 = sprintf("%5.2f", M_score_sort(n,0)) + txt5 = sprintf("%5.2f", M_score_sort(n,1)) + txt6 = sprintf("%5.2f", M_score_sort(n,2)) + txt7 = sprintf("%5.2f", M_score_sort(n,3)) + txt8 = sprintf("%5.2f", M_score_sort(n,4)) + txt9 = sprintf("%5.2f", M_score_sort(n,5)) + txt10 = sprintf("%5.2f", avg(M_score_sort(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/21.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/21.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,602 @@ +;************************************************************ +; add table +; add time series plot +; sort by latitude in decending order (N->S) +; find year_ob >= 4 +; add year_ob_i and year_ob_f +; change long_name +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; model data info +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + + ENERGY ="new" + +;************************************************ +; observed data info +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + year_ob = (/"2003-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1999-2006" \ + ,"2002-2006" \ + ,"2000-2005" \ + ,"2004-2005" \ + ,"1996-2006" \ + ,"2004-2006" \ + ,"1999-2004" \ + ,"2003-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2005-2006" \ + ,"2004-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2000-2006" \ + ,"2004-2006" \ + ,"2002-2006" \ + ,"1991-2004" \ + ,"2004-2004" \ + ,"1996-2004" \ + ,"1999-2004" \ + ,"2003-2006" \ + ,"2004-2006" \ + ,"2002-2002" \ + ,"2000-2006" \ + ,"2002-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2004-2005" \ + ,"2004-2005" \ + ,"2003-2005" \ + ,"1996-2000" \ + ,"2004-2006" \ + ,"1998-2004" \ + ,"1999-2005" \ + ,"1999-2003" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1996-2003" \ + ,"1998-1998" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2002-2006" \ + ,"2004-2005" \ + ,"2001-2006" \ + ,"2004-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2004" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2005" \ + ,"1999-2003" \ + ,"2001-2006" \ + ,"1995-1999" \ + ,"1999-2005" \ + ,"1999-2004" \ + ,"2003-2003" \ + ,"2003-2003" \ + ,"2002-2005" \ + ,"2004-2004" \ + ,"2002-2002" \ + ,"2005-2005" \ + ,"2002-2002" \ + ,"2004-2005" \ + ,"2002-2002" \ + /) + + field = (/"NEE Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"u mol/m2/s" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"u mol/m2/s" \ + ,"u mol/m2/s" \ + /) + + nstation = dimsizes(station) + nfield = dimsizes(field) + +;======================================================================== +; get observed info: number of year, first/last year, lat, lon + + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + year_station = new ((/nstation/),integer) ; number of year + year_ob_i = new ((/nstation/),integer) ; first year + year_ob_f = new ((/nstation/),integer) ; last year + lat_ob = new ((/nstation/),float) ; latitude + lon_ob = new ((/nstation/),float) ; longitude + + do n = 0, nstation-1 + + diro = dir_root + station(n)+"/" + filo = year_ob(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + lat_ob(n) = fo->lat + lon_ob(n) = fo->lon + + year = fo->year + + year_station(n) = dimsizes(year) + year_ob_i(n) = year(0) + year_ob_f(n) = year(year_station(n)-1) + + delete (year) + + end do + + delete (fo) +;print (year_ob_i) +;print (year_ob_f) + +;-------------------------------------------------------------- +; find (# of year observed) >=4 and year_ob_i <= 2001 + + i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001) + + station_long = station(i_long_ob) + lat_ob_long = lat_ob(i_long_ob) + lon_ob_long = lat_ob(i_long_ob) + year_ob_long = year_ob(i_long_ob) + year_ob_i_long = year_ob_i(i_long_ob) + year_ob_f_long = year_ob_f(i_long_ob) + year_station_long = year_station(i_long_ob) + + nstation_long = dimsizes(station_long) + +; print (i_long_ob) +; print (nstation_long) +; print (station_long) +; print (year_ob_i(i_long_ob)) + +;========================================================= +; get model data at observed lat-lon + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name+"_ameriflux_1990-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + xm = fm->lon + ym = fm->lat + date = fm->date + + date_dim = dimsizes(date) + nyear = date_dim(0) + + nmonth =12 + + data_mod = new ((/nfield,nyear,nmonth,nstation/),float) + data_mod_ann = new ((/nfield,nmonth,nstation/),float) + data_mod_long = new ((/nfield,nyear,nmonth,nstation_long/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + + factor = 1.e6 /12. + +;------------------------------------------------------------ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. +;------------------------------------------------------------ + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod(0,:,:,:) = data(:,:,:) * factor + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod(3,:,:,:) = data(:,:,:) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod(1,:,:,:) = data1(:,:,:)-data2(:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor + data_mod(0,:,:,:) = yy(:,:,:) * factor + +; printVarSummary(yy) + + data = fm->NETRAD + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(1,:,:,:) = yy(:,:,:) + + data = fm->LATENT + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(2,:,:,:) = yy(:,:,:) + +; data = fm->SENSIBLE + data = fm->FSH + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(3,:,:,:) = yy(:,:,:) + +end if + + data = fm->GPP + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(4,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor + data_mod(4,:,:,:) = yy(:,:,:) * factor + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(5,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor + data_mod(5,:,:,:) = yy(:,:,:) * factor + + data_mod_long(:,:,:,:) = data_mod(:,:,:,i_long_ob) + + delete (data_mod) + delete (fm) + delete (data) + delete (yy) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) + + res@tmXBFormat = "f" ; not to add trailing zeros + +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + +;============================================================== +; get ob data at each site with long observation + + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + do n = 0,nstation_long-1 +; do n = 0,0 + + year_setback = 0 + + nyear = year_station_long(n) + + if (year_ob_f_long(n).eq. 2006) then + year_setback = 2006 -2004 + end if + if (year_ob_f_long(n).eq. 2005) then + year_setback = 2005 -2004 + end if + + ntime = (nyear - year_setback) * nmonth + print (nyear) + + data_ob = new ((/nfield, nyear, nmonth/),float) + + diro = dir_root + station_long(n)+"/" + filo = year_ob_long(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + +; print (diro) +; print (filo) + + data_ob(0,:,:) = fo->NEE_or_fMDS + data_ob(1,:,:) = fo->Rg_f + data_ob(2,:,:) = fo->LE_f + data_ob(3,:,:) = fo->H_f + data_ob(4,:,:) = fo->GPP_or_MDS + data_ob(5,:,:) = fo->Reco_or + + delete (fo) + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_ob_i_long(n) + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + +;---------------------------- +; for model_vs_ob + + plot_name = station_long(n)+"_tseries_vs_ob" + title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + i_year_mod_i = year_ob_i_long(n) - 1990 + i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback + + i_year_ob_f = nyear - year_setback - 1 + +; print (nyear) +; print (i_year_ob_f) +; print (i_year_mod_i) +; print (i_year_mod_f) + + do i = 0,nfield-1 + plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:)) + plot_data(1,:) = ndtooned(data_mod_long(i,i_year_mod_i:i_year_mod_f,:,n)) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,timeF,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + delete (data_ob) + delete (timeI) + delete (timeF) + delete (plot_data) + + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) + + isort = dim_pqsort(lat_ob_long,-1) + + station_sort = station_long(isort) + year_ob_sort = year_ob_long(isort) + lat_ob_sort = lat_ob_long(isort) + lon_ob_sort = lon_ob_long(isort) + +; print(isort) +; print(lat_ob_sort) + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "tseries_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Timeseries at Site: "+model_name+" vs Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation_long-1 + + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/22.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/22.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,919 @@ +;************************************************************ +; merge annual +; add table +; add time series plot +; sort by latitude in decending order (N->S) +; find year_ob >= 4 +; add year_ob_i and year_ob_f +; change long_name +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; model data info +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + + ENERGY ="new" + + nmonth = 12 + +;************************************************ +; observed data info +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + year_ob = (/"2003-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1999-2006" \ + ,"2002-2006" \ + ,"2000-2005" \ + ,"2004-2005" \ + ,"1996-2006" \ + ,"2004-2006" \ + ,"1999-2004" \ + ,"2003-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2005-2006" \ + ,"2004-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2000-2006" \ + ,"2004-2006" \ + ,"2002-2006" \ + ,"1991-2004" \ + ,"2004-2004" \ + ,"1996-2004" \ + ,"1999-2004" \ + ,"2003-2006" \ + ,"2004-2006" \ + ,"2002-2002" \ + ,"2000-2006" \ + ,"2002-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2004-2005" \ + ,"2004-2005" \ + ,"2003-2005" \ + ,"1996-2000" \ + ,"2004-2006" \ + ,"1998-2004" \ + ,"1999-2005" \ + ,"1999-2003" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1996-2003" \ + ,"1998-1998" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2002-2006" \ + ,"2004-2005" \ + ,"2001-2006" \ + ,"2004-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2004" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2005" \ + ,"1999-2003" \ + ,"2001-2006" \ + ,"1995-1999" \ + ,"1999-2005" \ + ,"1999-2004" \ + ,"2003-2003" \ + ,"2003-2003" \ + ,"2002-2005" \ + ,"2004-2004" \ + ,"2002-2002" \ + ,"2005-2005" \ + ,"2002-2002" \ + ,"2004-2005" \ + ,"2002-2002" \ + /) + + field = (/"NEE Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"u mol/m2/s" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"u mol/m2/s" \ + ,"u mol/m2/s" \ + /) + + nstation = dimsizes(station) + nfield = dimsizes(field) + +;======================================================================== +; get observed info: number of year, first/last year, lat, lon +; and annual data + + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + year_station = new ((/nstation/),integer) ; number of year + year_ob_i = new ((/nstation/),integer) ; first year + year_ob_f = new ((/nstation/),integer) ; last year + lat_ob = new ((/nstation/),float) ; latitude + lon_ob = new ((/nstation/),float) ; longitude + + data_ob_ann = new ((/nfield, nmonth, nstation/),float) + + do n = 0, nstation-1 + + diro = dir_root + station(n)+"/" + filo = year_ob(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + lat_ob(n) = fo->lat + lon_ob(n) = fo->lon + + year = fo->year + + year_station(n) = dimsizes(year) + year_ob_i(n) = year(0) + year_ob_f(n) = year(year_station(n)-1) + + delete (year) + + data = fo->NEE_or_fMDS + data_ob_ann(0,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->Rg_f + data_ob_ann(1,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->LE_f + data_ob_ann(2,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->H_f + data_ob_ann(3,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->GPP_or_MDS + data_ob_ann(4,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->Reco_or + data_ob_ann(5,:,n) = dim_avg(data(month|:,year|:)) + + delete (data) + delete (fo) + end do + +;print (year_ob_i) +;print (year_ob_f) + +;-------------------------------------------------------------- +; find (# of year observed) >=4 and year_ob_i <= 2001 + + i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001) + + station_long = station(i_long_ob) + lat_ob_long = lat_ob(i_long_ob) + lon_ob_long = lat_ob(i_long_ob) + year_ob_long = year_ob(i_long_ob) + year_ob_i_long = year_ob_i(i_long_ob) + year_ob_f_long = year_ob_f(i_long_ob) + year_station_long = year_station(i_long_ob) + + nstation_long = dimsizes(station_long) + +; print (i_long_ob) +; print (nstation_long) +; print (station_long) +; print (year_ob_i(i_long_ob)) + +;========================================================= +; get model data at observed lat-lon + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name+"_ameriflux_1990-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + xm = fm->lon + ym = fm->lat + date = fm->date + + date_dim = dimsizes(date) + nyear = date_dim(0) + + data_mod = new ((/nfield,nyear,nmonth,nstation/),float) + data_mod_ann = new ((/nfield,nmonth,nstation/),float) + data_mod_long = new ((/nfield,nyear,nmonth,nstation_long/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + + factor = 1.e6 /12. + +;------------------------------------------------------------ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. +;------------------------------------------------------------ + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod(0,:,:,:) = data(:,:,:) * factor + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod(3,:,:,:) = data(:,:,:) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod(1,:,:,:) = data1(:,:,:)-data2(:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor + data_mod(0,:,:,:) = yy(:,:,:) * factor + +; printVarSummary(yy) + + data = fm->NETRAD + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(1,:,:,:) = yy(:,:,:) + + data = fm->LATENT + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(2,:,:,:) = yy(:,:,:) + +; data = fm->SENSIBLE + data = fm->FSH + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(3,:,:,:) = yy(:,:,:) + +end if + + data = fm->GPP + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(4,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor + data_mod(4,:,:,:) = yy(:,:,:) * factor + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(5,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor + data_mod(5,:,:,:) = yy(:,:,:) * factor + + data_mod_long(:,:,:,:) = data_mod(:,:,:,i_long_ob) + + delete (data_mod) + delete (fm) + delete (data) + delete (yy) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) + + res@tmXBFormat = "f" ; not to add trailing zeros + +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + +;============================================================== +; get ob data at each site with long observation + + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + do n = 0,nstation_long-1 +; do n = 0,0 + + year_setback = 0 + + nyear = year_station_long(n) + + if (year_ob_f_long(n).eq. 2006) then + year_setback = 2006 -2004 + end if + if (year_ob_f_long(n).eq. 2005) then + year_setback = 2005 -2004 + end if + + ntime = (nyear - year_setback) * nmonth + + data_ob = new ((/nfield, nyear, nmonth/),float) + + diro = dir_root + station_long(n)+"/" + filo = year_ob_long(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + +; print (diro) +; print (filo) + + data_ob(0,:,:) = fo->NEE_or_fMDS + data_ob(1,:,:) = fo->Rg_f + data_ob(2,:,:) = fo->LE_f + data_ob(3,:,:) = fo->H_f + data_ob(4,:,:) = fo->GPP_or_MDS + data_ob(5,:,:) = fo->Reco_or + + delete (fo) + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_ob_i_long(n) + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + +;---------------------------- +; for model_vs_ob + + plot_name = station_long(n)+"_tseries_vs_ob" + title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + i_year_mod_i = year_ob_i_long(n) - 1990 + i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback + + i_year_ob_f = nyear - year_setback - 1 + +; print (nyear) +; print (i_year_ob_f) +; print (i_year_mod_i) +; print (i_year_mod_f) + + do i = 0,nfield-1 + plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:)) + plot_data(1,:) = ndtooned(data_mod_long(i,i_year_mod_i:i_year_mod_f,:,n)) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,timeF,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + delete (data_ob) + delete (timeI) + delete (timeF) + delete (plot_data) + + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) + + isort = dim_pqsort(lat_ob_long,-1) + + station_sort = station_long(isort) + year_ob_sort = year_ob_long(isort) + lat_ob_sort = lat_ob_long(isort) + lon_ob_sort = lon_ob_long(isort) + +; print(isort) +; print(lat_ob_sort) + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "tseries_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Timeseries at Site: "+model_name+" vs Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation_long-1 + + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + + delete (isort) + delete (station_sort) + delete (year_ob_sort) + delete (lat_ob_sort) + delete (lon_ob_sort) + +;************************************************************ +; compute annual cycle correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob_ann(m,:,n),data_mod_ann(m,:,n),0) + 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)))) + M_score(n,m) = (1. -(bias/nmonth)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_gpp = sprintf("%.2f", M_gpp) + M_energy_er = sprintf("%.2f", M_er ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + +;------------------------------------------------------------------- + + plot_data = new((/2,nmonth/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob_ann(i,:,n)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob_ann(i,:,n)/) + plot_data(1,:) = (/data_mod_ann(i,:,n)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) +; sort by lat in decending order (N->S) + + isort = dim_pqsort(lat_ob,-1) + + station_sort = station(isort) + year_ob_sort = year_ob(isort) + lat_ob_sort = lat_ob(isort) + lon_ob_sort = lon_ob(isort) + M_score_sort = M_score(isort,:) + +; print(isort) +; print(lat_ob_sort) +;################################################################### +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + txt4 = sprintf("%5.2f", M_score_sort(n,0)) + txt5 = sprintf("%5.2f", M_score_sort(n,1)) + txt6 = sprintf("%5.2f", M_score_sort(n,2)) + txt7 = sprintf("%5.2f", M_score_sort(n,3)) + txt8 = sprintf("%5.2f", M_score_sort(n,4)) + txt9 = sprintf("%5.2f", M_score_sort(n,5)) + txt10 = sprintf("%5.2f", avg(M_score_sort(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end + diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/23.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/23.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,920 @@ +;************************************************************ +; move data +; merge annual +; add table +; add time series plot +; sort by latitude in decending order (N->S) +; find year_ob >= 4 +; add year_ob_i and year_ob_f +; change long_name +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; model data info +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + + ENERGY ="new" + + nmonth = 12 + +;************************************************ +; observed data info +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + year_ob = (/"2003-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1999-2006" \ + ,"2002-2006" \ + ,"2000-2005" \ + ,"2004-2005" \ + ,"1996-2006" \ + ,"2004-2006" \ + ,"1999-2004" \ + ,"2003-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2005-2006" \ + ,"2004-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"2000-2006" \ + ,"2004-2006" \ + ,"2002-2006" \ + ,"1991-2004" \ + ,"2004-2004" \ + ,"1996-2004" \ + ,"1999-2004" \ + ,"2003-2006" \ + ,"2004-2006" \ + ,"2002-2002" \ + ,"2000-2006" \ + ,"2002-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2004-2005" \ + ,"2004-2005" \ + ,"2003-2005" \ + ,"1996-2000" \ + ,"2004-2006" \ + ,"1998-2004" \ + ,"1999-2005" \ + ,"1999-2003" \ + ,"2005-2006" \ + ,"2005-2006" \ + ,"1996-2003" \ + ,"1998-1998" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2004-2006" \ + ,"1997-2006" \ + ,"2002-2006" \ + ,"2004-2005" \ + ,"2001-2006" \ + ,"2004-2005" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2004" \ + ,"2001-2005" \ + ,"2001-2005" \ + ,"2002-2005" \ + ,"1999-2003" \ + ,"2001-2006" \ + ,"1995-1999" \ + ,"1999-2005" \ + ,"1999-2004" \ + ,"2003-2003" \ + ,"2003-2003" \ + ,"2002-2005" \ + ,"2004-2004" \ + ,"2002-2002" \ + ,"2005-2005" \ + ,"2002-2002" \ + ,"2004-2005" \ + ,"2002-2002" \ + /) + + field = (/"NEE Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"u mol/m2/s" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"u mol/m2/s" \ + ,"u mol/m2/s" \ + /) + + nstation = dimsizes(station) + nfield = dimsizes(field) + +;======================================================================== +; get observed info: number of year, first/last year, lat, lon +; and annual data + + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/observed/ameriflux/" + + year_station = new ((/nstation/),integer) ; number of year + year_ob_i = new ((/nstation/),integer) ; first year + year_ob_f = new ((/nstation/),integer) ; last year + lat_ob = new ((/nstation/),float) ; latitude + lon_ob = new ((/nstation/),float) ; longitude + + data_ob_ann = new ((/nfield, nmonth, nstation/),float) + + do n = 0, nstation-1 + + diro = dir_root + station(n)+"/" + filo = year_ob(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + + lat_ob(n) = fo->lat + lon_ob(n) = fo->lon + + year = fo->year + + year_station(n) = dimsizes(year) + year_ob_i(n) = year(0) + year_ob_f(n) = year(year_station(n)-1) + + delete (year) + + data = fo->NEE_or_fMDS + data_ob_ann(0,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->Rg_f + data_ob_ann(1,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->LE_f + data_ob_ann(2,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->H_f + data_ob_ann(3,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->GPP_or_MDS + data_ob_ann(4,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->Reco_or + data_ob_ann(5,:,n) = dim_avg(data(month|:,year|:)) + + delete (data) + delete (fo) + end do + +;print (year_ob_i) +;print (year_ob_f) + +;-------------------------------------------------------------- +; find (# of year observed) >=4 and year_ob_i <= 2001 + + i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001) + + station_long = station(i_long_ob) + lat_ob_long = lat_ob(i_long_ob) + lon_ob_long = lat_ob(i_long_ob) + year_ob_long = year_ob(i_long_ob) + year_ob_i_long = year_ob_i(i_long_ob) + year_ob_f_long = year_ob_f(i_long_ob) + year_station_long = year_station(i_long_ob) + + nstation_long = dimsizes(station_long) + +; print (i_long_ob) +; print (nstation_long) +; print (station_long) +; print (year_ob_i(i_long_ob)) + +;========================================================= +; get model data at observed lat-lon + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name+"_ameriflux_1990-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + xm = fm->lon + ym = fm->lat + date = fm->date + + date_dim = dimsizes(date) + nyear = date_dim(0) + + data_mod = new ((/nfield,nyear,nmonth,nstation/),float) + data_mod_ann = new ((/nfield,nmonth,nstation/),float) + data_mod_long = new ((/nfield,nyear,nmonth,nstation_long/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + + factor = 1.e6 /12. + +;------------------------------------------------------------ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. +;------------------------------------------------------------ + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod(0,:,:,:) = data(:,:,:) * factor + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod(3,:,:,:) = data(:,:,:) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod(1,:,:,:) = data1(:,:,:)-data2(:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor + data_mod(0,:,:,:) = yy(:,:,:) * factor + +; printVarSummary(yy) + + data = fm->NETRAD + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(1,:,:,:) = yy(:,:,:) + + data = fm->LATENT + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(2,:,:,:) = yy(:,:,:) + +; data = fm->SENSIBLE + data = fm->FSH + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(3,:,:,:) = yy(:,:,:) + +end if + + data = fm->GPP + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(4,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor + data_mod(4,:,:,:) = yy(:,:,:) * factor + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(5,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor + data_mod(5,:,:,:) = yy(:,:,:) * factor + + data_mod_long(:,:,:,:) = data_mod(:,:,:,i_long_ob) + + delete (data_mod) + delete (fm) + delete (data) + delete (yy) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) + + res@tmXBFormat = "f" ; not to add trailing zeros + +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + +;============================================================== +; get ob data at each site with long observation + + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + do n = 0,nstation_long-1 +; do n = 0,0 + + year_setback = 0 + + nyear = year_station_long(n) + + if (year_ob_f_long(n).eq. 2006) then + year_setback = 2006 -2004 + end if + if (year_ob_f_long(n).eq. 2005) then + year_setback = 2005 -2004 + end if + + ntime = (nyear - year_setback) * nmonth + + data_ob = new ((/nfield, nyear, nmonth/),float) + + diro = dir_root + station_long(n)+"/" + filo = year_ob_long(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + +; print (diro) +; print (filo) + + data_ob(0,:,:) = fo->NEE_or_fMDS + data_ob(1,:,:) = fo->Rg_f + data_ob(2,:,:) = fo->LE_f + data_ob(3,:,:) = fo->H_f + data_ob(4,:,:) = fo->GPP_or_MDS + data_ob(5,:,:) = fo->Reco_or + + delete (fo) + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_ob_i_long(n) + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + +;---------------------------- +; for model_vs_ob + + plot_name = station_long(n)+"_tseries_vs_ob" + title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + i_year_mod_i = year_ob_i_long(n) - 1990 + i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback + + i_year_ob_f = nyear - year_setback - 1 + +; print (nyear) +; print (i_year_ob_f) +; print (i_year_mod_i) +; print (i_year_mod_f) + + do i = 0,nfield-1 + plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:)) + plot_data(1,:) = ndtooned(data_mod_long(i,i_year_mod_i:i_year_mod_f,:,n)) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,timeF,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + delete (data_ob) + delete (timeI) + delete (timeF) + delete (plot_data) + + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) + + isort = dim_pqsort(lat_ob_long,-1) + + station_sort = station_long(isort) + year_ob_sort = year_ob_long(isort) + lat_ob_sort = lat_ob_long(isort) + lon_ob_sort = lon_ob_long(isort) + +; print(isort) +; print(lat_ob_sort) + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "tseries_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Timeseries at Site: "+model_name+" vs Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation_long-1 + + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + + delete (isort) + delete (station_sort) + delete (year_ob_sort) + delete (lat_ob_sort) + delete (lon_ob_sort) + +;************************************************************ +; compute annual cycle correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob_ann(m,:,n),data_mod_ann(m,:,n),0) + 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)))) + M_score(n,m) = (1. -(bias/nmonth)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_gpp = sprintf("%.2f", M_gpp) + M_energy_er = sprintf("%.2f", M_er ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + +;------------------------------------------------------------------- + + plot_data = new((/2,nmonth/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob_ann(i,:,n)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob_ann(i,:,n)/) + plot_data(1,:) = (/data_mod_ann(i,:,n)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) +; sort by lat in decending order (N->S) + + isort = dim_pqsort(lat_ob,-1) + + station_sort = station(isort) + year_ob_sort = year_ob(isort) + lat_ob_sort = lat_ob(isort) + lon_ob_sort = lon_ob(isort) + M_score_sort = M_score(isort,:) + +; print(isort) +; print(lat_ob_sort) +;################################################################### +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + txt4 = sprintf("%5.2f", M_score_sort(n,0)) + txt5 = sprintf("%5.2f", M_score_sort(n,1)) + txt6 = sprintf("%5.2f", M_score_sort(n,2)) + txt7 = sprintf("%5.2f", M_score_sort(n,3)) + txt8 = sprintf("%5.2f", M_score_sort(n,4)) + txt9 = sprintf("%5.2f", M_score_sort(n,5)) + txt10 = sprintf("%5.2f", avg(M_score_sort(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end + diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/24.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/24.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,847 @@ +;************************************************************ +; change data name to timeseries_L4_m.nc +; move data +; merge annual +; add table +; add time series plot +; sort by latitude in decending order (N->S) +; find year_ob >= 4 +; add year_ob_i and year_ob_f +; change long_name +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; model data info +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + + ENERGY ="new" + + nmonth = 12 + +;************************************************ +; observed data info +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + field = (/"NEE Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"u mol/m2/s" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"u mol/m2/s" \ + ,"u mol/m2/s" \ + /) + + nstation = dimsizes(station) + nfield = dimsizes(field) + +;======================================================================== +; get observed info: number of year, first/last year, lat, lon +; and annual data + + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/observed/ameriflux/" + + year_station = new ((/nstation/),integer) ; number of year + year_ob = new ((/nstation/),string) ; observed year + year_ob_i = new ((/nstation/),integer) ; first year + year_ob_f = new ((/nstation/),integer) ; last year + lat_ob = new ((/nstation/),float) ; latitude + lon_ob = new ((/nstation/),float) ; longitude + + data_ob_ann = new ((/nfield, nmonth, nstation/),float) + + do n = 0, nstation-1 + + diro = dir_root + station(n)+"/" + filo = "timeseries_L4_m.nc" + fo = addfile (diro+filo,"r") + + lat_ob(n) = fo->lat + lon_ob(n) = fo->lon + + year = fo->year + + year_station(n) = dimsizes(year) + year_ob_i(n) = year(0) + year_ob_f(n) = year(year_station(n)-1) + year_ob(n) = year_ob_i(n) + "-" + year_ob_f(n) + + delete (year) + + data = fo->NEE_or_fMDS + data_ob_ann(0,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->Rg_f + data_ob_ann(1,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->LE_f + data_ob_ann(2,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->H_f + data_ob_ann(3,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->GPP_or_MDS + data_ob_ann(4,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->Reco_or + data_ob_ann(5,:,n) = dim_avg(data(month|:,year|:)) + + delete (data) + delete (fo) + end do + +;print (year_ob_i) +;print (year_ob_f) + +;-------------------------------------------------------------- +; find (# of year observed) >=4 and year_ob_i <= 2001 + + i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001) + + station_long = station(i_long_ob) + lat_ob_long = lat_ob(i_long_ob) + lon_ob_long = lat_ob(i_long_ob) + year_ob_long = year_ob(i_long_ob) + year_ob_i_long = year_ob_i(i_long_ob) + year_ob_f_long = year_ob_f(i_long_ob) + year_station_long = year_station(i_long_ob) + + nstation_long = dimsizes(station_long) + +; print (i_long_ob) +; print (nstation_long) +; print (station_long) +; print (year_ob_i(i_long_ob)) + +;========================================================= +; get model data at observed lat-lon + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name+"_ameriflux_1990-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + xm = fm->lon + ym = fm->lat + date = fm->date + + date_dim = dimsizes(date) + nyear = date_dim(0) + + data_mod = new ((/nfield,nyear,nmonth,nstation/),float) + data_mod_ann = new ((/nfield,nmonth,nstation/),float) + data_mod_long = new ((/nfield,nyear,nmonth,nstation_long/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + + factor = 1.e6 /12. + +;------------------------------------------------------------ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. +;------------------------------------------------------------ + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod(0,:,:,:) = data(:,:,:) * factor + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod(3,:,:,:) = data(:,:,:) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod(1,:,:,:) = data1(:,:,:)-data2(:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor + data_mod(0,:,:,:) = yy(:,:,:) * factor + +; printVarSummary(yy) + + data = fm->NETRAD + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(1,:,:,:) = yy(:,:,:) + + data = fm->LATENT + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(2,:,:,:) = yy(:,:,:) + +; data = fm->SENSIBLE + data = fm->FSH + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(3,:,:,:) = yy(:,:,:) + +end if + + data = fm->GPP + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(4,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor + data_mod(4,:,:,:) = yy(:,:,:) * factor + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(5,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor + data_mod(5,:,:,:) = yy(:,:,:) * factor + + data_mod_long(:,:,:,:) = data_mod(:,:,:,i_long_ob) + + delete (data_mod) + delete (fm) + delete (data) + delete (yy) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) + + res@tmXBFormat = "f" ; not to add trailing zeros + +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + +;============================================================== +; get ob data at each site with long observation + + dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/" + + do n = 0,nstation_long-1 +; do n = 0,0 + + year_setback = 0 + + nyear = year_station_long(n) + + if (year_ob_f_long(n).eq. 2006) then + year_setback = 2006 -2004 + end if + if (year_ob_f_long(n).eq. 2005) then + year_setback = 2005 -2004 + end if + + ntime = (nyear - year_setback) * nmonth + + data_ob = new ((/nfield, nyear, nmonth/),float) + + diro = dir_root + station_long(n)+"/" + filo = year_ob_long(n)+"_L4_m.nc" + fo = addfile (diro+filo,"r") + +; print (diro) +; print (filo) + + data_ob(0,:,:) = fo->NEE_or_fMDS + data_ob(1,:,:) = fo->Rg_f + data_ob(2,:,:) = fo->LE_f + data_ob(3,:,:) = fo->H_f + data_ob(4,:,:) = fo->GPP_or_MDS + data_ob(5,:,:) = fo->Reco_or + + delete (fo) + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_ob_i_long(n) + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + +;---------------------------- +; for model_vs_ob + + plot_name = station_long(n)+"_tseries_vs_ob" + title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + i_year_mod_i = year_ob_i_long(n) - 1990 + i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback + + i_year_ob_f = nyear - year_setback - 1 + +; print (nyear) +; print (i_year_ob_f) +; print (i_year_mod_i) +; print (i_year_mod_f) + + do i = 0,nfield-1 + plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:)) + plot_data(1,:) = ndtooned(data_mod_long(i,i_year_mod_i:i_year_mod_f,:,n)) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,timeF,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + delete (data_ob) + delete (timeI) + delete (timeF) + delete (plot_data) + + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) + + isort = dim_pqsort(lat_ob_long,-1) + + station_sort = station_long(isort) + year_ob_sort = year_ob_long(isort) + lat_ob_sort = lat_ob_long(isort) + lon_ob_sort = lon_ob_long(isort) + +; print(isort) +; print(lat_ob_sort) + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "tseries_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Timeseries at Site: "+model_name+" vs Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation_long-1 + + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + + delete (isort) + delete (station_sort) + delete (year_ob_sort) + delete (lat_ob_sort) + delete (lon_ob_sort) + +;************************************************************ +; compute annual cycle correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob_ann(m,:,n),data_mod_ann(m,:,n),0) + 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)))) + M_score(n,m) = (1. -(bias/nmonth)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_gpp = sprintf("%.2f", M_gpp) + M_energy_er = sprintf("%.2f", M_er ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + +;------------------------------------------------------------------- + + plot_data = new((/2,nmonth/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob_ann(i,:,n)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob_ann(i,:,n)/) + plot_data(1,:) = (/data_mod_ann(i,:,n)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) +; sort by lat in decending order (N->S) + + isort = dim_pqsort(lat_ob,-1) + + station_sort = station(isort) + year_ob_sort = year_ob(isort) + lat_ob_sort = lat_ob(isort) + lon_ob_sort = lon_ob(isort) + M_score_sort = M_score(isort,:) + +; print(isort) +; print(lat_ob_sort) +;################################################################### +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + txt4 = sprintf("%5.2f", M_score_sort(n,0)) + txt5 = sprintf("%5.2f", M_score_sort(n,1)) + txt6 = sprintf("%5.2f", M_score_sort(n,2)) + txt7 = sprintf("%5.2f", M_score_sort(n,3)) + txt8 = sprintf("%5.2f", M_score_sort(n,4)) + txt9 = sprintf("%5.2f", M_score_sort(n,5)) + txt10 = sprintf("%5.2f", avg(M_score_sort(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end + diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/25.plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/25.plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,863 @@ +;************************************************************ +; change data name to timeseries_L4_m.nc +; move data +; merge annual +; add table +; add time series plot +; sort by latitude in decending order (N->S) +; find year_ob >= 4 +; add year_ob_i and year_ob_f +; change long_name +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; model data info +;************************************************ + model = "cn" +; model = "casa" + + model_name = "i01.10" + model + + ENERGY ="new" + + nmonth = 12 + +; for nee, gpp, and ar +; observed unit is gC/m2/day +; model unit is gC/m2/s +; to change to observed unit, + + factor_flux = 86400. + +; for incident solar radiation, +; observed Rg_f unit is MJ/m2/day +; model (FSDS) unit is W/m2 +; to change to model unit, + + factor_rad = 1.e6/86400. + +; model unit is gC/m2/s +; change to unit of observed (u mol/m2/s) +; 12. = molecular weight of C +; u mol = 1e-6 mol +; factor_flux = 1.e6 /12. + +;************************************************ +; observed data info +;************************************************ + + station = (/"ARM_Oklahoma" \ + ,"ARM_Oklahoma_burn" \ + ,"ARM_Oklahoma_control" \ + ,"Atqasuk" \ + ,"Audubon" \ + ,"AustinCary" \ + ,"Bartlett" \ + ,"Bondville" \ + ,"Brookings" \ + ,"Donaldson" \ + ,"Duke_Forest_Hardwoods" \ + ,"Duke_Forest_Open_Field" \ + ,"Duke_Forest_Pine" \ + ,"Fermi_Ag" \ + ,"Fermi_Prairie" \ + ,"Flagstaff_Managed" \ + ,"Flagstaff_Unmanaged" \ + ,"Flagstaff_Wildfire" \ + ,"FortPeck" \ + ,"FreemanRanch_mesquite" \ + ,"Goodwin_Creek" \ + ,"HarvardForest" \ + ,"HarvardForestHemlock" \ + ,"HowlandForestMain" \ + ,"HowlandForestWest" \ + ,"Ivotuk" \ + ,"KendallGrasslands" \ + ,"KennedySpaceCenterPine" \ + ,"KennedySpaceCenterScrub" \ + ,"LittleProspect" \ + ,"LostCreek" \ + ,"Mead-irrigated" \ + ,"Mead-irrigated-rotation" \ + ,"Mead-rainfed" \ + ,"Metolius_2nd_YoungPonderosaPine" \ + ,"MetoliusEyerly" \ + ,"MetoliusIntermediatePine" \ + ,"MetoliusOldPonderosaPine" \ + ,"MissouriOzark" \ + ,"Mize" \ + ,"MorganMonroe" \ + ,"NiwotRidge" \ + ,"NorthCarolina_cc" \ + ,"NorthCarolina_lp" \ + ,"ParkFalls" \ + ,"Rayonier" \ + ,"SantaRita" \ + ,"SkyOaks_Old" \ + ,"SkyOaks_PostFire" \ + ,"SkyOaks_Young" \ + ,"SylvaniaWilderness" \ + ,"Toledo" \ + ,"Tonzi" \ + ,"UCI_1850" \ + ,"UCI_1930" \ + ,"UCI_1964" \ + ,"UCI_1964wet" \ + ,"UCI_1981" \ + ,"UCI_1989" \ + ,"UCI_1998" \ + ,"UMBS" \ + ,"Vaira" \ + ,"WalkerBranch" \ + ,"WillowCreek" \ + ,"WindRiver" \ + ,"Wisconsin_ihw" \ + ,"Wisconsin_irp" \ + ,"Wisconsin_mrp" \ + ,"Wisconsin_myjp" \ + ,"Wisconsin_pb" \ + ,"Wisconsin_rpcc" \ + ,"Wisconsin_yhw" \ + ,"Wisconsin_yjp" \ + ,"Wisconsin_yrp" \ + /) + + field = (/"NEE Flux" \ + ,"Shortwave Incoming" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + ,"GPP Flux" \ + ,"Respiration" \ + /) + + field_unit = (/"gC/m2/day" \ + ,"W/m2" \ + ,"W/m2" \ + ,"W/m2" \ + ,"gC/m2/day" \ + ,"gC/m2/day" \ + /) + + nstation = dimsizes(station) + nfield = dimsizes(field) + +;======================================================================== +; get observed info: number of year, first/last year, lat, lon +; and annual data + + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/observed/ameriflux/" + + year_station = new ((/nstation/),integer) ; number of year + year_ob = new ((/nstation/),string) ; observed year + year_ob_i = new ((/nstation/),integer) ; first year + year_ob_f = new ((/nstation/),integer) ; last year + lat_ob = new ((/nstation/),float) ; latitude + lon_ob = new ((/nstation/),float) ; longitude + + data_ob_ann = new ((/nfield, nmonth, nstation/),float) + + do n = 0, nstation-1 + + diro = dir_root + station(n)+"/" + filo = "timeseries_L4_m.nc" + fo = addfile (diro+filo,"r") + + lat_ob(n) = fo->lat + lon_ob(n) = fo->lon + + year = fo->year + + year_station(n) = dimsizes(year) + year_ob_i(n) = year(0) + year_ob_f(n) = year(year_station(n)-1) + year_ob(n) = year_ob_i(n) + "-" + year_ob_f(n) + + delete (year) + + data = fo->NEE_or_fMDS + data_ob_ann(0,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->Rg_f + data_ob_ann(1,:,n) = dim_avg(data(month|:,year|:))*factor_rad + + data = fo->LE_f + data_ob_ann(2,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->H_f + data_ob_ann(3,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->GPP_or_MDS + data_ob_ann(4,:,n) = dim_avg(data(month|:,year|:)) + + data = fo->Reco_or + data_ob_ann(5,:,n) = dim_avg(data(month|:,year|:)) + + delete (data) + delete (fo) + end do + +;print (year_ob_i) +;print (year_ob_f) + +;-------------------------------------------------------------- +; find (# of year observed) >=4 and year_ob_i <= 2001 + + i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001) + + station_long = station(i_long_ob) + lat_ob_long = lat_ob(i_long_ob) + lon_ob_long = lat_ob(i_long_ob) + year_ob_long = year_ob(i_long_ob) + year_ob_i_long = year_ob_i(i_long_ob) + year_ob_f_long = year_ob_f(i_long_ob) + year_station_long = year_station(i_long_ob) + + nstation_long = dimsizes(station_long) + +; print (i_long_ob) +; print (nstation_long) +; print (station_long) +; print (year_ob_i(i_long_ob)) + +;========================================================= +; get model data at observed lat-lon + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name+"_ameriflux_1990-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + xm = fm->lon + ym = fm->lat + date = fm->date + + date_dim = dimsizes(date) + nyear = date_dim(0) + + data_mod = new ((/nfield,nyear,nmonth,nstation/),float) + data_mod_ann = new ((/nfield,nmonth,nstation/),float) + data_mod_long = new ((/nfield,nyear,nmonth,nstation_long/),float) + +;------------------------------------------------------------ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. +;------------------------------------------------------------ + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod(0,:,:,:) = data(:,:,:) * factor + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod(3,:,:,:) = data(:,:,:) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod(1,:,:,:) = data1(:,:,:)-data2(:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor_flux + data_mod(0,:,:,:) = yy(:,:,:) * factor_flux + +; printVarSummary(yy) + +; data = fm->NETRAD + data = fm->FSDS + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(1,:,:,:) = yy(:,:,:) + + data = fm->LATENT + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(2,:,:,:) = yy(:,:,:) + +; data = fm->SENSIBLE + data = fm->FSH + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:)) + data_mod(3,:,:,:) = yy(:,:,:) + +end if + + data = fm->GPP + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(4,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor_flux + data_mod(4,:,:,:) = yy(:,:,:) * factor_flux + + if (model .eq. "cn") then + data = fm->ER + else + data1 = fm->AR + data2 = fm->HR + data = data1 + data2 + + delete (data1) + delete (data2) + end if + + yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0) + data_mod_ann(5,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor_flux + data_mod(5,:,:,:) = yy(:,:,:) * factor_flux + + data_mod_long(:,:,:,:) = data_mod(:,:,:,i_long_ob) + + delete (data_mod) + delete (fm) + delete (data) + delete (yy) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) + + res@tmXBFormat = "f" ; not to add trailing zeros + +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + +;============================================================== +; get ob data at each site with long observation + + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/observed/ameriflux/" + + do n = 0,nstation_long-1 +; do n = 0,0 + + year_setback = 0 + + nyear = year_station_long(n) + + if (year_ob_f_long(n).eq. 2006) then + year_setback = 2006 -2004 + end if + if (year_ob_f_long(n).eq. 2005) then + year_setback = 2005 -2004 + end if + + ntime = (nyear - year_setback) * nmonth + + data_ob = new ((/nfield, nyear, nmonth/),float) + + diro = dir_root + station_long(n)+"/" + filo = "timeseries_L4_m.nc" + fo = addfile (diro+filo,"r") + +; print (diro) +; print (filo) + + data_ob(0,:,:) = fo->NEE_or_fMDS + data_ob(1,:,:) = fo->Rg_f + data_ob(2,:,:) = fo->LE_f + data_ob(3,:,:) = fo->H_f + data_ob(4,:,:) = fo->GPP_or_MDS + data_ob(5,:,:) = fo->Reco_or + + data_ob(1,:,:) = data_ob(1,:,:) * factor_rad + + delete (fo) + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_ob_i_long(n) + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + +;---------------------------- +; for model_vs_ob + + plot_name = station_long(n)+"_tseries_vs_ob" + title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + i_year_mod_i = year_ob_i_long(n) - 1990 + i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback + + i_year_ob_f = nyear - year_setback - 1 + +; print (nyear) +; print (i_year_ob_f) +; print (i_year_mod_i) +; print (i_year_mod_f) + + do i = 0,nfield-1 + plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:)) + plot_data(1,:) = ndtooned(data_mod_long(i,i_year_mod_i:i_year_mod_f,:,n)) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,timeF,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + delete (data_ob) + delete (timeI) + delete (timeF) + delete (plot_data) + + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) + + isort = dim_pqsort(lat_ob_long,-1) + + station_sort = station_long(isort) + year_ob_sort = year_ob_long(isort) + lat_ob_sort = lat_ob_long(isort) + lon_ob_sort = lon_ob_long(isort) + +; print(isort) +; print(lat_ob_sort) + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "tseries_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Timeseries at Site: "+model_name+" vs Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation_long-1 + + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + + delete (isort) + delete (station_sort) + delete (year_ob_sort) + delete (lat_ob_sort) + delete (lon_ob_sort) + +;************************************************************ +; compute annual cycle correlation coef and M score +;************************************************************ + + score_max = 1. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob_ann(m,:,n),data_mod_ann(m,:,n),0) + 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)))) + M_score(n,m) = (1. -(bias/nmonth)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_gpp = avg(M_score(:,4)) + M_er = avg(M_score(:,5)) + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_gpp = sprintf("%.2f", M_gpp) + M_energy_er = sprintf("%.2f", M_er ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + +;------------------------------------------------------------------- + + plot_data = new((/2,nmonth/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob_ann(i,:,n)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(nfield,graphic) ; create graphic array + + do i = 0,nfield-1 + plot_data(0,:) = (/data_ob_ann(i,:,n)/) + plot_data(1,:) = (/data_mod_ann(i,:,n)/) + plot_data@long_name = field(i)+" ("+field_unit(i)+")" + plot(i)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot + end do + + gsn_panel(wks,plot,(/3,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;################################################################### +; for the following tables, +; sort by latitude in decending order (N->S) +; sort by lat in decending order (N->S) + + isort = dim_pqsort(lat_ob,-1) + + station_sort = station(isort) + year_ob_sort = year_ob(isort) + lat_ob_sort = lat_ob(isort) + lon_ob_sort = lon_ob(isort) + M_score_sort = M_score(isort,:) + +; print(isort) +; print(lat_ob_sort) +;################################################################### +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatGPP GluxRespirationAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station_sort(n) + txt1 = sprintf("%5.2f", lat_ob_sort(n)) + txt2 = sprintf("%5.2f", lon_ob_sort(n)) + txt3 = year_ob_sort(n) + txt4 = sprintf("%5.2f", M_score_sort(n,0)) + txt5 = sprintf("%5.2f", M_score_sort(n,1)) + txt6 = sprintf("%5.2f", M_score_sort(n,2)) + txt7 = sprintf("%5.2f", M_score_sort(n,3)) + txt8 = sprintf("%5.2f", M_score_sort(n,4)) + txt9 = sprintf("%5.2f", M_score_sort(n,5)) + txt10 = sprintf("%5.2f", avg(M_score_sort(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_gpp + txt9 = M_energy_er + txt10 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/ameriflux" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end + diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/line_ob.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/line_ob.html Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,458 @@ + + +CLAMP metrics + +

Energy at Site: Observation

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Site NameLatitudeLongitudeObserved
Atqasuk70.47202.591999-2006
Ivotuk68.49204.252003-2006
UCI_199856.64260.052002-2005
UCI_198955.92261.042001-2005
UCI_1964wet55.91261.622002-2004
UCI_196455.91261.622001-2005
UCI_193055.91261.482001-2005
UCI_185055.88261.522004-2005
UCI_198155.86261.522001-2005
FortPeck48.31254.902000-2006
Wisconsin_mrp46.74268.832002-2005
Wisconsin_ihw46.73268.772003-2003
Wisconsin_yhw46.72268.752002-2002
Wisconsin_irp46.69268.852003-2003
Wisconsin_myjp46.65268.912004-2004
Wisconsin_rpcc46.65268.932005-2005
Wisconsin_pb46.62268.702002-2002
Wisconsin_yjp46.62268.922004-2005
Wisconsin_yrp46.62268.922002-2002
SylvaniaWilderness46.24270.652002-2006
LostCreek46.08270.022001-2005
ParkFalls45.95269.731996-2003
WindRiver45.82238.051999-2004
WillowCreek45.81269.921999-2005
UMBS45.56275.291999-2003
HowlandForestWest45.21291.251999-2004
HowlandForestMain45.20291.261996-2004
MetoliusEyerly44.58238.502004-2005
MetoliusOldPonderosaPine44.50238.381996-2000
MetoliusIntermediatePine44.45238.442003-2005
Brookings44.35263.162004-2006
Metolius_2nd_YoungPonderosaPine44.32238.392004-2005
Bartlett44.06288.712004-2005
LittleProspect42.54287.822002-2005
HarvardForestHemlock42.54287.822004-2004
HarvardForest42.54287.831991-2004
Fermi_Ag41.86271.782005-2006
Fermi_Prairie41.84271.762004-2006
Toledo41.55276.162004-2005
Mead-rainfed41.18263.562001-2005
Mead-irrigated41.17263.522001-2005
Mead-irrigated-rotation41.16263.532001-2005
NiwotRidge40.03254.451999-2003
Bondville40.01271.711996-2006
MorganMonroe39.32273.591999-2005
MissouriOzark38.74267.802004-2006
Tonzi38.43239.032001-2006
Vaira38.41239.052001-2006
ARM_Oklahoma36.60262.512003-2006
Duke_Forest_Pine35.98280.912001-2005
Duke_Forest_Hardwoods35.97280.902003-2005
Duke_Forest_Open_Field35.97280.912001-2005
WalkerBranch35.96275.711995-1999
NorthCarolina_cc35.81283.292005-2006
NorthCarolina_lp35.80283.332005-2006
ARM_Oklahoma_burn35.55261.962005-2006
ARM_Oklahoma_control35.55261.962005-2006
Flagstaff_Wildfire35.45248.232005-2006
Flagstaff_Managed35.13248.272005-2006
Flagstaff_Unmanaged35.09248.242005-2006
Goodwin_Creek34.25270.032002-2006
SkyOaks_PostFire33.38243.362004-2006
SkyOaks_Young33.38243.381997-2006
SkyOaks_Old33.37243.381997-2006
SantaRita31.82249.132004-2006
KendallGrasslands31.74250.062004-2006
Audubon31.59249.492002-2006
FreemanRanch_mesquite29.95262.002004-2006
Rayonier29.80277.801998-1998
Mize29.76277.761998-2004
Donaldson29.75277.841999-2004
AustinCary29.74277.782000-2005
KennedySpaceCenterScrub28.61279.332000-2006
KennedySpaceCenterPine28.46279.332002-2002
+ diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/note.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/note.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,2 @@ +I believe the observed Reco = AR + HR, the sum of autotrophic and +heterotrophic respiration. Forrest \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/note.list_lat-lon --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/note.list_lat-lon Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,148 @@ + +ARM_Oklahoma: 36.605 -97.4884 + +ARM_Oklahoma_burn: 35.54974 -98.04023 + +ARM_Oklahoma_control: 35.54649 -98.04006 + +Atqasuk: 70.46961 -157.4089 + +Audubon: 31.59073 -110.5104 + +AustinCary: 29.73807 -82.21877 + +Bartlett: 44.06464 -71.28808 + +Bondville: 40.0061 -88.29187 + +Brookings: 44.34529 -96.83617 + +Donaldson: 29.75477 -82.16328 + +Duke_Forest_Hardwoods: 35.9735823 -79.1004304 + +Duke_Forest_Open_Field: 35.9712024 -79.0933759 + +Duke_Forest_Pine: 35.9781659 -79.0941956 + +Fermi_Ag: 41.8593 -88.22273 + +Fermi_Prairie: 41.84062 -88.24103 + +Flagstaff_Managed: 35.13333 -111.7275 + +Flagstaff_Unmanaged: 35.08973 -111.7625 + +Flagstaff_Wildfire: 35.44557 -111.7718 + +FortPeck: 48.30788 -105.10005 + +FreemanRanch_mesquite: 29.94949 -97.99623 + +Goodwin_Creek: 34.25 -89.97 + +HarvardForest: 42.53776 -72.17148 + +HarvardForestHemlock: 42.53933 -72.17794 + +HowlandForestMain: 45.20407 -68.74028 + +HowlandForestWest: 45.20912 -68.747 + +Ivotuk: 68.48647 -155.7503 + +KendallGrasslands: 31.73653 -109.9419 + +KennedySpaceCenterPine: 28.4583 -80.6709 + +KennedySpaceCenterScrub: 28.60858 -80.67153 + +LittleProspect: 42.54186 -72.18496 + +LostCreek: 46.08268 -89.97919 + +Mead-irrigated: 41.16506 -96.47664 + +Mead-irrigated-rotation: 41.16487 -96.4701 + +Mead-rainfed: 41.17967 -96.43965 + +Metolius_2nd_YoungPonderosaPine: 44.31569 -121.6079 + +MetoliusEyerly: 44.57944 -121.5001 + +MetoliusIntermediatePine: 44.45243 -121.5572 + +MetoliusOldPonderosaPine: 44.49917 -121.6224 + +MissouriOzark: 38.74411 -92.20001 + +Mize: 29.7648 -82.24482 + +MorganMonroe: 39.32315 -86.41314 + +NiwotRidge: 40.03288 -105.5464 + +NorthCarolina_cc: 35.81147 -76.71147 + +NorthCarolina_lp: 35.8031 -76.66791 + +ParkFalls: 45.94588 -90.2723 + +Rayonier: 29.80282 -82.20315 + +SantaRita: 31.82143 -110.8661 + +SkyOaks_Old: 33.37389 -116.6229 + +SkyOaks_PostFire: 33.3844 -116.6403 + +SkyOaks_Young: 33.37719 -116.6227 + +SylvaniaWilderness: 46.24202 -89.34765 + +Toledo: 41.55454 -83.84376 + +Tonzi: 38.4316 -120.966 + +UCI_1850: 55.87917 -98.48389 + +UCI_1930: 55.90583 -98.52472 + +UCI_1964: 55.91167 -98.38222 + +UCI_1964wet: 55.91167 -98.38222 + +UCI_1981: 55.86306 -98.485 + +UCI_1989: 55.91667 -98.96444 + +UCI_1998: 56.63583 -99.94883 + +UMBS: 45.55984 -84.71382 + +Vaira: 38.40667 -120.9507 + +WalkerBranch: 35.95877 -84.28743 + +WillowCreek: 45.80593 -90.07986 + +WindRiver: 45.82049 -121.9519 + +Wisconsin_ihw: 46.73047 -91.23294 + +Wisconsin_irp: 46.68689 -91.15283 + +Wisconsin_mrp: 46.73933 -91.16625 + +Wisconsin_myjp: 46.65308 -91.08581 + +Wisconsin_pb: 46.62489 -91.29822 + +Wisconsin_rpcc: 46.64911 -91.06928 + +Wisconsin_yhw: 46.72233 -91.25242 + +Wisconsin_yjp: 46.61878 -91.08144 + +Wisconsin_yrp: 46.61878 -91.08144 diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/note.missing_year --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/note.missing_year Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,15 @@ +Atqasuk 2000 2002 + +Bondville 2000 + +NiwotRidge 2001 + +ParkFalls 2001 2002 + +SkyOaks_Old 2000 2001 2002 2003 + +SkyOaks_Young 1999 2000 2002 2004 + +UCI_1989 2003 + +WindRiver 2003 \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/note.ncract --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/note.ncract Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1 @@ +ncrcat ????_L4_m.nc 2003-2005_L4_m.nc \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 ameriflux/note.unit --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ameriflux/note.unit Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,37 @@ +For the monthly files from L4 Ameriflux, we are comparing the +following quantities with the models: + +H_f This is sensible heat flux, in units of +W/m2/day according to Ameriflux documentation +LE_f This is latent heat flux, in units of +W/m2/day according to Ameriflux documentation +Rg_f This is global radiation, in units of MJ/m2/day +Reco_or This is the ecosystem respiration flux, in +units of gC/m2/day +NEE_or_fMDS This is the net ecosystem exchange flux, in units of +gC/m2/day +GPP_or_MDS This is the gross primary production flux, in units +of gC/m2/day + +I do not personally understand the H and LE units for the +observations and have asked Ameriflux for clarification. Please skip for now. + +For Rg_f, please compare with the model variable SOLAR. Please label: +Shortwave incoming (Wm-2) +To convert Rg_f to units of Wm-2: + +X MJ/m2/day * (1 x 10^6 J/MJ)/(24*3600s/day) = Y Wm-2 + +For Reco_or please compare with the sum of model variables ar and hr. +Please label: Re (gC/m2/day) +For NEE_or_fMDS please compare with model variable nep. Please label +NEE (gC/m2/day) +For GPP_or_MDS please compare with model variable gpp. Please label +GPP (gC/m2/day) + +The last three model variables have units of KgC/m2/s. To convert to +gC/m2/day, please use this approach: + +X Kg C/m2/s *(1000 g C/Kg C)*(3600*24 s/day) = Y gC/m2/day + +Jim diff -r 000000000000 -r 0c6405ab2ff4 beta/01.co2_f.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beta/01.co2_f.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,25 @@ +; **************************************************** +; combine scatter, histogram, global and zonal plots +; compute all correlation coef and M score +; **************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ + +; Main code. +begin + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "surf_co2.clamp.T42.20070208.nc" + fm = addfile (dirm+film,"r") + + surf_co2 = fm->surf_co2 + + print (surf_co2(:,0,0)) + + avg_co2_1990_2004 = avg(surf_co2(192:206,0,0)) + + print (avg_co2_1990_2004) + +end diff -r 000000000000 -r 0c6405ab2ff4 beta/02.site.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beta/02.site.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,83 @@ +; **************************************************** +; combine scatter, histogram, global and zonal plots +; ********************************************************* + +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +; ********************************************************** + +; Main code. +begin + +;=================================================== +; observed station name and location (lat,lon) +;=================================================== + + beta_4_ob = 0.60 + + station = (/"DukeFACE" \ + ,"AspenFACE" \ + ,"ORNL-FACE" \ + ,"POP-EUROFACE" \ + /) + + lat_ob = (/ 35.58, 45.40, 35.54, 42.22/) + lon_ob = (/-79.05, -89.37, -84.20, 11.48/) + lon_ob = where(lon_ob.lt.0.,lon_ob+360.,lon_ob) +;print (lon_ob) + + n_sta = dimsizes(station) + +;==================================================== +; model data +;==================================================== + + co2_i = 283.1878 + co2_f = 364.1252 + +;model_name_i = "i01.07cn" +;model_name_f = "i01.10cn" + + model_name_i = "i01.07casa" + model_name_f = "i01.10casa" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film_i = model_name_i + "_1990-2004_ANN_climo.nc" + film_f = model_name_f + "_1990-2004_ANN_climo.nc" + + fm_i = addfile (dirm+film_i,"r") + fm_f = addfile (dirm+film_f,"r") + + npp_i = fm_i->NPP + npp_f = fm_f->NPP + + xm = fm_i->lon + ym = fm_i->lat + + npp_i_4 =linint2_points(xm,ym,npp_i,True,lon_ob,lat_ob,0) + + npp_f_4 =linint2_points(xm,ym,npp_f,True,lon_ob,lat_ob,0) + +; Units for these variables are: +; npp_i: g C/m^2/s + + print (npp_i_4) + print (npp_f_4) +;============================ +;compute beta +;============================ + + beta_4 = new((/n_sta/),float) + + beta_4 = ((npp_f_4/npp_i_4) - 1.)/log(co2_f/co2_i) + + beta_4_avg = avg(beta_4) + + print (beta_4) + print (beta_4_avg) + + M_beta = abs((beta_4_avg/beta_4_ob) - 1.)* 5. + + print (M_beta) +end diff -r 000000000000 -r 0c6405ab2ff4 beta/03.biome.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beta/03.biome.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,185 @@ +;******************************************************** +; histogram normalized by rain and compute correleration +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; Main code. +begin + + nclass = 20 + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read data: model +;************************************************ + co2_i = 283.1878 + co2_f = 364.1252 + + model_grid = "T42" + +;model_name_i = "i01.07cn" +;model_name_f = "i01.10cn" + + model_name_i = "i01.07casa" + model_name_f = "i01.10casa" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film_i = model_name_i + "_1990-2004_ANN_climo.nc" + film_f = model_name_f + "_1990-2004_ANN_climo.nc" + + fm_i = addfile (dirm+film_i,"r") + fm_f = addfile (dirm+film_f,"r") + + npp_i = fm_i->NPP + npp_f = fm_f->NPP + +;************************************************ +; read data: observed +;************************************************ + + ob_name = "MODIS MOD 15A2 2000-2005" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "land_class_"+model_grid+".nc" + + fo = addfile(diro+filo,"r") + + classob = tofloat(fo->LAND_CLASS) + + class_name = (/"Water Bodies" \ + ,"Evergreen Needleleaf Forests" \ + ,"Evergreen Broadleaf Forests" \ + ,"Deciduous Needleleaf Forest" \ + ,"Deciduous Broadleaf Forests" \ + ,"Mixed Forests" \ + ,"Closed Bushlands" \ + ,"Open Bushlands" \ + ,"Woody Savannas (S. Hem.)" \ + ,"Savannas (S. Hem.)" \ + ,"Grasslands" \ + ,"Permanent Wetlands" \ + ,"Croplands" \ + ,"Urban and Built-Up" \ + ,"Cropland/Natural Vegetation Mosaic" \ + ,"Permanent Snow and Ice" \ + ,"Barren or Sparsely Vegetated" \ + ,"Unclassified" \ + ,"Woody Savannas (N. Hem.)" \ + ,"Savannas (N. Hem.)" \ + /) + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + +; get data + + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(npp_i) + DATA22_1D = ndtooned(npp_f) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((data_ob.ge.range(i)).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(data_ob.ge.range(i)) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do + +;============================ +;compute beta +;============================ + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + ww = class_name(good) + + n_biome = dimsizes(uu) + + beta_biome = new((/n_biome/),float) + + beta_biome = ((vv/uu) - 1.)/log(co2_f/co2_i) + + beta_biome_avg = avg(beta_biome) + + print("class/beta: " + ww + "/" + beta_biome) + print (beta_biome_avg) + +end + diff -r 000000000000 -r 0c6405ab2ff4 beta/04.biome.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beta/04.biome.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,290 @@ +;******************************************************** +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + nclass = 20 + + plot_type = "ps" + plot_type_new = "png" +;************************************************ +; read data: model +;************************************************ + co2_i = 283.1878 + co2_f = 364.1252 + + model_grid = "T42" + +;model_name_i = "i01.07cn" +;model_name_f = "i01.10cn" + + model_name_i = "i01.07casa" + model_name_f = "i01.10casa" + + model_name = model_name_f + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film_i = model_name_i + "_1990-2004_ANN_climo.nc" + film_f = model_name_f + "_1990-2004_ANN_climo.nc" + + fm_i = addfile (dirm+film_i,"r") + fm_f = addfile (dirm+film_f,"r") + + npp_i = fm_i->NPP + npp_f = fm_f->NPP + +;************************************************ +; read data: observed +;************************************************ + + ob_name = "MODIS MOD 15A2 2000-2005" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "land_class_"+model_grid+".nc" + + fo = addfile(diro+filo,"r") + + classob = tofloat(fo->LAND_CLASS) + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + +; get data + + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(npp_i) + DATA22_1D = ndtooned(npp_f) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((data_ob.ge.range(i)).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(data_ob.ge.range(i)) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;============================ +;compute beta +;============================ + + nsec_per_year = 60*60*24*365 + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good)* nsec_per_year + vv = v(good)* nsec_per_year + + n_biome = dimsizes(uu) + + beta_biome = new((/n_biome/),float) + + beta_biome = ((vv/uu) - 1.)/log(co2_f/co2_i) + + beta_biome_avg = avg(beta_biome) + + print (beta_biome_avg) +;******************************************************************* +; for html table +;******************************************************************* + +; column (not including header column) + + col_head = (/"CO2_i","CO2_f","NPP_i","NPP_f","Beta"/) + + ncol = dimsizes(col_head) + +; row (not including header row) + row_head = (/"Water Bodies" \ + ,"Evergreen Needleleaf Forests" \ + ,"Evergreen Broadleaf Forests" \ + ,"Deciduous Needleleaf Forest" \ + ,"Deciduous Broadleaf Forests" \ + ,"Mixed Forests" \ + ,"Closed Bushlands" \ + ,"Open Bushlands" \ + ,"Woody Savannas (S. Hem.)" \ + ,"Savannas (S. Hem.)" \ + ,"Grasslands" \ + ,"Permanent Wetlands" \ + ,"Croplands" \ + ,"Cropland/Natural Vegetation Mosaic" \ + ,"Permanent Snow and Ice" \ + ,"Barren or Sparsely Vegetated" \ + ,"Woody Savannas (N. Hem.)" \ + ,"Savannas (N. Hem.)" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.2f",co2_i) + text4(i,1) = sprintf("%.2f",co2_f) + text4(i,2) = sprintf("%.2f",uu(i)) + text4(i,3) = sprintf("%.2f",vv(i)) + text4(i,4) = sprintf("%.2f",beta_biome(i)) + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = "-" + text4(nrow-1,4) = sprintf("%.2f",beta_biome_avg) + +;************************************************** +; html table +;************************************************** + output_html = "table_biome.html" + + header_text = "

Beta Factor: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome ClassCO2_iCO2_fNPP_iNPP_fBeta
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + txt5 = text4(n,3) + txt6 = text4(n,4) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +end + diff -r 000000000000 -r 0c6405ab2ff4 beta/05.biome.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beta/05.biome.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,487 @@ +;******************************************************** +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read data: model +;************************************************ + co2_i = 283.1878 + co2_f = 364.1252 + + model_grid = "T42" + + model_name_i = "i01.07cn" + model_name_f = "i01.10cn" + +;model_name_i = "i01.07casa" +;model_name_f = "i01.10casa" + + model_name = model_name_f + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film_i = model_name_i + "_1990-2004_ANN_climo.nc" + film_f = model_name_f + "_1990-2004_ANN_climo.nc" + + fm_i = addfile (dirm+film_i,"r") + fm_f = addfile (dirm+film_f,"r") + + xm = fm_f->lon + ym = fm_f->lat + + npp_i = fm_i->NPP + npp_f = fm_f->NPP + +;Units for these variables are: +;npp_i: g C/m^2/s + + nsec_per_year = 60*60*24*365 + + npp_i = npp_i * nsec_per_year + npp_f = npp_f * nsec_per_year + +;=================================================== +; read data: observed -station +;=================================================== + + station = (/"DukeFACE" \ + ,"AspenFACE" \ + ,"ORNL-FACE" \ + ,"POP-EUROFACE" \ + /) + + lat_ob = (/ 35.58, 45.40, 35.54, 42.22/) + lon_ob = (/-79.05, -89.37, -84.20, 11.48/) + lon_ob = where(lon_ob.lt.0.,lon_ob+360.,lon_ob) +;print (lon_ob) + + n_sta = dimsizes(station) + beta_4_ob = new((/n_sta/),float) + beta_4_ob = 0.60 + +;=================================================== +; get model data at station +;=================================================== + + npp_i_4 =linint2_points(xm,ym,npp_i,True,lon_ob,lat_ob,0) + + npp_f_4 =linint2_points(xm,ym,npp_f,True,lon_ob,lat_ob,0) + +;print (npp_i_4) +;print (npp_f_4) +;============================ +;compute beta_4 +;============================ + beta_4 = new((/n_sta/),float) + + beta_4 = ((npp_f_4/npp_i_4) - 1.)/log(co2_f/co2_i) + + beta_4_avg = avg(beta_4) + +;print (beta_4) +;print (beta_4_avg) + +;M_beta = abs((beta_4_avg/beta_4_ob) - 1.)* 3. + + bias = sum(abs(beta_4-beta_4_ob)/(abs(beta_4)+abs(beta_4_ob))) + M_beta = (1. - (bias/n_sta))*3. + + print (M_beta) + +;========================= +; for html table - station +;========================= + + output_html = "table_station.html" + +; column (not including header column) + + col_head = (/"Latitude","Longitude","CO2_i","CO2_f","NPP_i","NPP_f","Beta_model","Beta_ob"/) + + ncol = dimsizes(col_head) + +; row (not including header row) + row_head = (/"DukeFACE" \ + ,"AspenFACE" \ + ,"ORNL-FACE" \ + ,"POP-EUROFACE" \ + ,"All Station" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",lat_ob(i)) + text4(i,1) = sprintf("%.1f",lon_ob(i)) + text4(i,2) = sprintf("%.1f",co2_i) + text4(i,3) = sprintf("%.1f",co2_f) + text4(i,4) = sprintf("%.1f",npp_i_4(0,i)) + text4(i,5) = sprintf("%.1f",npp_f_4(0,i)) + text4(i,6) = sprintf("%.1f",beta_4(i)) + text4(i,7) = "-" + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = "-" + text4(nrow-1,4) = "-" + text4(nrow-1,5) = "-" + text4(nrow-1,6) = sprintf("%.1f",beta_4_avg) + text4(nrow-1,7) = sprintf("%.1f",avg(beta_4_ob)) + +;----------- +; html table +;----------- + + header_text = "

Beta Factor: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Station"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+""+col_head(7)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + txt5 = text4(n,3) + txt6 = text4(n,4) + txt7 = text4(n,5) + txt8 = text4(n,6) + txt9 = text4(n,7) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (col_head) + delete (row_head) + delete (text4) + delete (table_header) + delete (idx) + +;************************************************ +; read data: observed-2 +;************************************************ + + ob_name = "MODIS MOD 15A2 2000-2005" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "land_class_"+model_grid+".nc" + + fo = addfile(diro+filo,"r") + + classob = tofloat(fo->LAND_CLASS) + + nclass = 20 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. +; get data + + base_1D = ndtooned(classob) + data1_1D = ndtooned(npp_i) + data2_1D = ndtooned(npp_f) + +; output + + yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing data1 (nd=0) or data2 (nd=1). + + base = base_1D + + if(nd.eq.0) then + data = data1_1D + else + data = data2_1D + end if + +; Loop through each range, using base. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(base.ge.range(i)) + end if + +; Calculate average + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data(idx)) + count = dimsizes(idx) + else + yvalues(nd,i) = yvalues@_FillValue + count = 0 + end if + +;############################################################# +; set the following 4 classes to _FillValue: +; Water Bodies(0), Urban and Build-Up(13), +; Permenant Snow and Ice(15), Unclassified(17) + + if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then + yvalues(nd,i) = yvalues@_FillValue + count = 0 + end if +;############################################################# + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + + delete(data) + end do + + +;============================ +;compute beta +;============================ + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + + uu = u(good) + vv = v(good) + + n_biome = dimsizes(uu) + + beta_biome = new((/n_biome/),float) + + beta_biome = ((vv/uu) - 1.)/log(co2_f/co2_i) + + beta_biome_avg = avg(beta_biome) + +;print (beta_biome_avg) + +;=========================== +; for html table - biome +;=========================== + + output_html = "table_biome.html" + +; column (not including header column) + + col_head = (/"CO2_i","CO2_f","NPP_i","NPP_f","Beta_model"/) + + ncol = dimsizes(col_head) + +; row (not including header row) +; 3 classes removed: Water Bodies, Urban and Build-Up, Unclassified +; function "good" removed the last 2 classes +; text4(i,2) = sprintf("%.2f",uu(i+1)) remove the first class + + row_head = (/"Evergreen Needleleaf Forests" \ + ,"Evergreen Broadleaf Forests" \ + ,"Deciduous Needleleaf Forest" \ + ,"Deciduous Broadleaf Forests" \ + ,"Mixed Forests" \ + ,"Closed Bushlands" \ + ,"Open Bushlands" \ + ,"Woody Savannas (S. Hem.)" \ + ,"Savannas (S. Hem.)" \ + ,"Grasslands" \ + ,"Permanent Wetlands" \ + ,"Croplands" \ + ,"Cropland/Natural Vegetation Mosaic" \ + ,"Barren or Sparsely Vegetated" \ + ,"Woody Savannas (N. Hem.)" \ + ,"Savannas (N. Hem.)" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",co2_i) + text4(i,1) = sprintf("%.1f",co2_f) + text4(i,2) = sprintf("%.1f",uu(i)) + text4(i,3) = sprintf("%.1f",vv(i)) + text4(i,4) = sprintf("%.1f",beta_biome(i)) + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = "-" + text4(nrow-1,4) = sprintf("%.1f",beta_biome_avg) + +;************************************************** +; html table +;************************************************** + + header_text = "

Beta Factor: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Class"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + txt5 = text4(n,3) + txt6 = text4(n,4) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +end + diff -r 000000000000 -r 0c6405ab2ff4 beta/06.biome_model.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beta/06.biome_model.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,571 @@ +;******************************************************** +; using model biome +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read data: model +;************************************************ + co2_i = 283.1878 + co2_f = 364.1252 + + model_grid = "T42" + +;model_name_i = "i01.07cn" +;model_name_f = "i01.10cn" + + model_name_i = "i01.07casa" + model_name_f = "i01.10casa" + + model_name = model_name_f + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film_i = model_name_i + "_1990-2004_ANN_climo.nc" + film_f = model_name_f + "_1990-2004_ANN_climo.nc" + + fm_i = addfile (dirm+film_i,"r") + fm_f = addfile (dirm+film_f,"r") + + xm = fm_f->lon + ym = fm_f->lat + + npp_i = fm_i->NPP + npp_f = fm_f->NPP + + delete (fm_i) + delete (fm_f) + +;Units for these variables are: +;npp_i: g C/m^2/s + + nsec_per_year = 60*60*24*365 + + npp_i = npp_i * nsec_per_year + npp_f = npp_f * nsec_per_year + +;=================================================== +; read data: observed at stations +;=================================================== + + station = (/"DukeFACE" \ + ,"AspenFACE" \ + ,"ORNL-FACE" \ + ,"POP-EUROFACE" \ + /) + + lat_ob = (/ 35.58, 45.40, 35.54, 42.22/) + lon_ob = (/-79.05, -89.37, -84.20, 11.48/) + lon_ob = where(lon_ob.lt.0.,lon_ob+360.,lon_ob) +;print (lon_ob) + + n_sta = dimsizes(station) + beta_4_ob = new((/n_sta/),float) + beta_4_ob = 0.60 + +;=================================================== +; get model data at station +;=================================================== + + npp_i_4 =linint2_points(xm,ym,npp_i,True,lon_ob,lat_ob,0) + + npp_f_4 =linint2_points(xm,ym,npp_f,True,lon_ob,lat_ob,0) + +;print (npp_i_4) +;print (npp_f_4) + +;============================ +;compute beta_4 +;============================ + + beta_4 = new((/n_sta/),float) + + beta_4 = ((npp_f_4/npp_i_4) - 1.)/log(co2_f/co2_i) + + beta_4_avg = avg(beta_4) + +;print (beta_4) +;print (beta_4_avg) + +;M_beta = abs((beta_4_avg/beta_4_ob) - 1.)* 3. + + bias = sum(abs(beta_4-beta_4_ob)/(abs(beta_4)+abs(beta_4_ob))) + M_beta = (1. - (bias/n_sta))*3. + + print (M_beta) + +;========================= +; for html table - station +;========================= + + output_html = "table_station.html" + +; column (not including header column) + + col_head = (/"Latitude","Longitude","CO2_i","CO2_f","NPP_i","NPP_f","Beta_model","Beta_ob"/) + + ncol = dimsizes(col_head) + +; row (not including header row) + row_head = (/"DukeFACE" \ + ,"AspenFACE" \ + ,"ORNL-FACE" \ + ,"POP-EUROFACE" \ + ,"All Station" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",lat_ob(i)) + text4(i,1) = sprintf("%.1f",lon_ob(i)) + text4(i,2) = sprintf("%.1f",co2_i) + text4(i,3) = sprintf("%.1f",co2_f) + text4(i,4) = sprintf("%.1f",npp_i_4(0,i)) + text4(i,5) = sprintf("%.1f",npp_f_4(0,i)) + text4(i,6) = sprintf("%.2f",beta_4(i)) + text4(i,7) = "-" + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = "-" + text4(nrow-1,4) = "-" + text4(nrow-1,5) = "-" + text4(nrow-1,6) = sprintf("%.2f",beta_4_avg) + text4(nrow-1,7) = sprintf("%.2f",avg(beta_4_ob)) + +;----------- +; html table +;----------- + + header_text = "

Beta Factor: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Station"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+""+col_head(7)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + txt5 = text4(n,3) + txt6 = text4(n,4) + txt7 = text4(n,5) + txt8 = text4(n,6) + txt9 = text4(n,7) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (col_head) + delete (row_head) + delete (text4) + delete (table_header) + delete (idx) + +;------------------------------------------------ +; read biome data: model + + biome_name_mod = "Model PFT Class" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "class_pft_"+model_grid+".nc" + + fm = addfile(dirm+film,"r") + + classmod = fm->CLASS_PFT + + delete (fm) + +; model data has 17 land-type classes + + nclass_mod = 17 + +;------------------------------------------------ +; read biome data: observed + + biome_name_ob = "MODIS LandCover" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "land_class_"+model_grid+".nc" + + fo = addfile(diro+filo,"r") + + classob = tofloat(fo->LAND_CLASS) + + delete (fo) + +; input observed data has 20 land-type classes + + nclass_ob = 20 + +;******************************************************************** +; use land-type class to bin the data in equally spaced ranges +;******************************************************************** + +; using observed biome class +; nclass = nclass_ob +; using model biome class + nclass = nclass_mod + + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base_1D = ndtooned(classob) +; using model biome class + base_1D = ndtooned(classmod) + + data1_1D = ndtooned(npp_i) + data2_1D = ndtooned(npp_f) + +; output + + yvalues = new((/2,nx/),float) + count = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing data1 (nd=0) or data2 (nd=1). + + base = base_1D + + if(nd.eq.0) then + data = data1_1D + else + data = data2_1D + end if + +; Loop through each range, using base. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(base.ge.range(i)) + end if + +; Calculate average + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data(idx)) + count(nd,i) = dimsizes(idx) + else + yvalues(nd,i) = yvalues@_FillValue + count(nd,i) = 0 + end if + +;############################################################# +;using observed biome class: +; +; set the following 4 classes to _FillValue: +; Water Bodies(0), Urban and Build-Up(13), +; Permenant Snow and Ice(15), Unclassified(17) + +; if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then +; yvalues(nd,i) = yvalues@_FillValue +; count(nd,i) = 0 +; end if +;############################################################# + +;############################################################# +;using model biome class: +; +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(nd,i) = yvalues@_FillValue + count(nd,i) = 0 + end if +;############################################################# + +; print(nd + ": " + count(nd,i) + " points, avg = " + yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + + delete(data) + end do + +;============================ +;compute beta +;============================ + + u = yvalues(0,:) + v = yvalues(1,:) + u_count = count(0,:) + v_count = count(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + + uu = u(good) + vv = v(good) + uu_count = u_count(good) + vv_count = v_count(good) + + n_biome = dimsizes(uu) + beta_biome = new((/n_biome/),float) + + beta_biome = ((vv/uu) - 1.)/log(co2_f/co2_i) + +;beta_biome_avg = avg(beta_biome) + beta_biome_avg = (sum(vv*vv_count)/sum(uu*uu_count) - 1.)/log(co2_f/co2_i) + +;print (beta_biome_avg) + +;=========================== +; for html table - biome +;=========================== + + output_html = "table_biome.html" + +; column (not including header column) + + col_head = (/"CO2_i","CO2_f","NPP_i","NPP_f","Beta_model"/) + + ncol = dimsizes(col_head) + +; row (not including header row) + +;---------------------------------------------------- +; using observed biome class: +; +; row_head = (/"Evergreen Needleleaf Forests" \ +; ,"Evergreen Broadleaf Forests" \ +; ,"Deciduous Needleleaf Forest" \ +; ,"Deciduous Broadleaf Forests" \ +; ,"Mixed Forests" \ +; ,"Closed Bushlands" \ +; ,"Open Bushlands" \ +; ,"Woody Savannas (S. Hem.)" \ +; ,"Savannas (S. Hem.)" \ +; ,"Grasslands" \ +; ,"Permanent Wetlands" \ +; ,"Croplands" \ +; ,"Cropland/Natural Vegetation Mosaic" \ +; ,"Barren or Sparsely Vegetated" \ +; ,"Woody Savannas (N. Hem.)" \ +; ,"Savannas (N. Hem.)" \ +; ,"All Biome" \ +; /) + +;---------------------------------------------------- +; using model biome class: +; + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",co2_i) + text4(i,1) = sprintf("%.1f",co2_f) + text4(i,2) = sprintf("%.1f",uu(i)) + text4(i,3) = sprintf("%.1f",vv(i)) + text4(i,4) = sprintf("%.2f",beta_biome(i)) + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = "-" + text4(nrow-1,4) = sprintf("%.2f",beta_biome_avg) + +;************************************************** +; html table +;************************************************** + + header_text = "

Beta Factor: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Class"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + txt5 = text4(n,3) + txt6 = text4(n,4) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +end + diff -r 000000000000 -r 0c6405ab2ff4 beta/06.biome_ob.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beta/06.biome_ob.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,494 @@ +;******************************************************** +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read data: model +;************************************************ + co2_i = 283.1878 + co2_f = 364.1252 + + model_grid = "T42" + + model_name_i = "i01.07cn" + model_name_f = "i01.10cn" + +;model_name_i = "i01.07casa" +;model_name_f = "i01.10casa" + + model_name = model_name_f + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film_i = model_name_i + "_1990-2004_ANN_climo.nc" + film_f = model_name_f + "_1990-2004_ANN_climo.nc" + + fm_i = addfile (dirm+film_i,"r") + fm_f = addfile (dirm+film_f,"r") + + xm = fm_f->lon + ym = fm_f->lat + + npp_i = fm_i->NPP + npp_f = fm_f->NPP + +;Units for these variables are: +;npp_i: g C/m^2/s + + nsec_per_year = 60*60*24*365 + + npp_i = npp_i * nsec_per_year + npp_f = npp_f * nsec_per_year + +;=================================================== +; read data: observed -station +;=================================================== + + station = (/"DukeFACE" \ + ,"AspenFACE" \ + ,"ORNL-FACE" \ + ,"POP-EUROFACE" \ + /) + + lat_ob = (/ 35.58, 45.40, 35.54, 42.22/) + lon_ob = (/-79.05, -89.37, -84.20, 11.48/) + lon_ob = where(lon_ob.lt.0.,lon_ob+360.,lon_ob) +;print (lon_ob) + + n_sta = dimsizes(station) + beta_4_ob = new((/n_sta/),float) + beta_4_ob = 0.60 + +;=================================================== +; get model data at station +;=================================================== + + npp_i_4 =linint2_points(xm,ym,npp_i,True,lon_ob,lat_ob,0) + + npp_f_4 =linint2_points(xm,ym,npp_f,True,lon_ob,lat_ob,0) + +;print (npp_i_4) +;print (npp_f_4) + +;============================ +;compute beta_4 +;============================ + + beta_4 = new((/n_sta/),float) + + beta_4 = ((npp_f_4/npp_i_4) - 1.)/log(co2_f/co2_i) + + beta_4_avg = avg(beta_4) + +;print (beta_4) +;print (beta_4_avg) + +;M_beta = abs((beta_4_avg/beta_4_ob) - 1.)* 3. + + bias = sum(abs(beta_4-beta_4_ob)/(abs(beta_4)+abs(beta_4_ob))) + M_beta = (1. - (bias/n_sta))*3. + + print (M_beta) + +;========================= +; for html table - station +;========================= + + output_html = "table_station.html" + +; column (not including header column) + + col_head = (/"Latitude","Longitude","CO2_i","CO2_f","NPP_i","NPP_f","Beta_model","Beta_ob"/) + + ncol = dimsizes(col_head) + +; row (not including header row) + row_head = (/"DukeFACE" \ + ,"AspenFACE" \ + ,"ORNL-FACE" \ + ,"POP-EUROFACE" \ + ,"All Station" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",lat_ob(i)) + text4(i,1) = sprintf("%.1f",lon_ob(i)) + text4(i,2) = sprintf("%.1f",co2_i) + text4(i,3) = sprintf("%.1f",co2_f) + text4(i,4) = sprintf("%.1f",npp_i_4(0,i)) + text4(i,5) = sprintf("%.1f",npp_f_4(0,i)) + text4(i,6) = sprintf("%.2f",beta_4(i)) + text4(i,7) = "-" + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = "-" + text4(nrow-1,4) = "-" + text4(nrow-1,5) = "-" + text4(nrow-1,6) = sprintf("%.2f",beta_4_avg) + text4(nrow-1,7) = sprintf("%.2f",avg(beta_4_ob)) + +;----------- +; html table +;----------- + + header_text = "

Beta Factor: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Station"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+""+col_head(7)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + txt5 = text4(n,3) + txt6 = text4(n,4) + txt7 = text4(n,5) + txt8 = text4(n,6) + txt9 = text4(n,7) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (col_head) + delete (row_head) + delete (text4) + delete (table_header) + delete (idx) + +;************************************************ +; read data: observed-2 +;************************************************ + + ob_name = "MODIS MOD 15A2 2000-2005" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "land_class_"+model_grid+".nc" + + fo = addfile(diro+filo,"r") + + classob = tofloat(fo->LAND_CLASS) + +; observed data has 20 land-type classes + nclass = 20 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. +; get data + + base_1D = ndtooned(classob) + data1_1D = ndtooned(npp_i) + data2_1D = ndtooned(npp_f) + +; output + + yvalues = new((/2,nx/),float) + count = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing data1 (nd=0) or data2 (nd=1). + + base = base_1D + + if(nd.eq.0) then + data = data1_1D + else + data = data2_1D + end if + +; Loop through each range, using base. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(base.ge.range(i)) + end if + +; Calculate average + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data(idx)) + count(nd,i) = dimsizes(idx) + else + yvalues(nd,i) = yvalues@_FillValue + count(nd,i) = 0 + end if + +;############################################################# +; set the following 4 classes to _FillValue: +; Water Bodies(0), Urban and Build-Up(13), +; Permenant Snow and Ice(15), Unclassified(17) + + if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then + yvalues(nd,i) = yvalues@_FillValue + count(nd,i) = 0 + end if +;############################################################# + +; print(nd + ": " + count(nd,i) + " points, avg = " + yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + + delete(data) + end do + +;============================ +;compute beta +;============================ + + u = yvalues(0,:) + v = yvalues(1,:) + u_count = count(0,:) + v_count = count(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + + uu = u(good) + vv = v(good) + uu_count = u_count(good) + vv_count = v_count(good) + + n_biome = dimsizes(uu) + beta_biome = new((/n_biome/),float) + + beta_biome = ((vv/uu) - 1.)/log(co2_f/co2_i) + +;beta_biome_avg = avg(beta_biome) + beta_biome_avg = (sum(vv*vv_count)/sum(uu*uu_count) - 1.)/log(co2_f/co2_i) + + print (beta_biome_avg) + +;=========================== +; for html table - biome +;=========================== + + output_html = "table_biome.html" + +; column (not including header column) + + col_head = (/"CO2_i","CO2_f","NPP_i","NPP_f","Beta_model"/) + + ncol = dimsizes(col_head) + +; row (not including header row) +; 3 classes removed: Water Bodies, Urban and Build-Up, Unclassified +; function "good" removed the last 2 classes +; text4(i,2) = sprintf("%.2f",uu(i+1)) remove the first class + + row_head = (/"Evergreen Needleleaf Forests" \ + ,"Evergreen Broadleaf Forests" \ + ,"Deciduous Needleleaf Forest" \ + ,"Deciduous Broadleaf Forests" \ + ,"Mixed Forests" \ + ,"Closed Bushlands" \ + ,"Open Bushlands" \ + ,"Woody Savannas (S. Hem.)" \ + ,"Savannas (S. Hem.)" \ + ,"Grasslands" \ + ,"Permanent Wetlands" \ + ,"Croplands" \ + ,"Cropland/Natural Vegetation Mosaic" \ + ,"Barren or Sparsely Vegetated" \ + ,"Woody Savannas (N. Hem.)" \ + ,"Savannas (N. Hem.)" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",co2_i) + text4(i,1) = sprintf("%.1f",co2_f) + text4(i,2) = sprintf("%.1f",uu(i)) + text4(i,3) = sprintf("%.1f",vv(i)) + text4(i,4) = sprintf("%.2f",beta_biome(i)) + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = "-" + text4(nrow-1,4) = sprintf("%.2f",beta_biome_avg) + +;************************************************** +; html table +;************************************************** + + header_text = "

Beta Factor: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Class"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + txt5 = text4(n,3) + txt6 = text4(n,4) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +end + diff -r 000000000000 -r 0c6405ab2ff4 beta/07.landfrac.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beta/07.landfrac.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,591 @@ +;******************************************************** +; take into account landfrac +; note: landfrac from lnd_T42.nc +; <= lnd_diag_4.0 has correct landfrac +; lnd_diag_3.1 has wrong landfrac +; +; using model biome +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read data: model +;************************************************ + co2_i = 283.1878 + co2_f = 364.1252 + + model_grid = "T42" + +;model_name_i = "i01.07cn" +;model_name_f = "i01.10cn" + + model_name_i = "i01.07casa" + model_name_f = "i01.10casa" + + model_name = model_name_f + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film_i = model_name_i + "_1990-2004_ANN_climo.nc" + film_f = model_name_f + "_1990-2004_ANN_climo.nc" + + fm_i = addfile (dirm+film_i,"r") + fm_f = addfile (dirm+film_f,"r") + + xm = fm_f->lon + ym = fm_f->lat + + npp_i = fm_i->NPP + npp_f = fm_f->NPP + + delete (fm_i) + delete (fm_f) + +;Units for these variables are: +;npp_i: g C/m^2/s + + nsec_per_year = 60*60*24*365 + + npp_i = npp_i * nsec_per_year + npp_f = npp_f * nsec_per_year + +;-------------------------------------------------- +;get landfrac data + + dirm= "/fis/cgd/cseg/people/jeff/surface_data/" + film_l = "lnd_T42.nc" + fm_l = addfile (dirm+film_l,"r") + + landfrac = fm_l->landfrac + +;npp_i(0,:,:) = npp_i(0,:,:) * landfrac(:,:) +;npp_f(0,:,:) = npp_f(0,:,:) * landfrac(:,:) + + npp_i = npp_i * conform(npp_i, landfrac, (/1,2/)) + npp_f = npp_f * conform(npp_f, landfrac, (/1,2/)) + +;=================================================== +; read data: observed at stations +;=================================================== + + station = (/"DukeFACE" \ + ,"AspenFACE" \ + ,"ORNL-FACE" \ + ,"POP-EUROFACE" \ + /) + + lat_ob = (/ 35.58, 45.40, 35.54, 42.22/) + lon_ob = (/-79.05, -89.37, -84.20, 11.48/) + lon_ob = where(lon_ob.lt.0.,lon_ob+360.,lon_ob) +;print (lon_ob) + + n_sta = dimsizes(station) + beta_4_ob = new((/n_sta/),float) + beta_4_ob = 0.60 + +;=================================================== +; get model data at station +;=================================================== + + npp_i_4 =linint2_points(xm,ym,npp_i,True,lon_ob,lat_ob,0) + + npp_f_4 =linint2_points(xm,ym,npp_f,True,lon_ob,lat_ob,0) + +;print (npp_i_4) +;print (npp_f_4) + +;============================ +;compute beta_4 +;============================ + + beta_4 = new((/n_sta/),float) + + beta_4 = ((npp_f_4/npp_i_4) - 1.)/log(co2_f/co2_i) + + beta_4_avg = avg(beta_4) + +;print (beta_4) +;print (beta_4_avg) + +;M_beta = abs((beta_4_avg/beta_4_ob) - 1.)* 3. + + bias = sum(abs(beta_4-beta_4_ob)/(abs(beta_4)+abs(beta_4_ob))) + M_beta = (1. - (bias/n_sta))*3. + + print (M_beta) + +;========================= +; for html table - station +;========================= + + output_html = "table_station.html" + +; column (not including header column) + + col_head = (/"Latitude","Longitude","CO2_i","CO2_f","NPP_i","NPP_f","Beta_model","Beta_ob"/) + + ncol = dimsizes(col_head) + +; row (not including header row) + row_head = (/"DukeFACE" \ + ,"AspenFACE" \ + ,"ORNL-FACE" \ + ,"POP-EUROFACE" \ + ,"All Station" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",lat_ob(i)) + text4(i,1) = sprintf("%.1f",lon_ob(i)) + text4(i,2) = sprintf("%.1f",co2_i) + text4(i,3) = sprintf("%.1f",co2_f) + text4(i,4) = sprintf("%.1f",npp_i_4(0,i)) + text4(i,5) = sprintf("%.1f",npp_f_4(0,i)) + text4(i,6) = sprintf("%.2f",beta_4(i)) + text4(i,7) = "-" + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = "-" + text4(nrow-1,4) = "-" + text4(nrow-1,5) = "-" + text4(nrow-1,6) = sprintf("%.2f",beta_4_avg) + text4(nrow-1,7) = sprintf("%.2f",avg(beta_4_ob)) + +;----------- +; html table +;----------- + + header_text = "

Beta Factor: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Station"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+""+col_head(7)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + txt5 = text4(n,3) + txt6 = text4(n,4) + txt7 = text4(n,5) + txt8 = text4(n,6) + txt9 = text4(n,7) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (col_head) + delete (row_head) + delete (text4) + delete (table_header) + delete (idx) + +;------------------------------------------------ +; read biome data: model + + biome_name_mod = "Model PFT Class" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "class_pft_"+model_grid+".nc" + + fm = addfile(dirm+film,"r") + + classmod = fm->CLASS_PFT + + delete (fm) + +; model data has 17 land-type classes + + nclass_mod = 17 + +;------------------------------------------------ +; read biome data: observed + + biome_name_ob = "MODIS LandCover" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "land_class_"+model_grid+".nc" + + fo = addfile(diro+filo,"r") + + classob = tofloat(fo->LAND_CLASS) + + delete (fo) + +; input observed data has 20 land-type classes + + nclass_ob = 20 + +;******************************************************************** +; use land-type class to bin the data in equally spaced ranges +;******************************************************************** + +; using observed biome class +; nclass = nclass_ob +; using model biome class + nclass = nclass_mod + + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base_1D = ndtooned(classob) +; using model biome class + base_1D = ndtooned(classmod) + + data1_1D = ndtooned(npp_i) + data2_1D = ndtooned(npp_f) + +; output + + yvalues = new((/2,nx/),float) + count = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing data1 (nd=0) or data2 (nd=1). + + base = base_1D + + if(nd.eq.0) then + data = data1_1D + else + data = data2_1D + end if + +; Loop through each range, using base. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(base.ge.range(i)) + end if + +; Calculate average + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data(idx)) + count(nd,i) = dimsizes(idx) + else + yvalues(nd,i) = yvalues@_FillValue + count(nd,i) = 0 + end if + +;############################################################# +;using observed biome class: +; +; set the following 4 classes to _FillValue: +; Water Bodies(0), Urban and Build-Up(13), +; Permenant Snow and Ice(15), Unclassified(17) + +; if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then +; yvalues(nd,i) = yvalues@_FillValue +; count(nd,i) = 0 +; end if +;############################################################# + +;############################################################# +;using model biome class: +; +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(nd,i) = yvalues@_FillValue + count(nd,i) = 0 + end if +;############################################################# + +; print(nd + ": " + count(nd,i) + " points, avg = " + yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + + delete(data) + end do + +;============================ +;compute beta +;============================ + + u = yvalues(0,:) + v = yvalues(1,:) + u_count = count(0,:) + v_count = count(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + + uu = u(good) + vv = v(good) + uu_count = u_count(good) + vv_count = v_count(good) + + n_biome = dimsizes(uu) + beta_biome = new((/n_biome/),float) + + beta_biome = ((vv/uu) - 1.)/log(co2_f/co2_i) + +;beta_biome_avg = avg(beta_biome) + beta_biome_avg = (sum(vv*vv_count)/sum(uu*uu_count) - 1.)/log(co2_f/co2_i) + +;print (beta_biome_avg) + +;=========================== +; for html table - biome +;=========================== + + output_html = "table_biome.html" + +; column (not including header column) + + col_head = (/"CO2_i","CO2_f","NPP_i","NPP_f","Beta_model"/) + + ncol = dimsizes(col_head) + +; row (not including header row) + +;---------------------------------------------------- +; using observed biome class: +; +; row_head = (/"Evergreen Needleleaf Forests" \ +; ,"Evergreen Broadleaf Forests" \ +; ,"Deciduous Needleleaf Forest" \ +; ,"Deciduous Broadleaf Forests" \ +; ,"Mixed Forests" \ +; ,"Closed Bushlands" \ +; ,"Open Bushlands" \ +; ,"Woody Savannas (S. Hem.)" \ +; ,"Savannas (S. Hem.)" \ +; ,"Grasslands" \ +; ,"Permanent Wetlands" \ +; ,"Croplands" \ +; ,"Cropland/Natural Vegetation Mosaic" \ +; ,"Barren or Sparsely Vegetated" \ +; ,"Woody Savannas (N. Hem.)" \ +; ,"Savannas (N. Hem.)" \ +; ,"All Biome" \ +; /) + +;---------------------------------------------------- +; using model biome class: +; + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",co2_i) + text4(i,1) = sprintf("%.1f",co2_f) + text4(i,2) = sprintf("%.1f",uu(i)) + text4(i,3) = sprintf("%.1f",vv(i)) + text4(i,4) = sprintf("%.2f",beta_biome(i)) + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = "-" + text4(nrow-1,4) = sprintf("%.2f",beta_biome_avg) + +;************************************************** +; html table +;************************************************** + + header_text = "

Beta Factor: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Class"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + txt5 = text4(n,3) + txt6 = text4(n,4) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +end + diff -r 000000000000 -r 0c6405ab2ff4 biomass/01.read.byte.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biomass/01.read.byte.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,71 @@ +;************************************************ +; Read byte, Write nc +; input data is : 13.8533N -> -21.1277S +; -82.7209 -> -33.5739 +; output data is : -21.1277S -> 13.8533N +; 277.2791 -> 326.4261 +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +; final output + diro = "/fis/cgd/cseg/people/jeff/clamp_data/biomass/ob/" + filo = "amazon_biomass.nc" + c = addfile(diro+filo,"c") + +; input byte file + diri = "/fis/cgd/cseg/people/jeff/clamp_data/biomass/ob/" + fili = "amazon_biomass_byte.nc" + b = addfile(diri+fili,"r") + + data = byte2flt(b->biomass) + + dsizes_data = dimsizes(data) + nlat = dsizes_data(0) + nlon = dsizes_data(1) +; print (nlat) +; print (nlon) + + lat = new((/nlat/),float) + lon = new((/nlon/),float) + + latS = -21.1277 + latN = 13.8533 + lonL = -82.7209 + lonR = -33.5739 + + dy = abs((latN-latS)/(nlat-1)) + dx = abs((lonR-lonL)/(nlon-1)) + + do n = 0,nlat-1 + lat(n) = latS + n*dy + end do + + do n = 0,nlon-1 + lon(n) = lonL + n*dx + 360. + end do + + lat!0 = "lat" + lon!0 = "lon" + lat@units = "degrees_north" + lat@long_name = "Latitude" + lon@units = "degrees_east" + lon@long_name = "Longitude" + print (lat) + print (lon) + + data!0 = "lat" + data!1 = "lon" + + data@units = "Mg C/ha" + data@long_name = "Amoazon Biomass" + data@_FillValue = 1.e+36 + +; print (data) + + c->lat = lat + c->lon = lon + c->BIOMASS = data(::-1,:) +end diff -r 000000000000 -r 0c6405ab2ff4 biomass/03.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biomass/03.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,115 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/biomass/ob/" + fili = "amazon_biomass.nc" + g = addfile (diri+fili,"r") + bi = g->BIOMASS + xi = g->lon + yi = g->lat + + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "b30.061n_1995-2004_ANN_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) + + ind_lonL = min(ind(lon .ge. xi(0))) + ind_lonR = max(ind(lon .le. xi(dimsizes(xi)-1))) + +print (ind_lonL) +print (xi(0)) +print (lon(ind_lonL)) + +print (ind_lonR) +print (xi(dimsizes(xi)-1)) +print (lon(ind_lonR)) + + ind_latS = min(ind(lat .ge. yi(0))) + ind_latN = max(ind(lat .le. yi(dimsizes(yi)-1))) + +print (ind_latS) +print (yi(0)) +print (lat(ind_latS)) + +print (ind_latN) +print (yi(dimsizes(yi)-1)) +print (lat(ind_latN)) +exit + bo = new((/nlat,nlon/),float) + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + +; CLAT = clat({LATS:LATN}) ; do once for *slight* efficiency +; TEMP = bi({LATS:LATN},:) ; 2D [lat,lon] + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + bo(j,i) = avg(bi({LATS:LATN},{LONL:LONR})) +; bo(j,i) = wgt_areaave(TEMP(:,{LONL:LONR}), CLAT, 1.0, 0) + end do + +; delete(CLAT) +; delete(TEMP) + end do + + bo!0 = "lat" + bo!1 = "lon" + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name +; bo@_FillValue = bi@_FillValue + bo@_FillValue = 1.e+36 + + c->NPP = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 biomass/03.ob_to_T31.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biomass/03.ob_to_T31.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,188 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +;************************************************ +; read in model data +;************************************************ +;fili2 = "b30.061n_1995-2004_ANN_climo_lnd.nc" +;model_grid = "T31" +;fili2 = "i01.03cn_1545-1569_ANN_climo.nc" +;model_grid = "T42" + fili2 = "newcn05_ncep_1i_ANN_climo_lnd.nc" + model_grid = "1.9" + + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/biomass/ob/" + filo = "amazon_biomass_"+model_grid+".nc" + c = addfile(diro+filo,"c") +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/biomass/ob/" + fili = "amazon_biomass.nc" + g = addfile (diri+fili,"r") + bi = g->BIOMASS + xi = g->lon + yi = g->lat +;************************************************ +; from class to value: +; Biomass map has 11 classes: (unit= Mg/ha) +; 0: (_FillValue) +; 1: 0-25 (12.5) +; 2: 25-50 (37.5) +; 3: 50-75 (62.5) +; 4: 75-100 (87.5) +; 5: 100-150 (125) +; 6: 150-200 (175) +; 7: 200-250 (225) +; 8: 250-300 (275) +; 9: 300-350 (325) +; 10: 350-400 (375) +; 11: >400 (425) +;-------------------------- + + bi@_FillValue = 1.e+36 + + bi = where(bi.eq.0., bi@_FillValue,bi) + bi = where(bi.eq.1., 12.5,bi) + bi = where(bi.eq.2., 37.5,bi) + bi = where(bi.eq.3., 62.5,bi) + bi = where(bi.eq.4., 87.5,bi) + bi = where(bi.eq.5., 125.,bi) + bi = where(bi.eq.6., 175.,bi) + bi = where(bi.eq.7., 225.,bi) + bi = where(bi.eq.8., 275.,bi) + bi = where(bi.eq.9., 325.,bi) + bi = where(bi.eq.10.,375.,bi) + bi = where(bi.eq.11.,425.,bi) + +;print("min/max = " + min(bi) + "/" + max(bi)) + +;************************************************ +; Observed factor_aboveground = 0.5 +;************************************************ + + factor_aboveground = 0.5 +;bi = bi * factor_aboveground + + +;************************************************ +; find model grids that is inside observed grids +;************************************************ + ind_lonL = min(ind(lon .ge. xi(0))) + ind_lonR = max(ind(lon .le. xi(dimsizes(xi)-1))) + + print (ind_lonL) +;print (xi(0)) +;print (lon(ind_lonL)) + + print (ind_lonR) +;print (xi(dimsizes(xi)-1)) +;print (lon(ind_lonR)) + + ind_latS = min(ind(lat .ge. yi(0))) + ind_latN = max(ind(lat .le. yi(dimsizes(yi)-1))) + + print (ind_latS) +;print (yi(0)) +;print (lat(ind_latS)) + + print (ind_latN) +;print (yi(dimsizes(yi)-1)) +;print (lat(ind_latN)) + + nlat_out = ind_latN - ind_latS + 1 + nlon_out = ind_lonR - ind_lonL + 1 + +print (nlat_out) +print (nlon_out) + + bo = new((/nlat_out,nlon_out/),float) + lat_out = new((/nlat_out/),float) + lon_out = new((/nlon_out/),float) + + do jj=0,nlat_out-1 + j = ind_latS + jj + lat_out(jj) = lat(j) + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + do ii=0,nlon_out-1 + i = ind_lonL + ii + if (jj.eq.0) then + lon_out(ii) = lon(i) + end if + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + + print (LATS) + print (LATN) + print (LONL) + print (LONR) + + bo(jj,ii) = avg(bi({LATS:LATN},{LONL:LONR})) + end do + end do + + lon_out!0 = "lon" + lon_out@long_name = "longitude" + lon_out@units = "degrees_east" + lon_out&lon = lon_out + + lat_out!0 = "lat" + lat_out@long_name = "latitude" + lat_out@units = "degrees_north" + lat_out&lat = lat_out + + bo!0 = "lat" + bo!1 = "lon" + bo&lat = lat_out + bo&lon = lon_out + bo@units = bi@units + bo@long_name = bi@long_name +; bo@_FillValue = bi@_FillValue + bo@_FillValue = 1.e+36 + + c->BIOMASS = bo + c->lat = lat_out + c->lon = lon_out +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 biomass/11.contour_ob.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biomass/11.contour_ob.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,59 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/biomass/ob/" +; fili = "amazon_biomass.nc" +; fili = "amazon_biomass_T31.nc" + fili = "amazon_biomass_T42.nc" + f = addfile(diri+fili,"r") + +; y = f->BIOMASS(::50,::50) + y = f->BIOMASS + printVarSummary(y) + + print (min(y)+"/"+max(y)) + +;************************************************ +; create default plot +;************************************************ + + wks = gsn_open_wks("ps","xy") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@gsnAddCyclic = False + res@tiMainString = "LC15_amazon_biomass" + + res@mpMinLatF = -21.1 ; range to zoom in on + res@mpMaxLatF = 13.8 + res@mpMinLonF = 277.28 + res@mpMaxLonF = 326.43 + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals +; res@cnMinLevelValF = 1. ; Min level +; res@cnMaxLevelValF = 11. ; Max level +; res@cnLevelSpacingF = 1. ; interval + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 450. ; Max level + res@cnLevelSpacingF = 50. ; interval +; pres = True ; panel plot mods desired +; pres@gsnMaximize = True ; fill the page + + plot = gsn_csm_contour_map_ce(wks,y,res) ; for observed +; gsn_panel(wks,plot,(/1,1/),pres) ; create panel plot +; system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 biomass/20.mask_to_1x1.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biomass/20.mask_to_1x1.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,112 @@ +;************************************************ +; Read ascii, Write nc +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;--------------------------------------------------- +; final data + + c = addfile("amazon_mask_1x1.nc","c") + + nlat = 180 + nlon = 360 + +;************************************************ +; read 1x1 mask data +;************************************************ + + diri = "/fis/cgd/cseg/people/jeff/clamp_data/observed/biomass/" + fili = "mask_1x1.txt" + t = asciiread(diri+fili,(/180,360/),"integer") + + printVarSummary(t) + + print (min(t)+"/"+max(t)) + + lon = new((/nlon/),float) + lat = new((/nlat/),float) + +; data is (89.5N->89.5S) (-179.5->179.5) + +; sam result +; lon = fspan(-179.5,179.5,nlon) +; lat = fspan( -89.5, 89.5,nlat) + + do i = 0,nlon-1 + lon(i) = -179.5 + i*(360./nlon) + end do + + do j = 0,nlat-1 +; lat(j) = -89.5 + j*(180./nlat) + lat(j) = 89.5 - j*(180./nlat) + end do + +; print (lon) +; print (lat) +;============================= + ; create lat and long coordinate variables + ;============================ + lon!0 = "lon" + lon@long_name = "lon" + lon@units = "degrees-east" + lon&lon = lon + + lat!0 = "lat" + lat@long_name = "lat" + lat@units = "degrees_north" + lat&lat = lat + ;============================= + ; name dimensions of t and assign coordinate variables + ;============================ + t!0 = "lat" + t!1 = "lon" + t&lat = lat + t&lon = lon + t@long_name = "amazon mask" +; t@units = "" + t@_FillValue= -999 + t@missing_value= -999 + + c->mask_amazon = t + c->lat = lat + c->lon = lon + +;************************************************ +; create default plot +;************************************************ + + wks = gsn_open_wks("ps","xy") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@gsnAddCyclic = False + res@tiMainString = "LC15_amazon_biomass" + + res@mpMinLatF = -21.1 ; range to zoom in on + res@mpMaxLatF = 13.8 + res@mpMinLonF = 277.28 + res@mpMaxLonF = 326.43 + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals +; res@cnMinLevelValF = 1. ; Min level +; res@cnMaxLevelValF = 11. ; Max level +; res@cnLevelSpacingF = 1. ; interval + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 1. ; Max level + res@cnLevelSpacingF = 0.1 ; interval +; pres = True ; panel plot mods desired +; pres@gsnMaximize = True ; fill the page + + plot = gsn_csm_contour_map_ce(wks,t,res) ; for observed + +end diff -r 000000000000 -r 0c6405ab2ff4 biomass/25.contour.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biomass/25.contour.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,61 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read data +;************************************************ + grid = "1x1" +; grid = "T31" +; grid = "T42" +; grid = "1.9" + + diri = "/fis/cgd/cseg/people/jeff/clamp_data/observed/biomass/" + fili = "amazon_mask_"+ grid + ".nc" + f = addfile (diri+fili,"r") + + y = f->mask_amazon + + printVarSummary(y) + +;************************************************ +; create default plot +;************************************************ + + wks = gsn_open_wks("ps","mask_"+grid) ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@gsnAddCyclic = False + res@tiMainString = "Amazon Mask: grid = "+ grid + + res@mpMinLatF = -21.1 ; range to zoom in on + res@mpMaxLatF = 13.8 + res@mpMinLonF = 277.28 + res@mpMaxLonF = 326.43 + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals +; res@cnMinLevelValF = 1. ; Min level +; res@cnMaxLevelValF = 11. ; Max level +; res@cnLevelSpacingF = 1. ; interval + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 1. ; Max level + res@cnLevelSpacingF = 0.1 ; interval + +; pres = True ; panel plot mods desired +; pres@gsnMaximize = True ; fill the page + + plot = gsn_csm_contour_map_ce(wks,y,res) ; for observed +; gsn_panel(wks,plot,(/1,1/),pres) ; create panel plot +; system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 biomass/26.contour.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biomass/26.contour.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,75 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read data +;************************************************ + grid = "1x1" +; grid = "T31" +; grid = "T42" +; grid = "1.9" + + diri = "/fis/cgd/cseg/people/jeff/clamp_data/observed/biomass/" + fili = "amazon_mask_"+ grid + ".nc" + f = addfile (diri+fili,"r") + + y = f->mask_amazon + + printVarSummary(y) + + wks = gsn_open_wks ("ps","test") ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + +;----------------------------------------- +; plot area sum + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + Sum_area = 7.41 + + area_sum_text = "(mask area = "+sprintf("%.2f", Sum_area)+"(x1.e12 m2))" + + gsn_text_ndc(wks,area_sum_text,0.50,0.80,gRes) +;----------------------------------------- + +;************************************************ +; create default plot +;************************************************ + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@gsnAddCyclic = False + res@tiMainString = "Amazon Mask: grid = "+ grid + + res@mpMinLatF = -21.1 ; range to zoom in on + res@mpMaxLatF = 13.8 + res@mpMinLonF = 277.28 + res@mpMaxLonF = 326.43 + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals +; res@cnMinLevelValF = 1. ; Min level +; res@cnMaxLevelValF = 11. ; Max level +; res@cnLevelSpacingF = 1. ; interval + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 1. ; Max level + res@cnLevelSpacingF = 0.1 ; interval + +; pres = True ; panel plot mods desired +; pres@gsnMaximize = True ; fill the page + + plot = gsn_csm_contour_map_ce(wks,y,res) ; for observed +; gsn_panel(wks,plot,(/1,1/),pres) ; create panel plot +; system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 biomass/30.mask_to_T31-T42_1.9.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biomass/30.mask_to_T31-T42_1.9.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,147 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +;************************************************ +; read model grid +;************************************************ + + model_grid = "T31" +;model_grid = "T42" +;model_grid = "1.9" + + diri = "/fis/cgd/cseg/people/jeff/clamp_data/surface_model/" + fili = "lnd_"+ model_grid +".nc" + f = addfile (diri+fili,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/observed/biomass/" + filo = "amazon_mask_"+model_grid + ".nc" + c = addfile(diro+filo,"c") + +;************************************************ +; read 1x1 amazon_mask data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/observed/biomass/" + fili = "amazon_mask_1x1.nc" + g = addfile(diri+fili,"r") + + bi = g->mask_amazon + xi = g->lon + yi = g->lat + +;************************************************ +; change from -180-180, 90N-90S into 0-360E, 90S-90N +; Observed NPP*scale_factor +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(::-1,:) /) + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 180) then + p = i + 180 + xi(p) = x2(i) + 360. + else + p = i - 180 + xi(p) = x2(i) + end if + bi(:,p)= b2(:,i) + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) + +;(A) +;bo = linint2_Wrap(xi,yi,bi,True,xo,yo,0) + +;(B) + + rad = 4.*atan(1.)/180. + clat = lat + clat = cos(lat*rad) + + clat@long_name = "cos(latitude)" + delete(clat@units) +; printVarSummary(clat) + + bo = new ((/nlat,nlon/),"float") + + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + +; CLAT = clat({LATS:LATN}) ; do once for *slight* efficiency +; TEMP = bi({LATS:LATN},:) ; 2D [lat,lon] + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + bo(j,i) = avg(bi({LATS:LATN},{LONL:LONR})) +; bo(j,i) = wgt_areaave(TEMP(:,{LONL:LONR}), CLAT, 1.0, 0) + + end do + +; delete(CLAT) +; delete(TEMP) + end do + +; bo = where(bo.ge.0.5, 1.0,0.) + + bo!0 = "lat" + bo!1 = "lon" + bo&lat = lat + bo&lon = lon +; bo@units = bi@units + bo@long_name = "amazon mask" +; bo@_FillValue = bi@_FillValue + bo@_FillValue = 1.e+36 + + c->mask_amazon = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 biomass/31_area_sum.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biomass/31_area_sum.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,194 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin + + plot_type = "ps" + plot_type_new = "png" + +;*********************************************** + + model = "cn" +;model = "casa" + + model_grid = "T42" + + model_name = "10" + model + +;************************************************ +; read amazon mask data +;************************************************ + + diri = "/fis/cgd/cseg/people/jeff/clamp_data/observed/biomass/" + fili = "amazon_mask_"+ model_grid + ".nc" + f = addfile (diri+fili,"r") + + mask_amazon0 = f->mask_amazon + + delete (f) + +;-------------------------------------------------- +; get model data: landfrac and area + + dirs = "/fis/cgd/cseg/people/jeff/clamp_data/surface_model/" + fils = "lnd_"+ model_grid +".nc" + fs = addfile (dirs+fils,"r") + + landfrac = fs->landfrac + area0 = fs->area + + delete (fs) + +; change area from km**2 to m**2 + area0 = area0 * 1.e6 + +;----------------------------- +; take into account landfrac + + area0 = area0 * landfrac + +;-------------------------------------------- +; read model data + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "i01.10"+ model +"_1948-2004_ANN_climo.nc" + fm = addfile (dirm+film,"r") + + if (model .eq. "cn") then +; unit: gC/m2 + data1 = fm->LIVESTEMC + data2 = fm->DEADSTEMC + data3 = fm->LEAFC + + datamod0 = data1(0,:,:) + datamod0 = data1(0,:,:) + data2(0,:,:) + data3(0,:,:) + end if + + if (model .eq. "casa") then +; unit: gC/m2 +; factor_WOODC = 0.7 + data1 = fm->WOODC + data2 = fm->LEAFC + + datamod0 = data1(0,:,:) + datamod0 = data1(0,:,:)*factor_WOODC + data2(0,:,:) + end if +;---------------------------------------------------- + + xm = fm->lon + ym = fm->lat + + delete (fm) +;************************************************ +; read observed data +;************************************************ + ob_name = "LC15_Amazon_Biomass" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/observed/biomass/" + filo = "amazon_biomass_"+model_grid+".nc" + fo = addfile (diro+filo,"r") + + dataob = fo->BIOMASS + xo = fo->lon + yo = fo->lat + + delete (fo) +;************************************************ +; Units for these variables are: + +; dataob : MgC/ha +; datamod0 : gC/m2 + +; We want to convert these to KgC/m2 +; ha = 100m*100m = 10,000 m2 +; MgC/ha*1000/10,000 = KgC/m2 +; Peta g = 1.e15 g = 1.e12 Kg + + factor_aboveground = 0.5 + factor_unit_ob = 0.1 + factor_unit_mod = 0.001 + + dataob = dataob * factor_aboveground * factor_unit_ob + datamod0 = datamod0 * factor_unit_mod + + dataob@units = "KgC/m2" + datamod0@units = "KgC/m2" + + dataob@long_name = "Amazon Biomass" + datamod0@long_name = "Amazon Biomass" + +;******************************************************** +; get subset of datamod that match dataob + + nlon = dimsizes(xo) + nlat = dimsizes(yo) + + ind_lonL = ind(xm .eq. xo(0)) + ind_lonR = ind(xm .eq. xo(nlon-1)) + ind_latS = ind(ym .eq. yo(0)) + ind_latN = ind(ym .eq. yo(nlat-1)) + + datamod = dataob + datamod(:,:) = datamod0(ind_latS:ind_latN,ind_lonL:ind_lonR) + + area = dataob + area(:,:) = area0(ind_latS:ind_latN,ind_lonL:ind_lonR) + + mask_amazon = dataob + mask_amazon(:,:) = mask_amazon0(ind_latS:ind_latN,ind_lonL:ind_lonR) + +;******************************************************** +; sum over amazom_mask area: + +; mask_amazon = where(mask_amazon .ge. 0.5, mask_amazon ,0.) + + area_sum = sum(area*mask_amazon) + + area_sum_amazon_ob = sum(dataob*area*mask_amazon) + area_sum_amazon_mod = sum(datamod*area*mask_amazon) + +; Peta g = 1.e15 g = 1.e12 Kg + + print (area_sum_amazon_ob) + print (area_sum_amazon_mod) + print (area_sum) +exit +;---------------------------------------------------------------------- +; global contour + +;res + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@gsnAddCyclic = False + + resg@gsnSpreadColors = True ; use full colormap + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 30. ; Max level + resg@cnLevelSpacingF = 2. ; interval + + resg@mpMinLatF = -21.1 ; range to zoom in on + resg@mpMaxLatF = 13.8 + resg@mpMinLonF = 277.28 + resg@mpMaxLonF = 326.43 +;------------------------------------------------------------------------ +;global contour ob + + plot_name = "global_ob" + title = ob_name+" "+ model_grid + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,dataob,resg) + frame(wks) +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 biomass/99.all.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biomass/99.all.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,262 @@ +; **************************************************** +; combine scatter, histogram, global and zonal plots +; compute all correlation coef and M score +; **************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + plot_type = "ps" + plot_type_new = "png" +;************************************************ +; read in model data +;************************************************ +;film = "b30.061n_1995-2004_ANN_climo_lnd.nc" +;model_name = "b30.061n" +;model_grid = "T31" + +;film = "newcn05_ncep_1i_ANN_climo_lnd.nc" +;model_name = "newcn" +;model_grid = "1.9" +;-------------------------------------------- + film = "i01.10cn_1948-2004_ANN_climo.nc" + model_name = "10cn" + model_grid = "T42" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile (dirm+film,"r") + +;unit: gC/m2 + data1 = fm->LIVESTEMC + data2 = fm->DEADSTEMC + data3 = fm->LEAFC + datamod0 = data1(0,:,:) + datamod0 = data1(0,:,:) + data2(0,:,:) + data3(0,:,:) +;------------------------------------------- +;film = "i01.10casa_1948-2004_ANN_climo.nc" +;model_name = "10casa" +;model_grid = "T42" + +;dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +;fm = addfile (dirm+film,"r") + +;unit: gC/m2 +;factor_WOODC = 0.7 +;data1 = fm->WOODC +;data2 = fm->LEAFC +;datamod0 = data1(0,:,:) +;datamod0 = data1(0,:,:)*factor_WOODC + data2(0,:,:) +;---------------------------------------------------- + html_name = "table.html." + model_name + html_new = html_name +".new" + system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + + xm = fm->lon + ym = fm->lat +;************************************************ +; read in ob data +;************************************************ + ob_name = "LC15_Amazon_Biomass" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/biomass/ob/" + filo = "amazon_biomass_"+model_grid+".nc" + fo = addfile (diro+filo,"r") + + dataob = fo->BIOMASS + xo = fo->lon + yo = fo->lat +;************************************************ +; Units for these variables are: +; dataob : MgC/ha +; datamod0 : gC/m2 +; We want to convert these to KgC/m2 +; ha = 100m*100m = 10,000 m2 +; MgC/ha*1000/10,000 = KgC/m2 + + factor_aboveground = 0.5 + factor_unit_ob = 0.1 + factor_unit_mod = 0.001 + + dataob = dataob * factor_aboveground * factor_unit_ob + datamod0 = datamod0 * factor_unit_mod + + dataob@units = "KgC/m2" + datamod0@units = "KgC/m2" + + dataob@long_name = "Amazon Biomass" + datamod0@long_name = "Amazon Biomass" +;******************************************************** +; get subset of datamod0 that match dataob + + nlon = dimsizes(xo) + nlat = dimsizes(yo) + + ind_lonL = ind(xm .eq. xo(0)) + ind_lonR = ind(xm .eq. xo(nlon-1)) + ind_latS = ind(ym .eq. yo(0)) + ind_latN = ind(ym .eq. yo(nlat-1)) + + datamod = dataob + datamod(:,:) = datamod0(ind_latS:ind_latN,ind_lonL:ind_lonR) + +; print (datamod) + +;---------------------------------------------------------------------- +; global contour + +;res + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@gsnAddCyclic = False + + resg@gsnSpreadColors = True ; use full colormap + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 30. ; Max level + resg@cnLevelSpacingF = 2. ; interval + + resg@mpMinLatF = -21.1 ; range to zoom in on + resg@mpMaxLatF = 13.8 + resg@mpMinLonF = 277.28 + resg@mpMaxLonF = 326.43 +;------------------------------------------------------------------------ +;global contour ob + + plot_name = "global_ob" + title = ob_name+" "+ model_grid + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,dataob,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_model" + title = "Model "+ model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,datamod,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;(d) compute correlation coef and M score + + uu = ndtooned(datamod) + vv = ndtooned(dataob) + + good = ind(.not.ismissing(uu) .and. .not.ismissing(vv)) + + ug = uu(good) + vg = vv(good) + + ccrG = esccr(ug,vg,0) +; print (ccrG) + + MG = (ccrG*ccrG)* 5.0 +; new eq + bias = sum(abs(ug-vg)/(abs(ug)+abs(vg))) + MG = (1. - (bias/dimsizes(ug)))*5. + + M_biomass = sprintf("%.2f", MG) + system("sed s#M_biomass#"+M_biomass+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_biomass) + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrG)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = ob_name+" "+ model_grid + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,dataob,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,datamod,resg) + +;(c) model-ob + + zz = datamod + zz = datamod - dataob + title = "Model_"+model_name+" - Observed" + + resg@cnMinLevelValF = -10. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 2. ; interval + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;------------------------------------------------------------------- + temp_name = "biomass." + model_name + system("mkdir -p " + temp_name+";"+ \ + "cp "+ html_name + " " +temp_name+"/table.html"+";"+ \ + "mv *.png " + temp_name +";"+ \ + "tar cf "+ temp_name +".tar " + temp_name) +;------------------------------------------------------------------- +end diff -r 000000000000 -r 0c6405ab2ff4 biomass/99.all.ncl.0 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biomass/99.all.ncl.0 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,258 @@ +; **************************************************** +; combine scatter, histogram, global and zonal plots +; compute all correlation coef and M score +; **************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + plot_type = "ps" + plot_type_new = "png" +;************************************************ +; read in model data +;************************************************ +;film = "i01.03cn_1545-1569_ANN_climo.nc" +;model_name = "i01.03cn" +;model_grid = "T42" + +;film = "b30.061n_1995-2004_ANN_climo_lnd.nc" +;model_name = "b30.061n" +;model_grid = "T31" + +;film = "newcn05_ncep_1i_ANN_climo_lnd.nc" +;model_name = "newcn" +;model_grid = "1.9" + +;film = "i01.06cn_1798-2004_ANN_climo.nc" +;model_name = "06cn" +;model_grid = "T42" + +;film = "i01.06casa_1798-2004_ANN_climo.nc" +;model_name = "06casa" +;model_grid = "T42" +;note: use 98.all.ncl + + film = "i01.10cn_1948-2004_ANN_climo.nc" + model_name = "10cn" + model_grid = "T42" + +;film = "i01.10casa_1948-2004_ANN_climo.nc" +;model_name = "10casa" +;model_grid = "T42" +;---------------------------------------------------- + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile (dirm+film,"r") + +;unit: gC/m2 + data1 = fm->LIVESTEMC + data2 = fm->DEADSTEMC + data3 = fm->LEAFC + datamod0 = data1(0,:,:) + datamod0 = data1(0,:,:) + data2(0,:,:) + data3(0,:,:) + + xm = fm->lon + ym = fm->lat +;************************************************ +; read in ob data +;************************************************ + ob_name = "LC15_Amazon_Biomass" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/biomass/ob/" + filo = "amazon_biomass_"+model_grid+".nc" + fo = addfile (diro+filo,"r") + + dataob = fo->BIOMASS + xo = fo->lon + yo = fo->lat +;************************************************ +; Units for these variables are: +; dataob : MgC/ha +; datamod0 : gC/m2 +; We want to convert these to KgC/m2 +; ha = 100m*100m = 10,000 m2 +; MgC/ha*1000/10,000 = KgC/m2 + + factor_aboveground = 0.5 + factor_unit_ob = 0.1 + factor_unit_mod = 0.001 + + dataob = dataob * factor_aboveground * factor_unit_ob + datamod0 = datamod0 * factor_unit_mod + + dataob@units = "KgC/m2" + datamod0@units = "KgC/m2" + + dataob@long_name = "Amazon Biomass" + datamod0@long_name = "Amazon Biomass" +;******************************************************** +; get subset of datamod0 that match dataob + + nlon = dimsizes(xo) + nlat = dimsizes(yo) + + ind_lonL = ind(xm .eq. xo(0)) + ind_lonR = ind(xm .eq. xo(nlon-1)) + ind_latS = ind(ym .eq. yo(0)) + ind_latN = ind(ym .eq. yo(nlat-1)) + + datamod = dataob + datamod(:,:) = datamod0(ind_latS:ind_latN,ind_lonL:ind_lonR) + +; print (datamod) + +;---------------------------------------------------------------------- +; global contour + +;res + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@gsnAddCyclic = False + + resg@gsnSpreadColors = True ; use full colormap + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 30. ; Max level + resg@cnLevelSpacingF = 2. ; interval + + resg@mpMinLatF = -21.1 ; range to zoom in on + resg@mpMaxLatF = 13.8 + resg@mpMinLonF = 277.28 + resg@mpMaxLonF = 326.43 +;------------------------------------------------------------------------ +;global contour ob + + plot_name = "global_ob" + title = ob_name+" "+ model_grid + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,dataob,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_model" + title = "Model "+ model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,datamod,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;(d) compute correlation coef and M score + + uu = ndtooned(datamod) + vv = ndtooned(dataob) + + good = ind(.not.ismissing(uu) .and. .not.ismissing(vv)) + + ug = uu(good) + vg = vv(good) + + ccrG = esccr(ug,vg,0) +; print (ccrG) + + MG = (ccrG*ccrG)* 5.0 +; new eq + bias = sum(abs(ug-vg)/(abs(ug)+abs(vg))) + MG = (1. - (bias/dimsizes(ug)))*5. + print (MG) + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrG)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = ob_name+" "+ model_grid + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,dataob,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,datamod,resg) + +;(c) model-ob + + zz = datamod + zz = datamod - dataob + title = "Model_"+model_name+" - Observed" + + resg@cnMinLevelValF = -10. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 2. ; interval + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + delete (plot) +;------------------------------------------------------------------------ +; temp_name = "temp." + model_name +; system("mkdir -p " + temp_name) +; system("mv *.png " + temp_name) +; system("tar cf "+ temp_name +".tar " + temp_name) +;------------------------------------------------------------------------ +end diff -r 000000000000 -r 0c6405ab2ff4 biomass/99.all.ncl.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/biomass/99.all.ncl.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,264 @@ +; **************************************************** +; combine scatter, histogram, global and zonal plots +; compute all correlation coef and M score +; **************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + plot_type = "ps" + plot_type_new = "png" +;************************************************ +; read in model data +;************************************************ +;film = "b30.061n_1995-2004_ANN_climo_lnd.nc" +;model_name = "b30.061n" +;model_grid = "T31" + +;film = "newcn05_ncep_1i_ANN_climo_lnd.nc" +;model_name = "newcn" +;model_grid = "1.9" +;-------------------------------------------- +;film = "i01.10cn_1948-2004_ANN_climo.nc" +;model_name = "10cn" +;model_grid = "T42" + +;dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +;fm = addfile (dirm+film,"r") + +;unit: gC/m2 +;data1 = fm->LIVESTEMC +;data2 = fm->DEADSTEMC +;data3 = fm->LEAFC +;datamod0 = data1(0,:,:) +;datamod0 = data1(0,:,:) + data2(0,:,:) + data3(0,:,:) +;------------------------------------------- + film = "i01.10casa_1948-2004_ANN_climo.nc" + model_name = "10casa" + model_grid = "T42" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile (dirm+film,"r") + +;unit: gC/m2 + factor_WOODC = 0.7 + data1 = fm->WOODC + data2 = fm->LEAFC + datamod0 = data1(0,:,:) + datamod0 = data1(0,:,:)*factor_WOODC + data2(0,:,:) +;---------------------------------------------------- + + system("sed s#model_name#"+model_name+"# table.html > table.html.new") + system("mv -f table.html.new table.html") + + xm = fm->lon + ym = fm->lat +;************************************************ +; read in ob data +;************************************************ + ob_name = "LC15_Amazon_Biomass" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/biomass/ob/" + filo = "amazon_biomass_"+model_grid+".nc" + fo = addfile (diro+filo,"r") + + dataob = fo->BIOMASS + xo = fo->lon + yo = fo->lat +;************************************************ +; Units for these variables are: +; dataob : MgC/ha +; datamod0 : gC/m2 +; We want to convert these to KgC/m2 +; ha = 100m*100m = 10,000 m2 +; MgC/ha*1000/10,000 = KgC/m2 + + factor_aboveground = 0.5 + factor_unit_ob = 0.1 + factor_unit_mod = 0.001 + + dataob = dataob * factor_aboveground * factor_unit_ob + datamod0 = datamod0 * factor_unit_mod + + dataob@units = "KgC/m2" + datamod0@units = "KgC/m2" + + dataob@long_name = "Amazon Biomass" + datamod0@long_name = "Amazon Biomass" +;******************************************************** +; get subset of datamod0 that match dataob + + nlon = dimsizes(xo) + nlat = dimsizes(yo) + + ind_lonL = ind(xm .eq. xo(0)) + ind_lonR = ind(xm .eq. xo(nlon-1)) + ind_latS = ind(ym .eq. yo(0)) + ind_latN = ind(ym .eq. yo(nlat-1)) + + datamod = dataob + datamod(:,:) = datamod0(ind_latS:ind_latN,ind_lonL:ind_lonR) + +; print (datamod) + +;---------------------------------------------------------------------- +; global contour + +;res + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@gsnAddCyclic = False + + resg@gsnSpreadColors = True ; use full colormap + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 30. ; Max level + resg@cnLevelSpacingF = 2. ; interval + + resg@mpMinLatF = -21.1 ; range to zoom in on + resg@mpMaxLatF = 13.8 + resg@mpMinLonF = 277.28 + resg@mpMaxLonF = 326.43 +;------------------------------------------------------------------------ +;global contour ob + + plot_name = "global_ob" + title = ob_name+" "+ model_grid + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,dataob,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_model" + title = "Model "+ model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,datamod,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;(d) compute correlation coef and M score + + uu = ndtooned(datamod) + vv = ndtooned(dataob) + + good = ind(.not.ismissing(uu) .and. .not.ismissing(vv)) + + ug = uu(good) + vg = vv(good) + + ccrG = esccr(ug,vg,0) +; print (ccrG) + + MG = (ccrG*ccrG)* 5.0 +; new eq + bias = sum(abs(ug-vg)/(abs(ug)+abs(vg))) + MG = (1. - (bias/dimsizes(ug)))*5. + + M_biomass = sprintf("%.2f", MG) + system("sed s#M_biomass#"+M_biomass+"# table.html > table.html.new") + system("mv -f table.html.new table.html") + print (M_biomass) + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrG)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = ob_name+" "+ model_grid + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,dataob,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,datamod,resg) + +;(c) model-ob + + zz = datamod + zz = datamod - dataob + title = "Model_"+model_name+" - Observed" + + resg@cnMinLevelValF = -10. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 2. ; interval + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + delete (plot) +;------------------------------------------------------------------------ + temp_name = "biomass." + model_name + system("mkdir -p " + temp_name) + system("cp table.html " + temp_name) + system("mv *.png " + temp_name) + system("tar cf "+ temp_name +".tar " + temp_name) +;------------------------------------------------------------------------ +end diff -r 000000000000 -r 0c6405ab2ff4 carbon_sink/01.write_tseries_casa.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbon_sink/01.write_tseries_casa.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,122 @@ +;************************************************ +; read from /ptmp/ +; output NPP, NEE +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +; input data + + model_name = "i01.10casa" + + nlat = 64 + nlon = 128 + + year_start = 1991 + year_end = 2004 + + diri = "/ptmp/jeff/"+model_name+"/" + + system("mkdir "+diri) + +; output + + diro = "/ptmp/jeff/" + filo = model_name + "_Fire_C_"+year_start+"-"+year_end+"_monthly.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"year",-1,True) + + + nyear = year_end - year_start + 1 + nmonth = 12 + +; data1 = new((/nyear,nmonth,nlat,nlon/),float) + data2 = new((/nyear,nmonth,nlat,nlon/),float) + data3 = new((/nyear,nmonth,nlat,nlon/),float) + date = new((/nyear,nmonth/),integer) + +; input from /ptmp/ + + + do m = 0,nyear-1 + year = year_start + m + +; text = "mss:/FORREST/CCSM/results/"+model_name+"/lnd/hist/*"+year+"* " +; print (text) + +; system("msrcp "+text+diri) +; system("dcswait") + print (year) + + do n = 0,nmonth-1 + nn = n+1 + date(m,n) = year*100 +nn + +; input file + if (nn .ge. 10) then + fili = model_name+".clm2.h0."+year+"-"+nn+".nc" + else + fili = model_name+".clm2.h0."+year+"-0"+nn+".nc" + end if + +; print (fili) + + g = addfile (diri+fili,"r") + +; b1 = g->COL_FIRE_CLOSS +; data1(m,n,:,:) = (/b1(0,:,:)/) + + b2 = g->NPP + data2(m,n,:,:) = (/b2(0,:,:)/) + + b3 = g->NEE + data3(m,n,:,:) = (/b3(0,:,:)/) + + end do + +; system("rm "+diri+"*") + + end do + +; name dimensions and assign coordinate variables + +; data1!0 ="year" +; data1!1 ="month" +; data1!2 = "lat" +; data1!3 = "lon" +; data1@long_name = b1@long_name +; data1@units = b1@units +; data1@_FillValue = b1@_FillValue + + data2!0 ="year" + data2!1 ="month" + data2!2 = "lat" + data2!3 = "lon" + data2@long_name = b2@long_name + data2@units = b2@units + data2@_FillValue = b2@_FillValue + + data3!0 ="year" + data3!1 ="month" + data3!2 = "lat" + data3!3 = "lon" + data3@long_name = b3@long_name + data3@units = b3@units + data3@_FillValue = b3@_FillValue + + date!0 ="year" + date!1 ="month" + date@long_name = "date: yyyymm" + +; c->COL_FIRE_CLOSS = data1 + c->NPP = data2 + c->NEE = data3 + c->date = date + c->area = g->area + + print (date) + +end diff -r 000000000000 -r 0c6405ab2ff4 carbon_sink/01.write_tseries_cn.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbon_sink/01.write_tseries_cn.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,122 @@ +;************************************************ +; read from /ptmp/ +; output fire(COL_FIRE_CLOSS), NPP, NEE +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +; input data + + model_name = "i01.10cn" + + nlat = 64 + nlon = 128 + + year_start = 1991 + year_end = 2004 + + diri = "/ptmp/jeff/"+model_name+"/" + + system("mkdir "+diri) + +; output + + diro = "/ptmp/jeff/" + filo = model_name + "_Fire_C_"+year_start+"-"+year_end+"_monthly.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"year",-1,True) + + + nyear = year_end - year_start + 1 + nmonth = 12 + + data1 = new((/nyear,nmonth,nlat,nlon/),float) + data2 = new((/nyear,nmonth,nlat,nlon/),float) + data3 = new((/nyear,nmonth,nlat,nlon/),float) + date = new((/nyear,nmonth/),integer) + +; input from /ptmp/ + + + do m = 0,nyear-1 + year = year_start + m + +; text = "mss:/FORREST/CCSM/results/"+model_name+"/lnd/hist/*"+year+"* " +; print (text) + +; system("msrcp "+text+diri) +; system("dcswait") + print (year) + + do n = 0,nmonth-1 + nn = n+1 + date(m,n) = year*100 +nn + +; input file + if (nn .ge. 10) then + fili = model_name+".clm2.h0."+year+"-"+nn+".nc" + else + fili = model_name+".clm2.h0."+year+"-0"+nn+".nc" + end if + +; print (fili) + + g = addfile (diri+fili,"r") + + b1 = g->COL_FIRE_CLOSS + data1(m,n,:,:) = (/b1(0,:,:)/) + + b2 = g->NPP + data2(m,n,:,:) = (/b2(0,:,:)/) + + b3 = g->NEE + data3(m,n,:,:) = (/b3(0,:,:)/) + + end do + +; system("rm "+diri+"*") + + end do + +; name dimensions and assign coordinate variables + + data1!0 ="year" + data1!1 ="month" + data1!2 = "lat" + data1!3 = "lon" + data1@long_name = b1@long_name + data1@units = b1@units + data1@_FillValue = b1@_FillValue + + data2!0 ="year" + data2!1 ="month" + data2!2 = "lat" + data2!3 = "lon" + data2@long_name = b2@long_name + data2@units = b2@units + data2@_FillValue = b2@_FillValue + + data3!0 ="year" + data3!1 ="month" + data3!2 = "lat" + data3!3 = "lon" + data3@long_name = b3@long_name + data3@units = b3@units + data3@_FillValue = b3@_FillValue + + date!0 ="year" + date!1 ="month" + date@long_name = "date: yyyymm" + + c->COL_FIRE_CLOSS = data1 + c->NPP = data2 + c->NEE = data3 + c->date = date + c->area = g->area + + print (date) + +end diff -r 000000000000 -r 0c6405ab2ff4 carbon_sink/02.write_tseries_casa.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbon_sink/02.write_tseries_casa.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,121 @@ +;************************************************ +; read from mss +; output fire(COL_FIRE_CLOSS), NPP, NEE +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +; input data + + model_name = "i01.10casa" + + nlat = 64 + nlon = 128 + + year_start = 1979 + year_end = 2004 + + diri = "/ptmp/jeff/"+model_name+"/" + + system("mkdir "+diri) + +; output + + diro = "/ptmp/jeff/" + filo = model_name + "_Fire_C_"+year_start+"-"+year_end+"_monthly.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"year",-1,True) + + + nyear = year_end - year_start + 1 + nmonth = 12 + +; data1 = new((/nyear,nmonth,nlat,nlon/),float) + data2 = new((/nyear,nmonth,nlat,nlon/),float) + data3 = new((/nyear,nmonth,nlat,nlon/),float) + date = new((/nyear,nmonth/),integer) + +; input from mss + + do m = 0,nyear-1 + year = year_start + m + + text = "mss:/FORREST/CCSM/results/"+model_name+"/lnd/hist/*"+year+"* " + print (text) + + system("msrcp "+text+diri) + system("dcswait") + print (year) + + do n = 0,nmonth-1 + nn = n+1 + date(m,n) = year*100 +nn + +; input file + if (nn .ge. 10) then + fili = model_name+".clm2.h0."+year+"-"+nn+".nc" + else + fili = model_name+".clm2.h0."+year+"-0"+nn+".nc" + end if + +; print (fili) + + g = addfile (diri+fili,"r") + +; b1 = g->COL_FIRE_CLOSS +; data1(m,n,:,:) = (/b1(0,:,:)/) + + b2 = g->NPP + data2(m,n,:,:) = (/b2(0,:,:)/) + + b3 = g->NEE + data3(m,n,:,:) = (/b3(0,:,:)/) + + end do + +; system("rm "+diri+"*") + + end do + +; name dimensions and assign coordinate variables + +; data1!0 ="year" +; data1!1 ="month" +; data1!2 = "lat" +; data1!3 = "lon" +; data1@long_name = b1@long_name +; data1@units = b1@units +; data1@_FillValue = b1@_FillValue + + data2!0 ="year" + data2!1 ="month" + data2!2 = "lat" + data2!3 = "lon" + data2@long_name = b2@long_name + data2@units = b2@units + data2@_FillValue = b2@_FillValue + + data3!0 ="year" + data3!1 ="month" + data3!2 = "lat" + data3!3 = "lon" + data3@long_name = b3@long_name + data3@units = b3@units + data3@_FillValue = b3@_FillValue + + date!0 ="year" + date!1 ="month" + date@long_name = "date: yyyymm" + +; c->COL_FIRE_CLOSS = data1 + c->NPP = data2 + c->NEE = data3 + c->date = date + c->area = g->area + + print (date) + +end diff -r 000000000000 -r 0c6405ab2ff4 carbon_sink/02.write_tseries_cn.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbon_sink/02.write_tseries_cn.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,122 @@ +;************************************************ +; read from mss +; output fire(COL_FIRE_CLOSS), NPP, NEE +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +; input data + +; model_name = "i01.10cn" + model_name = "i01.10casa" + + nlat = 64 + nlon = 128 + + year_start = 1979 + year_end = 1990 + + diri = "/ptmp/jeff/"+model_name+"/" + + system("mkdir "+diri) + +; output + + diro = "/ptmp/jeff/" + filo = model_name + "_Fire_C_"+year_start+"-"+year_end+"_monthly.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"year",-1,True) + + + nyear = year_end - year_start + 1 + nmonth = 12 + + data1 = new((/nyear,nmonth,nlat,nlon/),float) + data2 = new((/nyear,nmonth,nlat,nlon/),float) + data3 = new((/nyear,nmonth,nlat,nlon/),float) + date = new((/nyear,nmonth/),integer) + +; input from mss + + do m = 0,nyear-1 + year = year_start + m + + text = "mss:/FORREST/CCSM/results/"+model_name+"/lnd/hist/*"+year+"* " + print (text) + + system("msrcp "+text+diri) + system("dcswait") + print (year) + + do n = 0,nmonth-1 + nn = n+1 + date(m,n) = year*100 +nn + +; input file + if (nn .ge. 10) then + fili = model_name+".clm2.h0."+year+"-"+nn+".nc" + else + fili = model_name+".clm2.h0."+year+"-0"+nn+".nc" + end if + +; print (fili) + + g = addfile (diri+fili,"r") + + b1 = g->COL_FIRE_CLOSS + data1(m,n,:,:) = (/b1(0,:,:)/) + + b2 = g->NPP + data2(m,n,:,:) = (/b2(0,:,:)/) + + b3 = g->NEE + data3(m,n,:,:) = (/b3(0,:,:)/) + + end do + +; system("rm "+diri+"*") + + end do + +; name dimensions and assign coordinate variables + + data1!0 ="year" + data1!1 ="month" + data1!2 = "lat" + data1!3 = "lon" + data1@long_name = b1@long_name + data1@units = b1@units + data1@_FillValue = b1@_FillValue + + data2!0 ="year" + data2!1 ="month" + data2!2 = "lat" + data2!3 = "lon" + data2@long_name = b2@long_name + data2@units = b2@units + data2@_FillValue = b2@_FillValue + + data3!0 ="year" + data3!1 ="month" + data3!2 = "lat" + data3!3 = "lon" + data3@long_name = b3@long_name + data3@units = b3@units + data3@_FillValue = b3@_FillValue + + date!0 ="year" + date!1 ="month" + date@long_name = "date: yyyymm" + + c->COL_FIRE_CLOSS = data1 + c->NPP = data2 + c->NEE = data3 + c->date = date + c->area = g->area + + print (date) + +end diff -r 000000000000 -r 0c6405ab2ff4 carbon_sink/11.table1.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbon_sink/11.table1.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,447 @@ +;******************************************************** +;using model biome vlass +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; model name and grid +;************************************************ + + model_grid = "T42" + + model_name = "cn" + model_name1 = "i01.06cn" + model_name2 = "i01.10cn" + +;--------------------------------------------------- +; get biome data: model + + biome_name_mod = "Model PFT Class" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "class_pft_"+model_grid+".nc" + + fm = addfile(dirm+film,"r") + + classmod = fm->CLASS_PFT + + delete (fm) + +; model data has 17 land-type classes + + nclass_mod = 17 + +;-------------------------------------------------- +; get model data: landfrac and area + + dirm_l= "/fis/cgd/cseg/people/jeff/surface_data/" + film_l = "lnd_T42.nc" + fm_l = addfile (dirm_l+film_l,"r") + + landfrac = fm_l->landfrac + area = fm_l->area + +; change area from km**2 to m**2 + area = area * 1.e6 +;--------------------------------------------------- +; read data: model, group 1 + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name1 + "_1980-2004_ANN_climo.nc" + fm = addfile (dirm+film,"r") + + NPP1 = fm->NPP + + leafc = fm->LEAFC + woodc = fm->WOODC + frootc = fm->FROOTC + VegC = leafc + VegC = leafc + woodc + frootc + + litterc = fm->LITTERC + cwdc = fm->CWDC + LiCwC = litterc + LiCwC = litterc + cwdc + + SoilC = fm->SOILC + + delete (fm) +;--------------------------------------------------- +; read data: model, group 2 + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name2 + "_1990-2004_ANN_climo.nc" + fm = addfile (dirm+film,"r") + + NPP2 = fm->NPP + NEE2 = fm->NEE + +;--------------------------------------------------- +; Units for these variables are: + +;NPP1: g C/m^2/s +;NPP2: g C/m^2/s +;NEE2: g C/m^2/s + +;VegC: g C/m^2 +;LiCwC: g C/m^2 +;SoilC: g C/m^2 + + nsec_per_year = 60*60*24*365 + +; change unit to g C/m^2/year + + NPP1 = NPP1 * nsec_per_year + NPP2 = NPP2 * nsec_per_year + NEE2 = NEE2 * nsec_per_year + +;--------------------------------------------------- +; take into account landfrac + + area(:,:) = area(:,:) * landfrac(:,:) + NPP1(0,:,:) = NPP1(0,:,:) * landfrac(:,:) + VegC(0,:,:) = VegC(0,:,:) * landfrac(:,:) + LiCwC(0,:,:) = LiCwC(0,:,:) * landfrac(:,:) + SoilC(0,:,:) = SoilC(0,:,:) * landfrac(:,:) + NPP2(0,:,:) = NPP2(0,:,:) * landfrac(:,:) + NEE2(0,:,:) = NEE2(0,:,:) * landfrac(:,:) + + data_n = 7 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; print (range) +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + +; output + + yvalues = new((/data_n,nx/),float) + count = new((/data_n,nx/),float) + + do n = 0,data_n-1 + + if(n.eq.0) then + data = ndtooned(area) + end if + + if(n.eq.1) then + data = ndtooned(NPP1) + end if + + if(n.eq.2) then + data = ndtooned(VegC) + end if + + if(n.eq.3) then + data = ndtooned(LiCwC) + end if + + if(n.eq.4) then + data = ndtooned(SoilC) + end if + + if(n.eq.5) then + data = ndtooned(NPP2) + end if + + if(n.eq.6) then + data = ndtooned(NEE2) + end if + +; Loop through each range, using base. + + do i=0,nx-1 + if (i.ne.(nx-1)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(base.ge.range(i)) + end if + +; Calculate average + + if(.not.any(ismissing(idx))) then + if (n.eq.0) then + yvalues(n,i) = sum(data(idx)) + else + yvalues(n,i) = avg(data(idx)) + end if + + count(n,i) = dimsizes(idx) + else + yvalues(n,i) = yvalues@_FillValue + count(n,i) = 0 + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(n,i) = yvalues@_FillValue + count(n,i) = 0 + end if +;############################################################# + +; print(n + ": " + count + " points, avg = " + yvalues(n,i)) + + delete(idx) + end do + + delete(data) + end do + + delete (base) + delete (area) + delete (NPP1) + delete (VegC) + delete (LiCwC) + delete (SoilC) + delete (NPP2) + delete (NEE2) + +;---------------------------------------------------------------- +; data for table1 + + good = ind(.not.ismissing(yvalues(5,:)) .and. .not.ismissing(yvalues(1,:))) +;print (good) + + w = yvalues(0,:) + area_g = w(good) + + w = yvalues(1,:) + NPP1_g = w(good) + + w = yvalues(2,:) + VegC_g = w(good) + + w = yvalues(3,:) + LiCwC_g = w(good) + + w = yvalues(4,:) + SoilC_g = w(good) + + w = yvalues(5,:) + NPP2_g = w(good) + + w = yvalues(6,:) + NEE2_g = w(good) + + n_biome = dimsizes(NPP1_g) + + NPP1_t = new((/n_biome/),float) + VegC_t = new((/n_biome/),float) + LiCwC_t = new((/n_biome/),float) + SoilC_t = new((/n_biome/),float) + NEE2_t = new((/n_biome/),float) + NPP_ratio = new((/n_biome/),float) + + NPP_ratio = NPP2_g/NPP1_g + +;----------------------------------------------------------------- +; data for table2 + +; change unit from g to Pg (Peta gram) + factor_unit = 1.e-15 + + NPP1_t = NPP1_g * area_g * factor_unit + VegC_t = VegC_g * area_g * factor_unit + LiCwC_t = LiCwC_g * area_g * factor_unit + SoilC_t = SoilC_g * area_g * factor_unit + NEE2_t = NEE2_g * area_g * factor_unit + + print (NPP1_t) + +;------------------------------------------------------------- +; html table1 data + +; column (not including header column) + + col_head = (/"Area (1.e12m2)" \ + ,"NPP (gC/m2/yr)" \ + ,"VegC (gC/m2)" \ + ,"Litter+CWD (gC/m2)" \ + ,"SoilC (gC/m2)" \ + ,"NPP ratio" \ + ,"NEE (gC/m2/yr)" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",area_g(i)*1.e-12) + text4(i,1) = sprintf("%.1f",NPP1_g(i)) + text4(i,2) = sprintf("%.1f",VegC_g(i)) + text4(i,3) = sprintf("%.1f",LiCwC_g(i)) + text4(i,4) = sprintf("%.1f",SoilC_g(i)) + text4(i,5) = sprintf("%.1f",NPP_ratio(i)) + text4(i,6) = sprintf("%.1f",NEE2_g(i)) + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + +;------------------------------------------------------- +; create html table1 + + header_text = "

NEE and Carbon Stocks and Fluxes: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) + +;---------------------------- +;row of table + + do n = 0,nrow-2 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text4(n,0) + txt2 = text4(n,1) + txt3 = text4(n,2) + txt4 = text4(n,3) + txt5 = text4(n,4) + txt6 = text4(n,5) + txt7 = text4(n,6) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + + set_line(lines,nline,row_footer) + end do +;---------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_carbon_sink1.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (col_head) + delete (row_head) + delete (text4) + +end + diff -r 000000000000 -r 0c6405ab2ff4 carbon_sink/12.table1+2.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbon_sink/12.table1+2.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,593 @@ +;******************************************************** +;using model biome vlass +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; model name and grid +;************************************************ + + model_grid = "T42" + + model_name = "cn" + model_name1 = "i01.06cn" + model_name2 = "i01.10cn" + +;--------------------------------------------------- +; get biome data: model + + biome_name_mod = "Model PFT Class" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "class_pft_"+model_grid+".nc" + + fm = addfile(dirm+film,"r") + + classmod = fm->CLASS_PFT + + delete (fm) + +; model data has 17 land-type classes + + nclass_mod = 17 + +;-------------------------------------------------- +; get model data: landfrac and area + + dirm_l= "/fis/cgd/cseg/people/jeff/surface_data/" + film_l = "lnd_T42.nc" + fm_l = addfile (dirm_l+film_l,"r") + + landfrac = fm_l->landfrac + area = fm_l->area + +; change area from km**2 to m**2 + area = area * 1.e6 +;--------------------------------------------------- +; read data: model, group 1 + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name1 + "_1980-2004_ANN_climo.nc" + fm = addfile (dirm+film,"r") + + NPP1 = fm->NPP + + leafc = fm->LEAFC + woodc = fm->WOODC + frootc = fm->FROOTC + VegC = leafc + VegC = leafc + woodc + frootc + + litterc = fm->LITTERC + cwdc = fm->CWDC + LiCwC = litterc + LiCwC = litterc + cwdc + + SoilC = fm->SOILC + + delete (fm) +;--------------------------------------------------- +; read data: model, group 2 + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name2 + "_1990-2004_ANN_climo.nc" + fm = addfile (dirm+film,"r") + + NPP2 = fm->NPP + NEE2 = fm->NEE + +;--------------------------------------------------- +; Units for these variables are: + +;NPP1: g C/m^2/s +;NPP2: g C/m^2/s +;NEE2: g C/m^2/s + +;VegC: g C/m^2 +;LiCwC: g C/m^2 +;SoilC: g C/m^2 + + nsec_per_year = 60*60*24*365 + +; change unit to g C/m^2/year + + NPP1 = NPP1 * nsec_per_year + NPP2 = NPP2 * nsec_per_year + NEE2 = NEE2 * nsec_per_year + +;--------------------------------------------------- +; take into account landfrac + + area(:,:) = area(:,:) * landfrac(:,:) + NPP1(0,:,:) = NPP1(0,:,:) * landfrac(:,:) + VegC(0,:,:) = VegC(0,:,:) * landfrac(:,:) + LiCwC(0,:,:) = LiCwC(0,:,:) * landfrac(:,:) + SoilC(0,:,:) = SoilC(0,:,:) * landfrac(:,:) + NPP2(0,:,:) = NPP2(0,:,:) * landfrac(:,:) + NEE2(0,:,:) = NEE2(0,:,:) * landfrac(:,:) + + data_n = 7 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; print (range) +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + +; output + + yvalues = new((/data_n,nx/),float) + count = new((/data_n,nx/),float) + + do n = 0,data_n-1 + + if(n.eq.0) then + data = ndtooned(area) + end if + + if(n.eq.1) then + data = ndtooned(NPP1) + end if + + if(n.eq.2) then + data = ndtooned(VegC) + end if + + if(n.eq.3) then + data = ndtooned(LiCwC) + end if + + if(n.eq.4) then + data = ndtooned(SoilC) + end if + + if(n.eq.5) then + data = ndtooned(NPP2) + end if + + if(n.eq.6) then + data = ndtooned(NEE2) + end if + +; Loop through each range, using base. + + do i=0,nx-1 + if (i.ne.(nx-1)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(base.ge.range(i)) + end if + +; Calculate average + + if(.not.any(ismissing(idx))) then + if (n.eq.0) then + yvalues(n,i) = sum(data(idx)) + else + yvalues(n,i) = avg(data(idx)) + end if + + count(n,i) = dimsizes(idx) + else + yvalues(n,i) = yvalues@_FillValue + count(n,i) = 0 + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(n,i) = yvalues@_FillValue + count(n,i) = 0 + end if +;############################################################# + +; print(n + ": " + count + " points, avg = " + yvalues(n,i)) + + delete(idx) + end do + + delete(data) + end do + + delete (base) + delete (area) + delete (NPP1) + delete (VegC) + delete (LiCwC) + delete (SoilC) + delete (NPP2) + delete (NEE2) + +;---------------------------------------------------------------- +; data for table1 + + good = ind(.not.ismissing(yvalues(5,:)) .and. .not.ismissing(yvalues(1,:))) +;print (good) + + w = yvalues(0,:) + area_g = w(good) + + w = yvalues(1,:) + NPP1_g = w(good) + + w = yvalues(2,:) + VegC_g = w(good) + + w = yvalues(3,:) + LiCwC_g = w(good) + + w = yvalues(4,:) + SoilC_g = w(good) + + w = yvalues(5,:) + NPP2_g = w(good) + + w = yvalues(6,:) + NEE2_g = w(good) + + n_biome = dimsizes(NPP1_g) + + NPP1_t = new((/n_biome/),float) + VegC_t = new((/n_biome/),float) + LiCwC_t = new((/n_biome/),float) + SoilC_t = new((/n_biome/),float) + NEE2_t = new((/n_biome/),float) + NPP_ratio = new((/n_biome/),float) + + NPP_ratio = NPP2_g/NPP1_g + +;----------------------------------------------------------------- +; data for table2 + +; change unit from g to Pg (Peta gram) + factor_unit = 1.e-15 + + NPP1_t = NPP1_g * area_g * factor_unit + VegC_t = VegC_g * area_g * factor_unit + LiCwC_t = LiCwC_g * area_g * factor_unit + SoilC_t = SoilC_g * area_g * factor_unit + NEE2_t = NEE2_g * area_g * factor_unit + + print (NPP1_t) + +;------------------------------------------------------------- +; html table1 data + +; column (not including header column) + + col_head = (/"Area (1.e12m2)" \ + ,"NPP (gC/m2/yr)" \ + ,"VegC (gC/m2)" \ + ,"Litter+CWD (gC/m2)" \ + ,"SoilC (gC/m2)" \ + ,"NPP_ratio" \ + ,"NEE (gC/m2/yr)" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",area_g(i)*1.e-12) + text4(i,1) = sprintf("%.1f",NPP1_g(i)) + text4(i,2) = sprintf("%.1f",VegC_g(i)) + text4(i,3) = sprintf("%.1f",LiCwC_g(i)) + text4(i,4) = sprintf("%.1f",SoilC_g(i)) + text4(i,5) = sprintf("%.1f",NPP_ratio(i)) + text4(i,6) = sprintf("%.1f",NEE2_g(i)) + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + +;------------------------------------------------------- +; create html table1 + + header_text = "

NEE and Carbon Stocks and Fluxes: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) + +;---------------------------- +;row of table + + do n = 0,nrow-2 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text4(n,0) + txt2 = text4(n,1) + txt3 = text4(n,2) + txt4 = text4(n,3) + txt5 = text4(n,4) + txt6 = text4(n,5) + txt7 = text4(n,6) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + + set_line(lines,nline,row_footer) + end do +;---------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_carbon_sink1.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + + delete (col_head) + delete (row_head) + delete (text4) + delete (table_header) + +;----------------------------------------------------------------- +; html table2 data + +; column (not including header column) + + col_head = (/"NPP (PgC/yr)" \ + ,"VegC (PgC)" \ + ,"Litter+CWD (PgC)" \ + ,"SoilC (PgC)" \ + ,"NEE (PgC/yr)" \ + ,"NPP timeseries" \ + ,"NEE timeseries" \ + ,"Fire timeseries" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",NPP1_t(i)) + text4(i,1) = sprintf("%.1f",VegC_t(i)) + text4(i,2) = sprintf("%.1f",LiCwC_t(i)) + text4(i,3) = sprintf("%.1f",SoilC_t(i)) + text4(i,4) = sprintf("%.1f",NEE2_t(i)) + text4(i,5) = "-" + text4(i,6) = "-" + text4(i,7) = "-" + end do + text4(nrow-1,0) = sprintf("%.1f",sum(NPP1_t)) + text4(nrow-1,1) = sprintf("%.1f",sum(VegC_t)) + text4(nrow-1,2) = sprintf("%.1f",sum(LiCwC_t)) + text4(nrow-1,3) = sprintf("%.1f",sum(SoilC_t)) + text4(nrow-1,4) = sprintf("%.1f",sum(NEE2_t)) + text4(nrow-1,5) = "-" + text4(nrow-1,6) = "-" + text4(nrow-1,7) = "-" + +;************************************************** +; create html table1 +;************************************************** + + header_text = "

NEE and Carbon Stocks and Fluxes (per biome): Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+""+col_head(7)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text4(n,0) + txt2 = text4(n,1) + txt3 = text4(n,2) + txt4 = text4(n,3) + txt5 = text4(n,4) + txt6 = text4(n,5) + txt7 = text4(n,6) + txt8 = text4(n,7) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_carbon_sink2.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +end + diff -r 000000000000 -r 0c6405ab2ff4 carbon_sink/20.table+tseries.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbon_sink/20.table+tseries.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,867 @@ +;******************************************************** +;using model biome vlass +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; model name and grid +;************************************************ + + model_grid = "T42" + + model_name = "cn" + model_name1 = "i01.06cn" + model_name2 = "i01.10cn" + +;--------------------------------------------------- +; get biome data: model + + biome_name_mod = "Model PFT Class" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "class_pft_"+model_grid+".nc" + + fm = addfile(dirm+film,"r") + + classmod = fm->CLASS_PFT + + delete (fm) + +; model data has 17 land-type classes + + nclass_mod = 17 + +;-------------------------------------------------- +; get model data: landfrac and area + + dirm_l= "/fis/cgd/cseg/people/jeff/surface_data/" + film_l = "lnd_T42.nc" + fm_l = addfile (dirm_l+film_l,"r") + + landfrac = fm_l->landfrac + area = fm_l->area + +; change area from km**2 to m**2 + area = area * 1.e6 + +;--------------------------------------------------- +; take into account landfrac + + area = area * landfrac + + delete (landfrac) + +;--------------------------------------------------- +; read data: model, group 1 + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name1 + "_1980-2004_ANN_climo.nc" + fm = addfile (dirm+film,"r") + + NPP1 = fm->NPP + + leafc = fm->LEAFC + woodc = fm->WOODC + frootc = fm->FROOTC + VegC = leafc + VegC = leafc + woodc + frootc + + litterc = fm->LITTERC + cwdc = fm->CWDC + LiCwC = litterc + LiCwC = litterc + cwdc + + SoilC = fm->SOILC + + delete (fm) +;--------------------------------------------------- +; read data: model, group 2 + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name2 + "_1990-2004_ANN_climo.nc" + fm = addfile (dirm+film,"r") + + NPP2 = fm->NPP + NEE2 = fm->NEE + +;--------------------------------------------------- +; Units for these variables are: + +;NPP1: g C/m^2/s +;NPP2: g C/m^2/s +;NEE2: g C/m^2/s + +;VegC: g C/m^2 +;LiCwC: g C/m^2 +;SoilC: g C/m^2 + + nsec_per_year = 60*60*24*365 + +; change unit to g C/m^2/year + + NPP1 = NPP1 * nsec_per_year + NPP2 = NPP2 * nsec_per_year + NEE2 = NEE2 * nsec_per_year + + data_n = 7 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; print (range) +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + + area_1d = ndtooned(area) + +; output + + yvalues = new((/data_n,nx/),float) + yvalues_t = new((/data_n,nx/),float) + + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if + + do n = 0,data_n-1 + + if (n.eq.0) then + data = ndtooned(area) + end if + + if (n.eq.1) then + data = ndtooned(NPP1) + end if + + if (n.eq.2) then + data = ndtooned(VegC) + end if + + if (n.eq.3) then + data = ndtooned(LiCwC) + end if + + if (n.eq.4) then + data = ndtooned(SoilC) + end if + + if (n.eq.5) then + data = ndtooned(NPP2) + end if + + if (n.eq.6) then + data = ndtooned(NEE2) + end if + +; Calculate sum and average + + if (.not.any(ismissing(idx))) then + if (n.eq.0) then + yvalues(n,i) = sum(data(idx)) + yvalues_t(n,i) = sum(data(idx)) + else + yvalues(n,i) = avg(data(idx)) + yvalues_t(n,i) = sum(data(idx)*area_1d(idx)) + end if + else + yvalues(n,i) = yvalues@_FillValue + yvalues_t(n,i) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(n,i) = yvalues@_FillValue + yvalues_t(n,i) = yvalues@_FillValue + end if +;############################################################# + + delete (data) + end do + + delete (idx) + end do + + delete (base) + delete (area) + delete (NPP1) + delete (VegC) + delete (LiCwC) + delete (SoilC) + delete (NPP2) + delete (NEE2) + +;---------------------------------------------------------------- +; data for table1 + + good = ind(.not.ismissing(yvalues(5,:)) .and. .not.ismissing(yvalues(1,:))) +;print (good) + + area_g = yvalues(0,good) + NPP1_g = yvalues(1,good) + VegC_g = yvalues(2,good) + LiCwC_g = yvalues(3,good) + SoilC_g = yvalues(4,good) + NPP2_g = yvalues(5,good) + NEE2_g = yvalues(6,good) + + n_biome = dimsizes(NPP1_g) + + NPP_ratio = NPP2_g/NPP1_g + +;----------------------------------------------------------------- +; data for table2 + +; change unit from g to Pg (Peta gram) + factor_unit = 1.e-15 + + NPP1_t = yvalues_t(1,good) * factor_unit + VegC_t = yvalues_t(2,good) * factor_unit + LiCwC_t = yvalues_t(3,good) * factor_unit + SoilC_t = yvalues_t(4,good) * factor_unit + NEE2_t = yvalues_t(6,good) * factor_unit + + delete (yvalues) + delete (yvalues_t) + +;------------------------------------------------------------- +; html table1 data + +; column (not including header column) + + col_head = (/"Area (1.e12m2)" \ + ,"NPP (gC/m2/yr)" \ + ,"VegC (gC/m2)" \ + ,"Litter+CWD (gC/m2)" \ + ,"SoilC (gC/m2)" \ + ,"NPP_ratio" \ + ,"NEE (gC/m2/yr)" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",area_g(i)*1.e-12) + text4(i,1) = sprintf("%.1f",NPP1_g(i)) + text4(i,2) = sprintf("%.1f",VegC_g(i)) + text4(i,3) = sprintf("%.1f",LiCwC_g(i)) + text4(i,4) = sprintf("%.1f",SoilC_g(i)) + text4(i,5) = sprintf("%.2f",NPP_ratio(i)) + text4(i,6) = sprintf("%.1f",NEE2_g(i)) + end do + +;------------------------------------------------------- +; create html table1 + + header_text = "

NEE and Carbon Stocks and Fluxes: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) + +;---------------------------- +;row of table + + do n = 0,nrow-2 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text4(n,0) + txt2 = text4(n,1) + txt3 = text4(n,2) + txt4 = text4(n,3) + txt5 = text4(n,4) + txt6 = text4(n,5) + txt7 = text4(n,6) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + + set_line(lines,nline,row_footer) + end do +;---------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_carbon_sink1.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + + delete (col_head) + delete (row_head) + delete (text4) + delete (table_header) + +;----------------------------------------------------------------- +; html table2 data + +; column (not including header column) + + col_head = (/"NPP (PgC/yr)" \ + ,"VegC (PgC)" \ + ,"Litter+CWD (PgC)" \ + ,"SoilC (PgC)" \ + ,"NEE (PgC/yr)" \ + ,"NPP timeseries" \ + ,"NEE timeseries" \ + ,"Fire timeseries" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",NPP1_t(i)) + text4(i,1) = sprintf("%.1f",VegC_t(i)) + text4(i,2) = sprintf("%.1f",LiCwC_t(i)) + text4(i,3) = sprintf("%.1f",SoilC_t(i)) + text4(i,4) = sprintf("%.1f",NEE2_t(i)) + text4(i,5) = "monthly_plot
annual_plot" + text4(i,6) = "monthly_plot
annual_plot" + text4(i,7) = "monthly_plot
annual_plot" + end do + text4(nrow-1,0) = sprintf("%.1f",sum(NPP1_t)) + text4(nrow-1,1) = sprintf("%.1f",sum(VegC_t)) + text4(nrow-1,2) = sprintf("%.1f",sum(LiCwC_t)) + text4(nrow-1,3) = sprintf("%.1f",sum(SoilC_t)) + text4(nrow-1,4) = sprintf("%.1f",sum(NEE2_t)) + text4(nrow-1,5) = "monthly_plot
annual_plot" + text4(nrow-1,6) = "monthly_plot
annual_plot" + text4(nrow-1,7) = "monthly_plot
annual_plot" + +;************************************************** +; create html table2 +;************************************************** + + header_text = "

NEE and Carbon Stocks and Fluxes (per biome): Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+""+col_head(7)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text4(n,0) + txt2 = text4(n,1) + txt3 = text4(n,2) + txt4 = text4(n,3) + txt5 = text4(n,4) + txt6 = text4(n,5) + txt7 = text4(n,6) + txt8 = text4(n,7) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_carbon_sink2.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + +;--------------------------------------------------- +; read data: model, time series + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name2 + "_Fire_C_1979-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + NPP3 = fm->NPP + NEE3 = fm->NEE + Fire = fm->COL_FIRE_CLOSS + + delete (fm) + +; Units for these variables are: + +;NPP3: g C/m^2/s +;NEE3: g C/m^2/s +;Fire: g C/m^2/s + + nsec_per_month = 60*60*24*30 + +; change unit to g C/m^2/month + + NPP3 = NPP3 * nsec_per_month + NEE3 = NEE3 * nsec_per_month + Fire = Fire * nsec_per_month + + data_n = 3 + + dsizes = dimsizes(NPP3) + nyear = dsizes(0) + nmonth = dsizes(1) + ntime = nyear * nmonth + + year_start = 1979 + year_end = 2004 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; print (range) +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + +; output + + yvalues = new((/ntime,data_n,nx/),float) + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if + + do n = 0,data_n-1 + + t = -1 + do m = 0,nyear-1 + do k = 0,nmonth-1 + + t = t + 1 + + if (n.eq.0) then + data = ndtooned(NPP3(m,k,:,:)) + end if + + if (n.eq.1) then + data = ndtooned(NEE3(m,k,:,:)) + end if + + if (n.eq.2) then + data = ndtooned(Fire(m,k,:,:)) + end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(t,n,i) = sum(data(idx)*area_1d(idx)) + else + yvalues(t,n,i) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(t,n,i) = yvalues@_FillValue + end if +;############################################################# + + end do + end do + + delete(data) + end do + + delete(idx) + end do + + delete (base) + delete (NPP3) + delete (NEE3) + delete (Fire) + +;---------------------------------------------------------------- +; data for tseries plot + + yvalues_g = new((/ntime,data_n,n_biome/),float) + + yvalues_g@units = "TgC/month" + +; change unit to Tg C/month +; change unit from g to Tg (Tera gram) + factor_unit = 1.e-12 + + yvalues_g = yvalues(:,:,good) * factor_unit + +;******************************************************************* +; general settings for line plot +;******************************************************************* + +; res + res = True + res@xyDashPatterns = (/0/) ; make lines solid + res@xyLineThicknesses = (/2.0/) ; make lines thicker + res@xyLineColors = (/"blue"/) ; line color + + res@trXMinF = year_start + res@trXMaxF = year_end + 1 + + res@vpHeightF = 0.4 ; change aspect ratio of plot +; res@vpWidthF = 0.8 + res@vpWidthF = 0.75 + +; res@gsnMaximize = True + +;******************************************************************* +; (A) 1 component in each biome: monthly +;******************************************************************* + + component = (/"NPP","NEE","Fire"/) + +; for x-axis in xyplot + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_start + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/ntime/),float) + plot_data@long_name = "TgC/month" + + do n = 0, data_n-1 + do m = 0, n_biome-1 + + plot_name = component(n)+"_monthly_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": "+ row_head(m) + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + plot_data(:) = yvalues_g(:,n,m) + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + end do + + do n = 0, data_n-1 + + plot_name = component(n)+"_monthly_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": Global" + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + do k = 0,ntime-1 + plot_data(k) = sum(yvalues_g(k,n,:)) + end do + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + + delete (plot_data) + delete (timeI) + delete (timeF) + +;******************************************************************* +; (B) 1 component in each biome: annually +;******************************************************************* + + yvalues_a = new((/nyear,data_n,n_biome/),float) + yvalues_g!0 = "time" + yvalues_g!1 = "case" + yvalues_g!2 = "record" + + yvalues_a = month_to_annual(yvalues_g,0) + + delete (yvalues_g) + +; for x-axis in xyplot + + timeI = new((/nyear/),integer) + timeF = new((/nyear/),float) + timeI = ispan(1,nyear,1) + timeF = year_start + (timeI-1) + timeF@long_name = "year" + + plot_data = new((/nyear/),float) + plot_data@long_name = "TgC/year" + + do n = 0, data_n-1 + do m = 0, n_biome-1 + + plot_name = component(n)+"_annual_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": "+ row_head(m) + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + plot_data(:) = yvalues_a(:,n,m) + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + end do + + do n = 0, data_n-1 + + plot_name = component(n)+"_annual_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": Global" + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + do k = 0,nyear-1 + plot_data(k) = sum(yvalues_a(k,n,:)) + end do + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +end + diff -r 000000000000 -r 0c6405ab2ff4 carbon_sink/20x.table+tseries.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbon_sink/20x.table+tseries.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,869 @@ +;******************************************************** +; for casa (no fire) +; using model biome vlass +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; model name and grid +;************************************************ + + model_grid = "T42" + + model_name = "casa" + model_name1 = "i01.06casa" + model_name2 = "i01.10casa" + +;--------------------------------------------------- +; get biome data: model + + biome_name_mod = "Model PFT Class" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "class_pft_"+model_grid+".nc" + + fm = addfile(dirm+film,"r") + + classmod = fm->CLASS_PFT + + delete (fm) + +; model data has 17 land-type classes + + nclass_mod = 17 + +;-------------------------------------------------- +; get model data: landfrac and area + + dirm_l= "/fis/cgd/cseg/people/jeff/surface_data/" + film_l = "lnd_T42.nc" + fm_l = addfile (dirm_l+film_l,"r") + + landfrac = fm_l->landfrac + area = fm_l->area + +; change area from km**2 to m**2 + area = area * 1.e6 + +;--------------------------------------------------- +; take into account landfrac + + area = area * landfrac + + delete (landfrac) + +;--------------------------------------------------- +; read data: model, group 1 + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name1 + "_1980-2004_ANN_climo.nc" + fm = addfile (dirm+film,"r") + + NPP1 = fm->NPP + + leafc = fm->LEAFC + woodc = fm->WOODC + frootc = fm->FROOTC + VegC = leafc + VegC = leafc + woodc + frootc + + litterc = fm->LITTERC + cwdc = fm->CWDC + LiCwC = litterc + LiCwC = litterc + cwdc + + SoilC = fm->SOILC + + delete (fm) +;--------------------------------------------------- +; read data: model, group 2 + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name2 + "_1990-2004_ANN_climo.nc" + fm = addfile (dirm+film,"r") + + NPP2 = fm->NPP + NEE2 = fm->NEE + +;--------------------------------------------------- +; Units for these variables are: + +;NPP1: g C/m^2/s +;NPP2: g C/m^2/s +;NEE2: g C/m^2/s + +;VegC: g C/m^2 +;LiCwC: g C/m^2 +;SoilC: g C/m^2 + + nsec_per_year = 60*60*24*365 + +; change unit to g C/m^2/year + + NPP1 = NPP1 * nsec_per_year + NPP2 = NPP2 * nsec_per_year + NEE2 = NEE2 * nsec_per_year + + data_n = 7 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; print (range) +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + + area_1d = ndtooned(area) + +; output + + yvalues = new((/data_n,nx/),float) + yvalues_t = new((/data_n,nx/),float) + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if + + do n = 0,data_n-1 + + if (n.eq.0) then + data = ndtooned(area) + end if + + if (n.eq.1) then + data = ndtooned(NPP1) + end if + + if (n.eq.2) then + data = ndtooned(VegC) + end if + + if (n.eq.3) then + data = ndtooned(LiCwC) + end if + + if (n.eq.4) then + data = ndtooned(SoilC) + end if + + if (n.eq.5) then + data = ndtooned(NPP2) + end if + + if (n.eq.6) then + data = ndtooned(NEE2) + end if + +; Calculate sum and average + + if (.not.any(ismissing(idx))) then + if (n.eq.0) then + yvalues(n,i) = sum(data(idx)) + yvalues_t(n,i) = sum(data(idx)) + else + yvalues(n,i) = avg(data(idx)) + yvalues_t(n,i) = sum(data(idx)*area_1d(idx)) + end if + else + yvalues(n,i) = yvalues@_FillValue + yvalues_t(n,i) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(n,i) = yvalues@_FillValue + yvalues_t(n,i) = yvalues@_FillValue + end if +;############################################################# + + delete (data) + end do + + delete (idx) + end do + + delete (base) + delete (area) + delete (NPP1) + delete (VegC) + delete (LiCwC) + delete (SoilC) + delete (NPP2) + delete (NEE2) + +;---------------------------------------------------------------- +; data for table1 + + good = ind(.not.ismissing(yvalues(5,:)) .and. .not.ismissing(yvalues(1,:))) +;print (good) + + area_g = yvalues(0,good) + NPP1_g = yvalues(1,good) + VegC_g = yvalues(2,good) + LiCwC_g = yvalues(3,good) + SoilC_g = yvalues(4,good) + NPP2_g = yvalues(5,good) + NEE2_g = yvalues(6,good) + + n_biome = dimsizes(NPP1_g) + + NPP_ratio = NPP2_g/NPP1_g + +;----------------------------------------------------------------- +; data for table2 + +; change unit from g to Pg (Peta gram) + factor_unit = 1.e-15 + + NPP1_t = yvalues_t(1,good) * factor_unit + VegC_t = yvalues_t(2,good) * factor_unit + LiCwC_t = yvalues_t(3,good) * factor_unit + SoilC_t = yvalues_t(4,good) * factor_unit + NEE2_t = yvalues_t(6,good) * factor_unit + + delete (yvalues) + delete (yvalues_t) + +;------------------------------------------------------------- +; html table1 data + +; column (not including header column) + + col_head = (/"Area (1.e12m2)" \ + ,"NPP (gC/m2/yr)" \ + ,"VegC (gC/m2)" \ + ,"Litter+CWD (gC/m2)" \ + ,"SoilC (gC/m2)" \ + ,"NPP_ratio" \ + ,"NEE (gC/m2/yr)" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",area_g(i)*1.e-12) + text4(i,1) = sprintf("%.1f",NPP1_g(i)) + text4(i,2) = sprintf("%.1f",VegC_g(i)) + text4(i,3) = sprintf("%.1f",LiCwC_g(i)) + text4(i,4) = sprintf("%.1f",SoilC_g(i)) + text4(i,5) = sprintf("%.2f",NPP_ratio(i)) + text4(i,6) = sprintf("%.1f",NEE2_g(i)) + end do + +;------------------------------------------------------- +; create html table1 + + header_text = "

NEE and Carbon Stocks and Fluxes: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) + +;---------------------------- +;row of table + + do n = 0,nrow-2 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text4(n,0) + txt2 = text4(n,1) + txt3 = text4(n,2) + txt4 = text4(n,3) + txt5 = text4(n,4) + txt6 = text4(n,5) + txt7 = text4(n,6) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + + set_line(lines,nline,row_footer) + end do +;---------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_carbon_sink1.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + + delete (col_head) + delete (row_head) + delete (text4) + delete (table_header) + +;----------------------------------------------------------------- +; html table2 data + +; column (not including header column) + + col_head = (/"NPP (PgC/yr)" \ + ,"VegC (PgC)" \ + ,"Litter+CWD (PgC)" \ + ,"SoilC (PgC)" \ + ,"NEE (PgC/yr)" \ + ,"NPP timeseries" \ + ,"NEE timeseries" \ + ,"Fire timeseries" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",NPP1_t(i)) + text4(i,1) = sprintf("%.1f",VegC_t(i)) + text4(i,2) = sprintf("%.1f",LiCwC_t(i)) + text4(i,3) = sprintf("%.1f",SoilC_t(i)) + text4(i,4) = sprintf("%.1f",NEE2_t(i)) + text4(i,5) = "monthly_plot
annual_plot" + text4(i,6) = "monthly_plot
annual_plot" + text4(i,7) = "--" + end do + text4(nrow-1,0) = sprintf("%.1f",sum(NPP1_t)) + text4(nrow-1,1) = sprintf("%.1f",sum(VegC_t)) + text4(nrow-1,2) = sprintf("%.1f",sum(LiCwC_t)) + text4(nrow-1,3) = sprintf("%.1f",sum(SoilC_t)) + text4(nrow-1,4) = sprintf("%.1f",sum(NEE2_t)) + text4(nrow-1,5) = "monthly_plot
annual_plot" + text4(nrow-1,6) = "monthly_plot
annual_plot" + text4(nrow-1,7) = "--" + +;************************************************** +; create html table2 +;************************************************** + + header_text = "

NEE and Carbon Stocks and Fluxes (per biome): Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+""+col_head(6)+""+col_head(7)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text4(n,0) + txt2 = text4(n,1) + txt3 = text4(n,2) + txt4 = text4(n,3) + txt5 = text4(n,4) + txt6 = text4(n,5) + txt7 = text4(n,6) + txt8 = text4(n,7) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_carbon_sink2.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + +;--------------------------------------------------- +; read data: model, time series + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name2 + "_Fire_C_1979-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + NPP3 = fm->NPP + NEE3 = fm->NEE +;Fire = fm->COL_FIRE_CLOSS + + delete (fm) + +; Units for these variables are: + +;NPP3: g C/m^2/s +;NEE3: g C/m^2/s +;Fire: g C/m^2/s + + nsec_per_month = 60*60*24*30 + +; change unit to g C/m^2/month + + NPP3 = NPP3 * nsec_per_month + NEE3 = NEE3 * nsec_per_month +;Fire = Fire * nsec_per_month + +;data_n = 3 + data_n = 2 + + dsizes = dimsizes(NPP3) + nyear = dsizes(0) + nmonth = dsizes(1) + ntime = nyear * nmonth + + year_start = 1979 + year_end = 2004 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; print (range) +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + +; output + + yvalues = new((/ntime,data_n,nx/),float) + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if + + do n = 0,data_n-1 + + t = -1 + do m = 0,nyear-1 + do k = 0,nmonth-1 + + t = t + 1 + + if (n.eq.0) then + data = ndtooned(NPP3(m,k,:,:)) + end if + + if (n.eq.1) then + data = ndtooned(NEE3(m,k,:,:)) + end if + +; if (n.eq.2) then +; data = ndtooned(Fire(m,k,:,:)) +; end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(t,n,i) = sum(data(idx)*area_1d(idx)) + else + yvalues(t,n,i) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(t,n,i) = yvalues@_FillValue + end if +;############################################################# + + end do + end do + + delete(data) + end do + + delete(idx) + end do + + delete (base) + delete (NPP3) + delete (NEE3) +; delete (Fire) + +;---------------------------------------------------------------- +; data for tseries plot + + yvalues_g = new((/ntime,data_n,n_biome/),float) + + yvalues_g@units = "TgC/month" + +; change unit to Tg C/month +; change unit from g to Tg (Tera gram) + factor_unit = 1.e-12 + + yvalues_g = yvalues(:,:,good) * factor_unit + +;******************************************************************* +; general settings for line plot +;******************************************************************* + +; res + res = True + res@xyDashPatterns = (/0/) ; make lines solid + res@xyLineThicknesses = (/2.0/) ; make lines thicker + res@xyLineColors = (/"blue"/) ; line color + + res@trXMinF = year_start + res@trXMaxF = year_end + 1 + + res@vpHeightF = 0.4 ; change aspect ratio of plot +; res@vpWidthF = 0.8 + res@vpWidthF = 0.75 + +; res@gsnMaximize = True + +;******************************************************************* +; (A) 1 component in each biome: monthly +;******************************************************************* + +; component = (/"NPP","NEE","Fire"/) + component = (/"NPP","NEE"/) + +; for x-axis in xyplot + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_start + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/ntime/),float) + plot_data@long_name = "TgC/month" + + do n = 0, data_n-1 + do m = 0, n_biome-1 + + plot_name = component(n)+"_monthly_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": "+ row_head(m) + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + plot_data(:) = yvalues_g(:,n,m) + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + end do + + do n = 0, data_n-1 + + plot_name = component(n)+"_monthly_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": Global" + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + do k = 0,ntime-1 + plot_data(k) = sum(yvalues_g(k,n,:)) + end do + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + + delete (plot_data) + delete (timeI) + delete (timeF) + +;******************************************************************* +; (B) 1 component in each biome: annually +;******************************************************************* + + yvalues_a = new((/nyear,data_n,n_biome/),float) + yvalues_g!0 = "time" + yvalues_g!1 = "case" + yvalues_g!2 = "record" + + yvalues_a = month_to_annual(yvalues_g,0) + + delete (yvalues_g) + +; for x-axis in xyplot + + timeI = new((/nyear/),integer) + timeF = new((/nyear/),float) + timeI = ispan(1,nyear,1) + timeF = year_start + (timeI-1) + timeF@long_name = "year" + + plot_data = new((/nyear/),float) + plot_data@long_name = "TgC/year" + + do n = 0, data_n-1 + do m = 0, n_biome-1 + + plot_name = component(n)+"_annual_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": "+ row_head(m) + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + plot_data(:) = yvalues_a(:,n,m) + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + end do + + do n = 0, data_n-1 + + plot_name = component(n)+"_annual_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = component(n)+ ": Global" + res@tiMainString = title + res@tiMainFontHeightF = 0.025 + + do k = 0,nyear-1 + plot_data(k) = sum(yvalues_a(k,n,:)) + end do + + plot=gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +end + diff -r 000000000000 -r 0c6405ab2ff4 carbon_sink/note.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbon_sink/note.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1 @@ +casa does not have fire. \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 class/01.test.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/class/01.test.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,33 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin + +;************************************************ +; read in model data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp/class/" + fili = "T42.clamp.surface-data.060412.nc" + f = addfile(diri+fili,"r") + + y = f->PCT_PFT + printVarSummary(y) + + x = y(0,:,:) + + dimx = dimsizes(y) + nlat = dimx(1) + nlon = dimx(2) + + do j= 0,nlat-1 + do i= 0,nlon-1 + x(j,i) = sum(y(:,j,i)) + end do + end do + + print (x) + +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 class/02.class.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/class/02.class.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,72 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +;************************************************ +; read in model data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp/class/" + fili = "T42.clamp.surface-data.060412.nc" + f = addfile(diri+fili,"r") + + y = f->PCT_PFT + printVarSummary(y) + + diri = "/fis/cgd/cseg/people/jeff/surface_data/" + fili = "lnd_T42.nc" + g = addfile(diri+fili,"r") + + landmask = g->landmask + lat = g->lat + lon = g->lon + + nlat = dimsizes(lat) + nlon = dimsizes(lon) + + x = y(0,:,:) + + x!0 = "lat" + x&lat = lat + x!1 = "lon" + x&lon = lon + x@_FillValue = 1.e36 + x@long_name = "Model PFT Classes" + + do j= 0,nlat-1 + do i= 0,nlon-1 + x(j,i) = maxind(y(:,j,i)) + end do + end do + +; print (x) + + x = where(landmask .lt. 1.,x@_FillValue,x) + +;************************************************ +; create default plot +;************************************************ + + wks = gsn_open_wks("ps","class") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@tiMainString = "Class" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 16. ; Max level + res@cnLevelSpacingF = 1. ; interval + + plot = gsn_csm_contour_map_ce(wks,x,res) + +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 class/03.class_1.9_write.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/class/03.class_1.9_write.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,61 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +; final output + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + filo = "class_pft_1.9.nc" + c = addfile(diro+filo,"c") + +; read model data + + diri = "/fis/cgd/cseg/people/jeff/surface_data/" + fili = "surfdata_1.9x2.5_cn_070119.nc" + f = addfile(diri+fili,"r") + + y = f->PCT_PFT +; printVarSummary(y) + +; read model grid data + + diri = "/fis/cgd/cseg/people/jeff/surface_data/" + fili = "lnd_1.9.nc" + g = addfile(diri+fili,"r") + + landmask = g->landmask + lat = g->lat + lon = g->lon + + nlat = dimsizes(lat) + nlon = dimsizes(lon) + + x = y(0,:,:) + + x!0 = "lat" + x&lat = lat + x!1 = "lon" + x&lon = lon + x@_FillValue = 1.e36 + x@long_name = "Model PFT Classes" + + do j= 0,nlat-1 + do i= 0,nlon-1 + x(j,i) = maxind(y(:,j,i)) + end do + end do + +; print (x) + + x = where(landmask .lt. 1.,x@_FillValue,x) + + c->CLASS_PFT = x + c->lat = lat + c->lon = lon + +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 class/03.class_T31_write.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/class/03.class_T31_write.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,61 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +; final output + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + filo = "class_pft_T31.nc" + c = addfile(diro+filo,"c") + +; read model data + + diri = "/fis/cgd/cseg/people/jeff/surface_data/" + fili = "surfdata_48x96_c070501.nc" + f = addfile(diri+fili,"r") + + y = f->PCT_PFT +; printVarSummary(y) + +; read model grid data + + diri = "/fis/cgd/cseg/people/jeff/surface_data/" + fili = "lnd_T31.nc" + g = addfile(diri+fili,"r") + + landmask = g->landmask + lat = g->lat + lon = g->lon + + nlat = dimsizes(lat) + nlon = dimsizes(lon) + + x = y(0,:,:) + + x!0 = "lat" + x&lat = lat + x!1 = "lon" + x&lon = lon + x@_FillValue = 1.e36 + x@long_name = "Model PFT Classes" + + do j= 0,nlat-1 + do i= 0,nlon-1 + x(j,i) = maxind(y(:,j,i)) + end do + end do + +; print (x) + + x = where(landmask .lt. 1.,x@_FillValue,x) + + c->CLASS_PFT = x + c->lat = lat + c->lon = lon + +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 class/03.class_T42_write.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/class/03.class_T42_write.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,61 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +; final output + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + filo = "class_pft_T42.nc" + c = addfile(diro+filo,"c") + +; read model data + + diri = "/fis/cgd/cseg/people/jeff/surface_data/" + fili = "T42.clamp.surface-data.060412.nc" + f = addfile(diri+fili,"r") + + y = f->PCT_PFT +; printVarSummary(y) + +; read model grid data + + diri = "/fis/cgd/cseg/people/jeff/surface_data/" + fili = "lnd_T42.nc" + g = addfile(diri+fili,"r") + + landmask = g->landmask + lat = g->lat + lon = g->lon + + nlat = dimsizes(lat) + nlon = dimsizes(lon) + + x = y(0,:,:) + + x!0 = "lat" + x&lat = lat + x!1 = "lon" + x&lon = lon + x@_FillValue = 1.e36 + x@long_name = "Model PFT Classes" + + do j= 0,nlat-1 + do i= 0,nlon-1 + x(j,i) = maxind(y(:,j,i)) + end do + end do + +; print (x) + + x = where(landmask .lt. 1.,x@_FillValue,x) + + c->CLASS_PFT = x + c->lat = lat + c->lon = lon + +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 class/04.check_write.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/class/04.check_write.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,42 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +; read data + + diri = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili = "class_pft_T42.nc" + fili = "class_pft_1.9.nc" + f = addfile(diri+fili,"r") + + x = f->CLASS_PFT + printVarSummary(x) + +;************************************************ +; create default plot +;************************************************ + + wks = gsn_open_wks("ps","class") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@tiMainString = "Class" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 16. ; Max level + res@cnLevelSpacingF = 1. ; interval + + plot = gsn_csm_contour_map_ce(wks,x,res) + +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 class/note.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/class/note.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1 @@ +create from /surface_data/T42.clamp.surface-data.060412.nc \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 co2/00.test.html.csh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/00.test.html.csh Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,8 @@ +#!/bin/sh + +fout=test.html + +echo "" > $fout + + +exit diff -r 000000000000 -r 0c6405ab2ff4 co2/01.test.html.csh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/01.test.html.csh Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,30 @@ +#!/bin/sh + +fout=test2.html + +echo "" > $fout +echo "" >> $fout +echo " CO2 Model " >> $fout +echo "" >> $fout +echo "" >> $fout +echo "" >> $fout +echo "" >> $fout + +echo "" >>$ fout +echo "

CLAMP Metric

" >> $fout +echo "

Seasonal cycle of atmospheric CO2 metrics

" >> $fout +echo "

Stations In 60N-90N (in progress)

" >> $fout +echo "" >> $fout +echo "" >> $fout +echo "" >> $fout + echo "" >> $fout + echo "" >> $fout + echo "" >> $fout + echo "" >> $fout + echo "" >> $fout + echo "" >> $fout + echo "" >> $fout +echo "" >> $fout + + +exit diff -r 000000000000 -r 0c6405ab2ff4 co2/01.test.read.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/01.test.read.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,19 @@ +;************************************************ +; Read ascii, Write nc +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + b = "zot005_45D2_seas.co2" + ncol = 4 + data = readAsciiTable(b, ncol, "float", (/10,17/)) + print (data) + + ncol = 5 + data2 = readAsciiTable(b, ncol, "float", 16) + print (data2) + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/02.test.read.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/02.test.read.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,22 @@ +;************************************************ +; Read ascii, Write nc +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/globalView-C4Mip/seas/" + b = (/"zot005_45D2_seas.co2", "zot015_45D2_seas.co2"/) + do n = 0,1 + print (b(n)) + ncol1 = 4 + data1 = readAsciiTable(diri+b(n), ncol1, "float", (/10,17/)) + print (data1) + + ncol2 = 5 + data2 = readAsciiTable(diri+b(n), ncol2, "float", 16) + print (data2) + end do + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/03.test.read.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/03.test.read.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,249 @@ +;************************************************ +; Read ascii, Write nc +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/globalView-C4Mip/seas/" + b = (/ \ +"aia005_02D2_seas.co2", \ +"aia015_02D2_seas.co2", \ +"aia025_02D2_seas.co2", \ +"aia035_02D2_seas.co2", \ +"aia045_02D2_seas.co2", \ +"aia055_02D2_seas.co2", \ +"aia065_02D2_seas.co2", \ +"alt_01D0_seas.co2", \ +"alt_02D0_seas.co2", \ +"alt_04D0_seas.co2", \ +"alt_06C0_seas.co2", \ +"alt_06D0_seas.co2", \ +"ams_01D0_seas.co2", \ +"ams_11C0_seas.co2", \ +"asc_01D0_seas.co2", \ +"ask_01D0_seas.co2", \ +"avi_01D0_seas.co2", \ +"azr_01D0_seas.co2", \ +"bal_01D1_seas.co2", \ +"bgu_11D0_seas.co2", \ +"bhd_15C0_seas.co2", \ +"bme_01D0_seas.co2", \ +"bmw_01D0_seas.co2", \ +"brw_01C0_seas.co2", \ +"brw_01D0_seas.co2", \ +"bsc_01D0_seas.co2", \ +"car030_01D2_seas.co2", \ +"car040_01D2_seas.co2", \ +"car050_01D2_seas.co2", \ +"car060_01D2_seas.co2", \ +"car070_01D2_seas.co2", \ +"car080_01D2_seas.co2", \ +"cba_01D0_seas.co2", \ +"cba_04D0_seas.co2", \ +"cfa_02D0_seas.co2", \ +"cgo_01D0_seas.co2", \ +"cgo_02D0_seas.co2", \ +"cgo_04D0_seas.co2", \ +"chr_01D0_seas.co2", \ +"cmn_17C0_seas.co2", \ +"cmo_01D0_seas.co2", \ +"coi_20C0_seas.co2", \ +"cpt_36C0_seas.co2", \ +"cri_02D0_seas.co2", \ +"crz_01D0_seas.co2", \ +"csj_06D0_seas.co2", \ +"daa_02D0_seas.co2", \ +"eic_01D0_seas.co2", \ +"esp005_01D2_seas.co2", \ +"esp015_01D2_seas.co2", \ +"esp025_01D2_seas.co2", \ +"esp035_01D2_seas.co2", \ +"esp045_01D2_seas.co2", \ +"esp055_01D2_seas.co2", \ +"esp_02D0_seas.co2", \ +"esp_06D0_seas.co2", \ +"frd040_06C3_seas.co2", \ +"gmi_01D0_seas.co2", \ +"goz_01D0_seas.co2", \ +"gsn_24D0_seas.co2", \ +"haa005_01D2_seas.co2", \ +"haa015_01D2_seas.co2", \ +"haa025_01D2_seas.co2", \ +"haa035_01D2_seas.co2", \ +"haa045_01D2_seas.co2", \ +"haa055_01D2_seas.co2", \ +"haa065_01D2_seas.co2", \ +"haa075_01D2_seas.co2", \ +"hat_20C0_seas.co2", \ +"hba_01D0_seas.co2", \ +"hfm005_01D2_seas.co2", \ +"hfm015_01D2_seas.co2", \ +"hfm025_01D2_seas.co2", \ +"hfm035_01D2_seas.co2", \ +"hfm045_01D2_seas.co2", \ +"hfm055_01D2_seas.co2", \ +"hfm065_01D2_seas.co2", \ +"hfm075_01D2_seas.co2", \ +"hun010_35C3_seas.co2", \ +"hun048_35C3_seas.co2", \ +"hun082_35C3_seas.co2", \ +"hun115_35C3_seas.co2", \ +"hun_01D0_seas.co2", \ +"ice_01D0_seas.co2", \ +"itn051_01C3_seas.co2", \ +"itn123_01C3_seas.co2", \ +"itn496_01C3_seas.co2", \ +"itn_01D0_seas.co2", \ +"izo_01D0_seas.co2", \ +"izo_27C0_seas.co2", \ +"jbn_29C0_seas.co2", \ +"key_01D0_seas.co2", \ +"kum_01D0_seas.co2", \ +"kum_04D0_seas.co2", \ +"kzd_01D0_seas.co2", \ +"kzm_01D0_seas.co2", \ +"lef011_01C3_seas.co2", \ +"lef030_01C3_seas.co2", \ +"lef076_01C3_seas.co2", \ +"lef122_01C3_seas.co2", \ +"lef244_01C3_seas.co2", \ +"lef396_01C3_seas.co2", \ +"lef_01D0_seas.co2", \ +"ljo_04D0_seas.co2", \ +"lmp_28D0_seas.co2", \ +"maa_02D0_seas.co2", \ +"mbc_01D0_seas.co2", \ +"mhd_01D0_seas.co2", \ +"mhdcbc_11C0_seas.co2", \ +"mhdrbc_11C0_seas.co2", \ +"mid_01D0_seas.co2", \ +"mlo_01C0_seas.co2", \ +"mlo_01D0_seas.co2", \ +"mlo_02D0_seas.co2", \ +"mlo_04D0_seas.co2", \ +"mnm_19C0_seas.co2", \ +"mqa_02D0_seas.co2", \ +"nwr_01D0_seas.co2", \ +"obs023_06C3_seas.co2", \ +"opw_01D0_seas.co2", \ +"orl005_11D2_seas.co2", \ +"orl015_11D2_seas.co2", \ +"orl025_11D2_seas.co2", \ +"orl035_11D2_seas.co2", \ +"palcbc_30C0_seas.co2", \ +"palmbc_30C0_seas.co2", \ +"pdm_11D0_seas.co2", \ +"pfa015_01D2_seas.co2", \ +"pfa025_01D2_seas.co2", \ +"pfa035_01D2_seas.co2", \ +"pfa045_01D2_seas.co2", \ +"pfa055_01D2_seas.co2", \ +"pfa065_01D2_seas.co2", \ +"pfa075_01D2_seas.co2", \ +"poc000_01D1_seas.co2", \ +"pocn05_01D1_seas.co2", \ +"pocn10_01D1_seas.co2", \ +"pocn15_01D1_seas.co2", \ +"pocn20_01D1_seas.co2", \ +"pocn25_01D1_seas.co2", \ +"pocn30_01D1_seas.co2", \ +"pocn35_01D1_seas.co2", \ +"pocn40_01D1_seas.co2", \ +"pocn45_01D1_seas.co2", \ +"pocs05_01D1_seas.co2", \ +"pocs10_01D1_seas.co2", \ +"pocs15_01D1_seas.co2", \ +"pocs20_01D1_seas.co2", \ +"pocs25_01D1_seas.co2", \ +"pocs30_01D1_seas.co2", \ +"pocs35_01D1_seas.co2", \ +"prs_21C0_seas.co2", \ +"prs_21D0_seas.co2", \ +"psa_01D0_seas.co2", \ +"psa_04D0_seas.co2", \ +"rpb_01D0_seas.co2", \ +"rta005_01D2_seas.co2", \ +"rta015_01D2_seas.co2", \ +"rta025_01D2_seas.co2", \ +"rta035_01D2_seas.co2", \ +"rta045_01D2_seas.co2", \ +"ryo_19C0_seas.co2", \ +"sbl_06C0_seas.co2", \ +"sbl_06D0_seas.co2", \ +"sch_23C0_seas.co2", \ +"scsn03_01D1_seas.co2", \ +"scsn06_01D1_seas.co2", \ +"scsn09_01D1_seas.co2", \ +"scsn12_01D1_seas.co2", \ +"scsn15_01D1_seas.co2", \ +"scsn18_01D1_seas.co2", \ +"scsn21_01D1_seas.co2", \ +"sey_01D0_seas.co2", \ +"shm_01D0_seas.co2", \ +"sis_02D0_seas.co2", \ +"smo_01C0_seas.co2", \ +"smo_01D0_seas.co2", \ +"smo_04D0_seas.co2", \ +"spo_01C0_seas.co2", \ +"spo_01D0_seas.co2", \ +"spo_02D0_seas.co2", \ +"spo_04D0_seas.co2", \ +"stm_01D0_seas.co2", \ +"stmebc_01D0_seas.co2", \ +"stp_12D0_seas.co2", \ +"sum_01D0_seas.co2", \ +"syo_01D0_seas.co2", \ +"syo_09C0_seas.co2", \ +"tap_01D0_seas.co2", \ +"tdf_01D0_seas.co2", \ +"trm_11D0_seas.co2", \ +"uta_01D0_seas.co2", \ +"uum_01D0_seas.co2", \ +"wes_23C0_seas.co2", \ +"wis_01D0_seas.co2", \ +"wkt009_01C3_seas.co2", \ +"wkt030_01C3_seas.co2", \ +"wkt061_01C3_seas.co2", \ +"wkt122_01C3_seas.co2", \ +"wkt244_01C3_seas.co2", \ +"wkt457_01C3_seas.co2", \ +"wlg_01D0_seas.co2", \ +"wlg_33C0_seas.co2", \ +"wpo000_10D2_seas.co2", \ +"wpon05_10D2_seas.co2", \ +"wpon10_10D2_seas.co2", \ +"wpon15_10D2_seas.co2", \ +"wpon20_10D2_seas.co2", \ +"wpon25_10D2_seas.co2", \ +"wpon30_10D2_seas.co2", \ +"wpos05_10D2_seas.co2", \ +"wpos10_10D2_seas.co2", \ +"wpos15_10D2_seas.co2", \ +"wpos20_10D2_seas.co2", \ +"wpos25_10D2_seas.co2", \ +"yon_19C0_seas.co2", \ +"zep_01D0_seas.co2", \ +"zep_31C0_seas.co2", \ +"zot005_45D2_seas.co2", \ +"zot015_45D2_seas.co2", \ +"zot025_45D2_seas.co2", \ +"zot035_45D2_seas.co2"/) + +print (dimsizes(b)) +exit + do n = 0,dimsizes(b)-1 + print (b(n)) + end do + exit + ncol1 = 4 + data1 = readAsciiTable(diri+b(n), ncol1, "float", (/10,17/)) + print (data1) + + ncol2 = 5 + data2 = readAsciiTable(diri+b(n), ncol2, "float", 16) + print (data2) +; end do + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/04.test.read.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/04.test.read.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,270 @@ +;************************************************ +; Read ascii, Write nc +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +; final output +; diro = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" +; filo = "co2_globalView_222.nc" +; c = addfile(diro+filo,"c") + +; input ascii files + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/globalView-C4Mip/seas/" + b = (/ \ +"aia005_02D2_seas.co2", \ +"aia015_02D2_seas.co2", \ +"aia025_02D2_seas.co2", \ +"aia035_02D2_seas.co2", \ +"aia045_02D2_seas.co2", \ +"aia055_02D2_seas.co2", \ +"aia065_02D2_seas.co2", \ +"alt_01D0_seas.co2", \ +"alt_02D0_seas.co2", \ +"alt_04D0_seas.co2", \ +"alt_06C0_seas.co2", \ +"alt_06D0_seas.co2", \ +"ams_01D0_seas.co2", \ +"ams_11C0_seas.co2", \ +"asc_01D0_seas.co2", \ +"ask_01D0_seas.co2", \ +"avi_01D0_seas.co2", \ +"azr_01D0_seas.co2", \ +"bal_01D1_seas.co2", \ +"bgu_11D0_seas.co2", \ +"bhd_15C0_seas.co2", \ +"bme_01D0_seas.co2", \ +"bmw_01D0_seas.co2", \ +"brw_01C0_seas.co2", \ +"brw_01D0_seas.co2", \ +"bsc_01D0_seas.co2", \ +"car030_01D2_seas.co2", \ +"car040_01D2_seas.co2", \ +"car050_01D2_seas.co2", \ +"car060_01D2_seas.co2", \ +"car070_01D2_seas.co2", \ +"car080_01D2_seas.co2", \ +"cba_01D0_seas.co2", \ +"cba_04D0_seas.co2", \ +"cfa_02D0_seas.co2", \ +"cgo_01D0_seas.co2", \ +"cgo_02D0_seas.co2", \ +"cgo_04D0_seas.co2", \ +"chr_01D0_seas.co2", \ +"cmn_17C0_seas.co2", \ +"cmo_01D0_seas.co2", \ +"coi_20C0_seas.co2", \ +"cpt_36C0_seas.co2", \ +"cri_02D0_seas.co2", \ +"crz_01D0_seas.co2", \ +"csj_06D0_seas.co2", \ +"daa_02D0_seas.co2", \ +"eic_01D0_seas.co2", \ +"esp005_01D2_seas.co2", \ +"esp015_01D2_seas.co2", \ +"esp025_01D2_seas.co2", \ +"esp035_01D2_seas.co2", \ +"esp045_01D2_seas.co2", \ +"esp055_01D2_seas.co2", \ +"esp_02D0_seas.co2", \ +"esp_06D0_seas.co2", \ +"frd040_06C3_seas.co2", \ +"gmi_01D0_seas.co2", \ +"goz_01D0_seas.co2", \ +"gsn_24D0_seas.co2", \ +"haa005_01D2_seas.co2", \ +"haa015_01D2_seas.co2", \ +"haa025_01D2_seas.co2", \ +"haa035_01D2_seas.co2", \ +"haa045_01D2_seas.co2", \ +"haa055_01D2_seas.co2", \ +"haa065_01D2_seas.co2", \ +"haa075_01D2_seas.co2", \ +"hat_20C0_seas.co2", \ +"hba_01D0_seas.co2", \ +"hfm005_01D2_seas.co2", \ +"hfm015_01D2_seas.co2", \ +"hfm025_01D2_seas.co2", \ +"hfm035_01D2_seas.co2", \ +"hfm045_01D2_seas.co2", \ +"hfm055_01D2_seas.co2", \ +"hfm065_01D2_seas.co2", \ +"hfm075_01D2_seas.co2", \ +"hun010_35C3_seas.co2", \ +"hun048_35C3_seas.co2", \ +"hun082_35C3_seas.co2", \ +"hun115_35C3_seas.co2", \ +"hun_01D0_seas.co2", \ +"ice_01D0_seas.co2", \ +"itn051_01C3_seas.co2", \ +"itn123_01C3_seas.co2", \ +"itn496_01C3_seas.co2", \ +"itn_01D0_seas.co2", \ +"izo_01D0_seas.co2", \ +"izo_27C0_seas.co2", \ +"jbn_29C0_seas.co2", \ +"key_01D0_seas.co2", \ +"kum_01D0_seas.co2", \ +"kum_04D0_seas.co2", \ +"kzd_01D0_seas.co2", \ +"kzm_01D0_seas.co2", \ +"lef011_01C3_seas.co2", \ +"lef030_01C3_seas.co2", \ +"lef076_01C3_seas.co2", \ +"lef122_01C3_seas.co2", \ +"lef244_01C3_seas.co2", \ +"lef396_01C3_seas.co2", \ +"lef_01D0_seas.co2", \ +"ljo_04D0_seas.co2", \ +"lmp_28D0_seas.co2", \ +"maa_02D0_seas.co2", \ +"mbc_01D0_seas.co2", \ +"mhd_01D0_seas.co2", \ +"mhdcbc_11C0_seas.co2", \ +"mhdrbc_11C0_seas.co2", \ +"mid_01D0_seas.co2", \ +"mlo_01C0_seas.co2", \ +"mlo_01D0_seas.co2", \ +"mlo_02D0_seas.co2", \ +"mlo_04D0_seas.co2", \ +"mnm_19C0_seas.co2", \ +"mqa_02D0_seas.co2", \ +"nwr_01D0_seas.co2", \ +"obs023_06C3_seas.co2", \ +"opw_01D0_seas.co2", \ +"orl005_11D2_seas.co2", \ +"orl015_11D2_seas.co2", \ +"orl025_11D2_seas.co2", \ +"orl035_11D2_seas.co2", \ +"palcbc_30C0_seas.co2", \ +"palmbc_30C0_seas.co2", \ +"pdm_11D0_seas.co2", \ +"pfa015_01D2_seas.co2", \ +"pfa025_01D2_seas.co2", \ +"pfa035_01D2_seas.co2", \ +"pfa045_01D2_seas.co2", \ +"pfa055_01D2_seas.co2", \ +"pfa065_01D2_seas.co2", \ +"pfa075_01D2_seas.co2", \ +"poc000_01D1_seas.co2", \ +"pocn05_01D1_seas.co2", \ +"pocn10_01D1_seas.co2", \ +"pocn15_01D1_seas.co2", \ +"pocn20_01D1_seas.co2", \ +"pocn25_01D1_seas.co2", \ +"pocn30_01D1_seas.co2", \ +"pocn35_01D1_seas.co2", \ +"pocn40_01D1_seas.co2", \ +"pocn45_01D1_seas.co2", \ +"pocs05_01D1_seas.co2", \ +"pocs10_01D1_seas.co2", \ +"pocs15_01D1_seas.co2", \ +"pocs20_01D1_seas.co2", \ +"pocs25_01D1_seas.co2", \ +"pocs30_01D1_seas.co2", \ +"pocs35_01D1_seas.co2", \ +"prs_21C0_seas.co2", \ +"prs_21D0_seas.co2", \ +"psa_01D0_seas.co2", \ +"psa_04D0_seas.co2", \ +"rpb_01D0_seas.co2", \ +"rta005_01D2_seas.co2", \ +"rta015_01D2_seas.co2", \ +"rta025_01D2_seas.co2", \ +"rta035_01D2_seas.co2", \ +"rta045_01D2_seas.co2", \ +"ryo_19C0_seas.co2", \ +"sbl_06C0_seas.co2", \ +"sbl_06D0_seas.co2", \ +"sch_23C0_seas.co2", \ +"scsn03_01D1_seas.co2", \ +"scsn06_01D1_seas.co2", \ +"scsn09_01D1_seas.co2", \ +"scsn12_01D1_seas.co2", \ +"scsn15_01D1_seas.co2", \ +"scsn18_01D1_seas.co2", \ +"scsn21_01D1_seas.co2", \ +"sey_01D0_seas.co2", \ +"shm_01D0_seas.co2", \ +"sis_02D0_seas.co2", \ +"smo_01C0_seas.co2", \ +"smo_01D0_seas.co2", \ +"smo_04D0_seas.co2", \ +"spo_01C0_seas.co2", \ +"spo_01D0_seas.co2", \ +"spo_02D0_seas.co2", \ +"spo_04D0_seas.co2", \ +"stm_01D0_seas.co2", \ +"stmebc_01D0_seas.co2", \ +"stp_12D0_seas.co2", \ +"sum_01D0_seas.co2", \ +"syo_01D0_seas.co2", \ +"syo_09C0_seas.co2", \ +"tap_01D0_seas.co2", \ +"tdf_01D0_seas.co2", \ +"trm_11D0_seas.co2", \ +"uta_01D0_seas.co2", \ +"uum_01D0_seas.co2", \ +"wes_23C0_seas.co2", \ +"wis_01D0_seas.co2", \ +"wkt009_01C3_seas.co2", \ +"wkt030_01C3_seas.co2", \ +"wkt061_01C3_seas.co2", \ +"wkt122_01C3_seas.co2", \ +"wkt244_01C3_seas.co2", \ +"wkt457_01C3_seas.co2", \ +"wlg_01D0_seas.co2", \ +"wlg_33C0_seas.co2", \ +"wpo000_10D2_seas.co2", \ +"wpon05_10D2_seas.co2", \ +"wpon10_10D2_seas.co2", \ +"wpon15_10D2_seas.co2", \ +"wpon20_10D2_seas.co2", \ +"wpon25_10D2_seas.co2", \ +"wpon30_10D2_seas.co2", \ +"wpos05_10D2_seas.co2", \ +"wpos10_10D2_seas.co2", \ +"wpos15_10D2_seas.co2", \ +"wpos20_10D2_seas.co2", \ +"wpos25_10D2_seas.co2", \ +"yon_19C0_seas.co2", \ +"zep_01D0_seas.co2", \ +"zep_31C0_seas.co2", \ +"zot005_45D2_seas.co2", \ +"zot015_45D2_seas.co2", \ +"zot025_45D2_seas.co2", \ +"zot035_45D2_seas.co2"/) + + ntime = 12 + ncase = dimsizes(b) + print (ncase) + + mean = new((/ncase,ntime/),float) + lat = new((/ncase/),float) + lon = new((/ncase/),float) + elev = new((/ncase/),float) + + do n = 0,dimsizes(b)-1 + fili = diri + b(n) + print (fili) + + ncol1 = 4 + data1 = readAsciiTable(fili, ncol1, "float", (/10,17/)) + + lat(n) = data1(0,0) + lon(n) = data1(0,1) + elev(n) = data1(0,2) + + ncol2 = 5 + data2 = readAsciiTable(fili, ncol2, "float", 16) + + mean(n,:) = data2(:,1) + end do + + print (lat) + print (mean) + + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/05.read_ascci_122.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/05.read_ascci_122.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,195 @@ +;************************************************ +; Read ascii, Write nc +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +; final output + diro = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + filo = "co2_globalView_.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +; input ascii files + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/globalView-C4Mip/seas/" + b = (/ \ +"aia005_02D2_seas.co2", \ +"alt_01D0_seas.co2", \ +"alt_06C0_seas.co2", \ +"alt_06D0_seas.co2", \ +"ams_01D0_seas.co2", \ +"ams_11C0_seas.co2", \ +"asc_01D0_seas.co2", \ +"ask_01D0_seas.co2", \ +"avi_01D0_seas.co2", \ +"azr_01D0_seas.co2", \ +"bal_01D1_seas.co2", \ +"bgu_11D0_seas.co2", \ +"bhd_15C0_seas.co2", \ +"bme_01D0_seas.co2", \ +"bmw_01D0_seas.co2", \ +"brw_01C0_seas.co2", \ +"brw_01D0_seas.co2", \ +"bsc_01D0_seas.co2", \ +"car030_01D2_seas.co2", \ +"cba_01D0_seas.co2", \ +"cba_04D0_seas.co2", \ +"cfa_02D0_seas.co2", \ +"cgo_01D0_seas.co2", \ +"chr_01D0_seas.co2", \ +"cmn_17C0_seas.co2", \ +"cmo_01D0_seas.co2", \ +"coi_20C0_seas.co2", \ +"cpt_36C0_seas.co2", \ +"cri_02D0_seas.co2", \ +"crz_01D0_seas.co2", \ +"csj_06D0_seas.co2", \ +"daa_02D0_seas.co2", \ +"eic_01D0_seas.co2", \ +"esp005_01D2_seas.co2", \ +"esp_02D0_seas.co2", \ +"frd040_06C3_seas.co2", \ +"gmi_01D0_seas.co2", \ +"goz_01D0_seas.co2", \ +"gsn_24D0_seas.co2", \ +"haa005_01D2_seas.co2", \ +"hat_20C0_seas.co2", \ +"hba_01D0_seas.co2", \ +"hfm005_01D2_seas.co2", \ +"hun010_35C3_seas.co2", \ +"hun_01D0_seas.co2", \ +"ice_01D0_seas.co2", \ +"itn051_01C3_seas.co2", \ +"itn123_01C3_seas.co2", \ +"itn496_01C3_seas.co2", \ +"itn_01D0_seas.co2", \ +"izo_01D0_seas.co2", \ +"izo_27C0_seas.co2", \ +"jbn_29C0_seas.co2", \ +"key_01D0_seas.co2", \ +"kum_01D0_seas.co2", \ +"kzd_01D0_seas.co2", \ +"kzm_01D0_seas.co2", \ +"lef011_01C3_seas.co2", \ +"lef_01D0_seas.co2", \ +"ljo_04D0_seas.co2", \ +"lmp_28D0_seas.co2", \ +"maa_02D0_seas.co2", \ +"mbc_01D0_seas.co2", \ +"mhd_01D0_seas.co2", \ +"mhdcbc_11C0_seas.co2", \ +"mhdrbc_11C0_seas.co2", \ +"mid_01D0_seas.co2", \ +"mlo_01C0_seas.co2", \ +"mlo_01D0_seas.co2", \ +"mnm_19C0_seas.co2", \ +"mqa_02D0_seas.co2", \ +"nwr_01D0_seas.co2", \ +"obs023_06C3_seas.co2", \ +"opw_01D0_seas.co2", \ +"orl005_11D2_seas.co2", \ +"palcbc_30C0_seas.co2", \ +"palmbc_30C0_seas.co2", \ +"pdm_11D0_seas.co2", \ +"pfa015_01D2_seas.co2", \ +"poc000_01D1_seas.co2", \ +"pocn05_01D1_seas.co2", \ +"pocs05_01D1_seas.co2", \ +"prs_21C0_seas.co2", \ +"prs_21D0_seas.co2", \ +"psa_01D0_seas.co2", \ +"rpb_01D0_seas.co2", \ +"rta005_01D2_seas.co2", \ +"ryo_19C0_seas.co2", \ +"sbl_06C0_seas.co2", \ +"sbl_06D0_seas.co2", \ +"sch_23C0_seas.co2", \ +"scsn03_01D1_seas.co2", \ +"sey_01D0_seas.co2", \ +"shm_01D0_seas.co2", \ +"sis_02D0_seas.co2", \ +"smo_01C0_seas.co2", \ +"smo_01D0_seas.co2", \ +"spo_01C0_seas.co2", \ +"spo_01D0_seas.co2", \ +"stm_01D0_seas.co2", \ +"stmebc_01D0_seas.co2", \ +"stp_12D0_seas.co2", \ +"sum_01D0_seas.co2", \ +"syo_01D0_seas.co2", \ +"syo_09C0_seas.co2", \ +"tap_01D0_seas.co2", \ +"tdf_01D0_seas.co2", \ +"trm_11D0_seas.co2", \ +"uta_01D0_seas.co2", \ +"uum_01D0_seas.co2", \ +"wes_23C0_seas.co2", \ +"wis_01D0_seas.co2", \ +"wkt009_01C3_seas.co2", \ +"wlg_01D0_seas.co2", \ +"wlg_33C0_seas.co2", \ +"wpo000_10D2_seas.co2", \ +"wpon05_10D2_seas.co2", \ +"wpos05_10D2_seas.co2", \ +"yon_19C0_seas.co2", \ +"zep_01D0_seas.co2", \ +"zep_31C0_seas.co2", \ +"zot005_45D2_seas.co2"/) + + ntime = 12 + ncase = dimsizes(b) + print (ncase) + + mean = new((/ncase,ntime/),float) + lat = new((/ncase/),float) + lon = new((/ncase/),float) + elev = new((/ncase/),float) + + do n = 0,dimsizes(b)-1 + fili = diri + b(n) + print (fili) + + ncol1 = 4 + data1 = readAsciiTable(fili, ncol1, "float", (/10,17/)) + + lat(n) = data1(0,0) + lon(n) = data1(0,1) + elev(n) = data1(0,2) + + ncol2 = 5 + data2 = readAsciiTable(fili, ncol2, "float", 16) + + mean(n,:) = data2(:,1) + end do + +; mean!0 = "case" +; mean!1 = "time" +; mean&case= ispan(1,ncase,1) +; mean&time= ispan(1,ntime,1) + mean@units = "u mol/mol" + mean@long_name = "CO2 GlobalView seasonal" + +; lat!0 = "case" +; lon!0 = "case" +; elev!0 = "case" +; lat&case = mean&case +; lon&case = mean&case +; elev&case = mean&case + + lat@units = "degrees_north" + lat@long_name = "Latitude" + lon@units = "degrees_ease" + lon@long_name = "Longitude" + elev@units = "m" + elev@long_name = "Elevation above sea level" + + print (lat) + print (mean) + + c->LAT = lat + c->LON = lon + c->ELEV = elev + c->CO2_SEAS = mean +end diff -r 000000000000 -r 0c6405ab2ff4 co2/05.read_ascci_222.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/05.read_ascci_222.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,295 @@ +;************************************************ +; Read ascii, Write nc +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +; final output + diro = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + filo = "co2_globalView_222.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +; input ascii files + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/globalView-C4Mip/seas/" + b = (/ \ +"aia005_02D2_seas.co2", \ +"aia015_02D2_seas.co2", \ +"aia025_02D2_seas.co2", \ +"aia035_02D2_seas.co2", \ +"aia045_02D2_seas.co2", \ +"aia055_02D2_seas.co2", \ +"aia065_02D2_seas.co2", \ +"alt_01D0_seas.co2", \ +"alt_02D0_seas.co2", \ +"alt_04D0_seas.co2", \ +"alt_06C0_seas.co2", \ +"alt_06D0_seas.co2", \ +"ams_01D0_seas.co2", \ +"ams_11C0_seas.co2", \ +"asc_01D0_seas.co2", \ +"ask_01D0_seas.co2", \ +"avi_01D0_seas.co2", \ +"azr_01D0_seas.co2", \ +"bal_01D1_seas.co2", \ +"bgu_11D0_seas.co2", \ +"bhd_15C0_seas.co2", \ +"bme_01D0_seas.co2", \ +"bmw_01D0_seas.co2", \ +"brw_01C0_seas.co2", \ +"brw_01D0_seas.co2", \ +"bsc_01D0_seas.co2", \ +"car030_01D2_seas.co2", \ +"car040_01D2_seas.co2", \ +"car050_01D2_seas.co2", \ +"car060_01D2_seas.co2", \ +"car070_01D2_seas.co2", \ +"car080_01D2_seas.co2", \ +"cba_01D0_seas.co2", \ +"cba_04D0_seas.co2", \ +"cfa_02D0_seas.co2", \ +"cgo_01D0_seas.co2", \ +"cgo_02D0_seas.co2", \ +"cgo_04D0_seas.co2", \ +"chr_01D0_seas.co2", \ +"cmn_17C0_seas.co2", \ +"cmo_01D0_seas.co2", \ +"coi_20C0_seas.co2", \ +"cpt_36C0_seas.co2", \ +"cri_02D0_seas.co2", \ +"crz_01D0_seas.co2", \ +"csj_06D0_seas.co2", \ +"daa_02D0_seas.co2", \ +"eic_01D0_seas.co2", \ +"esp005_01D2_seas.co2", \ +"esp015_01D2_seas.co2", \ +"esp025_01D2_seas.co2", \ +"esp035_01D2_seas.co2", \ +"esp045_01D2_seas.co2", \ +"esp055_01D2_seas.co2", \ +"esp_02D0_seas.co2", \ +"esp_06D0_seas.co2", \ +"frd040_06C3_seas.co2", \ +"gmi_01D0_seas.co2", \ +"goz_01D0_seas.co2", \ +"gsn_24D0_seas.co2", \ +"haa005_01D2_seas.co2", \ +"haa015_01D2_seas.co2", \ +"haa025_01D2_seas.co2", \ +"haa035_01D2_seas.co2", \ +"haa045_01D2_seas.co2", \ +"haa055_01D2_seas.co2", \ +"haa065_01D2_seas.co2", \ +"haa075_01D2_seas.co2", \ +"hat_20C0_seas.co2", \ +"hba_01D0_seas.co2", \ +"hfm005_01D2_seas.co2", \ +"hfm015_01D2_seas.co2", \ +"hfm025_01D2_seas.co2", \ +"hfm035_01D2_seas.co2", \ +"hfm045_01D2_seas.co2", \ +"hfm055_01D2_seas.co2", \ +"hfm065_01D2_seas.co2", \ +"hfm075_01D2_seas.co2", \ +"hun010_35C3_seas.co2", \ +"hun048_35C3_seas.co2", \ +"hun082_35C3_seas.co2", \ +"hun115_35C3_seas.co2", \ +"hun_01D0_seas.co2", \ +"ice_01D0_seas.co2", \ +"itn051_01C3_seas.co2", \ +"itn123_01C3_seas.co2", \ +"itn496_01C3_seas.co2", \ +"itn_01D0_seas.co2", \ +"izo_01D0_seas.co2", \ +"izo_27C0_seas.co2", \ +"jbn_29C0_seas.co2", \ +"key_01D0_seas.co2", \ +"kum_01D0_seas.co2", \ +"kum_04D0_seas.co2", \ +"kzd_01D0_seas.co2", \ +"kzm_01D0_seas.co2", \ +"lef011_01C3_seas.co2", \ +"lef030_01C3_seas.co2", \ +"lef076_01C3_seas.co2", \ +"lef122_01C3_seas.co2", \ +"lef244_01C3_seas.co2", \ +"lef396_01C3_seas.co2", \ +"lef_01D0_seas.co2", \ +"ljo_04D0_seas.co2", \ +"lmp_28D0_seas.co2", \ +"maa_02D0_seas.co2", \ +"mbc_01D0_seas.co2", \ +"mhd_01D0_seas.co2", \ +"mhdcbc_11C0_seas.co2", \ +"mhdrbc_11C0_seas.co2", \ +"mid_01D0_seas.co2", \ +"mlo_01C0_seas.co2", \ +"mlo_01D0_seas.co2", \ +"mlo_02D0_seas.co2", \ +"mlo_04D0_seas.co2", \ +"mnm_19C0_seas.co2", \ +"mqa_02D0_seas.co2", \ +"nwr_01D0_seas.co2", \ +"obs023_06C3_seas.co2", \ +"opw_01D0_seas.co2", \ +"orl005_11D2_seas.co2", \ +"orl015_11D2_seas.co2", \ +"orl025_11D2_seas.co2", \ +"orl035_11D2_seas.co2", \ +"palcbc_30C0_seas.co2", \ +"palmbc_30C0_seas.co2", \ +"pdm_11D0_seas.co2", \ +"pfa015_01D2_seas.co2", \ +"pfa025_01D2_seas.co2", \ +"pfa035_01D2_seas.co2", \ +"pfa045_01D2_seas.co2", \ +"pfa055_01D2_seas.co2", \ +"pfa065_01D2_seas.co2", \ +"pfa075_01D2_seas.co2", \ +"poc000_01D1_seas.co2", \ +"pocn05_01D1_seas.co2", \ +"pocn10_01D1_seas.co2", \ +"pocn15_01D1_seas.co2", \ +"pocn20_01D1_seas.co2", \ +"pocn25_01D1_seas.co2", \ +"pocn30_01D1_seas.co2", \ +"pocn35_01D1_seas.co2", \ +"pocn40_01D1_seas.co2", \ +"pocn45_01D1_seas.co2", \ +"pocs05_01D1_seas.co2", \ +"pocs10_01D1_seas.co2", \ +"pocs15_01D1_seas.co2", \ +"pocs20_01D1_seas.co2", \ +"pocs25_01D1_seas.co2", \ +"pocs30_01D1_seas.co2", \ +"pocs35_01D1_seas.co2", \ +"prs_21C0_seas.co2", \ +"prs_21D0_seas.co2", \ +"psa_01D0_seas.co2", \ +"psa_04D0_seas.co2", \ +"rpb_01D0_seas.co2", \ +"rta005_01D2_seas.co2", \ +"rta015_01D2_seas.co2", \ +"rta025_01D2_seas.co2", \ +"rta035_01D2_seas.co2", \ +"rta045_01D2_seas.co2", \ +"ryo_19C0_seas.co2", \ +"sbl_06C0_seas.co2", \ +"sbl_06D0_seas.co2", \ +"sch_23C0_seas.co2", \ +"scsn03_01D1_seas.co2", \ +"scsn06_01D1_seas.co2", \ +"scsn09_01D1_seas.co2", \ +"scsn12_01D1_seas.co2", \ +"scsn15_01D1_seas.co2", \ +"scsn18_01D1_seas.co2", \ +"scsn21_01D1_seas.co2", \ +"sey_01D0_seas.co2", \ +"shm_01D0_seas.co2", \ +"sis_02D0_seas.co2", \ +"smo_01C0_seas.co2", \ +"smo_01D0_seas.co2", \ +"smo_04D0_seas.co2", \ +"spo_01C0_seas.co2", \ +"spo_01D0_seas.co2", \ +"spo_02D0_seas.co2", \ +"spo_04D0_seas.co2", \ +"stm_01D0_seas.co2", \ +"stmebc_01D0_seas.co2", \ +"stp_12D0_seas.co2", \ +"sum_01D0_seas.co2", \ +"syo_01D0_seas.co2", \ +"syo_09C0_seas.co2", \ +"tap_01D0_seas.co2", \ +"tdf_01D0_seas.co2", \ +"trm_11D0_seas.co2", \ +"uta_01D0_seas.co2", \ +"uum_01D0_seas.co2", \ +"wes_23C0_seas.co2", \ +"wis_01D0_seas.co2", \ +"wkt009_01C3_seas.co2", \ +"wkt030_01C3_seas.co2", \ +"wkt061_01C3_seas.co2", \ +"wkt122_01C3_seas.co2", \ +"wkt244_01C3_seas.co2", \ +"wkt457_01C3_seas.co2", \ +"wlg_01D0_seas.co2", \ +"wlg_33C0_seas.co2", \ +"wpo000_10D2_seas.co2", \ +"wpon05_10D2_seas.co2", \ +"wpon10_10D2_seas.co2", \ +"wpon15_10D2_seas.co2", \ +"wpon20_10D2_seas.co2", \ +"wpon25_10D2_seas.co2", \ +"wpon30_10D2_seas.co2", \ +"wpos05_10D2_seas.co2", \ +"wpos10_10D2_seas.co2", \ +"wpos15_10D2_seas.co2", \ +"wpos20_10D2_seas.co2", \ +"wpos25_10D2_seas.co2", \ +"yon_19C0_seas.co2", \ +"zep_01D0_seas.co2", \ +"zep_31C0_seas.co2", \ +"zot005_45D2_seas.co2", \ +"zot015_45D2_seas.co2", \ +"zot025_45D2_seas.co2", \ +"zot035_45D2_seas.co2"/) + + ntime = 12 + ncase = dimsizes(b) + print (ncase) + + mean = new((/ncase,ntime/),float) + lat = new((/ncase/),float) + lon = new((/ncase/),float) + elev = new((/ncase/),float) + + do n = 0,dimsizes(b)-1 + fili = diri + b(n) + print (fili) + + ncol1 = 4 + data1 = readAsciiTable(fili, ncol1, "float", (/10,17/)) + + lat(n) = data1(0,0) + lon(n) = data1(0,1) + elev(n) = data1(0,2) + + ncol2 = 5 + data2 = readAsciiTable(fili, ncol2, "float", 16) + + mean(n,:) = data2(:,1) + end do + +; mean!0 = "case" +; mean!1 = "time" +; mean&case= ispan(1,ncase,1) +; mean&time= ispan(1,ntime,1) + mean@units = "u mol/mol" + mean@long_name = "CO2 GlobalView seasonal" + +; lat!0 = "case" +; lon!0 = "case" +; elev!0 = "case" +; lat&case = mean&case +; lon&case = mean&case +; elev&case = mean&case + + lat@units = "degrees_north" + lat@long_name = "Latitude" + lon@units = "degrees_ease" + lon@long_name = "Longitude" + elev@units = "m" + elev@long_name = "Elevation above sea level" + + print (lat) + print (mean) + + c->LAT = lat + c->LON = lon + c->ELEV = elev + c->CO2_SEAS = mean +end diff -r 000000000000 -r 0c6405ab2ff4 co2/06.read_ascci_98.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/06.read_ascci_98.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,175 @@ +;************************************************ +; Read ascii, Write nc +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +; final output + diro = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + filo = "co2_globalView_98.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +; input ascii files + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/globalView-C4Mip/seas/" + b = (/ \ +"aia005_02D2", \ +"alt_01D0", \ +"ams_01D0", \ +"asc_01D0", \ +"ask_01D0", \ +"avi_01D0", \ +"azr_01D0", \ +"bal_01D1", \ +"bgu_11D0", \ +"bhd_15C0", \ +"bme_01D0", \ +"bmw_01D0", \ +"brw_01C0", \ +"bsc_01D0", \ +"car030_01D2", \ +"cba_01D0", \ +"cfa_02D0", \ +"cgo_01D0", \ +"chr_01D0", \ +"cmn_17C0", \ +"cmo_01D0", \ +"coi_20C0", \ +"cpt_36C0", \ +"cri_02D0", \ +"crz_01D0", \ +"csj_06D0", \ +"daa_02D0", \ +"eic_01D0", \ +"esp_02D0", \ +"frd040_06C3", \ +"gmi_01D0", \ +"goz_01D0", \ +"gsn_24D0", \ +"haa005_01D2", \ +"hat_20C0", \ +"hba_01D0", \ +"hfm005_01D2", \ +"hun010_35C3", \ +"ice_01D0", \ +"itn051_01C3", \ +"izo_01D0", \ +"jbn_29C0", \ +"key_01D0", \ +"kum_01D0", \ +"kzd_01D0", \ +"kzm_01D0", \ +"lef011_01C3", \ +"ljo_04D0", \ +"lmp_28D0", \ +"maa_02D0", \ +"mbc_01D0", \ +"mhd_01D0", \ +"mid_01D0", \ +"mlo_01C0", \ +"mnm_19C0", \ +"mqa_02D0", \ +"nwr_01D0", \ +"obs023_06C3", \ +"opw_01D0", \ +"orl005_11D2", \ +"palcbc_30C0", \ +"pdm_11D0", \ +"pfa015_01D2", \ +"poc000_01D1", \ +"pocn05_01D1", \ +"pocs05_01D1", \ +"prs_21C0", \ +"psa_01D0", \ +"rpb_01D0", \ +"rta005_01D2", \ +"ryo_19C0", \ +"sbl_06C0", \ +"sch_23C0", \ +"scsn03_01D1", \ +"sey_01D0", \ +"shm_01D0", \ +"sis_02D0", \ +"smo_01C0", \ +"spo_01C0", \ +"stm_01D0", \ +"stp_12D0", \ +"sum_01D0", \ +"syo_01D0", \ +"tap_01D0", \ +"tdf_01D0", \ +"trm_11D0", \ +"uta_01D0", \ +"uum_01D0", \ +"wes_23C0", \ +"wis_01D0", \ +"wkt009_01C3", \ +"wlg_01D0", \ +"wpo000_10D2", \ +"wpon05_10D2", \ +"wpos05_10D2", \ +"yon_19C0", \ +"zep_01D0", \ +"zot005_45D2"/) + + ntime = 12 + ncase = dimsizes(b) + print (ncase) + + mean = new((/ncase,ntime/),float) + lat = new((/ncase/),float) + lon = new((/ncase/),float) + elev = new((/ncase/),float) + + do n = 0,dimsizes(b)-1 + fili = diri + b(n) + "_seas.co2" + print (fili) + + ncol1 = 4 + data1 = readAsciiTable(fili, ncol1, "float", (/10,17/)) + + lat(n) = data1(0,0) + lon(n) = data1(0,1) + elev(n) = data1(0,2) + + ncol2 = 5 + data2 = readAsciiTable(fili, ncol2, "float", 16) + + mean(n,:) = data2(:,1) + end do + +; mean!0 = "case" +; mean!1 = "time" +; mean&case= ispan(1,ncase,1) +; mean&time= ispan(1,ntime,1) + mean@units = "u mol/mol" + mean@long_name = "CO2 GlobalView seasonal" + +; lat!0 = "case" +; lon!0 = "case" +; elev!0 = "case" +; lat&case = mean&case +; lon&case = mean&case +; elev&case = mean&case + + lat@units = "degrees_north" + lat@long_name = "Latitude" + lon@units = "degrees_ease" + lon@long_name = "Longitude" + elev@units = "m" + elev@long_name = "Elevation above sea level" + b@units = "" + b@long_name = "Station" + + print (lat) + print (mean) + print (b) + + c->LAT = lat + c->LON = lon + c->ELEV = elev + c->CO2_SEAS = mean + c->STATION = stringtochar(b) +end diff -r 000000000000 -r 0c6405ab2ff4 co2/11.test.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/11.test.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,44 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_222.nc" + g = addfile (diri+fili,"r") + a = g->CO2_SEAS + lon = g->LON + lat = g->LAT + + ncase = dimsizes(lat) + print (ncase) + + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) + print (indexes) + + lat_new = lat(indexes) + lon_new = lon(indexes) + print (lat_new +"/"+lon_new) + +exit + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/12.test.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/12.test.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,104 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_222.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + delete (g) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "b30.061m_401_425_MONS_climo.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = val_ob + val_model = yo(pts|:,time|:) + printVarSummary (val_model) + print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) + print (min(val_model)+"/"+max(val_model)) +exit +;************************************************************** +; get stations of 60N-90N +;************************************************************** + + ind_1 = ind(lat_new .gt. 60.) + print (ind_1) + print (lat_new(ind_1)+"/"+lon_new(ind_1)) + print (val_new(ind_1(0),:)) +exit + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/13.metric.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/13.metric.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,191 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_222.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + delete (g) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "b30.061m_401_425_MONS_climo.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = val_ob + val_model = yo(pts|:,time|:) +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + nzone = 4 + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + u = ndtooned(val_ob(ind_z,:)) + v = ndtooned(val_model(ind_z,:)) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + + uu = u(good) + vv = v(good) + + npts = dimsizes(uu)/12 + print (npts) + + ccr = esccr(uu,vv,0) + print (ccr) + + un = onedtond(uu,(/npts,12/)) + vn = onedtond(vv,(/npts,12/)) +;print (un) +;print (vn) + + score = new((/npts/),float) + + do n=0,npts-1 + amp_ob = max(un(n,:)) - min(un(n,:)) + amp_model = max(vn(n,:)) - min(vn(n,:)) + score(n) = 1.-abs((amp_model/amp_ob)-1.) +; print (amp_ob) +; print (amp_model) + end do +;print (score) + + M = avg(score) + print (M) + + M_total = (ccr*ccr + M)*0.5 * score_max + print (M_total) + + delete (ind_z) + delete (good) + delete (u) + delete (v) + delete (uu) + delete (vv) + delete (un) + delete (vn) + delete (score) + end do +end diff -r 000000000000 -r 0c6405ab2ff4 co2/14.metric.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/14.metric.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,197 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "b30.061m_401_425_MONS_climo.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = val_ob + val_model = yo(pts|:,time|:) +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + nzone = 4 + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + u = ndtooned(val_ob(ind_z,:)) + v = ndtooned(val_model(ind_z,:)) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + + uu = u(good) + vv = v(good) + st = sta(ind_z) + + npts = dimsizes(st) + print (npts) + + ccr = esccr(uu,vv,0) +;print (ccr) + + un = onedtond(uu,(/npts,12/)) + vn = onedtond(vv,(/npts,12/)) +;print (un) +;print (vn) + + score = new((/npts/),float) + + do n=0,npts-1 + amp_ob = max(un(n,:)) - min(un(n,:)) + amp_model = max(vn(n,:)) - min(vn(n,:)) + score(n) = 1.-abs((amp_model/amp_ob)-1.) +; print (amp_ob) +; print (amp_model) + end do +;print (score) + + M = avg(score) + print (M) + + M_total = (ccr*ccr + M)*0.5 * score_max + print (M_total) + + delete (ind_z) + delete (good) + delete (u) + delete (v) + delete (uu) + delete (vv) + delete (un) + delete (vn) + delete (st) + delete (score) + end do +end diff -r 000000000000 -r 0c6405ab2ff4 co2/15.metric.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/15.metric.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,191 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +; fili2 = "b30.061m_401_425_MONS_climo.nc" + fili2 = "b30.061n_1995-2004_MONS_climo.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + nzone = 4 + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) + + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) + + do n=0,npts-1 + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + + print (sta(ind_z(n))+"/"+lat(ind_z(n))+"/"+lon(ind_z(n))+"/"+amp_ratio_sta(n)+"/"+ccr_sta(n)+"/"+M_sta(n)+"/"+score_sta(n)) + end do + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone) + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + end do +end diff -r 000000000000 -r 0c6405ab2ff4 co2/16.metric_plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/16.metric_plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,241 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +load "/fis/cgd/cseg/people/jeff/clamp/co2/taylor_metrics_table.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +; fili2 = "b30.061m_401_425_MONS_climo_atm.nc" + fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + nzone = 1 + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) + + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) + + do n=0,npts-1 + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + + print (sta(ind_z(n))+"/"+lat(ind_z(n))+"/"+lon(ind_z(n))+"/"+amp_ratio_sta(n)+"/"+ccr_sta(n)+"/"+M_sta(n)+"/"+score_sta(n)) + end do + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone) +;**************************************************************************** +; Cases [Model] + case = (/ "Lat", "Lon", "AR" /) + nCase = dimsizes(case ) ; # of Cases [Cases] + +; variables compared + var = sta(ind_z) + nVar = dimsizes(var) ; # of Variables + +; "Case A" + CA_ratio = (/lat(ind_z)/) + +; "Case B" + CB_ratio = (/lon(ind_z)/) + +; "Case C" + CC_ratio = (/amp_ratio_sta/) + + +; arrays to be passed to taylor_diagram. It will calculate the x xnd y coordinates. + ratio = new ((/nCase, nVar/),typeof(CA_ratio) ) + + ratio(0,:) = CA_ratio + ratio(1,:) = CB_ratio + ratio(2,:) = CC_ratio + +;************************************************** +; fill an array for a "taylor metrics table" +;************************************************** + +; season = (/ "ANN" /) +; nSeason = dimsizes(season) + season = (/ "" /) + nSeason = dimsizes(season) + + table = new ( (/nCase,nSeason,nVar/), typeof(ratio) ) + table(0,0,:) = CA_ratio + table(1,0,:) = CB_ratio + table(2,0,:) = CC_ratio + + tt_opt = True + tt_opt@pltType= "ps" ; "eps" [default], "pdf", "ps" + ; "png", "gif" [if you have ImageMajik 'convert'] + + tt_opt@tableTitle = "Station in 60N_90N" + + varSource =var + + taylor_metrics_table("metrics", varSource, case ,season, table, tt_opt) + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + end do +end diff -r 000000000000 -r 0c6405ab2ff4 co2/17.metric_plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/17.metric_plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,241 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +; fili2 = "b30.061m_401_425_MONS_climo_atm.nc" + fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + nzone = 1 + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) + + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) + + do n=0,npts-1 + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + + print (sta(ind_z(n))+"/"+lat(ind_z(n))+"/"+lon(ind_z(n))+"/"+amp_ratio_sta(n)+"/"+ccr_sta(n)+"/"+M_sta(n)+"/"+score_sta(n)) + end do + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone) +;**************************************************************************** +; Cases [Model] + case = (/ "Lat", "Lon", "AR" /) + nCase = dimsizes(case ) ; # of Cases [Cases] + +; variables compared + var = sta(ind_z) + nVar = dimsizes(var) ; # of Variables + +; "Case A" + CA_ratio = (/lat(ind_z)/) + +; "Case B" + CB_ratio = (/lon(ind_z)/) + +; "Case C" + CC_ratio = (/amp_ratio_sta/) + + +; arrays to be passed to taylor_diagram. It will calculate the x xnd y coordinates. + ratio = new ((/nCase, nVar/),typeof(CA_ratio) ) + + ratio(0,:) = CA_ratio + ratio(1,:) = CB_ratio + ratio(2,:) = CC_ratio + +;************************************************** +; fill an array for a "taylor metrics table" +;************************************************** + +; season = (/ "ANN" /) +; nSeason = dimsizes(season) + season = (/ "" /) + nSeason = dimsizes(season) + + table = new ( (/nCase,nVar/), typeof(ratio) ) + table(0,:) = CA_ratio + table(1,:) = CB_ratio + table(2,:) = CC_ratio + + tt_opt = True + tt_opt@pltType= "ps" ; "eps" [default], "pdf", "ps" + ; "png", "gif" [if you have ImageMajik 'convert'] + + tt_opt@tableTitle = "Station in 60N_90N" + + varSource =var + + metrics_table("metrics", varSource, case , table, tt_opt) + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + end do +end diff -r 000000000000 -r 0c6405ab2ff4 co2/18.metric_plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/18.metric_plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,230 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +; fili2 = "b30.061m_401_425_MONS_climo_atm.nc" + fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + nzone = 4 + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + zone = "60N-90N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + zone = "30N-60N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + zone = "EQ-30N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + zone = "90S-EQ" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) + + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) + + do n=0,npts-1 + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + + print (sta(ind_z(n))+"/"+lat(ind_z(n))+"/"+lon(ind_z(n))+"/"+amp_ratio_sta(n)+"/"+ccr_sta(n)+"/"+M_sta(n)+"/"+score_sta(n)) + end do + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone) +;**************************************************************************** +; Cases [Model] + case = (/"Latitude","Longitude","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + nCase = dimsizes(case ) ; # of Cases [Cases] + +; variables compared + var = sta(ind_z) + nVar = dimsizes(var) ; # of Variables + +; arrays to be passed to diagram. It will calculate the x xnd y coordinates. + case_value = new ((/nCase, nVar/),float ) + + case_value(0,:) = (/lat(ind_z)/) + case_value(1,:) = (/lon(ind_z)/) + case_value(2,:) = (/amp_ratio_sta/) + case_value(3,:) = (/ccr_sta/) + case_value(4,:) = (/M_sta/) + case_value(5,:) = (/score_sta/) + +;************************************************** +; fill an array for a "metrics table" +;************************************************** + + tt_opt = True + tt_opt@pltType= "ps" ; "eps" [default], "pdf", "ps" + ; "png", "gif" [if you have ImageMajik 'convert'] + + tt_opt@tableTitle = "Zone "+ zone + plot_name = "co2." + zone + + metrics_table(plot_name, var, case , case_value, tt_opt) + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + delete (var) + delete (case_value) + end do +end diff -r 000000000000 -r 0c6405ab2ff4 co2/19.metric_plot.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/19.metric_plot.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,268 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +; fili2 = "b30.061m_401_425_MONS_climo_atm.nc" + fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + nzone = 4 + +; column + case_zone = (/"Stations","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + nCase_zone = dimsizes(case_zone ) + +; row + var_zone = (/"60N-90N","30N-60N","EQ-30N","90S-EQ","Total"/) + nVar_zone = dimsizes(var_zone) + +; arrays to be passed to diagram. + case_value_zone = new ((/nCase_zone, nVar_zone/),float ) + + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + zone = "60N-90N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + zone = "30N-60N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + zone = "EQ-30N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + zone = "90S-EQ" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) + + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) + + do n=0,npts-1 + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + + print (sta(ind_z(n))+"/"+lat(ind_z(n))+"/"+lon(ind_z(n))+"/"+amp_ratio_sta(n)+"/"+ccr_sta(n)+"/"+M_sta(n)+"/"+score_sta(n)) + end do + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone) + + case_value_zone(0,z) = npts + case_value_zone(1,z) = (/amp_ratio_zone/) + case_value_zone(2,z) = (/ccr_zone/) + case_value_zone(3,z) = (/M_zone/) + case_value_zone(4,z) = (/score_zone/) +;************************************************** +; plot station table +;************************************************** +; column for station table + case_sta = (/"Latitude","Longitude","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + nCase_sta = dimsizes(case_sta ) + +; row for station table + var_sta = sta(ind_z) + nVar_sta = dimsizes(var_sta) + +; arrays to be passed to diagram. + case_value_sta = new ((/nCase_sta, nVar_sta/),float ) + + case_value_sta(0,:) = (/lat(ind_z)/) + case_value_sta(1,:) = (/lon(ind_z)/) + case_value_sta(2,:) = (/amp_ratio_sta/) + case_value_sta(3,:) = (/ccr_sta/) + case_value_sta(4,:) = (/M_sta/) + case_value_sta(5,:) = (/score_sta/) + +;************************************************** +; plot station table +;************************************************** + tt_opt = True + tt_opt@pltType= "png" ; "eps" [default], "pdf", "ps" + ; "png", "gif" [if you have ImageMajik 'convert'] + + tt_opt@tableTitle = "Zone "+ zone + plot_name = "table_sta." + zone + + metrics_table(plot_name, var_sta, case_sta , case_value_sta, tt_opt) + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + delete (var_sta) + delete (case_value_sta) + end do +;************************************************** +; plot zone table +;************************************************** + case_value_zone(0,4) = case_value_zone(0,0)+case_value_zone(0,1)+case_value_zone(0,2)+case_value_zone(0,3) + case_value_zone(1,4) = 0. + case_value_zone(2,4) = 0. + case_value_zone(3,4) = 0. + case_value_zone(4,4) = case_value_zone(4,0)+case_value_zone(4,1)+case_value_zone(4,2)+case_value_zone(4,3) + + tt_opt = True + tt_opt@pltType= "png" ; "eps" [default], "pdf", "ps" + ; "png", "gif" [if you have ImageMajik 'convert'] + + tt_opt@tableTitle = "Zone" + plot_name = "table_zone" + + metrics_table(plot_name, var_zone, case_zone , case_value_zone, tt_opt) + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/21.lines.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/21.lines.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,215 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "b30.061m_401_425_MONS_climo.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + plot_sta = new((/2,12/),float) + plot_sta@long_name = "Seasonal CO2" + + mon = ispan(1,12,1) + mon@long_name = "month" + + plot_type = "ps" + plot_type_new = "png" + + res = True ; plot mods desired + res@xyLineThicknesses = (/1.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; change line color + +;------------------------------------------------------------------ +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed","model_b30.061m"/) +;------------------------------------------------------------------- + + nzone = 4 + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) + + do n=0,npts-1 + + plot_sta(0,:) = (/val_ob(ind_z(n),:)/) + plot_sta(1,:) = (/val_model(ind_z(n),:)/) + + title = sta(ind_z(n))+"("+lat(ind_z(n))+","+lon(ind_z(n))+")" + plot_name = sta(ind_z(n)) + +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res@tiMainString = title ; add title + + plot = gsn_csm_xy (wks,mon,plot_sta,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + clear (wks) + end do + + delete (ind_z) + + end do +end diff -r 000000000000 -r 0c6405ab2ff4 co2/22.lines.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/22.lines.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,247 @@ +; *********************************************** +; add zone plot to 21.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "b30.061m_401_425_MONS_climo.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + plot_sta = new((/2,12/),float) + plot_sta@long_name = "Seasonal CO2" + + mon = ispan(1,12,1) + mon@long_name = "month" + + plot_type = "ps" + plot_type_new = "png" + + res = True ; plot mods desired + res@xyLineThicknesses = (/1.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; change line color + +;------------------------------------------------------------------ +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed","model_b30.061m"/) +;------------------------------------------------------------------- + + nzone = 4 + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + score_max = 5.0 + zone = "60N-90N" +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + score_max = 5.0 + zone = "30N-60N" +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + score_max = 5.0 + zone = "EQ-30N" +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + score_max = 5.0 + zone = "90S-EQ" +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) + + npts_str = "" + npts_str = npts +;print (npts_str) + + plot_zon = new((/2,12,npts/),float) + + do n=0,npts-1 + plot_zon(0,:,n) = (/val_ob(ind_z(n),:)/) + plot_zon(1,:,n) = (/val_model(ind_z(n),:)/) + +; plot_sta(0,:) = (/val_ob(ind_z(n),:)/) +; plot_sta(1,:) = (/val_model(ind_z(n),:)/) + +; title = sta(ind_z(n))+"("+lat(ind_z(n))+","+lon(ind_z(n))+")" +; plot_name = sta(ind_z(n)) + +; print (title) +; print (plot_name) + +; wks = gsn_open_wks (plot_type,plot_name) ; open workstation +; res@tiMainString = title ; add title + +; plot = gsn_csm_xy (wks,mon,plot_sta,res) ; create plot +; frame(wks) + +; system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) +; clear (wks) + end do + + plot_sta = dim_avg(plot_zon) + + plot_name = "All_"+npts_str + title = plot_name + " in "+ zone + + print (title) + print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res@tiMainString = title ; add title + + plot = gsn_csm_xy (wks,mon,plot_sta,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + clear (wks) + delete (ind_z) + delete (plot_zon) + + end do +end diff -r 000000000000 -r 0c6405ab2ff4 co2/23.lines.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/23.lines.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,288 @@ +; *********************************************** +; add panel plot to 22.lines.ncl +; add zone plot to 21.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +; fili2 = "b30.061m_401_425_MONS_climo.nc" + fili2 = "b30.061n_1995-2004_MONS_climo.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) + val_model_0 = val_model +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + mon = ispan(1,12,1) + mon@long_name = "month" + + plot_type = "ps" + plot_type_new = "png" + + res = True ; plot mods desired + res@xyLineThicknesses = (/1.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"red","blue"/) ; change line color + +;------------------------------------------------------------------ +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 +; res@xyExplicitLegendLabels = (/"model_b30.061m","observed"/) + res@xyExplicitLegendLabels = (/"model_b30.061n","observed"/) +;------------------------------------------------------------------- + + nzone = 4 + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + score_max = 5.0 + zone = "60N-90N" +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + score_max = 5.0 + zone = "30N-60N" +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + score_max = 5.0 + zone = "EQ-30N" +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + score_max = 5.0 + zone = "90S-EQ" +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) + + npts_str = "" + npts_str = npts +; print (npts_str) + + plot_data = new((/2,12,npts/),float) + plot_data_0 = new((/12,npts/),float) + + plot_data!0 = "case" + plot_data!1 = "month" + plot_data!2 = "pts" + plot_data@long_name = "CO2 Seasonal" + + plot_data_0!0 = "month" + plot_data_0!1 = "pts" + plot_data_0@long_name = "CO2" + + do n=0,npts-1 + + plot_data(1,:,n) = (/val_ob(ind_z(n),:)/) + plot_data(0,:,n) = (/val_model(ind_z(n),:)/) + plot_data_0(:,n) = (/val_model_0(ind_z(n),:)/) + + title1 = sta(ind_z(n))+"("+lat(ind_z(n))+","+lon(ind_z(n))+")" + plot_name = sta(ind_z(n)) + +; print (title1) +; print (plot_name) +;*********************************************** +; create panel plot +;*********************************************** + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + res@tiMainString = title1 ; add title + plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1 + +; title2 = "Model b30.061m" + title2 = "Model b30.061n" + res@tiMainString = title2 ; add title + plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,n),res) ; create plot 2 + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + clear (wks) + end do + +; plot zone average + + plot_name = "All_"+npts_str + title = plot_name + " in "+ zone + + print (title) + print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + res@tiMainString = title ; add title + plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1 + +; title2 = "Model b30.061m" + title2 = "Model b30.061n" + res@tiMainString = title2 + plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2 + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + delete (ind_z) + delete (plot_data) + delete (plot_data_0) + end do +end diff -r 000000000000 -r 0c6405ab2ff4 co2/24.check.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/24.check.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,143 @@ +; *********************************************** +; add another model to plot +; add panel plot to 22.lines.ncl +; add zone plot to 21.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc" + fili3 = "b30.061m_401_425_MONS_climo_atm.nc" +;-------------------------------------------- + g = addfile(diri2+fili2,"r") + x1 = g->CO2 + xi = g->lon + yi = g->lat + delete (g) + + xdim = dimsizes(x1) + nlev = xdim(1) +; y1 = x1(:,0,:,:) + y1 = x1 +; printVarSummary (y1) + +; get the co2 at the lowest level +; y1 = x1(:,nlev-1,:,:) + delete (x1) +;--------------------------------------------- +; g = addfile(diri2+fili3,"r") +; x2 = g->CO2 +; delete (g) +; y2 = x2(:,0,:,:) +; y2 = x2(:,nlev-1,:,:) +; delete (x2) +;--------------------------------------------- +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 +;--------------------------------------------- + y1 = y1 * factor + y1@_FillValue = 1.e36 + y1@units = "u mol/mol" +; y1 = where(y0 .lt. 287.,y1@_FillValue,y1) +; printVarSummary (y1) +; print (min(y1)+"/"+max(y1)) +;--------------------------------------------- +; y2 = y2 * factor +; y2@_FillValue = 1.e36 +; y2@units = "u mol/mol" +;--------------------------------------------- +; interpolate into observed station +; note: model is 0-360E, 90S-90N +; ob is -180-180, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) +; print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. +;---------------------------------------------------------------- + yo = linint2_points_Wrap(xi,yi,y1,True,lon_ob,lat_ob,0) + printVarSummary (yo) +; yo:[time | 12] x [lev | 26] x [pts | 98] + + val_model1 = yo(pts|:,lev|:,time|:) + delete (yo) + val_model1_0 = val_model1 +; printVarSummary (val_model1) +; print (min(val_model1)+"/"+max(val_model1)) + +; remove annual mean + val_model1 = val_model1 - conform(val_model1,dim_avg(val_model1),(/0,1/)) +; print (min(val_model1)+"/"+max(val_model1)) + +;----------------------------------------------------------------- +; index of station Barrow, Alaska (71.32,-156.60) + ind_z = ind(lat_ob .eq. 71.32) + print (ind_z) + print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) + print ("observation at Barrow, Alaska (71.32,-156.60)") + print (val_ob(ind_z,:)) + print ("model top atm at Barrow, Alaska (71.32,-156.60)") + print (val_model1_0(ind_z,0,:)) + print ("model surface at Barrow, Alaska (71.32,-156.60)") + print (val_model1_0(ind_z,nlev-1,:)) + print ("model top atm at Barrow, Alaska (71.32,-156.60)") + print (val_model1(ind_z,0,:)) + print ("model surface at Barrow, Alaska (71.32,-156.60)") + print (val_model1(ind_z,nlev-1,:)) +end diff -r 000000000000 -r 0c6405ab2ff4 co2/24.lines.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/24.lines.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,319 @@ +; *********************************************** +; add another model to plot +; add panel plot to 22.lines.ncl +; add zone plot to 21.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc" + fili3 = "b30.061m_401_425_MONS_climo_atm.nc" +;-------------------------------------------- + g = addfile(diri2+fili2,"r") + x1 = g->CO2 + xi = g->lon + yi = g->lat + delete (g) + + xdim = dimsizes(x1) + nlev = xdim(1) + y1 = x1(:,0,:,:) +; printVarSummary (y1) + +; get the co2 at the lowest level + y1 = x1(:,nlev-1,:,:) + delete (x1) +;--------------------------------------------- + g = addfile(diri2+fili3,"r") + x2 = g->CO2 + delete (g) + y2 = x2(:,0,:,:) + y2 = x2(:,nlev-1,:,:) + delete (x2) +;--------------------------------------------- +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 +;--------------------------------------------- + y1 = y1 * factor + y1@_FillValue = 1.e36 + y1@units = "u mol/mol" +; y1 = where(y0 .lt. 287.,1y@_FillValue,y1) +; printVarSummary (y1) +; print (min(y1)+"/"+max(y1)) +;--------------------------------------------- + y2 = y2 * factor + y2@_FillValue = 1.e36 + y2@units = "u mol/mol" +;--------------------------------------------- +; interpolate into observed station +; note: model is 0-360E, 90S-90N +; ob is -180-180, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. +;---------------------------------------------------------------- + yo = linint2_points_Wrap(xi,yi,y1,True,lon_ob,lat_ob,0) + + val_model1 = yo(pts|:,time|:) + val_model1_0 = val_model1 +; printVarSummary (val_model1) +; print (min(val_model1)+"/"+max(val_model1)) + +; remove annual mean + val_model1 = val_model1 - conform(val_model1,dim_avg(val_model1),0) +; print (min(val_model1)+"/"+max(val_model1)) + delete (yo) +;----------------------------------------------------------------- + yo = linint2_points_Wrap(xi,yi,y2,True,lon_ob,lat_ob,0) + + val_model2 = yo(pts|:,time|:) + val_model2_0 = val_model2 +; printVarSummary (val_model2) +; print (min(val_model2)+"/"+max(val_model2)) + +; remove annual mean + val_model2 = val_model2 - conform(val_model2,dim_avg(val_model2),0) +; print (min(val_model2)+"/"+max(val_model2)) + delete (yo) +;----------------------------------------------------------------- +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" +;----------------------------------------------------------------- + plot_type = "ps" + plot_type_new = "png" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"red","blue","black"/) ; change line color +;------------------------------------------------------------------ +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"b30.061n","b30.061m","observed"/) +;------------------------------------------------------------------- + + nzone = 4 + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + score_max = 5.0 + zone = "60N-90N" +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + score_max = 5.0 + zone = "30N-60N" +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + score_max = 5.0 + zone = "EQ-30N" +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + score_max = 5.0 + zone = "90S-EQ" +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) + + npts_str = "" + npts_str = npts +; print (npts_str) + + plot_data = new((/3,12,npts/),float) + plot_data_0 = new((/2,12,npts/),float) + + plot_data!0 = "case" + plot_data!1 = "month" + plot_data!2 = "pts" + plot_data@long_name = "CO2 Seasonal" + + plot_data_0!0 = "month" + plot_data_0!1 = "pts" + plot_data_0@long_name = "CO2" + + do n=0,npts-1 + + plot_data(0,:,n) = (/val_model1(ind_z(n),:)/) + plot_data(1,:,n) = (/val_model2(ind_z(n),:)/) + plot_data(2,:,n) = (/val_ob(ind_z(n),:)/) + + plot_data_0(0,:,n) = (/val_model1_0(ind_z(n),:)/) + plot_data_0(1,:,n) = (/val_model2_0(ind_z(n),:)/) + +;***************************************************** +; create plot with 3 lines for each observed station +;***************************************************** + plot_name = sta(ind_z(n)) + title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")" +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;--------------------------------------------------------------------------- +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;--------------------------------------------------------------------------- + res@tiMainString = title ; add title + + plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1 + +; plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,:,n),res) ; create plot 2 + plot(1)=gsn_csm_xy(wks,mon,plot_data_0(0,:,n),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + clear (wks) + end do +;***************************************************************************** +; plot zone average +;***************************************************************************** + plot_name = "All_"+npts_str + title = plot_name + " in "+ zone +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;--------------------------------------------------------------------------- +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;--------------------------------------------------------------------------- + res@tiMainString = title ; add title + + plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1 + +; plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2 + + xx = dim_avg_Wrap(plot_data_0) + plot(1) = gsn_csm_xy (wks,mon,xx(0,:),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + clear (wks) + delete (ind_z) + delete (plot_data) + delete (plot_data_0) + end do +end diff -r 000000000000 -r 0c6405ab2ff4 co2/31.contour_model.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/31.contour_model.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,61 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read in model data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili = "b30.061m_401_425_ANN_climo.nc" + + g = addfile(diri+fili,"r") + x = g->CO2 + xdim = dimsizes(x) + nlev = xdim(1) + y0 = x(0,0,:,:) + +; get the co2 at the lowest level + y0 = x(0,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y0 = y0 * factor + + y0@_FillValue = 1.e36 + y0@units = "u mol/mol" +; y0 = where(y0 .lt. 287.,y0@_FillValue,y0) + print (min(y0)+"/"+max(y0)) + +;************************************************ +; create default plot +;************************************************ + + wks = gsn_open_wks("ps","xy") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@tiMainString = "Model b30.061m 401-425" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 286. ; Min level + res@cnMaxLevelValF = 310. ; Max level + res@cnLevelSpacingF = 2. ; interval + + plot = gsn_csm_contour_map_ce(wks,y0,res) ; for model + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 co2/41.metric+lines.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/41.metric+lines.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,396 @@ +; *********************************************** +; combine 19.metric_plot.ncl and 24.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +; fili2 = "b30.061m_401_425_MONS_climo_atm.nc" + fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) + val_model_0 = val_model +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + nzone = 4 +;-------------------------------------------------------------- +; for metric table plots +; column + case_zone = (/"Stations","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + nCase_zone = dimsizes(case_zone ) + +; row + var_zone = (/"60N-90N","30N-60N","EQ-30N","90S-EQ","Total"/) + nVar_zone = dimsizes(var_zone) + +; arrays to be passed to diagram. + case_value_zone = new ((/nCase_zone, nVar_zone/),float ) +;-------------------------------------------------------------- +; for station line plot + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + plot_type = "ps" + plot_type_new = "png" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"red","black"/) ; change line color + +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"b30.061n","observed"/) +;------------------------------------------------------------------- + + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + zone = "60N-90N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + zone = "30N-60N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + zone = "EQ-30N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + zone = "90S-EQ" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) +;------------------------------------------------------------------------- +; for metric table plot + + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) +;------------------------------------------------------------------------- +; for station line plot + + npts_str = "" + npts_str = npts +; print (npts_str) + + plot_data = new((/2,12,npts/),float) + plot_data_0 = new((/12,npts/),float) + + plot_data!0 = "case" + plot_data!1 = "month" + plot_data!2 = "pts" + plot_data@long_name = "CO2 Seasonal" + + plot_data_0!0 = "month" + plot_data_0!1 = "pts" + plot_data_0@long_name = "CO2" +;-------------------------------------------------------------------------- + do n=0,npts-1 + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + + print (sta(ind_z(n))+"/"+lat(ind_z(n))+"/"+lon(ind_z(n))+"/"+amp_ratio_sta(n)+"/"+ccr_sta(n)+"/"+M_sta(n)+"/"+score_sta(n)) +;---------------------------------------------------------------------- +; for station line plot + + plot_data(0,:,n) = (/val_model(ind_z(n),:)/) + plot_data(1,:,n) = (/val_ob(ind_z(n),:)/) + + plot_data_0(:,n) = (/val_model_0(ind_z(n),:)/) + + plot_name = sta(ind_z(n)) + title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")" +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;------------------------------------------ +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------ + res@tiMainString = title ; add title + + plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1 + + plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,n),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + clear (wks) +;--------------------------------------------------------------------------- + end do +;------------------------------------------------------------------------- +; fo line plot in a zone + + plot_name = "All_"+npts_str + title = plot_name + " in "+ zone +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;----------------------------------------- +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;----------------------------------------- + res@tiMainString = title ; add title + + plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1 + + plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + clear (wks) +; delete (ind_z) + delete (plot_data) + delete (plot_data_0) +;--------------------------------------------------------------------------- +;--------------------------------------------------------------------------- +; metric table in a zone + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone) + + case_value_zone(0,z) = npts + case_value_zone(1,z) = (/amp_ratio_zone/) + case_value_zone(2,z) = (/ccr_zone/) + case_value_zone(3,z) = (/M_zone/) + case_value_zone(4,z) = (/score_zone/) + +; column for station table + case_sta = (/"Latitude","Longitude","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + nCase_sta = dimsizes(case_sta ) + +; row for station table + var_sta = sta(ind_z) + nVar_sta = dimsizes(var_sta) + +; arrays to be passed to diagram. + case_value_sta = new ((/nCase_sta, nVar_sta/),float ) + + case_value_sta(0,:) = (/lat(ind_z)/) + case_value_sta(1,:) = (/lon(ind_z)/) + case_value_sta(2,:) = (/amp_ratio_sta/) + case_value_sta(3,:) = (/ccr_sta/) + case_value_sta(4,:) = (/M_sta/) + case_value_sta(5,:) = (/score_sta/) + +;************************************************** +; plot station table +;************************************************** + tt_opt = True + tt_opt@pltType= "png" ; "eps" [default], "pdf", "ps" + ; "png", "gif" [if you have ImageMajik 'convert'] + + tt_opt@tableTitle = "Zone "+ zone + plot_name = "table_sta." + zone + + metrics_table(plot_name, var_sta, case_sta , case_value_sta, tt_opt) + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + delete (var_sta) + delete (case_value_sta) + end do +;************************************************** +; plot zone table +;************************************************** + case_value_zone(0,4) = case_value_zone(0,0)+case_value_zone(0,1)+case_value_zone(0,2)+case_value_zone(0,3) + case_value_zone(1,4) = 0. + case_value_zone(2,4) = 0. + case_value_zone(3,4) = 0. + case_value_zone(4,4) = case_value_zone(4,0)+case_value_zone(4,1)+case_value_zone(4,2)+case_value_zone(4,3) + + tt_opt = True + tt_opt@pltType= "png" ; "eps" [default], "pdf", "ps" + ; "png", "gif" [if you have ImageMajik 'convert'] + + tt_opt@tableTitle = "Zone" + plot_name = "table_zone" + + metrics_table(plot_name, var_zone, case_zone , case_value_zone, tt_opt) + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/42.metric+lines.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/42.metric+lines.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,514 @@ +; *********************************************** +; combine 19.metric_plot.ncl and 24.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +; fili2 = "b30.061m_401_425_MONS_climo_atm.nc" + fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) + val_model_0 = val_model +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + nzone = 4 + +;******************************************************************* +; for table -- zone +;******************************************************************* +; table header name + table_header_name = "Zone" + +; column (not including header column) + col_header_zone = (/"Stations","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + ncol_zone = dimsizes(col_header_zone ) + +; row (not including header row) + row_header_zone = (/"60N-90N","30N-60N","EQ-30N","90S-EQ","Total"/) + nrow_zone = dimsizes(row_header_zone) + +; arrays to be passed to table. + value_zone = new ((/nrow_zone, ncol_zone/),string ) +;-------------------------------------------------------------------- + + table_length_zone = 0.4 + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.995/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol_zone/) ; 1 rows, 5 columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header_zone + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow_zone,1/) ; 5 rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length_zone,0.900/) ; end at start of y1 + text3 = row_header_zone + res3 = True + res3@txFontHeightF = 0.02 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow_zone,ncol_zone/) ; 5 rows, 5 columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow_zone,ncol_zone/),string) + + color_fill4 = new((/nrow_zone,ncol_zone/),string) + color_fill4 = "white" + color_fill4(:,ncol_zone-1) = "grey" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.02 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +;******************************************************************* +; for table -- station +;******************************************************************* +; table header name + table_header_name = "Zone" + +; column (not including header column) + col_header_zone = (/"Stations","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + ncol_zone = dimsizes(col_header_zone ) + +; row (not including header row) + row_header_zone = (/"60N-90N","30N-60N","EQ-30N","90S-EQ","Total"/) + nrow_zone = dimsizes(row_header_zone) + +; arrays to be passed to table. + value_zone = new ((/nrow_zone, ncol_zone/),string ) +;------------------------------------------------------------------- + + table_length_zone = 0.4 + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.995/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol_zone/) ; 1 rows, 5 columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header_zone + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow_zone,1/) ; 5 rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length_zone,0.900/) ; end at start of y1 + text3 = row_header_zone + res3 = True + res3@txFontHeightF = 0.02 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow_zone,ncol_zone/) ; 5 rows, 5 columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow_zone,ncol_zone/),string) + + color_fill4 = new((/nrow_zone,ncol_zone/),string) + color_fill4 = "white" + color_fill4(:,ncol_zone-1) = "grey" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.02 + res4@gsFillColor = color_fill4 + + delete (color_fill4) +;-------------------------------------------------------------- +; for station line plot + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + plot_type = "ps" + plot_type_new = "png" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"red","black"/) ; change line color + +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"b30.061n","observed"/) +;------------------------------------------------------------------- + + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + zone = "60N-90N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + zone = "30N-60N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + zone = "EQ-30N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + zone = "90S-EQ" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) +;------------------------------------------------------------------------- +; for metric table + + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) +;------------------------------------------------------------------------- +; for station line plot + + npts_str = "" + npts_str = npts +; print (npts_str) + + plot_data = new((/2,12,npts/),float) + plot_data_0 = new((/12,npts/),float) + + plot_data!0 = "case" + plot_data!1 = "month" + plot_data!2 = "pts" + plot_data@long_name = "CO2 Seasonal" + + plot_data_0!0 = "month" + plot_data_0!1 = "pts" + plot_data_0@long_name = "CO2" +;-------------------------------------------------------------------------- + do n=0,npts-1 + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + + print (sta(ind_z(n))+"/"+lat(ind_z(n))+"/"+lon(ind_z(n))+"/"+amp_ratio_sta(n)+"/"+ccr_sta(n)+"/"+M_sta(n)+"/"+score_sta(n)) +;---------------------------------------------------------------------- +; for station line plot + + plot_data(0,:,n) = (/val_model(ind_z(n),:)/) + plot_data(1,:,n) = (/val_ob(ind_z(n),:)/) + + plot_data_0(:,n) = (/val_model_0(ind_z(n),:)/) + + plot_name = sta(ind_z(n)) + title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")" +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;------------------------------------------ +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------ + res@tiMainString = title ; add title + + plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1 + + plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,n),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + clear (wks) +;--------------------------------------------------------------------------- + end do +;------------------------------------------------------------------------- +; for line plot in a zone + + plot_name = "All_"+npts_str + title = plot_name + " in "+ zone +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;----------------------------------------- +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;----------------------------------------- + res@tiMainString = title ; add title + + plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1 + + plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + clear (wks) +; delete (ind_z) + delete (plot_data) + delete (plot_data_0) +;--------------------------------------------------------------------------- +; for zone table + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone) + + text4(z,0) = sprintf("%5.2f", npts) + text4(z,1) = sprintf("%5.2f", amp_ratio_zone) + text4(z,2) = sprintf("%5.2f", ccr_zone) + text4(z,3) = sprintf("%5.2f", M_zone) + text4(z,4) = sprintf("%5.2f", score_zone) +;--------------------------------------------------------------------------- +; column for station table + case_sta = (/"Latitude","Longitude","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + nCase_sta = dimsizes(case_sta ) + +; row for station table + var_sta = sta(ind_z) + nVar_sta = dimsizes(var_sta) + +; arrays to be passed to diagram. + case_value_sta = new ((/nCase_sta, nVar_sta/),float ) + + case_value_sta(0,:) = (/lat(ind_z)/) + case_value_sta(1,:) = (/lon(ind_z)/) + case_value_sta(2,:) = (/amp_ratio_sta/) + case_value_sta(3,:) = (/ccr_sta/) + case_value_sta(4,:) = (/M_sta/) + case_value_sta(5,:) = (/score_sta/) + +;************************************************** +; plot station table +;************************************************** + tt_opt = True + tt_opt@pltType= "png" ; "eps" [default], "pdf", "ps" + ; "png", "gif" [if you have ImageMajik 'convert'] + + tt_opt@tableTitle = "Zone "+ zone + plot_name = "table_sta." + zone + +; metrics_table(plot_name, var_sta, case_sta , case_value_sta, tt_opt) + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + delete (var_sta) + delete (case_value_sta) + end do +;************************************************** +; plot zone table +;************************************************** + + text4(4,0) = sum(stringtofloat(text4(0:3,0))) + text4(4,1) = 0. + text4(4,2) = 0. + text4(4,3) = 0. + text4(4,4) = sum(stringtofloat(text4(0:3,4))) + + plot_name = "table_zone" + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/42.metric+lines.ncl.0 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/42.metric+lines.ncl.0 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,448 @@ +; *********************************************** +; combine 19.metric_plot.ncl and 24.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +; fili2 = "b30.061m_401_425_MONS_climo_atm.nc" + fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) + val_model_0 = val_model +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + nzone = 4 +;-------------------------------------------------------------- +; for zone table +;********************************** +; table header name + table_header_name = "Zone" + +; column (not including header column) + col_header_zone = (/"Stations","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + ncol_zone = dimsizes(col_header_zone ) + +; row (not including header row) + row_header_zone = (/"60N-90N","30N-60N","EQ-30N","90S-EQ","Total"/) + nrow_zone = dimsizes(row_header_zone) + +; arrays to be passed to table. + value_zone = new ((/nrow_zone, ncol_zone/),string ) +;********************************** + + table_length_zone = 0.4 + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.995/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol_zone/) ; 1 rows, 5 columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header_zone + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow_zone,1/) ; 5 rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length_zone,0.900/) ; end at start of y1 + text3 = row_header_zone + res3 = True + res3@txFontHeightF = 0.02 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow_zone,ncol_zone/) ; 5 rows, 5 columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow_zone,ncol_zone/),string) + + color_fill4 = new((/nrow_zone,ncol_zone/),string) + color_fill4 = "white" + color_fill4(:,ncol_zone-1) = "grey" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.02 + res4@gsFillColor = color_fill4 + + delete (color_fill4) +;-------------------------------------------------------------- +; for station line plot + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + plot_type = "ps" + plot_type_new = "png" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"red","black"/) ; change line color + +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"b30.061n","observed"/) +;------------------------------------------------------------------- + + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + zone = "60N-90N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + zone = "30N-60N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + zone = "EQ-30N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + zone = "90S-EQ" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) +;------------------------------------------------------------------------- +; for metric table + + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) +;------------------------------------------------------------------------- +; for station line plot + + npts_str = "" + npts_str = npts +; print (npts_str) + + plot_data = new((/2,12,npts/),float) + plot_data_0 = new((/12,npts/),float) + + plot_data!0 = "case" + plot_data!1 = "month" + plot_data!2 = "pts" + plot_data@long_name = "CO2 Seasonal" + + plot_data_0!0 = "month" + plot_data_0!1 = "pts" + plot_data_0@long_name = "CO2" +;-------------------------------------------------------------------------- + do n=0,npts-1 + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + + print (sta(ind_z(n))+"/"+lat(ind_z(n))+"/"+lon(ind_z(n))+"/"+amp_ratio_sta(n)+"/"+ccr_sta(n)+"/"+M_sta(n)+"/"+score_sta(n)) +;---------------------------------------------------------------------- +; for station line plot + + plot_data(0,:,n) = (/val_model(ind_z(n),:)/) + plot_data(1,:,n) = (/val_ob(ind_z(n),:)/) + + plot_data_0(:,n) = (/val_model_0(ind_z(n),:)/) + + plot_name = sta(ind_z(n)) + title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")" +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;------------------------------------------ +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------ + res@tiMainString = title ; add title + + plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1 + + plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,n),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + clear (wks) +;--------------------------------------------------------------------------- + end do +;------------------------------------------------------------------------- +; for line plot in a zone + + plot_name = "All_"+npts_str + title = plot_name + " in "+ zone +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;----------------------------------------- +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;----------------------------------------- + res@tiMainString = title ; add title + + plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1 + + plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + clear (wks) +; delete (ind_z) + delete (plot_data) + delete (plot_data_0) +;--------------------------------------------------------------------------- +; for zone table + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone) + + text4(z,0) = sprintf("%5.2f", npts) + text4(z,1) = sprintf("%5.2f", amp_ratio_zone) + text4(z,2) = sprintf("%5.2f", ccr_zone) + text4(z,3) = sprintf("%5.2f", M_zone) + text4(z,4) = sprintf("%5.2f", score_zone) +;--------------------------------------------------------------------------- +; column for station table + case_sta = (/"Latitude","Longitude","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + nCase_sta = dimsizes(case_sta ) + +; row for station table + var_sta = sta(ind_z) + nVar_sta = dimsizes(var_sta) + +; arrays to be passed to diagram. + case_value_sta = new ((/nCase_sta, nVar_sta/),float ) + + case_value_sta(0,:) = (/lat(ind_z)/) + case_value_sta(1,:) = (/lon(ind_z)/) + case_value_sta(2,:) = (/amp_ratio_sta/) + case_value_sta(3,:) = (/ccr_sta/) + case_value_sta(4,:) = (/M_sta/) + case_value_sta(5,:) = (/score_sta/) + +;************************************************** +; plot station table +;************************************************** + tt_opt = True + tt_opt@pltType= "png" ; "eps" [default], "pdf", "ps" + ; "png", "gif" [if you have ImageMajik 'convert'] + + tt_opt@tableTitle = "Zone "+ zone + plot_name = "table_sta." + zone + +; metrics_table(plot_name, var_sta, case_sta , case_value_sta, tt_opt) + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + delete (var_sta) + delete (case_value_sta) + end do +;************************************************** +; plot zone table +;************************************************** + + text4(4,0) = sum(stringtofloat(text4(0:3,0))) + text4(4,1) = 0. + text4(4,2) = 0. + text4(4,3) = 0. + text4(4,4) = sum(stringtofloat(text4(0:3,4))) + + plot_name = "table_zone" + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/42.test.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/42.test.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,93 @@ +; *********************************************** +; combine 19.metric_plot.ncl and 24.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin + + plot_type ="ps" + plot_name = "table_zone" + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;-------------------------------------------------------------- +; for zone table + +;********************************** +; table header name + table_header_name = "Zone" + +; column (not including header column) + col_header_zone = (/"Stations","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + ncol_zone = dimsizes(col_header_zone ) + +; row (not including header row) + row_header_zone = (/"60N-90N","30N-60N","EQ-30N","90S-EQ","Total"/) + nrow_zone = dimsizes(row_header_zone) + +; arrays to be passed to table. + value_zone = new ((/nrow_zone, ncol_zone/),string ) +;********************************** + + table_length_zone = 0.4 + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.995/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol_zone/) ; 1 rows, 5 columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header_zone + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow_zone,1/) ; 5 rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length_zone,0.900/) ; end at start of y1 + text3 = row_header_zone + res3 = True + res3@txFontHeightF = 0.02 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow_zone,ncol_zone/) ; 5 rows, 5 columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow_zone,ncol_zone/),string) + + color_fill4 = new((/nrow_zone,ncol_zone/),string) + color_fill4 = "white" + color_fill4(:,ncol_zone-1) = "grey" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.02 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +;************************************************** +; plot zone table +;************************************************** + + text4 = sprintf("%5.2f", 0.9999 ) + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/43.metric+lines.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/43.metric+lines.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,553 @@ +; *********************************************** +; using gsn_table for all +; combine 19.metric_plot.ncl and 24.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +; fili2 = "b30.061m_401_425_MONS_climo_atm.nc" + fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +; interpolate into observed station +; note: model is 0-360E, 90S-90N + +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) + val_model_0 = val_model +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + nzone = 4 + +;******************************************************************* +; for table -- zone +;******************************************************************* +; table header name + table_header_name = "Zone" + +; column (not including header column) + col_header_zone = (/"Stations","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + ncol_zone = dimsizes(col_header_zone ) + +; row (not including header row) + row_header_zone = (/"60N-90N","30N-60N","EQ-30N","90S-EQ","Total"/) + nrow_zone = dimsizes(row_header_zone) + +; arrays to be passed to table. + value_zone = new ((/nrow_zone, ncol_zone/),string ) +;-------------------------------------------------------------------- + + table_length_zone = 0.4 + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.995/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol_zone/) ; 1 rows, 5 columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header_zone + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow_zone,1/) ; 5 rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length_zone,0.900/) ; end at start of y1 + text3 = row_header_zone + res3 = True + res3@txFontHeightF = 0.02 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow_zone,ncol_zone/) ; 5 rows, 5 columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow_zone,ncol_zone/),string) + + color_fill4 = new((/nrow_zone,ncol_zone/),string) + color_fill4 = "white" + color_fill4(:,ncol_zone-1) = "grey" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.02 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +;******************************************************************* +; for table -- station +;******************************************************************* +; column (not including header column) + col_header_sta = (/"Latitude","Longitude","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + ncol_sta = dimsizes(col_header_sta ) +;------------------------------------------------------------------- + +; Table header + ncr5 = (/1,1/) ; 1 row, 1 column + x5 = (/0.005,0.15/) ; Start and end X + y5 = (/0.900,0.995/) ; Start and end Y + res5 = True + res5@txFontHeightF = 0.02 + res5@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr6 = (/1,ncol_sta/) ; 1 rows, 5 columns + x6 = (/x5(1),0.995/) ; start from end of x1 + y6 = y5 ; same as y1 + text6 = col_header_sta + res6 = True + res6@txFontHeightF = 0.012 + res6@gsFillColor = "Gray" + +; Row header (equally space in y2) + + res7 = True + res7@txFontHeightF = 0.015 + res7@gsFillColor = "Gray" +;-------------------------------------------------------------- +; for station line plot + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + plot_type = "ps" + plot_type_new = "png" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"red","black"/) ; change line color + +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"b30.061n","observed"/) +;------------------------------------------------------------------- + + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + zone = "60N-90N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + zone = "30N-60N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + zone = "EQ-30N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + zone = "90S-EQ" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) +;------------------------------------------------------------------------- +; for metric table computation + + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) + +;---------------------- +; for table -- station +;---------------------- + +; row (not including header row) + nrow_sta = npts + +; Table header + ncr5 = (/1,1/) ; 1 row, 1 column + x5 = (/0.005,0.15/) ; Start and end X + y5 = (/0.900,0.995/) ; Start and end Y + res5 = True + res5@txFontHeightF = 0.02 + res5@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr6 = (/1,ncol_sta/) ; 1 rows, 5 columns + x6 = (/x1(1),0.995/) ; start from end of x1 + y6 = y1 ; same as y1 + text6 = col_header_sta + res6 = True + res6@txFontHeightF = 0.012 + res6@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr7 = (/nrow_sta,1/) ; 5 rows, 1 columns + x7 = x1 ; same as x1 +; y7 = (/1.0-table_length_sta,0.900/) ; end at start of y1 + text7 = new((/nrow_sta/),string) + res7 = True + res7@txFontHeightF = 0.015 + res7@gsFillColor = "Gray" +;------------------------------------------------------------------------- +; for station line plot + + npts_str = "" + npts_str = npts +; print (npts_str) + + plot_data = new((/2,12,npts/),float) + plot_data_0 = new((/12,npts/),float) + + plot_data!0 = "case" + plot_data!1 = "month" + plot_data!2 = "pts" + plot_data@long_name = "CO2 Seasonal" + + plot_data_0!0 = "month" + plot_data_0!1 = "pts" + plot_data_0@long_name = "CO2" +;-------------------------------------------------------------------------- + do n=0,npts-1 + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + + print (sta(ind_z(n))+"/"+lat(ind_z(n))+"/"+lon(ind_z(n))+"/"+amp_ratio_sta(n)+"/"+ccr_sta(n)+"/"+M_sta(n)+"/"+score_sta(n)) +;---------------------------------------------------------------------- +; for station line plot + + plot_data(0,:,n) = (/val_model(ind_z(n),:)/) + plot_data(1,:,n) = (/val_ob(ind_z(n),:)/) + + plot_data_0(:,n) = (/val_model_0(ind_z(n),:)/) + + plot_name = sta(ind_z(n)) + title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")" +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;------------------------------------------ +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------ + res@tiMainString = title ; add title + + plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1 + + plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,n),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + clear (wks) +;--------------------------------------------------------------------------- + end do +;------------------------------------------------------------------------- +; for line plot in a zone + + plot_name = "All_"+npts_str + title = plot_name + " in "+ zone +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;----------------------------------------- +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;----------------------------------------- + res@tiMainString = title ; add title + + plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1 + + plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + clear (wks) +; delete (ind_z) + delete (plot_data) + delete (plot_data_0) +;--------------------------------------------------------------------------- +; for zone table value + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone) + + text4(z,0) = sprintf("%5.2f", npts) + text4(z,1) = sprintf("%5.2f", amp_ratio_zone) + text4(z,2) = sprintf("%5.2f", ccr_zone) + text4(z,3) = sprintf("%5.2f", M_zone) + text4(z,4) = sprintf("%5.2f", score_zone) +;--------------------------------------------------------------------------- +; plot station table +;---------------------------------- +; header value for station table + text5 = zone + +; row value for station table + text7 = sta(ind_z) + + if (z .eq. 0) then + table_length_sta = 0.5 + end if + if (z .eq. 1) then + table_length_sta = 0.995 + end if + if (z .eq. 2) then + table_length_sta = 0.8 + end if + if (z .eq. 3) then + table_length_sta = 0.8 + end if + + x7 = x5 + y7 = (/1.0-table_length_sta,0.900/) ; end at start of y1 + +; Main table body + ncr8 = (/nrow_sta,ncol_sta/) ; 5 rows, 5 columns + x8 = x6 ; Start and end x + y8 = y7 ; Start and end Y + text8 = new((/nrow_sta,ncol_sta/),string) + + color_fill8 = text8 + color_fill8 = "white" + color_fill8(:,ncol_sta-1) = "grey" + + res8 = True ; Set up resource list + res8@gsnDebug = True ; Useful to print NDC row,col values used. + res8@txFontHeightF = 0.02 + res8@gsFillColor = color_fill8 + + delete (color_fill8) + +; table value for station table + text8(:,0) = sprintf("%5.2f", (/lat(ind_z)/)) + text8(:,1) = sprintf("%5.2f", (/lon(ind_z)/)) + text8(:,2) = sprintf("%5.2f", (/amp_ratio_sta/)) + text8(:,3) = sprintf("%5.2f", (/ccr_sta/)) + text8(:,4) = sprintf("%5.2f", (/M_sta/)) + text8(:,5) = sprintf("%5.2f", (/score_sta/)) + + plot_name = "table_sta." + zone + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + gsn_table(wks,ncr5,x5,y5,text5,res5) + gsn_table(wks,ncr6,x6,y6,text6,res6) + gsn_table(wks,ncr7,x7,y7,text7,res7) + gsn_table(wks,ncr8,x8,y8,text8,res8) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + delete (text7) + delete (text8) + delete (res7) + delete (res8) + clear (wks) + end do +;************************************************** +; plot zone table +;************************************************** + + text4(4,0) = sum(stringtofloat(text4(0:3,0))) + text4(4,1) = 0. + text4(4,2) = 0. + text4(4,3) = 0. + text4(4,4) = sum(stringtofloat(text4(0:3,4))) + + plot_name = "table_zone" + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/99.all.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/99.all.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,532 @@ +; *********************************************** +; using gsn_table for all +; combine 19.metric_plot.ncl and 24.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;**************************************************************************** + +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ + +; from command line inputs + +;-------------------------------------------------- +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + +; the following only needs to execute once +; system("sed 1,/model_nameA/s//"+model_name+"/ "+html_name2+" > "+html_new2+";"+ \ +; "mv -f "+html_new2+" "+html_name2+";"+ \ +; "sed 1,/model_nameB/s//"+model_name+"/ "+html_name2+" > "+html_new2+";"+ \ +; "mv -f "+html_new2+" "+html_name2+";"+ \ +; "sed s#"+modeln+"#"+model_name+"# "+html_name2+" > "+html_new2+";"+ \ +; "mv -f "+html_new2+" "+html_name2) + end if + +;------------------------------------- +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +; the following only needs to execute once +; system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new+";"+ \ +; "mv -f "+html_new+" "+html_name) +;------------------------------------------------ + fm = addfile(dirm+film3,"r") + + x = fm->CO2 + xi = fm->lon + yi = fm->lat + + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) + +; get co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +;************************************************ +; read data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/ob/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + + ncase = dimsizes(lat) +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ +; to be able to handle observation at (-89.98,-24.80) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) + val_model_0 = val_model +;************************************************************ +; remove annual mean +;************************************************************ + val_model = val_model - conform(val_model,dim_avg(val_model),0) + +;******************************************************************* +; res for station line plot +;******************************************************************* +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"red","black"/) ; change line color + +; Add a boxed legend using the more simple method + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/model_name,"observed"/) +;************************************************************ +; number of latitude zone +;************************************************************ + nzone = 4 + +; saving data for zone +; number of rows for zone table (with data) + nrow_zone = nzone + +; number of columns for zone table + ncol_zone = 6 + + text4 = new((/nrow_zone,ncol_zone/),string) + +do z = 0,nzone-1 + + if (z .eq. 0) then + zone = "60N-90N" + score_max = 5.0 + ind_z = ind(lat_ob .ge. 60.) + end if + + if (z .eq. 1) then + zone = "30N-60N" + score_max = 5.0 + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) + end if + + if (z .eq. 2) then + zone = "EQ-30N" + score_max = 5.0 + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) + end if + + if (z .eq. 3) then + zone = "90S-EQ" + score_max = 5.0 + ind_z = ind(lat_ob .lt. 0. ) + end if + + npts = dimsizes(ind_z) + +;------------------------------------------------------ +; for metric table computation + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) +;----------------------------------------------------- +; for station line plot + npts_str = "" + npts_str = npts + + plot_data = new((/2,12,npts/),float) + plot_data_0 = new((/12,npts/),float) + + plot_data!0 = "case" + plot_data!1 = "month" + plot_data!2 = "pts" + plot_data@long_name = "CO2 Seasonal" + + plot_data_0!0 = "month" + plot_data_0!1 = "pts" + plot_data_0@long_name = "CO2" +;-------------------------------------------------------------------------- + do n=0,npts-1 + + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + +;---------------------------------------------------------------------- +; for station line plot + + plot_data(0,:,n) = (/val_model(ind_z(n),:)/) + plot_data(1,:,n) = (/val_ob(ind_z(n),:)/) + + plot_data_0(:,n) = (/val_model_0(ind_z(n),:)/) + + plot_name = sta(ind_z(n)) + title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;------------------------------------------ +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------ + res@tiMainString = title ; add title + + plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1 + + plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,n),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + clear (wks) +;--------------------------------------------------------------------------- + end do +;------------------------------------------------------------------------- +; for line plot in a zone + + plot_name = "All_"+npts_str + title = plot_name + " in "+ zone + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;----------------------------------------- +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;----------------------------------------- + res@tiMainString = title ; add title + + plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1 + + plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + clear (wks) +; delete (ind_z) + delete (plot_data) + delete (plot_data_0) +;--------------------------------------------------------------------------- +; values saved for zone table + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + text4(z,0) = zone + text4(z,1) = sprintf("%.0f", npts) + text4(z,2) = sprintf("%.2f", amp_ratio_zone) + text4(z,3) = sprintf("%.2f", ccr_zone) + text4(z,4) = sprintf("%.2f", M_zone) + text4(z,5) = sprintf("%.2f", score_zone) + +;******************************************************************* +; html table -- station +;******************************************************************* + output_html = "score+line_"+zone+".html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

CO2 in Zone "+zone+": Model "+model_name+"

" \ + /) + footer = "" + + table_header = (/ \ + "
Name of
Station
Latitude Longitude Amplitude
Ratio
Correlation
Coefficient
M
Score
Combined
Score
" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeAmplitude RatioCorreleration CoefM ScoreCombined Score
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,npts-1 + set_line(lines,nline,row_header) + + txt0 = sta(ind_z(n)) + txt1 = sprintf("%5.2f", (/lat(ind_z(n))/)) + txt2 = sprintf("%5.2f", (/lon(ind_z(n))/)) + txt3 = sprintf("%5.2f", (/amp_ratio_sta(n)/)) + txt4 = sprintf("%5.2f", (/ccr_sta(n)/)) + txt5 = sprintf("%5.2f", (/M_sta(n)/)) + txt6 = sprintf("%5.2f", (/score_sta(n)/)) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", (/npts/)) + txt1 = "-" + txt2 = "-" + txt3 = sprintf("%5.2f", (/amp_ratio_zone/)) + txt4 = sprintf("%5.2f", (/ccr_zone/)) + txt5 = sprintf("%5.2f", (/M_zone/)) + txt6 = sprintf("%5.2f", (/score_zone/)) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) +;----------------------------------------------------------------- + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + clear (wks) +end do + +;******************************************************************* +; html table -- zone +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

CO2 in Latitude Zone: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
ZoneNumber of SiteAmplitide RatioCorreleration CoefM ScoreCombined Score
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow_zone-1 + set_line(lines,nline,row_header) + + set_line(lines,nline,""+text4(n,0)+"") + set_line(lines,nline,""+text4(n,1)+"") + set_line(lines,nline,""+text4(n,2)+"") + set_line(lines,nline,""+text4(n,3)+"") + set_line(lines,nline,""+text4(n,4)+"") + set_line(lines,nline,""+text4(n,5)+"") + + set_line(lines,nline,row_footer) + end do + +; for the last row + + txt0 = "All" + txt1 = sum(stringtofloat(text4(0:3,1))) + txt2 = "-" + txt3 = "-" + txt4 = "-" + txt5 = sum(stringtofloat(text4(0:3,5))) + + set_line(lines,nline,row_header) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) +;-------------------------------------------------------------------------- + + M_co2 = txt5 + + if (isvar("compare")) then + system("sed 1,/M_co2/s//"+M_co2+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_co2#"+M_co2+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/co2" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 co2/99.all.ncl.0 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/99.all.ncl.0 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,558 @@ +; *********************************************** +; using gsn_table for all +; combine 19.metric_plot.ncl and 24.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +; fili2 = "b30.061m_401_425_MONS_climo_atm.nc" + fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc" + + g = addfile(diri2+fili2,"r") + x = g->CO2 + xi = g->lon + yi = g->lat + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) +; printVarSummary (y) + +; get the co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +; y = where(y0 .lt. 287.,y@_FillValue,y) +; printVarSummary (y) +; print (min(y)+"/"+max(y)) + +;************************************************ +; read in data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/ob/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + +;print (sta(0)) + + ncase = dimsizes(lat) +;print (ncase) + +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) +;print (dimsizes(indexes)) +;print (indexes) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;printVarSummary (val_ob) +;print (lat_ob +"/"+lon_ob) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ +; to be able to handle observation at (-89.98,-24.80) + print (yi(0)) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) + val_model_0 = val_model +; printVarSummary (val_model) +; print (min(val_model)+"/"+max(val_model)) + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) +; print (min(val_model)+"/"+max(val_model)) + + nzone = 4 + +;******************************************************************* +; for table -- zone +;******************************************************************* +; table header name + table_header_name = "Zone" + +; column (not including header column) + col_header_zone = (/"Stations","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + ncol_zone = dimsizes(col_header_zone ) + +; row (not including header row) + row_header_zone = (/"60N-90N","30N-60N","EQ-30N","90S-EQ","Total"/) + nrow_zone = dimsizes(row_header_zone) + +; arrays to be passed to table. + value_zone = new ((/nrow_zone, ncol_zone/),string ) +;-------------------------------------------------------------------- + + table_length_zone = 0.4 + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.995/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol_zone/) ; 1 rows, 5 columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header_zone + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow_zone,1/) ; 5 rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length_zone,0.900/) ; end at start of y1 + text3 = row_header_zone + res3 = True + res3@txFontHeightF = 0.02 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow_zone,ncol_zone/) ; 5 rows, 5 columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow_zone,ncol_zone/),string) + + color_fill4 = new((/nrow_zone,ncol_zone/),string) + color_fill4 = "white" + color_fill4(:,ncol_zone-1) = "grey" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.02 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +;******************************************************************* +; for table -- station +;******************************************************************* +; column (not including header column) + col_header_sta = (/"Latitude","Longitude","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + ncol_sta = dimsizes(col_header_sta ) +;------------------------------------------------------------------- + +; Table header + ncr5 = (/1,1/) ; 1 row, 1 column + x5 = (/0.005,0.15/) ; Start and end X + y5 = (/0.900,0.995/) ; Start and end Y + res5 = True + res5@txFontHeightF = 0.02 + res5@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr6 = (/1,ncol_sta/) ; 1 rows, 5 columns + x6 = (/x5(1),0.995/) ; start from end of x1 + y6 = y5 ; same as y1 + text6 = col_header_sta + res6 = True + res6@txFontHeightF = 0.012 + res6@gsFillColor = "Gray" + +; Row header (equally space in y2) + + res7 = True + res7@txFontHeightF = 0.015 + res7@gsFillColor = "Gray" +;-------------------------------------------------------------- +; for station line plot + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + plot_type = "ps" + plot_type_new = "png" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"red","black"/) ; change line color + +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"b30.061n","observed"/) +;------------------------------------------------------------------- + + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + zone = "60N-90N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + zone = "30N-60N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + zone = "EQ-30N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + zone = "90S-EQ" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) +; print (ind_z) +; print (lat_ob(ind_z)+"/"+lon_ob(ind_z)) +; print (val_ob(ind_z,:)) +; print (val_model(ind_z,:)) + end if + + npts = dimsizes(ind_z) + print (npts) +;------------------------------------------------------------------------- +; for metric table computation + + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) + +;---------------------- +; for table -- station +;---------------------- + +; row (not including header row) + nrow_sta = npts + +; Table header + ncr5 = (/1,1/) ; 1 row, 1 column + x5 = (/0.005,0.15/) ; Start and end X + y5 = (/0.900,0.995/) ; Start and end Y + res5 = True + res5@txFontHeightF = 0.02 + res5@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr6 = (/1,ncol_sta/) ; 1 rows, 5 columns + x6 = (/x1(1),0.995/) ; start from end of x1 + y6 = y1 ; same as y1 + text6 = col_header_sta + res6 = True + res6@txFontHeightF = 0.012 + res6@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr7 = (/nrow_sta,1/) ; 5 rows, 1 columns + x7 = x1 ; same as x1 +; y7 = (/1.0-table_length_sta,0.900/) ; end at start of y1 + text7 = new((/nrow_sta/),string) + res7 = True + res7@txFontHeightF = 0.015 + res7@gsFillColor = "Gray" +;------------------------------------------------------------------------- +; for station line plot + + npts_str = "" + npts_str = npts +; print (npts_str) + + plot_data = new((/2,12,npts/),float) + plot_data_0 = new((/12,npts/),float) + + plot_data!0 = "case" + plot_data!1 = "month" + plot_data!2 = "pts" + plot_data@long_name = "CO2 Seasonal" + + plot_data_0!0 = "month" + plot_data_0!1 = "pts" + plot_data_0@long_name = "CO2" +;-------------------------------------------------------------------------- + do n=0,npts-1 + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + + print (sta(ind_z(n))+"/"+lat(ind_z(n))+"/"+lon(ind_z(n))+"/"+amp_ratio_sta(n)+"/"+ccr_sta(n)+"/"+M_sta(n)+"/"+score_sta(n)) +;---------------------------------------------------------------------- +; for station line plot + + plot_data(0,:,n) = (/val_model(ind_z(n),:)/) + plot_data(1,:,n) = (/val_ob(ind_z(n),:)/) + + plot_data_0(:,n) = (/val_model_0(ind_z(n),:)/) + + plot_name = sta(ind_z(n)) + title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")" +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;------------------------------------------ +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------ + res@tiMainString = title ; add title + + plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1 + + plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,n),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + clear (wks) +;--------------------------------------------------------------------------- + end do +;------------------------------------------------------------------------- +; for line plot in a zone + + plot_name = "All_"+npts_str + title = plot_name + " in "+ zone +; print (title) +; print (plot_name) + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;----------------------------------------- +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;----------------------------------------- + res@tiMainString = title ; add title + + plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1 + + plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + clear (wks) +; delete (ind_z) + delete (plot_data) + delete (plot_data_0) +;--------------------------------------------------------------------------- +; for zone table value + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone) + + text4(z,0) = sprintf("%5.2f", npts) + text4(z,1) = sprintf("%5.2f", amp_ratio_zone) + text4(z,2) = sprintf("%5.2f", ccr_zone) + text4(z,3) = sprintf("%5.2f", M_zone) + text4(z,4) = sprintf("%5.2f", score_zone) +;--------------------------------------------------------------------------- +; plot station table +;---------------------------------- +; header value for station table + text5 = zone + +; row value for station table + text7 = sta(ind_z) + + if (z .eq. 0) then + table_length_sta = 0.5 + end if + if (z .eq. 1) then + table_length_sta = 0.995 + end if + if (z .eq. 2) then + table_length_sta = 0.8 + end if + if (z .eq. 3) then + table_length_sta = 0.8 + end if + + x7 = x5 + y7 = (/1.0-table_length_sta,0.900/) ; end at start of y1 + +; Main table body + ncr8 = (/nrow_sta,ncol_sta/) ; 5 rows, 5 columns + x8 = x6 ; Start and end x + y8 = y7 ; Start and end Y + text8 = new((/nrow_sta,ncol_sta/),string) + + color_fill8 = text8 + color_fill8 = "white" + color_fill8(:,ncol_sta-1) = "grey" + + res8 = True ; Set up resource list + res8@gsnDebug = True ; Useful to print NDC row,col values used. + res8@txFontHeightF = 0.02 + res8@gsFillColor = color_fill8 + + delete (color_fill8) + +; table value for station table + text8(:,0) = sprintf("%5.2f", (/lat(ind_z)/)) + text8(:,1) = sprintf("%5.2f", (/lon(ind_z)/)) + text8(:,2) = sprintf("%5.2f", (/amp_ratio_sta/)) + text8(:,3) = sprintf("%5.2f", (/ccr_sta/)) + text8(:,4) = sprintf("%5.2f", (/M_sta/)) + text8(:,5) = sprintf("%5.2f", (/score_sta/)) + + plot_name = "table_sta." + zone + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + gsn_table(wks,ncr5,x5,y5,text5,res5) + gsn_table(wks,ncr6,x6,y6,text6,res6) + gsn_table(wks,ncr7,x7,y7,text7,res7) + gsn_table(wks,ncr8,x8,y8,text8,res8) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + delete (text7) + delete (text8) + delete (res7) + delete (res8) + clear (wks) + end do +;************************************************** +; plot zone table +;************************************************** + + text4(4,0) = sum(stringtofloat(text4(0:3,0))) + text4(4,1) = 0. + text4(4,2) = 0. + text4(4,3) = 0. + text4(4,4) = sum(stringtofloat(text4(0:3,4))) + + plot_name = "table_zone" + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +;------------------------------------------------------------------- + system("mkdir temp") + system("mv *.png temp") + system("tar cf temp.tar temp") +;------------------------------------------------------------------- +end diff -r 000000000000 -r 0c6405ab2ff4 co2/99.all.ncl.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/99.all.ncl.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,558 @@ +; *********************************************** +; using gsn_table for all +; combine 19.metric_plot.ncl and 24.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin + +;************************************************ +; read model data +;************************************************ + +; from command line inputs + +;-------------------------------------------------- +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + +; the following only needs to execute once +; system("sed 1,/model_nameA/s//"+model_name+"/ "+html_name2+" > "+html_new2+";"+ \ +; "mv -f "+html_new2+" "+html_name2+";"+ \ +; "sed 1,/model_nameB/s//"+model_name+"/ "+html_name2+" > "+html_new2+";"+ \ +; "mv -f "+html_new2+" "+html_name2+";"+ \ +; "sed s#"+modeln+"#"+model_name+"# "+html_name2+" > "+html_new2+";"+ \ +; "mv -f "+html_new2+" "+html_name2) + end if + +;------------------------------------- +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +; the following only needs to execute once +; system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new+";"+ \ +; "mv -f "+html_new+" "+html_name) +;------------------------------------------------ + + fm = addfile(dirm+film3,"r") + + x = fm->CO2 + xi = fm->lon + yi = fm->lat + + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) + +; get co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +;************************************************ +; read data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/ob/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + + ncase = dimsizes(lat) +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ +; to be able to handle observation at (-89.98,-24.80) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) + val_model_0 = val_model + +; remove annual mean + val_model = val_model - conform(val_model,dim_avg(val_model),0) + + nzone = 4 + +;******************************************************************* +; for table -- zone +;******************************************************************* +; table header name + table_header_name = "Zone" + +; column (not including header column) + col_header_zone = (/"Stations","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + ncol_zone = dimsizes(col_header_zone ) + +; row (not including header row) + row_header_zone = (/"60N-90N","30N-60N","EQ-30N","90S-EQ","Total"/) + nrow_zone = dimsizes(row_header_zone) + +; arrays to be passed to table. + value_zone = new ((/nrow_zone, ncol_zone/),string ) +;-------------------------------------------------------------------- + + table_length_zone = 0.4 + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.995/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol_zone/) ; 1 rows, 5 columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header_zone + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow_zone,1/) ; 5 rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length_zone,0.900/) ; end at start of y1 + text3 = row_header_zone + res3 = True + res3@txFontHeightF = 0.02 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow_zone,ncol_zone/) ; 5 rows, 5 columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow_zone,ncol_zone/),string) + + color_fill4 = new((/nrow_zone,ncol_zone/),string) + color_fill4 = "white" + color_fill4(:,ncol_zone-1) = "grey" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.02 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +;******************************************************************* +; for table -- station +;******************************************************************* +; column (not including header column) + col_header_sta = (/"Latitude","Longitude","Amplitude Ratio", \ + "Correlation Coef","M score","Combined Score"/) + ncol_sta = dimsizes(col_header_sta ) +;------------------------------------------------------------------- + +; Table header + ncr5 = (/1,1/) ; 1 row, 1 column + x5 = (/0.005,0.15/) ; Start and end X + y5 = (/0.900,0.995/) ; Start and end Y + res5 = True + res5@txFontHeightF = 0.02 + res5@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr6 = (/1,ncol_sta/) ; 1 rows, 5 columns + x6 = (/x5(1),0.995/) ; start from end of x1 + y6 = y5 ; same as y1 + text6 = col_header_sta + res6 = True + res6@txFontHeightF = 0.012 + res6@gsFillColor = "Gray" + +; Row header (equally space in y2) + + res7 = True + res7@txFontHeightF = 0.015 + res7@gsFillColor = "Gray" +;-------------------------------------------------------------- +; for station line plot + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + plot_type = "ps" + plot_type_new = "png" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"red","black"/) ; change line color + +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"b30.061n","observed"/) +;------------------------------------------------------------------- + + do z = 0,nzone-1 + + if (z .eq. 0) then +; maximum score for the zone, 60N-90N + zone = "60N-90N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 60.) + end if + + if (z .eq. 1) then +; maximum score for the zone, 30N-60N + zone = "30N-60N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) + end if + + if (z .eq. 2) then +; maximum score for the zone, EQ-30N + zone = "EQ-30N" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) + end if + + if (z .eq. 3) then +; maximum score for the zone, 90S-EQ + zone = "90S-EQ" + score_max = 5.0 +; index of stations in this zone + ind_z = ind(lat_ob .lt. 0. ) + end if + + npts = dimsizes(ind_z) + +;------------------------------------------------------------------------- +; for metric table computation + + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) + +;---------------------- +; for table -- station +;---------------------- + +; row (not including header row) + nrow_sta = npts + +; Table header + ncr5 = (/1,1/) ; 1 row, 1 column + x5 = (/0.005,0.15/) ; Start and end X + y5 = (/0.900,0.995/) ; Start and end Y + res5 = True + res5@txFontHeightF = 0.02 + res5@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr6 = (/1,ncol_sta/) ; 1 rows, 5 columns + x6 = (/x1(1),0.995/) ; start from end of x1 + y6 = y1 ; same as y1 + text6 = col_header_sta + res6 = True + res6@txFontHeightF = 0.012 + res6@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr7 = (/nrow_sta,1/) ; 5 rows, 1 columns + x7 = x1 ; same as x1 +; y7 = (/1.0-table_length_sta,0.900/) ; end at start of y1 + text7 = new((/nrow_sta/),string) + res7 = True + res7@txFontHeightF = 0.015 + res7@gsFillColor = "Gray" +;------------------------------------------------------------------------- +; for station line plot + + npts_str = "" + npts_str = npts + + plot_data = new((/2,12,npts/),float) + plot_data_0 = new((/12,npts/),float) + + plot_data!0 = "case" + plot_data!1 = "month" + plot_data!2 = "pts" + plot_data@long_name = "CO2 Seasonal" + + plot_data_0!0 = "month" + plot_data_0!1 = "pts" + plot_data_0@long_name = "CO2" +;-------------------------------------------------------------------------- + do n=0,npts-1 + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + +;---------------------------------------------------------------------- +; for station line plot + + plot_data(0,:,n) = (/val_model(ind_z(n),:)/) + plot_data(1,:,n) = (/val_ob(ind_z(n),:)/) + + plot_data_0(:,n) = (/val_model_0(ind_z(n),:)/) + + plot_name = sta(ind_z(n)) + title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;------------------------------------------ +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------ + res@tiMainString = title ; add title + + plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1 + + plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,n),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + clear (wks) +;--------------------------------------------------------------------------- + end do +;------------------------------------------------------------------------- +; for line plot in a zone + + plot_name = "All_"+npts_str + title = plot_name + " in "+ zone + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;----------------------------------------- +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;----------------------------------------- + res@tiMainString = title ; add title + + plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1 + + plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + clear (wks) +; delete (ind_z) + delete (plot_data) + delete (plot_data_0) +;--------------------------------------------------------------------------- +; for zone table value + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + text4(z,0) = sprintf("%5.2f", npts) + text4(z,1) = sprintf("%5.2f", amp_ratio_zone) + text4(z,2) = sprintf("%5.2f", ccr_zone) + text4(z,3) = sprintf("%5.2f", M_zone) + text4(z,4) = sprintf("%5.2f", score_zone) +;--------------------------------------------------------------------------- +; plot station table +;---------------------------------- +; header value for station table + text5 = zone + +; row value for station table + text7 = sta(ind_z) + + if (z .eq. 0) then + table_length_sta = 0.5 + end if + if (z .eq. 1) then + table_length_sta = 0.995 + end if + if (z .eq. 2) then + table_length_sta = 0.8 + end if + if (z .eq. 3) then + table_length_sta = 0.8 + end if + + x7 = x5 + y7 = (/1.0-table_length_sta,0.900/) ; end at start of y1 + +; Main table body + ncr8 = (/nrow_sta,ncol_sta/) ; 5 rows, 5 columns + x8 = x6 ; Start and end x + y8 = y7 ; Start and end Y + text8 = new((/nrow_sta,ncol_sta/),string) + + color_fill8 = text8 + color_fill8 = "white" + color_fill8(:,ncol_sta-1) = "grey" + + res8 = True ; Set up resource list +; res8@gsnDebug = True ; Useful to print NDC row,col values used. + res8@txFontHeightF = 0.02 + res8@gsFillColor = color_fill8 + + delete (color_fill8) + +; table value for station table + text8(:,0) = sprintf("%5.2f", (/lat(ind_z)/)) + text8(:,1) = sprintf("%5.2f", (/lon(ind_z)/)) + text8(:,2) = sprintf("%5.2f", (/amp_ratio_sta/)) + text8(:,3) = sprintf("%5.2f", (/ccr_sta/)) + text8(:,4) = sprintf("%5.2f", (/M_sta/)) + text8(:,5) = sprintf("%5.2f", (/score_sta/)) + + plot_name = "table_sta." + zone + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + gsn_table(wks,ncr5,x5,y5,text5,res5) + gsn_table(wks,ncr6,x6,y6,text6,res6) + gsn_table(wks,ncr7,x7,y7,text7,res7) + gsn_table(wks,ncr8,x8,y8,text8,res8) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + delete (text7) + delete (text8) + delete (res7) + delete (res8) + clear (wks) + end do +;************************************************** +; plot zone table +;************************************************** + + text4(4,0) = sum(stringtofloat(text4(0:3,0))) + text4(4,1) = 0. + text4(4,2) = 0. + text4(4,3) = 0. + text4(4,4) = sum(stringtofloat(text4(0:3,4))) + + plot_name = "table_zone" + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + M_co2 = text4(4,4) + + if (isvar("compare")) then + system("sed 1,/M_co2/s//"+M_co2+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_co2#"+M_co2+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/co2" + + system("mv *.png " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 co2/99.all.ncl.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/99.all.ncl.2 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,521 @@ +; *********************************************** +; using gsn_table for all +; combine 19.metric_plot.ncl and 24.lines.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;**************************************************************************** + +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ + +; from command line inputs + +;-------------------------------------------------- +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + +; the following only needs to execute once +; system("sed 1,/model_nameA/s//"+model_name+"/ "+html_name2+" > "+html_new2+";"+ \ +; "mv -f "+html_new2+" "+html_name2+";"+ \ +; "sed 1,/model_nameB/s//"+model_name+"/ "+html_name2+" > "+html_new2+";"+ \ +; "mv -f "+html_new2+" "+html_name2+";"+ \ +; "sed s#"+modeln+"#"+model_name+"# "+html_name2+" > "+html_new2+";"+ \ +; "mv -f "+html_new2+" "+html_name2) + end if + +;------------------------------------- +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +; the following only needs to execute once +; system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new+";"+ \ +; "mv -f "+html_new+" "+html_name) +;------------------------------------------------ + fm = addfile(dirm+film3,"r") + + x = fm->CO2 + xi = fm->lon + yi = fm->lat + + xdim = dimsizes(x) + nlev = xdim(1) + y = x(:,0,:,:) + +; get co2 at the lowest level + y = x(:,nlev-1,:,:) + +; change to unit of observed (u mol/mol) +; Model_units [=] kgCO2 / kgDryAir +; 28.966 = molecular weight of dry air +; 44. = molecular weight of CO2 +; u mol = 1e-6 mol + + factor = (28.966/44.) * 1e6 + y = y * factor + + y@_FillValue = 1.e36 + y@units = "u mol/mol" +;************************************************ +; read data: observed +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/co2/ob/" + fili = "co2_globalView_98.nc" + g = addfile (diri+fili,"r") + val = g->CO2_SEAS + lon = g->LON + lat = g->LAT + sta = chartostring(g->STATION) + delete (g) + + ncase = dimsizes(lat) +;************************************************************** +; get only the lowest level at each station +;************************************************************** + lat_tmp = lat + lat_tmp@_FillValue = 1.e+36 + + do n = 0,ncase-1 + if (.not. ismissing(lat_tmp(n))) then + indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon) + if (dimsizes(indexes) .gt. 1) then + lat_tmp(indexes(1:)) = lat_tmp@_FillValue + end if + delete (indexes) + end if + end do + + indexes = ind(.not. ismissing(lat_tmp)) + + lat_ob = lat(indexes) + lon_ob = lon(indexes) + val_ob = val(indexes,:) +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ +; to be able to handle observation at (-89.98,-24.80) + yi(0) = -90. + + i = ind(lon_ob .lt. 0.) + lon_ob(i) = lon_ob(i) + 360. + + yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0) + + val_model = yo(pts|:,time|:) + val_model_0 = val_model +;************************************************************ +; remove annual mean +;************************************************************ + val_model = val_model - conform(val_model,dim_avg(val_model),0) + +;******************************************************************* +; res for station line plot +;******************************************************************* +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"red","black"/) ; change line color + +; Add a boxed legend using the more simple method + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/model_name,"observed"/) +;************************************************************ +; number of latitude zone +;************************************************************ + nzone = 4 + +; number of rows for zone table + nrow_zone = nzone + 1 + +; number of columns for zone table + ncol_zone = 6 + +; saving data for zone + text4 = new((/nrow_zone,ncol_zone/),string) + +do z = 0,nzone-1 + + if (z .eq. 0) then + zone = "60N-90N" + score_max = 5.0 + ind_z = ind(lat_ob .ge. 60.) + end if + + if (z .eq. 1) then + zone = "30N-60N" + score_max = 5.0 + ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.) + end if + + if (z .eq. 2) then + zone = "EQ-30N" + score_max = 5.0 + ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.) + end if + + if (z .eq. 3) then + zone = "90S-EQ" + score_max = 5.0 + ind_z = ind(lat_ob .lt. 0. ) + end if + + npts = dimsizes(ind_z) + +;------------------------------------------------------ +; for metric table computation + amp_ob = new((/npts/),float) + amp_model = new((/npts/),float) + + amp_ratio_sta = new((/npts/),float) + ccr_sta = new((/npts/),float) + M_sta = new((/npts/),float) + score_sta = new((/npts/),float) +;----------------------------------------------------- +; for station line plot + npts_str = "" + npts_str = npts + + plot_data = new((/2,12,npts/),float) + plot_data_0 = new((/12,npts/),float) + + plot_data!0 = "case" + plot_data!1 = "month" + plot_data!2 = "pts" + plot_data@long_name = "CO2 Seasonal" + + plot_data_0!0 = "month" + plot_data_0!1 = "pts" + plot_data_0@long_name = "CO2" +;-------------------------------------------------------------------------- + do n=0,npts-1 + + amp_ob(n) = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) + amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:)) + + amp_ratio_sta(n) = amp_model(n)/amp_ob(n) + ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0) + M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.) + score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max + +;---------------------------------------------------------------------- +; for station line plot + + plot_data(0,:,n) = (/val_model(ind_z(n),:)/) + plot_data(1,:,n) = (/val_ob(ind_z(n),:)/) + + plot_data_0(:,n) = (/val_model_0(ind_z(n),:)/) + + plot_name = sta(ind_z(n)) + title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;------------------------------------------ +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------ + res@tiMainString = title ; add title + + plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res) ; create plot 1 + + plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,n),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + clear (wks) +;--------------------------------------------------------------------------- + end do +;------------------------------------------------------------------------- +; for line plot in a zone + + plot_name = "All_"+npts_str + title = plot_name + " in "+ zone + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;----------------------------------------- +; for panel plot + + plot=new(2,graphic) ; create graphic array + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;----------------------------------------- + res@tiMainString = title ; add title + + plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res) ; create plot 1 + + plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2 + + gsn_panel(wks,plot,(/2,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + clear (wks) +; delete (ind_z) + delete (plot_data) + delete (plot_data_0) +;--------------------------------------------------------------------------- +; values saved for zone table + + amp_ratio_zone = avg(amp_ratio_sta) + ccr_zone = avg(ccr_sta) + M_zone = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) + score_zone = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max + + text4(z,0) = zone + text4(z,1) = sprintf("%.0f", npts) + text4(z,2) = sprintf("%.2f", amp_ratio_zone) + text4(z,3) = sprintf("%.2f", ccr_zone) + text4(z,4) = sprintf("%.2f", M_zone) + text4(z,5) = sprintf("%.2f", score_zone) + +;******************************************************************* +; html table -- station +;******************************************************************* + output_html = "score+line_"+zone+".html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

CO2 in Zone "+zone+": Model "+model_name+"

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeAmplitude RatioCorreleration CoefM ScoreCombined Score
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,npts-1 + set_line(lines,nline,row_header) + + txt0 = sta(ind_z(n)) + txt1 = sprintf("%5.2f", (/lat(ind_z(n))/)) + txt2 = sprintf("%5.2f", (/lon(ind_z(n))/)) + txt3 = sprintf("%5.2f", (/amp_ratio_sta(n)/)) + txt4 = sprintf("%5.2f", (/ccr_sta(n)/)) + txt5 = sprintf("%5.2f", (/M_sta(n)/)) + txt6 = sprintf("%5.2f", (/score_sta(n)/)) + + set_line(lines,nline,"
"+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", (/npts/)) + txt1 = "-" + txt2 = "-" + txt3 = sprintf("%5.2f", (/amp_ratio_zone/)) + txt4 = sprintf("%5.2f", (/ccr_zone/)) + txt5 = sprintf("%5.2f", (/M_zone/)) + txt6 = sprintf("%5.2f", (/score_zone/)) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) +;----------------------------------------------------------------- + + delete (ind_z) + delete (amp_model) + delete (amp_ob) + delete (amp_ratio_sta) + delete (ccr_sta) + delete (M_sta) + delete (score_sta) + clear (wks) +end do + +;******************************************************************* +; html table -- zone +;******************************************************************* + output_html = "score_zone.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

CO2 in Latitude Zone: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
ZoneNumber of SiteAmplitide RatioCorreleration CoefM ScoreCombined Score
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + +; sum for the last row + text4(4,0) = "All" + text4(4,1) = sum(stringtofloat(text4(0:3,1))) + text4(4,2) = "-" + text4(4,3) = "-" + text4(4,4) = "-" + text4(4,5) = sum(stringtofloat(text4(0:3,5))) + + do n = 0,nrow_zone-1 + set_line(lines,nline,row_header) + + set_line(lines,nline,""+text4(n,0)+"") + set_line(lines,nline,""+text4(n,1)+"") + set_line(lines,nline,""+text4(n,2)+"") + set_line(lines,nline,""+text4(n,3)+"") + set_line(lines,nline,""+text4(n,4)+"") + set_line(lines,nline,""+text4(n,5)+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) +;-------------------------------------------------------------------------- + + M_co2 = text4(4,5) + + if (isvar("compare")) then + system("sed 1,/M_co2/s//"+M_co2+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_co2#"+M_co2+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/co2" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 co2/metrics_table.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/metrics_table.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,93 @@ +;************************************************* +; NCL Graphics: table_2.ncl +;************************************************* + +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" + +begin +; Header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.335/) ; Start and end X + y1 = (/0.900,0.995/) ; Start and end Y + text1 = "CAM METRICS" + +; Sub header + ncr2 = (/2,2/) ; 2 rows, 2 columns + x2 = (/0.335,0.995/) ; Start and end X + y2 = (/0.900,0.995/) ; Start and end Y + text2 = (/ (/"Case A","Case B"/),(/"ANN","ANN"/)/) + +; Main table body + ncr3 = (/16,3/) ; 16 rows, 3 columns + x3 = (/0.005,0.995/) ; Start and end X + y3 = (/0.005,0.900/) ; Start and end Y + + text3 = (/ (/"SLP_ERA40", "1.230", "1.129"/), \ + (/"Tsfc_ERA40", "0.988", "0.996"/), \ + (/"Prc_GPCP", "1.092", "1.016"/), \ + (/"Prc 30S-30N_GPCP", "1.172", "1.134"/), \ + (/"LW_ERS", "1.064", "1.023"/), \ + (/"SW_ERS", "0.966", "0.962"/), \ + (/"U300_ERA40", "1.079", "1.048"/), \ + (/"Guess_BOGUS", "0.781", "0.852"/), \ + (/"RH_NCEP", "1.122", "0.911"/), \ + (/"LHFLX_ERA40", "1.000", "0.835"/), \ + (/"TWP_ERA40", "0.998", "0.712"/), \ + (/"CLDTOT_NCEP", "1.321", "1.122"/), \ + (/"O3_NASA", "0.842", "0.956"/), \ + (/"Q_JMA", "0.978", "0.832"/), \ + (/"PBLH_JMA", "0.998", "0.900"/), \ + (/"Omega_CAS", "0.811", "1.311"/)/) + + + wks = gsn_open_wks("ps","table") + +; +; Main header. +; + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + + gsn_table(wks,ncr1,x1,y1,text1,res1) + +; +; Sub header +; + res2 = True + res2@txFontHeightF = 0.02 + res2@gsFillColor = "Gray" + + gsn_table(wks,ncr2,x2,y2,text2,res2) + +; +; Main body of table. +; + res3 = True ; Set up resource list + +; res3@gsnDebug = True ; Useful to print NDC row,col values used. + + res3@txFontHeightF = 0.02 + + res3@gsFillColor = (/ (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","hotpink"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","hotpink"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","hotpink"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","hotpink"/)/) + + gsn_table(wks,ncr3,x3,y3,text3,res3) + + frame(wks) ; Advance the frame. + +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 co2/metrics_table.ncl.0 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/metrics_table.ncl.0 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,209 @@ +;******************************************************************* +; procedure to draw the Taylor Diagram Metrics Table +; +; AWWG METRICS 0.3 ;;; +; 27 Jun 06 ASP +; 5 Jul 06 DJS +; +; Arguments: +; mfname : name of the output table +; varNames : variable names [metrics] +; cases : case (model) names +; seasons : season names +; values : array containing the values to be plotted +; opt : used to pass optional arguments + +procedure metrics_table(mfname[1]:string \ ; plot name + ,varNames[*]:string \ ; variables + ,cases[*]:string \ + ,values[*][*]:numeric \ + ,opt:logical ) + + +;;; +;;; Output of metrics to a table [grid] + +begin + if (.not.isatt(opt,"pltType") .or. \ + (opt@pltType.eq."eps" .or. opt@pltType.eq."png" .or. opt@pltType.eq."gif")) then + wks = gsn_open_wks("eps",mfname) ; default + else + wks = gsn_open_wks(opt@pltType,mfname) + end if + + xbox0 = (/0.0,1.0,1.0,0.0,0.0/) ; Box template. + ybox0 = (/0.0,0.0,1.0,1.0,0.0/) + + nvar = dimsizes(varNames) + ncases = dimsizes(cases) + + dimt = dimsizes(values) ; table dimensions + + if (ncases.ne.dimt(0)) then + print("metrics_table fatal error: Number of case names ("+ncases+ \ + ") does not match the number of cases passed in ("+dimt(0)+")") + exit + end if + + if (dimsizes(varNames).ne.dimt(1)) then + print("metrics_table fatal error: Number of metric variables names ("+dimsizes(varNames)+ \ + ") does not match the number of metric variables passed in ("+dimt(1)+")") + exit + end if + + ncolm1 = dimt(0) + if (ncolm1.le.12) then + if (ncolm1.le.6) then +; tt_width = .4 + tt_width = .2 + end if + if (ncolm1.ge.7.and.ncolm1.le.12) then + tt_width = .2 + end if + tt_height = 0.1 + tt_theight = 0.02 + mn_height = 0.03 + mn_theight = 0.012 + else + if (ncolm1.le.20) then + tt_width = .15 + tt_height = 0.06 + tt_theight = 0.012 + mn_height = 0.018 + mn_theight = 0.0072 + else + tt_width = .1 + tt_height = 0.05 + tt_theight = 0.01 + mn_height = 0.015 + mn_theight = 0.006 + end if + end if + if (ncolm1.gt.26.or.dimt(1).gt.63) then + print("Warning: Recommended maximium size of array passed into metrics_table is "+ \ + "26 columns (#cases * #seasons) by 63 rows (#variables), continuing") + end if + + mn_width = tt_width + mv_height = mn_height + mv_width = 0.1 + mv_theight = mn_theight + + tt_pRes = True + tt_pRes@gsFillColor = "CornflowerBlue" ; background color for + values + + tt_tRes = True + tt_tRes@txFontHeightF = tt_theight + + mn_pRes = True + mn_pRes@gsFillColor = "Gray70" ; background color for variable names + + mn_tRes = True + mn_tRes@txFontHeightF = mn_theight + + mv_pRes = True + mv_pRes@gsFillColor = "White" ; background color for reference values + + mv_tRes = True + mv_tRes@txFontHeightF = mn_theight + +; Title + + xbox = tt_width*xbox0 + ybox = 1.-tt_height*ybox0 + + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + + gsn_polygon_ndc(wks,xbox,ybox,tt_pRes) + if (isatt(opt,"tableTitle") ) then + gsn_text_ndc(wks, opt@tableTitle ,ixtbox,iytbox, tt_tRes) + else + gsn_text_ndc(wks,"METRICS",ixtbox,iytbox, tt_tRes) + end if + gsn_polyline_ndc(wks,xbox,ybox,False) + + do im = 0,nvar-1 + ybox = min(ybox)-(ybox0*mn_height) + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + + gsn_polygon_ndc(wks,xbox,ybox,mn_pRes) + gsn_polyline_ndc(wks,xbox,ybox,False) + gsn_text_ndc(wks,varNames(im),ixtbox,iytbox, mn_tRes) + end do + + do icase = 0, ncases-1 +; ybox = 1.-0.5*tt_height*ybox0 + ybox = 1.-tt_height*ybox0 + xbox = ((1.-tt_width)/ncases)*(xbox0+icase)+tt_width + xboxi = min(xbox) + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + gsn_polygon_ndc(wks,xbox,ybox,mn_pRes) + gsn_polyline_ndc(wks,xbox,ybox,False) + gsn_text_ndc(wks,cases(icase),ixtbox,iytbox, mn_tRes) + +; do iseas = 0, nseas-1 +; ybox = 1.-0.5*tt_height-0.5*tt_height*ybox0 +; xbox = xboxi + ((1.-tt_width)/(ncases*nseas))*(xbox0+iseas) +; ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) +; iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) +; gsn_polygon_ndc(wks,xbox,ybox,mn_pRes) +; gsn_polyline_ndc(wks,xbox,ybox,False) +; gsn_text_ndc(wks,seasons(iseas),ixtbox,iytbox, mn_tRes) + + if (icase .eq. ncases-1) then + mv_pRes@gsFillColor = "Green" + else + mv_pRes@gsFillColor = "White" + end if + + do im=0,nvar-1 + if (im .eq. 0) then + ybox = 1.-tt_height-mv_height*ybox0 + else + ybox = ybox - mv_height + end if + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) ; add + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + +; if (icase .gt. 0) then +; if (ismissing(values(icase,im)) .or. \ ; ??? +; ismissing(values(icase,im)))then +; ; print ("Missing values skipped") +; else +; if (values(icase,im).le.values(0,im)) then +; if (isatt(opt,"color0")) then +; mv_pRes@gsFillColor = opt@color0 +; else +; mv_pRes@gsFillColor = "DarkOliveGreen3" +; end if +; else +; if (isatt(opt,"color1")) then +; mv_pRes@gsFillColor = opt@color1 +; else +; mv_pRes@gsFillColor = "IndianRed1" +; end if +; end if +; end if +; end if + gsn_polygon_ndc(wks,xbox,ybox,mv_pRes) + gsn_polyline_ndc(wks,xbox,ybox,False) + gsn_text_ndc(wks,sprintf("%4.2f",values(icase,im)),ixtbox,iytbox, mv_tRes) + end do +; end do + end do + + draw(wks) + ;; activate the ;; lines if this is made a function + ;;if (.not.isatt(opt,"gsnFrame") .or. opt@gsnFrame) then + frame(wks) + ; if png or gif then use convert + if (isatt(opt,"pltType") .and. \ + (opt@pltType.eq."png" .or. opt@pltType.eq."gif")) then + system("convert -trim +repage "+mfname+".eps "+mfname+"."+opt@pltType) + end if + ;;end if + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/metrics_table.ncl.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/metrics_table.ncl.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,209 @@ +;******************************************************************* +; procedure to draw the Taylor Diagram Metrics Table +; +; AWWG METRICS 0.3 ;;; +; 27 Jun 06 ASP +; 5 Jul 06 DJS +; +; Arguments: +; mfname : name of the output table +; varNames : variable names [metrics] +; cases : case (model) names +; seasons : season names +; values : array containing the values to be plotted +; opt : used to pass optional arguments + +procedure metrics_table(mfname[1]:string \ ; plot name + ,varNames[*]:string \ ; variables + ,cases[*]:string \ + ,values[*][*]:numeric \ + ,opt:logical ) + + +;;; +;;; Output of metrics to a table [grid] + +begin + if (.not.isatt(opt,"pltType") .or. \ + (opt@pltType.eq."eps" .or. opt@pltType.eq."png" .or. opt@pltType.eq."gif")) then + wks = gsn_open_wks("eps",mfname) ; default + else + wks = gsn_open_wks(opt@pltType,mfname) + end if + + xbox0 = (/0.0,1.0,1.0,0.0,0.0/) ; Box template. + ybox0 = (/0.0,0.0,1.0,1.0,0.0/) + + nvar = dimsizes(varNames) + ncases = dimsizes(cases) + + dimt = dimsizes(values) ; table dimensions + + if (ncases.ne.dimt(0)) then + print("metrics_table fatal error: Number of case names ("+ncases+ \ + ") does not match the number of cases passed in ("+dimt(0)+")") + exit + end if + + if (dimsizes(varNames).ne.dimt(1)) then + print("metrics_table fatal error: Number of metric variables names ("+dimsizes(varNames)+ \ + ") does not match the number of metric variables passed in ("+dimt(1)+")") + exit + end if + + ncolm1 = dimt(0) + if (ncolm1.le.12) then + if (ncolm1.le.6) then +; tt_width = .4 + tt_width = .2 + end if + if (ncolm1.ge.7.and.ncolm1.le.12) then + tt_width = .2 + end if + tt_height = 0.1 + tt_theight = 0.02 + mn_height = 0.03 + mn_theight = 0.012 + else + if (ncolm1.le.20) then + tt_width = .15 + tt_height = 0.06 + tt_theight = 0.012 + mn_height = 0.018 + mn_theight = 0.0072 + else + tt_width = .1 + tt_height = 0.05 + tt_theight = 0.01 + mn_height = 0.015 + mn_theight = 0.006 + end if + end if + if (ncolm1.gt.26.or.dimt(1).gt.63) then + print("Warning: Recommended maximium size of array passed into metrics_table is "+ \ + "26 columns (#cases * #seasons) by 63 rows (#variables), continuing") + end if + + mn_width = tt_width + mv_height = mn_height + mv_width = 0.1 + mv_theight = mn_theight + + tt_pRes = True + tt_pRes@gsFillColor = "CornflowerBlue" ; background color for + values + + tt_tRes = True + tt_tRes@txFontHeightF = tt_theight + + mn_pRes = True + mn_pRes@gsFillColor = "Gray70" ; background color for variable names + + mn_tRes = True + mn_tRes@txFontHeightF = mn_theight + + mv_pRes = True + mv_pRes@gsFillColor = "White" ; background color for reference values + + mv_tRes = True + mv_tRes@txFontHeightF = mn_theight + +; Title + + xbox = tt_width*xbox0 + ybox = 1.-tt_height*ybox0 + + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + + gsn_polygon_ndc(wks,xbox,ybox,tt_pRes) + if (isatt(opt,"tableTitle") ) then + gsn_text_ndc(wks, opt@tableTitle ,ixtbox,iytbox, tt_tRes) + else + gsn_text_ndc(wks,"METRICS",ixtbox,iytbox, tt_tRes) + end if + gsn_polyline_ndc(wks,xbox,ybox,False) + + do im = 0,nvar-1 + ybox = min(ybox)-(ybox0*mn_height) + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + + gsn_polygon_ndc(wks,xbox,ybox,mn_pRes) + gsn_polyline_ndc(wks,xbox,ybox,False) + gsn_text_ndc(wks,varNames(im),ixtbox,iytbox, mn_tRes) + end do + + do icase = 0, ncases-1 +; ybox = 1.-0.5*tt_height*ybox0 + ybox = 1.-tt_height*ybox0 + xbox = ((1.-tt_width)/ncases)*(xbox0+icase)+tt_width + xboxi = min(xbox) + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + gsn_polygon_ndc(wks,xbox,ybox,mn_pRes) + gsn_polyline_ndc(wks,xbox,ybox,False) + gsn_text_ndc(wks,cases(icase),ixtbox,iytbox, mn_tRes) + +; do iseas = 0, nseas-1 +; ybox = 1.-0.5*tt_height-0.5*tt_height*ybox0 +; xbox = xboxi + ((1.-tt_width)/(ncases*nseas))*(xbox0+iseas) +; ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) +; iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) +; gsn_polygon_ndc(wks,xbox,ybox,mn_pRes) +; gsn_polyline_ndc(wks,xbox,ybox,False) +; gsn_text_ndc(wks,seasons(iseas),ixtbox,iytbox, mn_tRes) + + if (icase .eq. ncases-1) then + mv_pRes@gsFillColor = "Green" + else + mv_pRes@gsFillColor = "White" + end if + + do im=0,nvar-1 + if (im .eq. 0) then + ybox = 1.-tt_height-mv_height*ybox0 + else + ybox = ybox - mv_height + end if + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) ; add + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + +; if (icase .gt. 0) then +; if (ismissing(values(icase,im)) .or. \ ; ??? +; ismissing(values(icase,im)))then +; ; print ("Missing values skipped") +; else +; if (values(icase,im).le.values(0,im)) then +; if (isatt(opt,"color0")) then +; mv_pRes@gsFillColor = opt@color0 +; else +; mv_pRes@gsFillColor = "DarkOliveGreen3" +; end if +; else +; if (isatt(opt,"color1")) then +; mv_pRes@gsFillColor = opt@color1 +; else +; mv_pRes@gsFillColor = "IndianRed1" +; end if +; end if +; end if +; end if + gsn_polygon_ndc(wks,xbox,ybox,mv_pRes) + gsn_polyline_ndc(wks,xbox,ybox,False) + gsn_text_ndc(wks,sprintf("%4.2f",values(icase,im)),ixtbox,iytbox, mv_tRes) + end do +; end do + end do + + draw(wks) + ;; activate the ;; lines if this is made a function + ;;if (.not.isatt(opt,"gsnFrame") .or. opt@gsnFrame) then + frame(wks) + ; if png or gif then use convert + if (isatt(opt,"pltType") .and. \ + (opt@pltType.eq."png" .or. opt@pltType.eq."gif")) then + system("convert -trim +repage "+mfname+".eps "+mfname+"."+opt@pltType) + end if + ;;end if + +end diff -r 000000000000 -r 0c6405ab2ff4 co2/metrics_table.ncl.example --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/metrics_table.ncl.example Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,93 @@ +;************************************************* +; NCL Graphics: table_2.ncl +;************************************************* + +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" + +begin +; Header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.335/) ; Start and end X + y1 = (/0.900,0.995/) ; Start and end Y + text1 = "CAM METRICS" + +; Sub header + ncr2 = (/2,2/) ; 2 rows, 2 columns + x2 = (/0.335,0.995/) ; Start and end X + y2 = (/0.900,0.995/) ; Start and end Y + text2 = (/ (/"Case A","Case B"/),(/"ANN","ANN"/)/) + +; Main table body + ncr3 = (/16,3/) ; 16 rows, 3 columns + x3 = (/0.005,0.995/) ; Start and end X + y3 = (/0.005,0.900/) ; Start and end Y + + text3 = (/ (/"SLP_ERA40", "1.230", "1.129"/), \ + (/"Tsfc_ERA40", "0.988", "0.996"/), \ + (/"Prc_GPCP", "1.092", "1.016"/), \ + (/"Prc 30S-30N_GPCP", "1.172", "1.134"/), \ + (/"LW_ERS", "1.064", "1.023"/), \ + (/"SW_ERS", "0.966", "0.962"/), \ + (/"U300_ERA40", "1.079", "1.048"/), \ + (/"Guess_BOGUS", "0.781", "0.852"/), \ + (/"RH_NCEP", "1.122", "0.911"/), \ + (/"LHFLX_ERA40", "1.000", "0.835"/), \ + (/"TWP_ERA40", "0.998", "0.712"/), \ + (/"CLDTOT_NCEP", "1.321", "1.122"/), \ + (/"O3_NASA", "0.842", "0.956"/), \ + (/"Q_JMA", "0.978", "0.832"/), \ + (/"PBLH_JMA", "0.998", "0.900"/), \ + (/"Omega_CAS", "0.811", "1.311"/)/) + + + wks = gsn_open_wks("ps","table") + +; +; Main header. +; + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + + gsn_table(wks,ncr1,x1,y1,text1,res1) + +; +; Sub header +; + res2 = True + res2@txFontHeightF = 0.02 + res2@gsFillColor = "Gray" + + gsn_table(wks,ncr2,x2,y2,text2,res2) + +; +; Main body of table. +; + res3 = True ; Set up resource list + +; res3@gsnDebug = True ; Useful to print NDC row,col values used. + + res3@txFontHeightF = 0.02 + + res3@gsFillColor = (/ (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","hotpink"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","hotpink"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","hotpink"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","palegreen"/), \ + (/"gray","transparent","hotpink"/)/) + + gsn_table(wks,ncr3,x3,y3,text3,res3) + + frame(wks) ; Advance the frame. + +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 co2/taylor_metrics_table.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/co2/taylor_metrics_table.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,206 @@ +;******************************************************************* +; procedure to draw the Taylor Diagram Metrics Table +; +; AWWG METRICS 0.3 ;;; +; 27 Jun 06 ASP +; 5 Jul 06 DJS +; +; Arguments: +; mfname : name of the output table +; varNames : variable names [metrics] +; cases : case (model) names +; seasons : season names +; values : array containing the values to be plotted +; opt : used to pass optional arguments + +procedure taylor_metrics_table(mfname[1]:string \ ; plot name + ,varNames[*]:string \ ; variables + ,cases[*]:string \ + ,seasons[*]:string \ + ,values[*][*][*]:numeric \ + ,opt:logical ) + + +;;; +;;; Output of metrics to a table [grid] + +begin + if (.not.isatt(opt,"pltType") .or. \ + (opt@pltType.eq."eps" .or. opt@pltType.eq."png" .or. opt@pltType.eq."gif")) then + wks = gsn_open_wks("eps",mfname) ; default + else + wks = gsn_open_wks(opt@pltType,mfname) + end if + + xbox0 = (/0.0,1.0,1.0,0.0,0.0/) ; Box template. + ybox0 = (/0.0,0.0,1.0,1.0,0.0/) + + nvar = dimsizes(varNames) + ncases = dimsizes(cases) + nseas = dimsizes(seasons) + + dimt = dimsizes(values) ; table dimensions + + if (ncases.ne.dimt(0)) then + print("taylor_metrics_table fatal error: Number of case names ("+ncases+ \ + ") does not match the number of cases passed in ("+dimt(0)+")") + exit + end if + if (nseas.ne.dimt(1)) then + print("taylor_metrics_table fatal error: Number of season names ("+nseas+ \ + ") does not match the number of seasons passed in ("+dimt(1)+")") + exit + end if + if (dimsizes(varNames).ne.dimt(2)) then + print("taylor_metrics_table fatal error: Number of metric variables names ("+dimsizes(varNames)+ \ + ") does not match the number of metric variables passed in ("+dimt(2)+")") + exit + end if + + ncolm1 = dimt(0)*dimt(1) + if (ncolm1.le.12) then + if (ncolm1.le.6) then + tt_width = .4 + end if + if (ncolm1.ge.7.and.ncolm1.le.12) then + tt_width = .2 + end if + tt_height = 0.1 + tt_theight = 0.02 + mn_height = 0.03 + mn_theight = 0.012 + else + if (ncolm1.le.20) then + tt_width = .15 + tt_height = 0.06 + tt_theight = 0.012 + mn_height = 0.018 + mn_theight = 0.0072 + else + tt_width = .1 + tt_height = 0.05 + tt_theight = 0.01 + mn_height = 0.015 + mn_theight = 0.006 + end if + end if + if (ncolm1.gt.26.or.dimt(2).gt.63) then + print("Warning: Recommended maximium size of array passed into taylor_metrics_table is "+ \ + "26 columns (#cases * #seasons) by 63 rows (#variables), continuing") + end if + + mn_width = tt_width + mv_height = mn_height + mv_width = 0.1 + mv_theight = mn_theight + + tt_pRes = True + tt_pRes@gsFillColor = "CornflowerBlue" ; background color for + values + + tt_tRes = True + tt_tRes@txFontHeightF = tt_theight + + mn_pRes = True + mn_pRes@gsFillColor = "Gray70" ; background color for variable names + + mn_tRes = True + mn_tRes@txFontHeightF = mn_theight + + mv_pRes = True + mv_pRes@gsFillColor = "White" ; background color for reference values + + mv_tRes = True + mv_tRes@txFontHeightF = mn_theight + +; Title + + xbox = tt_width*xbox0 + ybox = 1.-tt_height*ybox0 + + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + + gsn_polygon_ndc(wks,xbox,ybox,tt_pRes) + if (isatt(opt,"tableTitle") ) then + gsn_text_ndc(wks, opt@tableTitle ,ixtbox,iytbox, tt_tRes) + else + gsn_text_ndc(wks,"CAM METRICS",ixtbox,iytbox, tt_tRes) + end if + gsn_polyline_ndc(wks,xbox,ybox,False) + + do im = 0,nvar-1 + ybox = min(ybox)-(ybox0*mn_height) + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + + gsn_polygon_ndc(wks,xbox,ybox,mn_pRes) + gsn_polyline_ndc(wks,xbox,ybox,False) + gsn_text_ndc(wks,varNames(im),ixtbox,iytbox, mn_tRes) + end do + + do icase = 0, ncases-1 + ybox = 1.-0.5*tt_height*ybox0 + xbox = ((1.-tt_width)/ncases)*(xbox0+icase)+tt_width + xboxi = min(xbox) + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + gsn_polygon_ndc(wks,xbox,ybox,mn_pRes) + gsn_polyline_ndc(wks,xbox,ybox,False) + gsn_text_ndc(wks,cases(icase),ixtbox,iytbox, mn_tRes) + + do iseas = 0, nseas-1 + ybox = 1.-0.5*tt_height-0.5*tt_height*ybox0 + xbox = xboxi + ((1.-tt_width)/(ncases*nseas))*(xbox0+iseas) + ixtbox = xbox(0)+0.5*(xbox(1)-xbox(0)) + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + gsn_polygon_ndc(wks,xbox,ybox,mn_pRes) + gsn_polyline_ndc(wks,xbox,ybox,False) + gsn_text_ndc(wks,seasons(iseas),ixtbox,iytbox, mn_tRes) + + do im=0,nvar-1 + if (im .eq. 0) then + ybox = 1.-tt_height-mv_height*ybox0 + else + ybox = ybox - mv_height + end if + iytbox = ybox(0)+0.5*(ybox(2)-ybox(0)) + mv_pRes@gsFillColor = "White" + if (icase .gt. 0) then + if (ismissing(values(icase,iseas,im)) .or. \ ; ??? + ismissing(values(icase,iseas,im)))then + ; print ("Missing values skipped") + else + if (values(icase,iseas,im).le.values(0,iseas,im)) then + if (isatt(opt,"color0")) then + mv_pRes@gsFillColor = opt@color0 + else + mv_pRes@gsFillColor = "DarkOliveGreen3" + end if + else + if (isatt(opt,"color1")) then + mv_pRes@gsFillColor = opt@color1 + else + mv_pRes@gsFillColor = "IndianRed1" + end if + end if + end if + end if + gsn_polygon_ndc(wks,xbox,ybox,mv_pRes) + gsn_polyline_ndc(wks,xbox,ybox,False) + gsn_text_ndc(wks,sprintf("%4.3f",values(icase,iseas,im)),ixtbox,iytbox, mv_tRes) + end do + end do + end do + + draw(wks) + ;; activate the ;; lines if this is made a function + ;;if (.not.isatt(opt,"gsnFrame") .or. opt@gsnFrame) then + frame(wks) + ; if png or gif then use convert + if (isatt(opt,"pltType") .and. \ + (opt@pltType.eq."png" .or. opt@pltType.eq."gif")) then + system("convert -trim +repage "+mfname+".eps "+mfname+"."+opt@pltType) + end if + ;;end if + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/01.monthly_avg.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/01.monthly_avg.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,161 @@ +;************************************************ +; Read half-hourly data and write monthly data +; input data is : half-hourly +; +; output data is : CO2_flux, RAD_FLUX, SH_FLUX, LH_FLUX +; date, lat, lon +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + station_name = "Kaamanen" + file_name_add = "carboeurope" + year_start = 2000 + year_end = 2003 + +; final output + diro = dir_root + station_name + "/" + filo = station_name+"_"+year_start+"-"+year_end+"_monthly.nc" + c = addfile(diro+filo,"c") + print (filo) + +; input dir + diri = dir_root + station_name + "/" + + nyear = year_end - year_start + 1 + nmon = 12 + nlat = 1 + nlon = 1 + +; day_of_month = (/31.,28.,31.,30.,31.,30.,31.,31.,30.,31.,30.,31./) + end_of_month1 = (/31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334.,365./) + end_of_month2 = (/31.,60.,91.,121.,152.,182.,213.,244.,274.,305.,335.,366./) + + data_out1 = new((/nyear,nmon/),float) + data_out2 = new((/nyear,nmon/),float) + data_out3 = new((/nyear,nmon/),float) + data_out4 = new((/nyear,nmon/),float) + time_out = new((/nyear,nmon/),integer) + lat_out = new((/nlat/),float) + lon_out = new((/nlon/),float) + + do m = 0,nyear-1 + year = year_start + m + +; if (mod(year,4) .eq. 0) then + if (year .eq. 2000) then + hour_of_month = end_of_month2 * 24. + else + hour_of_month = end_of_month1 * 24. + end if +; print (hour_of_month) + +; input file + fili = file_name_add+"."+station_name+"."+year+".nc" + b = addfile(diri+fili,"r") + print (fili) + +; co2 flux unit: umol m-2 s-1 + data1 = b->FCO2M +; net radiation flux unit: W m-2 + data2 = b->RN +; sensible heat flux unit: W m-2 + data3 = b->H +; latent heat flux unit: W m-2 + data4 = b->LE + +; time unit: hour since 01-01 (mm-dd) + time = b->time + + do n= 0,nmon-1 + if (n.eq.0) then + timeL = 0. + timeR = hour_of_month(0) + else + timeL = hour_of_month(n-1) + timeR = hour_of_month(n) + end if +; print (timeL) +; print (timeR) + + i = ind(time.ge.timeL .and. time.lt.timeR) +; print (i) + + data_out1(m,n) = avg(data1(i)) + data_out2(m,n) = avg(data2(i)) + data_out3(m,n) = avg(data3(i)) + data_out4(m,n) = avg(data4(i)) + + time_out(m,n) = year*100 + n + 1 +; print (time_out(m,n)) + + delete (i) + end do + if (m.lt.nyear-1) then + delete (data1) + delete (data2) + delete (data3) + delete (data4) + delete (time) + end if + end do + + lat_out = 69.1407 + lon_out = 27.2950 + + data_out1!0 = "year" + data_out1!1 = "month" + data_out1@long_name = data1@long_name + data_out1@units = data1@units + data_out1@_FillValue = 1.e+36 +; print (data_out1) + + data_out2!0 = "year" + data_out2!1 = "month" + data_out2@long_name = data2@long_name + data_out2@units = data2@units + data_out2@_FillValue = 1.e+36 +; print (data_out2) + + data_out3!0 = "year" + data_out3!1 = "month" + data_out3@long_name = data3@long_name + data_out3@units = data3@units + data_out3@_FillValue = 1.e+36 +; print (data_out3) + + data_out4!0 = "year" + data_out4!1 = "month" + data_out4@long_name = data4@long_name + data_out4@units = data4@units + data_out4@_FillValue = 1.e+36 +; print (data_out4) + + time_out!0 = "year" + time_out!1 = "month" + time_out@long_name = "current date as yyyymm" + time_out@units = "current date as yyyymm" + print (time_out) + + lat_out!0 = "lat" + lon_out!0 = "lon" + lat_out@units = "degrees_north" + lat_out@long_name = "Latitude" + lon_out@units = "degrees_east" + lon_out@long_name = "Longitude" + print (lat_out) + print (lon_out) + + c->lat = lat_out + c->lon = lon_out + c->date = time_out + c->CO2_FLUX = data_out1 + c->RAD_FLUX = data_out2 + c->SH_FLUX = data_out3 + c->LH_FLUX = data_out4 + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/02.monthly_avg.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/02.monthly_avg.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,162 @@ +;************************************************ +; Read half-hourly data and write monthly data +; input data is : half-hourly +; +; output data is : CO2_flux, RAD_FLUX, SH_FLUX, LH_FLUX +; date, lat, lon +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + station_name = "LBA_Tapajos_KM67" + file_name_add = "ameriflux" + year_start = 2002 + year_end = 2005 + year_leap = 2004 + + lat_out = -3.01030 + lon_out = -54.58150 + 360. + +; final output + diro = dir_root + station_name + "/" + filo = station_name+"_"+year_start+"-"+year_end+"_monthly.nc" + c = addfile(diro+filo,"c") + print (filo) + +; input dir + diri = dir_root + station_name + "/" + + nyear = year_end - year_start + 1 + nmon = 12 + nlat = 1 + nlon = 1 + +; day_of_month = (/31.,28.,31.,30.,31.,30.,31.,31.,30.,31.,30.,31./) + end_of_month1 = (/31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334.,365./) + end_of_month2 = (/31.,60.,91.,121.,152.,182.,213.,244.,274.,305.,335.,366./) + + data_out1 = new((/nyear,nmon/),float) + data_out2 = new((/nyear,nmon/),float) + data_out3 = new((/nyear,nmon/),float) + data_out4 = new((/nyear,nmon/),float) + time_out = new((/nyear,nmon/),integer) +; lat_out = new((/nlat/),float) +; lon_out = new((/nlon/),float) + + do m = 0,nyear-1 + year = year_start + m + +; if (mod(year,4) .eq. 0) then + if (year .eq. year_leap) then + hour_of_month = end_of_month2 * 24. + else + hour_of_month = end_of_month1 * 24. + end if +; print (hour_of_month) + +; input file + fili = file_name_add+"."+station_name+"."+year+".nc" + b = addfile(diri+fili,"r") + print (fili) + +; co2 flux unit: umol m-2 s-1 + data1 = b->FCO2M +; net radiation flux unit: W m-2 + data2 = b->RN +; sensible heat flux unit: W m-2 + data3 = b->H +; latent heat flux unit: W m-2 + data4 = b->LE + +; time unit: hour since 01-01 (mm-dd) + time = b->time + + do n= 0,nmon-1 + if (n.eq.0) then + timeL = 0. + timeR = hour_of_month(0) + else + timeL = hour_of_month(n-1) + timeR = hour_of_month(n) + end if +; print (timeL) +; print (timeR) + + i = ind(time.ge.timeL .and. time.lt.timeR) +; print (i) + + data_out1(m,n) = avg(data1(i)) + data_out2(m,n) = avg(data2(i)) + data_out3(m,n) = avg(data3(i)) + data_out4(m,n) = avg(data4(i)) + + time_out(m,n) = year*100 + n + 1 +; print (time_out(m,n)) + + delete (i) + end do + if (m.lt.nyear-1) then + delete (data1) + delete (data2) + delete (data3) + delete (data4) + delete (time) + end if + end do + + data_out1!0 = "year" + data_out1!1 = "month" + data_out1@long_name = data1@long_name + data_out1@units = data1@units + data_out1@_FillValue = 1.e+36 +; print (data_out1) + + data_out2!0 = "year" + data_out2!1 = "month" + data_out2@long_name = data2@long_name + data_out2@units = data2@units + data_out2@_FillValue = 1.e+36 +; print (data_out2) + + data_out3!0 = "year" + data_out3!1 = "month" + data_out3@long_name = data3@long_name + data_out3@units = data3@units + data_out3@_FillValue = 1.e+36 +; print (data_out3) + + data_out4!0 = "year" + data_out4!1 = "month" + data_out4@long_name = data4@long_name + data_out4@units = data4@units + data_out4@_FillValue = 1.e+36 +; print (data_out4) + + time_out!0 = "year" + time_out!1 = "month" + time_out@long_name = "current date as yyyymm" + time_out@units = "current date as yyyymm" + print (time_out) + + lat_out!0 = "lat" + lon_out!0 = "lon" + lat_out@units = "degrees_north" + lat_out@long_name = "Latitude" + lon_out@units = "degrees_east" + lon_out@long_name = "Longitude" + print (lat_out) + print (lon_out) + + c->lat = lat_out + c->lon = lon_out + c->date = time_out + c->CO2_FLUX = data_out1 + c->RAD_FLUX = data_out2 + c->SH_FLUX = data_out3 + c->LH_FLUX = data_out4 + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/03.monthly_avg.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/03.monthly_avg.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,163 @@ +;************************************************ +; Read half-hourly data and write monthly data +; input data is : half-hourly +; +; output data is : CO2_flux, RAD_FLUX, SH_FLUX, LH_FLUX +; date, lat, lon +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + station_name = "Lethbridge" + file_name_add = "ameriflux" + year_start = 1999 + year_end = 2004 + year_leap1 = 2000 + year_leap2 = 2004 + + lat_out = 49.709278 + lon_out = -112.940167 + 360. + +; final output + diro = dir_root + station_name + "/" + filo = station_name+"_"+year_start+"-"+year_end+"_monthly.nc" + c = addfile(diro+filo,"c") + print (filo) + +; input dir + diri = dir_root + station_name + "/" + + nyear = year_end - year_start + 1 + nmon = 12 + nlat = 1 + nlon = 1 + +; day_of_month = (/31.,28.,31.,30.,31.,30.,31.,31.,30.,31.,30.,31./) + end_of_month1 = (/31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334.,365./) + end_of_month2 = (/31.,60.,91.,121.,152.,182.,213.,244.,274.,305.,335.,366./) + + data_out1 = new((/nyear,nmon/),float) + data_out2 = new((/nyear,nmon/),float) + data_out3 = new((/nyear,nmon/),float) + data_out4 = new((/nyear,nmon/),float) + time_out = new((/nyear,nmon/),integer) +; lat_out = new((/nlat/),float) +; lon_out = new((/nlon/),float) + + do m = 0,nyear-1 + year = year_start + m + +; if (mod(year,4) .eq. 0) then + if (year .eq. year_leap1 .or. year .eq. year_leap2 ) then + hour_of_month = end_of_month2 * 24. + else + hour_of_month = end_of_month1 * 24. + end if +; print (hour_of_month) + +; input file + fili = file_name_add+"."+station_name+"."+year+".nc" + b = addfile(diri+fili,"r") + print (fili) + +; co2 flux unit: umol m-2 s-1 + data1 = b->FCO2M +; net radiation flux unit: W m-2 + data2 = b->RN +; sensible heat flux unit: W m-2 + data3 = b->H +; latent heat flux unit: W m-2 + data4 = b->LE + +; time unit: hour since 01-01 (mm-dd) + time = b->time + + do n= 0,nmon-1 + if (n.eq.0) then + timeL = 0. + timeR = hour_of_month(0) + else + timeL = hour_of_month(n-1) + timeR = hour_of_month(n) + end if +; print (timeL) +; print (timeR) + + i = ind(time.ge.timeL .and. time.lt.timeR) +; print (i) + + data_out1(m,n) = avg(data1(i)) + data_out2(m,n) = avg(data2(i)) + data_out3(m,n) = avg(data3(i)) + data_out4(m,n) = avg(data4(i)) + + time_out(m,n) = year*100 + n + 1 +; print (time_out(m,n)) + + delete (i) + end do + if (m.lt.nyear-1) then + delete (data1) + delete (data2) + delete (data3) + delete (data4) + delete (time) + end if + end do + + data_out1!0 = "year" + data_out1!1 = "month" + data_out1@long_name = data1@long_name + data_out1@units = data1@units + data_out1@_FillValue = 1.e+36 +; print (data_out1) + + data_out2!0 = "year" + data_out2!1 = "month" + data_out2@long_name = data2@long_name + data_out2@units = data2@units + data_out2@_FillValue = 1.e+36 +; print (data_out2) + + data_out3!0 = "year" + data_out3!1 = "month" + data_out3@long_name = data3@long_name + data_out3@units = data3@units + data_out3@_FillValue = 1.e+36 +; print (data_out3) + + data_out4!0 = "year" + data_out4!1 = "month" + data_out4@long_name = data4@long_name + data_out4@units = data4@units + data_out4@_FillValue = 1.e+36 +; print (data_out4) + + time_out!0 = "year" + time_out!1 = "month" + time_out@long_name = "current date as yyyymm" + time_out@units = "current date as yyyymm" + print (time_out) + + lat_out!0 = "lat" + lon_out!0 = "lon" + lat_out@units = "degrees_north" + lat_out@long_name = "Latitude" + lon_out@units = "degrees_east" + lon_out@long_name = "Longitude" + print (lat_out) + print (lon_out) + + c->lat = lat_out + c->lon = lon_out + c->date = time_out + c->CO2_FLUX = data_out1 + c->RAD_FLUX = data_out2 + c->SH_FLUX = data_out3 + c->LH_FLUX = data_out4 + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/04.monthly_avg.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/04.monthly_avg.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,161 @@ +;************************************************ +; Read half-hourly data and write monthly data +; input data is : half-hourly +; +; output data is : CO2_flux, RAD_FLUX, SH_FLUX, LH_FLUX +; date, lat, lon +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + station_name = "Tharandt" + file_name_add = "carboeurope" + year_start = 1996 + year_end = 2003 + year_leap1 = 1996 + year_leap2 = 2000 + + lat_out = 50.9636 + lon_out = 13.5669 + +; final output + diro = dir_root + station_name + "/" + filo = station_name+"_"+year_start+"-"+year_end+"_monthly.nc" + c = addfile(diro+filo,"c") + print (filo) + +; input dir + diri = dir_root + station_name + "/" + + nyear = year_end - year_start + 1 + nmon = 12 + nlat = 1 + nlon = 1 + +; day_of_month = (/31.,28.,31.,30.,31.,30.,31.,31.,30.,31.,30.,31./) + end_of_month1 = (/31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334.,365./) + end_of_month2 = (/31.,60.,91.,121.,152.,182.,213.,244.,274.,305.,335.,366./) + + data_out1 = new((/nyear,nmon/),float) + data_out2 = new((/nyear,nmon/),float) + data_out3 = new((/nyear,nmon/),float) + data_out4 = new((/nyear,nmon/),float) + time_out = new((/nyear,nmon/),integer) + + do m = 0,nyear-1 + year = year_start + m + +; if (mod(year,4) .eq. 0) then + if (year .eq. year_leap1 .or. year .eq. year_leap2 ) then + hour_of_month = end_of_month2 * 24. + else + hour_of_month = end_of_month1 * 24. + end if +; print (hour_of_month) + +; input file + fili = file_name_add+"."+station_name+"."+year+".nc" + b = addfile(diri+fili,"r") + print (fili) + +; co2 flux unit: umol m-2 s-1 + data1 = b->FCO2M +; net radiation flux unit: W m-2 + data2 = b->RN +; sensible heat flux unit: W m-2 + data3 = b->H +; latent heat flux unit: W m-2 + data4 = b->LE + +; time unit: hour since 01-01 (mm-dd) + time = b->time + + do n= 0,nmon-1 + if (n.eq.0) then + timeL = 0. + timeR = hour_of_month(0) + else + timeL = hour_of_month(n-1) + timeR = hour_of_month(n) + end if +; print (timeL) +; print (timeR) + + i = ind(time.ge.timeL .and. time.lt.timeR) +; print (i) + + data_out1(m,n) = avg(data1(i)) + data_out2(m,n) = avg(data2(i)) + data_out3(m,n) = avg(data3(i)) + data_out4(m,n) = avg(data4(i)) + + time_out(m,n) = year*100 + n + 1 +; print (time_out(m,n)) + + delete (i) + end do + if (m.lt.nyear-1) then + delete (data1) + delete (data2) + delete (data3) + delete (data4) + delete (time) + end if + end do + + data_out1!0 = "year" + data_out1!1 = "month" + data_out1@long_name = data1@long_name + data_out1@units = data1@units + data_out1@_FillValue = 1.e+36 +; print (data_out1) + + data_out2!0 = "year" + data_out2!1 = "month" + data_out2@long_name = data2@long_name + data_out2@units = data2@units + data_out2@_FillValue = 1.e+36 +; print (data_out2) + + data_out3!0 = "year" + data_out3!1 = "month" + data_out3@long_name = data3@long_name + data_out3@units = data3@units + data_out3@_FillValue = 1.e+36 +; print (data_out3) + + data_out4!0 = "year" + data_out4!1 = "month" + data_out4@long_name = data4@long_name + data_out4@units = data4@units + data_out4@_FillValue = 1.e+36 +; print (data_out4) + + time_out!0 = "year" + time_out!1 = "month" + time_out@long_name = "current date as yyyymm" + time_out@units = "current date as yyyymm" + print (time_out) + + lat_out!0 = "lat" + lon_out!0 = "lon" + lat_out@units = "degrees_north" + lat_out@long_name = "Latitude" + lon_out@units = "degrees_east" + lon_out@long_name = "Longitude" + print (lat_out) + print (lon_out) + + c->lat = lat_out + c->lon = lon_out + c->date = time_out + c->CO2_FLUX = data_out1 + c->RAD_FLUX = data_out2 + c->SH_FLUX = data_out3 + c->LH_FLUX = data_out4 + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/05.monthly_avg.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/05.monthly_avg.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,161 @@ +;************************************************ +; Read half-hourly data and write monthly data +; input data is : half-hourly +; +; output data is : CO2_flux, RAD_FLUX, SH_FLUX, LH_FLUX +; date, lat, lon +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + station_name = "Vielsalm" + file_name_add = "carboeurope" + year_start = 1998 + year_end = 2003 + year_leap1 = 1996 + year_leap2 = 2000 + + lat_out = 50.3089 + lon_out = 5.99861 + +; final output + diro = dir_root + station_name + "/" + filo = station_name+"_"+year_start+"-"+year_end+"_monthly.nc" + c = addfile(diro+filo,"c") + print (filo) + +; input dir + diri = dir_root + station_name + "/" + + nyear = year_end - year_start + 1 + nmon = 12 + nlat = 1 + nlon = 1 + +; day_of_month = (/31.,28.,31.,30.,31.,30.,31.,31.,30.,31.,30.,31./) + end_of_month1 = (/31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334.,365./) + end_of_month2 = (/31.,60.,91.,121.,152.,182.,213.,244.,274.,305.,335.,366./) + + data_out1 = new((/nyear,nmon/),float) + data_out2 = new((/nyear,nmon/),float) + data_out3 = new((/nyear,nmon/),float) + data_out4 = new((/nyear,nmon/),float) + time_out = new((/nyear,nmon/),integer) + + do m = 0,nyear-1 + year = year_start + m + +; if (mod(year,4) .eq. 0) then + if (year .eq. year_leap1 .or. year .eq. year_leap2 ) then + hour_of_month = end_of_month2 * 24. + else + hour_of_month = end_of_month1 * 24. + end if +; print (hour_of_month) + +; input file + fili = file_name_add+"."+station_name+"."+year+".nc" + b = addfile(diri+fili,"r") + print (fili) + +; co2 flux unit: umol m-2 s-1 + data1 = b->FCO2M +; net radiation flux unit: W m-2 + data2 = b->RN +; sensible heat flux unit: W m-2 + data3 = b->H +; latent heat flux unit: W m-2 + data4 = b->LE + +; time unit: hour since 01-01 (mm-dd) + time = b->time + + do n= 0,nmon-1 + if (n.eq.0) then + timeL = 0. + timeR = hour_of_month(0) + else + timeL = hour_of_month(n-1) + timeR = hour_of_month(n) + end if +; print (timeL) +; print (timeR) + + i = ind(time.ge.timeL .and. time.lt.timeR) +; print (i) + + data_out1(m,n) = avg(data1(i)) + data_out2(m,n) = avg(data2(i)) + data_out3(m,n) = avg(data3(i)) + data_out4(m,n) = avg(data4(i)) + + time_out(m,n) = year*100 + n + 1 +; print (time_out(m,n)) + + delete (i) + end do + if (m.lt.nyear-1) then + delete (data1) + delete (data2) + delete (data3) + delete (data4) + delete (time) + end if + end do + + data_out1!0 = "year" + data_out1!1 = "month" + data_out1@long_name = data1@long_name + data_out1@units = data1@units + data_out1@_FillValue = 1.e+36 +; print (data_out1) + + data_out2!0 = "year" + data_out2!1 = "month" + data_out2@long_name = data2@long_name + data_out2@units = data2@units + data_out2@_FillValue = 1.e+36 +; print (data_out2) + + data_out3!0 = "year" + data_out3!1 = "month" + data_out3@long_name = data3@long_name + data_out3@units = data3@units + data_out3@_FillValue = 1.e+36 +; print (data_out3) + + data_out4!0 = "year" + data_out4!1 = "month" + data_out4@long_name = data4@long_name + data_out4@units = data4@units + data_out4@_FillValue = 1.e+36 +; print (data_out4) + + time_out!0 = "year" + time_out!1 = "month" + time_out@long_name = "current date as yyyymm" + time_out@units = "current date as yyyymm" + print (time_out) + + lat_out!0 = "lat" + lon_out!0 = "lon" + lat_out@units = "degrees_north" + lat_out@long_name = "Latitude" + lon_out@units = "degrees_east" + lon_out@long_name = "Longitude" + print (lat_out) + print (lon_out) + + c->lat = lat_out + c->lon = lon_out + c->date = time_out + c->CO2_FLUX = data_out1 + c->RAD_FLUX = data_out2 + c->SH_FLUX = data_out3 + c->LH_FLUX = data_out4 + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/06.monthly_avg.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/06.monthly_avg.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,162 @@ +;************************************************ +; Read half-hourly data and write monthly data +; input data is : half-hourly +; +; output data is : CO2_flux, RAD_FLUX, SH_FLUX, LH_FLUX +; date, lat, lon +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + station_name = "BOREAS_NSA_OBS" + file_name_add = "ameriflux" + year_start = 1994 + year_end = 2004 + year_leap1 = 1996 + year_leap2 = 2000 + year_leap3 = 2004 + + lat_out = 55.879620 + lon_out = -98.480810 + 360. + +; final output + diro = dir_root + station_name + "/" + filo = station_name+"_"+year_start+"-"+year_end+"_monthly.nc" + c = addfile(diro+filo,"c") + print (filo) + +; input dir + diri = dir_root + station_name + "/" + + nyear = year_end - year_start + 1 + nmon = 12 + nlat = 1 + nlon = 1 + +; day_of_month = (/31.,28.,31.,30.,31.,30.,31.,31.,30.,31.,30.,31./) + end_of_month1 = (/31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334.,365./) + end_of_month2 = (/31.,60.,91.,121.,152.,182.,213.,244.,274.,305.,335.,366./) + + data_out1 = new((/nyear,nmon/),float) + data_out2 = new((/nyear,nmon/),float) + data_out3 = new((/nyear,nmon/),float) + data_out4 = new((/nyear,nmon/),float) + time_out = new((/nyear,nmon/),integer) + + do m = 0,nyear-1 + year = year_start + m + +; if (mod(year,4) .eq. 0) then + if (year.eq.year_leap1.or.year.eq.year_leap2.or.year.eq.year_leap3) then + hour_of_month = end_of_month2 * 24. + else + hour_of_month = end_of_month1 * 24. + end if +; print (hour_of_month) + +; input file + fili = file_name_add+"."+station_name+"."+year+".nc" + b = addfile(diri+fili,"r") + print (fili) + +; co2 flux unit: umol m-2 s-1 + data1 = b->FCO2M +; net radiation flux unit: W m-2 + data2 = b->RN +; sensible heat flux unit: W m-2 + data3 = b->H +; latent heat flux unit: W m-2 + data4 = b->LE + +; time unit: hour since 01-01 (mm-dd) + time = b->time + + do n= 0,nmon-1 + if (n.eq.0) then + timeL = 0. + timeR = hour_of_month(0) + else + timeL = hour_of_month(n-1) + timeR = hour_of_month(n) + end if +; print (timeL) +; print (timeR) + + i = ind(time.ge.timeL .and. time.lt.timeR) +; print (i) + + data_out1(m,n) = avg(data1(i)) + data_out2(m,n) = avg(data2(i)) + data_out3(m,n) = avg(data3(i)) + data_out4(m,n) = avg(data4(i)) + + time_out(m,n) = year*100 + n + 1 +; print (time_out(m,n)) + + delete (i) + end do + if (m.lt.nyear-1) then + delete (data1) + delete (data2) + delete (data3) + delete (data4) + delete (time) + end if + end do + + data_out1!0 = "year" + data_out1!1 = "month" + data_out1@long_name = data1@long_name + data_out1@units = data1@units + data_out1@_FillValue = 1.e+36 +; print (data_out1) + + data_out2!0 = "year" + data_out2!1 = "month" + data_out2@long_name = data2@long_name + data_out2@units = data2@units + data_out2@_FillValue = 1.e+36 +; print (data_out2) + + data_out3!0 = "year" + data_out3!1 = "month" + data_out3@long_name = data3@long_name + data_out3@units = data3@units + data_out3@_FillValue = 1.e+36 +; print (data_out3) + + data_out4!0 = "year" + data_out4!1 = "month" + data_out4@long_name = data4@long_name + data_out4@units = data4@units + data_out4@_FillValue = 1.e+36 +; print (data_out4) + + time_out!0 = "year" + time_out!1 = "month" + time_out@long_name = "current date as yyyymm" + time_out@units = "current date as yyyymm" + print (time_out) + + lat_out!0 = "lat" + lon_out!0 = "lon" + lat_out@units = "degrees_north" + lat_out@long_name = "Latitude" + lon_out@units = "degrees_east" + lon_out@long_name = "Longitude" + print (lat_out) + print (lon_out) + + c->lat = lat_out + c->lon = lon_out + c->date = time_out + c->CO2_FLUX = data_out1 + c->RAD_FLUX = data_out2 + c->SH_FLUX = data_out3 + c->LH_FLUX = data_out4 + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/07.monthly_avg.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/07.monthly_avg.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,169 @@ +;************************************************ +; Read half-hourly data and write monthly data +; input data is : half-hourly +; +; output data is : CO2_flux, RAD_FLUX, SH_FLUX, LH_FLUX +; date, lat, lon +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;!!!!!!!!!!!!!!!!!!!!!!!!!!!! +; missing year 1999 +;!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + station_name = "CastelPorziano" + file_name_add = "carboeurope" + year_start = 1997 + year_end = 2003 + year_leap1 = 1996 + year_leap2 = 2000 + year_leap3 = 2004 + + lat_out = 41.7058 + lon_out = 12.3773 + +; final output + diro = dir_root + station_name + "/" + filo = station_name+"_"+year_start+"-"+year_end+"_monthly.nc" + c = addfile(diro+filo,"c") + print (filo) + +; input dir + diri = dir_root + station_name + "/" + + nyear = year_end - year_start + 1 - 1 + nmon = 12 + nlat = 1 + nlon = 1 + +; day_of_month = (/31.,28.,31.,30.,31.,30.,31.,31.,30.,31.,30.,31./) + end_of_month1 = (/31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334.,365./) + end_of_month2 = (/31.,60.,91.,121.,152.,182.,213.,244.,274.,305.,335.,366./) + + data_out1 = new((/nyear,nmon/),float) + data_out2 = new((/nyear,nmon/),float) + data_out3 = new((/nyear,nmon/),float) + data_out4 = new((/nyear,nmon/),float) + time_out = new((/nyear,nmon/),integer) + + do m = 0,nyear-1 + year = year_start + m + + if (m.ge.2) then + year = year + 1 + end if + +; if (mod(year,4) .eq. 0) then + if (year.eq.year_leap1.or.year.eq.year_leap2.or.year.eq.year_leap3) then + hour_of_month = end_of_month2 * 24. + else + hour_of_month = end_of_month1 * 24. + end if +; print (hour_of_month) + +; input file + fili = file_name_add+"."+station_name+"."+year+".nc" + b = addfile(diri+fili,"r") + print (fili) + +; co2 flux unit: umol m-2 s-1 + data1 = b->FCO2M +; net radiation flux unit: W m-2 + data2 = b->RN +; sensible heat flux unit: W m-2 + data3 = b->H +; latent heat flux unit: W m-2 + data4 = b->LE + +; time unit: hour since 01-01 (mm-dd) + time = b->time + + do n= 0,nmon-1 + if (n.eq.0) then + timeL = 0. + timeR = hour_of_month(0) + else + timeL = hour_of_month(n-1) + timeR = hour_of_month(n) + end if +; print (timeL) +; print (timeR) + + i = ind(time.ge.timeL .and. time.lt.timeR) +; print (i) + + data_out1(m,n) = avg(data1(i)) + data_out2(m,n) = avg(data2(i)) + data_out3(m,n) = avg(data3(i)) + data_out4(m,n) = avg(data4(i)) + + time_out(m,n) = year*100 + n + 1 +; print (time_out(m,n)) + + delete (i) + end do + if (m.lt.nyear-1) then + delete (data1) + delete (data2) + delete (data3) + delete (data4) + delete (time) + end if + end do + + data_out1!0 = "year" + data_out1!1 = "month" + data_out1@long_name = data1@long_name + data_out1@units = data1@units + data_out1@_FillValue = 1.e+36 +; print (data_out1) + + data_out2!0 = "year" + data_out2!1 = "month" + data_out2@long_name = data2@long_name + data_out2@units = data2@units + data_out2@_FillValue = 1.e+36 +; print (data_out2) + + data_out3!0 = "year" + data_out3!1 = "month" + data_out3@long_name = data3@long_name + data_out3@units = data3@units + data_out3@_FillValue = 1.e+36 +; print (data_out3) + + data_out4!0 = "year" + data_out4!1 = "month" + data_out4@long_name = data4@long_name + data_out4@units = data4@units + data_out4@_FillValue = 1.e+36 +; print (data_out4) + + time_out!0 = "year" + time_out!1 = "month" + time_out@long_name = "current date as yyyymm" + time_out@units = "current date as yyyymm" + print (time_out) + + lat_out!0 = "lat" + lon_out!0 = "lon" + lat_out@units = "degrees_north" + lat_out@long_name = "Latitude" + lon_out@units = "degrees_east" + lon_out@long_name = "Longitude" + print (lat_out) + print (lon_out) + + c->lat = lat_out + c->lon = lon_out + c->date = time_out + c->CO2_FLUX = data_out1 + c->RAD_FLUX = data_out2 + c->SH_FLUX = data_out3 + c->LH_FLUX = data_out4 + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/08.monthly_avg.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/08.monthly_avg.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,162 @@ +;************************************************ +; Read half-hourly data and write monthly data +; input data is : half-hourly +; +; output data is : CO2_flux, RAD_FLUX, SH_FLUX, LH_FLUX +; date, lat, lon +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + station_name = "Hyytiala" + file_name_add = "carboeurope" + year_start = 1996 + year_end = 2003 + year_leap1 = 1996 + year_leap2 = 2000 + year_leap3 = 2004 + + lat_out = 61.8474 + lon_out = 24.2948 + +; final output + diro = dir_root + station_name + "/" + filo = station_name+"_"+year_start+"-"+year_end+"_monthly.nc" + c = addfile(diro+filo,"c") + print (filo) + +; input dir + diri = dir_root + station_name + "/" + + nyear = year_end - year_start + 1 + nmon = 12 + nlat = 1 + nlon = 1 + +; day_of_month = (/31.,28.,31.,30.,31.,30.,31.,31.,30.,31.,30.,31./) + end_of_month1 = (/31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334.,365./) + end_of_month2 = (/31.,60.,91.,121.,152.,182.,213.,244.,274.,305.,335.,366./) + + data_out1 = new((/nyear,nmon/),float) + data_out2 = new((/nyear,nmon/),float) + data_out3 = new((/nyear,nmon/),float) + data_out4 = new((/nyear,nmon/),float) + time_out = new((/nyear,nmon/),integer) + + do m = 0,nyear-1 + year = year_start + m + +; if (mod(year,4) .eq. 0) then + if (year.eq.year_leap1.or.year.eq.year_leap2.or.year.eq.year_leap3) then + hour_of_month = end_of_month2 * 24. + else + hour_of_month = end_of_month1 * 24. + end if +; print (hour_of_month) + +; input file + fili = file_name_add+"."+station_name+"."+year+".nc" + b = addfile(diri+fili,"r") + print (fili) + +; co2 flux unit: umol m-2 s-1 + data1 = b->FCO2M +; net radiation flux unit: W m-2 + data2 = b->RN +; sensible heat flux unit: W m-2 + data3 = b->H +; latent heat flux unit: W m-2 + data4 = b->LE + +; time unit: hour since 01-01 (mm-dd) + time = b->time + + do n= 0,nmon-1 + if (n.eq.0) then + timeL = 0. + timeR = hour_of_month(0) + else + timeL = hour_of_month(n-1) + timeR = hour_of_month(n) + end if +; print (timeL) +; print (timeR) + + i = ind(time.ge.timeL .and. time.lt.timeR) +; print (i) + + data_out1(m,n) = avg(data1(i)) + data_out2(m,n) = avg(data2(i)) + data_out3(m,n) = avg(data3(i)) + data_out4(m,n) = avg(data4(i)) + + time_out(m,n) = year*100 + n + 1 +; print (time_out(m,n)) + + delete (i) + end do + if (m.lt.nyear-1) then + delete (data1) + delete (data2) + delete (data3) + delete (data4) + delete (time) + end if + end do + + data_out1!0 = "year" + data_out1!1 = "month" + data_out1@long_name = data1@long_name + data_out1@units = data1@units + data_out1@_FillValue = 1.e+36 +; print (data_out1) + + data_out2!0 = "year" + data_out2!1 = "month" + data_out2@long_name = data2@long_name + data_out2@units = data2@units + data_out2@_FillValue = 1.e+36 +; print (data_out2) + + data_out3!0 = "year" + data_out3!1 = "month" + data_out3@long_name = data3@long_name + data_out3@units = data3@units + data_out3@_FillValue = 1.e+36 +; print (data_out3) + + data_out4!0 = "year" + data_out4!1 = "month" + data_out4@long_name = data4@long_name + data_out4@units = data4@units + data_out4@_FillValue = 1.e+36 +; print (data_out4) + + time_out!0 = "year" + time_out!1 = "month" + time_out@long_name = "current date as yyyymm" + time_out@units = "current date as yyyymm" + print (time_out) + + lat_out!0 = "lat" + lon_out!0 = "lon" + lat_out@units = "degrees_north" + lat_out@long_name = "Latitude" + lon_out@units = "degrees_east" + lon_out@long_name = "Longitude" + print (lat_out) + print (lon_out) + + c->lat = lat_out + c->lon = lon_out + c->date = time_out + c->CO2_FLUX = data_out1 + c->RAD_FLUX = data_out2 + c->SH_FLUX = data_out3 + c->LH_FLUX = data_out4 + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/97.all.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/97.all.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,421 @@ +; *********************************************** +; using gsn_table for all +; output: line plot for each site (4 fields) +; table for M_score +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ + model_name = "newcn" + film = "newcn05_ncep_1i_MONS_climo_lnd.nc" + +; model_name = "b30.061n" +; film = "b30.061n_1995-2004_MONS_climo_lnd.nc" +;-------------------------------------------- + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile(dirm+film,"r") + + xm = fm->lon + ym = fm->lat + nlat = dimsizes(ym) + nlon = dimsizes(xm) + + nmon = 12 + nfield = 4 + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + data = fm->NEE + + factor = 1e6/12. + + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:) + delete (data1) + delete (data2) + +; printVarSummary (data_mod0) +;************************************************ +; read in data: observed +;************************************************ + station = (/"BOREAS_NSA_OBS" \ + ,"CastelPorziano" \ + ,"Hyytiala" \ + ,"Kaamanen" \ + ,"LBA_Tapajos_KM67" \ + ,"Lethbridge" \ + ,"Tharandt" \ + ,"Vielsalm" \ + /) + + year_ob = (/"1994-2004" \ + ,"1997-2003" \ + ,"1996-2003" \ + ,"2000-2003" \ + ,"2002-2005" \ + ,"1999-2004" \ + ,"1996-2003" \ + ,"1998-2003" \ + /) + + field = (/"CO2 Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + /) + + nstation = dimsizes(station) + nmon = 12 + nfield = dimsizes(field) + + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + + diri_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + + do n = 0,nstation-1 + diri = diri_root + station(n)+"/" + fili = station(n)+"_"+year_ob(n)+"_monthly.nc" + g = addfile (diri+fili,"r") + + lon_ob(n) = g->lon + lat_ob(n) = g->lat + + data = g->CO2_FLUX + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->RAD_FLUX + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->LH_FLUX + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->SH_FLUX + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (g) + end do + +;print (lat_ob) +;print (lon_ob) +;printVarSummary (data_ob) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) +; print (ym(0)) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0) + + delete (data_mod0) + yy!0 = "field" + data_mod = yy(pts|:,field|:,time|:) +; printVarSummary (data_mod) + +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data(1,:) = (/data_mod(n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data(1,:) = (/data_mod(n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data(1,:) = (/data_mod(n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data(1,:) = (/data_mod(n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + clear (wks) + delete (plot) + end do + +;******************************************************************* +; for table of site score +;******************************************************************* + + table_length = 0.8 + +; table header name + table_header_name = "Site" + +; column (not including header column) + col_header = (/"Latitude","Longitude","observed" \ + ,"CO2 Flux","Net Radiation","Latent Heat" \ + ,"Sensible Heat","Average" \ + /) + ncol = dimsizes(col_header) + +; row (not including header row) + nrow = nstation + 1 + row_header = new ((/nrow/),string ) + row_header(0:nstation-1) = station(:) + row_header(nrow-1) = "All Sites" + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.800,0.895/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.010 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" + color_fill4(:,ncol-1) = "grey" + color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-2 + text4(n,0) = sprintf("%5.2f", lat_ob(n)) + text4(n,1) = sprintf("%5.2f", lon_ob(n)) + text4(n,2) = year_ob(n) + text4(n,3) = sprintf("%5.2f", M_score(n,0)) ; CO2 Flux + text4(n,4) = sprintf("%5.2f", M_score(n,1)) ; Net Radiation + text4(n,5) = sprintf("%5.2f", M_score(n,2)) ; Latent Heat + text4(n,6) = sprintf("%5.2f", M_score(n,3)) ; Sensible Heat + text4(n,7) = sprintf("%5.2f", avg(M_score(n,:))) ; avg all fields + end do + +; for the last row + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_all = M_co2+ M_rad +M_lh + M_sh + + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = sprintf("%5.2f", M_co2) ; avg all sites + text4(nrow-1,4) = sprintf("%5.2f", M_rad) ; avg all sites + text4(nrow-1,5) = sprintf("%5.2f", M_lh ) ; avg all sites + text4(nrow-1,6) = sprintf("%5.2f", M_sh ) ; avg all sites + text4(nrow-1,7) = sprintf("%5.2f", M_all) ; avg all sites + + print (M_co2) + print (M_rad) + print (M_lh ) + print (M_sh) + print (M_all) +;--------------------------------------------------------------------------- + + plot_name = "table_site_score" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Model " + model_name + " M_Score" + + gsn_text_ndc(wks,title_text,0.50,0.95,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +;------------------------------------------------------------------- + temp_name = "temp." + model_name + system("mkdir -p " + temp_name) + system("mv *.png " + temp_name) + system("tar cf "+ temp_name +".tar " + temp_name) +;------------------------------------------------------------------- + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/99.all.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/99.all.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,553 @@ +;************************************************************ +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; using gsn_table for all +; output: line plot for each site (4 fields) +; table for M_score +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ + +; from command line inputs + +;-------------------------------------------------- +; edit table.html of current model for movel1_vs_model2 + + if (isvar("compare")) then + html_name2 = compare+"/table.html" + html_new2 = html_name2 +".new" + +; the following only needs to execute once +; system("sed 1,/model_nameA/s//"+model_name+"/ "+html_name2+" > "+html_new2+";"+ \ +; "mv -f "+html_new2+" "+html_name2+";"+ \ +; "sed 1,/model_nameB/s//"+model_name+"/ "+html_name2+" > "+html_new2+";"+ \ +; "mv -f "+html_new2+" "+html_name2+";"+ \ +; "sed s#"+modeln+"#"+model_name+"# "+html_name2+" > "+html_new2+";"+ \ +; "mv -f "+html_new2+" "+html_name2) + end if + +;------------------------------------- +; edit table.html for current model + + html_name = model_name+"/table.html" + html_new = html_name +".new" + +; the following only needs to execute once +; system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new+";"+ \ +; "mv -f "+html_new+" "+html_name) +;------------------------------------------------ + fm = addfile(dirm+film2,"r") + + xm = fm->lon + ym = fm->lat +;------------------------------------------------ + nlat = dimsizes(ym) + nlon = dimsizes(xm) + +; for 4 fields, 12-monthly + nmon = 12 + nfield = 4 + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + + data = fm->SENSIBLE + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) +end if + +;************************************************ +; read data: observed +;************************************************ + + station = (/"BOREAS_NSA_OBS" \ + ,"CastelPorziano" \ + ,"Hyytiala" \ + ,"Kaamanen" \ + ,"LBA_Tapajos_KM67" \ + ,"Lethbridge" \ + ,"Tharandt" \ + ,"Vielsalm" \ + /) + + year_ob = (/"1994-2004" \ + ,"1997-2003" \ + ,"1996-2003" \ + ,"2000-2003" \ + ,"2002-2005" \ + ,"1999-2004" \ + ,"1996-2003" \ + ,"1998-2003" \ + /) + + field = (/"CO2 Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + /) + + nstation = dimsizes(station) + nmon = 12 + nfield = dimsizes(field) + + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + + diri_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + + do n = 0,nstation-1 + diri = diri_root + station(n)+"/" + fili = station(n)+"_"+year_ob(n)+"_monthly.nc" + g = addfile (diri+fili,"r") + + lon_ob(n) = g->lon + lat_ob(n) = g->lat + + data = g->CO2_FLUX + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->RAD_FLUX + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->LH_FLUX + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->SH_FLUX + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (g) + end do + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0) + + delete (data_mod0) + yy!0 = "field" + data_mod = yy(pts|:,field|:,time|:) + +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_all = M_co2+ M_rad +M_lh + M_sh + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data(1,:) = (/data_mod(n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data(1,:) = (/data_mod(n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data(1,:) = (/data_mod(n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data(1,:) = (/data_mod(n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + txt4 = sprintf("%5.2f", M_score(n,0)) + txt5 = sprintf("%5.2f", M_score(n,1)) + txt6 = sprintf("%5.2f", M_score(n,2)) + txt7 = sprintf("%5.2f", M_score(n,3)) + txt8 = sprintf("%5.2f", avg(M_score(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;************************************************************************************** +; update score +;************************************************************************************** + + if (isvar("compare")) then + system("sed 1,/M_energy_co2/s//"+M_energy_co2+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed 1,/M_energy_rad/s//"+M_energy_rad+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed 1,/M_energy_lh/s//"+M_energy_lh+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2+";"+ \ + "sed 1,/M_energy_sh/s//"+M_energy_sh+"/ "+html_name2+" > "+html_new2+";"+ \ + "mv -f "+html_new2+" "+html_name2) + end if + + system("sed s#M_energy_co2#"+M_energy_co2+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_energy_rad#"+M_energy_rad+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_energy_lh#"+M_energy_lh+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name+";"+ \ + "sed s#M_energy_sh#"+M_energy_sh+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/energy" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 energy/99.all.ncl.0 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/99.all.ncl.0 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,420 @@ +; *********************************************** +; using gsn_table for all +; output: line plot for each site (4 fields) +; table for M_score +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ +; model_name = "06cn" +; film = "i01.06cn_1798-2004_MONS_climo.nc" + +; model_name = "06casa" +; film = "i01.06casa_1798-2004_MONS_climo.nc" + +; model_name = "10cn" +; film = "i01.10cn_1948-2004_MONS_climo.nc" + + model_name = "10casa" + film = "i01.10casa_1948-2004_MONS_climo.nc" +;-------------------------------------------- + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile(dirm+film,"r") + + xm = fm->lon + ym = fm->lat + nlat = dimsizes(ym) + nlon = dimsizes(xm) + + nmon = 12 + nfield = 4 + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + data = fm->NEE + + factor = 1e6 /12. + + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + + data = fm->SENSIBLE + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; printVarSummary (data_mod0) +;************************************************ +; read in data: observed +;************************************************ + station = (/"BOREAS_NSA_OBS" \ + ,"CastelPorziano" \ + ,"Hyytiala" \ + ,"Kaamanen" \ + ,"LBA_Tapajos_KM67" \ + ,"Lethbridge" \ + ,"Tharandt" \ + ,"Vielsalm" \ + /) + + year_ob = (/"1994-2004" \ + ,"1997-2003" \ + ,"1996-2003" \ + ,"2000-2003" \ + ,"2002-2005" \ + ,"1999-2004" \ + ,"1996-2003" \ + ,"1998-2003" \ + /) + + field = (/"CO2 Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + /) + + nstation = dimsizes(station) + nmon = 12 + nfield = dimsizes(field) + + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + + diri_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + + do n = 0,nstation-1 + diri = diri_root + station(n)+"/" + fili = station(n)+"_"+year_ob(n)+"_monthly.nc" + g = addfile (diri+fili,"r") + + lon_ob(n) = g->lon + lat_ob(n) = g->lat + + data = g->CO2_FLUX + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->RAD_FLUX + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->LH_FLUX + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->SH_FLUX + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (g) + end do + +;print (lat_ob) +;print (lon_ob) +;printVarSummary (data_ob) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) +; print (ym(0)) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0) + + delete (data_mod0) + yy!0 = "field" + data_mod = yy(pts|:,field|:,time|:) +; printVarSummary (data_mod) + +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data(1,:) = (/data_mod(n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data(1,:) = (/data_mod(n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data(1,:) = (/data_mod(n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data(1,:) = (/data_mod(n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + clear (wks) + delete (plot) + end do + +;******************************************************************* +; for table of site score +;******************************************************************* + + table_length = 0.8 + +; table header name + table_header_name = "Site" + +; column (not including header column) + col_header = (/"Latitude","Longitude","observed" \ + ,"CO2 Flux","Net Radiation","Latent Heat" \ + ,"Sensible Heat","Average" \ + /) + ncol = dimsizes(col_header) + +; row (not including header row) + nrow = nstation + 1 + row_header = new ((/nrow/),string ) + row_header(0:nstation-1) = station(:) + row_header(nrow-1) = "All Sites" + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.800,0.895/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.010 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" + color_fill4(:,ncol-1) = "grey" + color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-2 + text4(n,0) = sprintf("%5.2f", lat_ob(n)) + text4(n,1) = sprintf("%5.2f", lon_ob(n)) + text4(n,2) = year_ob(n) + text4(n,3) = sprintf("%5.2f", M_score(n,0)) ; CO2 Flux + text4(n,4) = sprintf("%5.2f", M_score(n,1)) ; Net Radiation + text4(n,5) = sprintf("%5.2f", M_score(n,2)) ; Latent Heat + text4(n,6) = sprintf("%5.2f", M_score(n,3)) ; Sensible Heat + text4(n,7) = sprintf("%5.2f", avg(M_score(n,:))) ; avg all fields + end do + +; for the last row + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_all = M_co2+ M_rad +M_lh + M_sh + + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = sprintf("%5.2f", M_co2) ; avg all sites + text4(nrow-1,4) = sprintf("%5.2f", M_rad) ; avg all sites + text4(nrow-1,5) = sprintf("%5.2f", M_lh ) ; avg all sites + text4(nrow-1,6) = sprintf("%5.2f", M_sh ) ; avg all sites + text4(nrow-1,7) = sprintf("%5.2f", M_all) ; avg all sites + + print (M_co2) + print (M_rad) + print (M_lh ) + print (M_sh) + print (M_all) +;--------------------------------------------------------------------------- + + plot_name = "table_site_score" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Model " + model_name + " M_Score" + + gsn_text_ndc(wks,title_text,0.50,0.95,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +;------------------------------------------------------------------- + temp_name = "temp." + model_name + system("mkdir -p " + temp_name) + system("mv *.png " + temp_name) + system("tar cf "+ temp_name +".tar " + temp_name) +;------------------------------------------------------------------- + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/99.all.ncl.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/99.all.ncl.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,438 @@ +; *********************************************** +; using gsn_table for all +; output: line plot for each site (4 fields) +; table for M_score +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ + model_name = "10cn" + film = "i01.10cn_1948-2004_MONS_climo.nc" + +; model_name = "10casa" +; film = "i01.10casa_1948-2004_MONS_climo.nc" + + system("sed s#model_name#"+model_name+"# table.html > table.html.new") + system("mv -f table.html.new table.html") +;-------------------------------------------- + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile(dirm+film,"r") + + xm = fm->lon + ym = fm->lat + nlat = dimsizes(ym) + nlon = dimsizes(xm) + + nmon = 12 + nfield = 4 + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + data = fm->NEE + + factor = 1e6 /12. + + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + + data = fm->SENSIBLE + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; printVarSummary (data_mod0) +;************************************************ +; read in data: observed +;************************************************ + station = (/"BOREAS_NSA_OBS" \ + ,"CastelPorziano" \ + ,"Hyytiala" \ + ,"Kaamanen" \ + ,"LBA_Tapajos_KM67" \ + ,"Lethbridge" \ + ,"Tharandt" \ + ,"Vielsalm" \ + /) + + year_ob = (/"1994-2004" \ + ,"1997-2003" \ + ,"1996-2003" \ + ,"2000-2003" \ + ,"2002-2005" \ + ,"1999-2004" \ + ,"1996-2003" \ + ,"1998-2003" \ + /) + + field = (/"CO2 Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + /) + + nstation = dimsizes(station) + nmon = 12 + nfield = dimsizes(field) + + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + + diri_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + + do n = 0,nstation-1 + diri = diri_root + station(n)+"/" + fili = station(n)+"_"+year_ob(n)+"_monthly.nc" + g = addfile (diri+fili,"r") + + lon_ob(n) = g->lon + lat_ob(n) = g->lat + + data = g->CO2_FLUX + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->RAD_FLUX + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->LH_FLUX + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->SH_FLUX + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (g) + end do + +;print (lat_ob) +;print (lon_ob) +;printVarSummary (data_ob) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) +; print (ym(0)) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0) + + delete (data_mod0) + yy!0 = "field" + data_mod = yy(pts|:,field|:,time|:) +; printVarSummary (data_mod) + +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data(1,:) = (/data_mod(n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data(1,:) = (/data_mod(n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data(1,:) = (/data_mod(n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data(1,:) = (/data_mod(n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + clear (wks) + delete (plot) + end do + +;******************************************************************* +; for table of site score +;******************************************************************* + + table_length = 0.8 + +; table header name + table_header_name = "Site" + +; column (not including header column) + col_header = (/"Latitude","Longitude","observed" \ + ,"CO2 Flux","Net Radiation","Latent Heat" \ + ,"Sensible Heat","Average" \ + /) + ncol = dimsizes(col_header) + +; row (not including header row) + nrow = nstation + 1 + row_header = new ((/nrow/),string ) + row_header(0:nstation-1) = station(:) + row_header(nrow-1) = "All Sites" + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.800,0.895/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.010 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" + color_fill4(:,ncol-1) = "grey" + color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-2 + text4(n,0) = sprintf("%5.2f", lat_ob(n)) + text4(n,1) = sprintf("%5.2f", lon_ob(n)) + text4(n,2) = year_ob(n) + text4(n,3) = sprintf("%5.2f", M_score(n,0)) ; CO2 Flux + text4(n,4) = sprintf("%5.2f", M_score(n,1)) ; Net Radiation + text4(n,5) = sprintf("%5.2f", M_score(n,2)) ; Latent Heat + text4(n,6) = sprintf("%5.2f", M_score(n,3)) ; Sensible Heat + text4(n,7) = sprintf("%5.2f", avg(M_score(n,:))) ; avg all fields + end do + +; for the last row + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_all = M_co2+ M_rad +M_lh + M_sh + + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = sprintf("%5.2f", M_co2) ; avg all sites + text4(nrow-1,4) = sprintf("%5.2f", M_rad) ; avg all sites + text4(nrow-1,5) = sprintf("%5.2f", M_lh ) ; avg all sites + text4(nrow-1,6) = sprintf("%5.2f", M_sh ) ; avg all sites + text4(nrow-1,7) = sprintf("%5.2f", M_all) ; avg all sites + + print (M_co2) + print (M_rad) + print (M_lh ) + print (M_sh) + print (M_all) + + M_energy_co2 = sprintf("%.2f", M_co2) + system("sed s#M_energy_co2#"+M_energy_co2+"# table.html > table.html.new") + system("mv -f table.html.new table.html") + print (M_energy_co2) + + M_energy_rad = sprintf("%.2f", M_rad) + system("sed s#M_energy_rad#"+M_energy_rad+"# table.html > table.html.new") + system("mv -f table.html.new table.html") + print (M_energy_rad) + + M_energy_lh = sprintf("%.2f", M_lh) + system("sed s#M_energy_lh#"+M_energy_lh+"# table.html > table.html.new") + system("mv -f table.html.new table.html") + print (M_energy_lh) + + M_energy_sh = sprintf("%.2f", M_sh) + system("sed s#M_energy_sh#"+M_energy_sh+"# table.html > table.html.new") + system("mv -f table.html.new table.html") + print (M_energy_sh) +;--------------------------------------------------------------------------- + + plot_name = "table_site_score" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Model " + model_name + " M_Score" + + gsn_text_ndc(wks,title_text,0.50,0.95,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +;------------------------------------------------------------------- + temp_name = "energy." + model_name + system("mkdir -p " + temp_name) + system("cp table.html " + temp_name) + system("mv *.png " + temp_name) + system("tar cf "+ temp_name +".tar " + temp_name) +;------------------------------------------------------------------- + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/99.all.ncl.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/99.all.ncl.2 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,442 @@ +; *********************************************** +; using gsn_table for all +; output: line plot for each site (4 fields) +; table for M_score +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl" +;************************************************ +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ + model_name = "10cn" + film = "i01.10cn_1948-2004_MONS_climo.nc" + +; model_name = "10casa" +; film = "i01.10casa_1948-2004_MONS_climo.nc" +;------------------------------------------------------------------------ + html_name = "table.html." + model_name + html_new = html_name +".new" + system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile(dirm+film,"r") + + xm = fm->lon + ym = fm->lat + nlat = dimsizes(ym) + nlon = dimsizes(xm) + + nmon = 12 + nfield = 4 + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + data = fm->NEE + + factor = 1e6 /12. + + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + + data = fm->SENSIBLE + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; printVarSummary (data_mod0) +;************************************************ +; read in data: observed +;************************************************ + station = (/"BOREAS_NSA_OBS" \ + ,"CastelPorziano" \ + ,"Hyytiala" \ + ,"Kaamanen" \ + ,"LBA_Tapajos_KM67" \ + ,"Lethbridge" \ + ,"Tharandt" \ + ,"Vielsalm" \ + /) + + year_ob = (/"1994-2004" \ + ,"1997-2003" \ + ,"1996-2003" \ + ,"2000-2003" \ + ,"2002-2005" \ + ,"1999-2004" \ + ,"1996-2003" \ + ,"1998-2003" \ + /) + + field = (/"CO2 Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + /) + + nstation = dimsizes(station) + nmon = 12 + nfield = dimsizes(field) + + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + + diri_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + + do n = 0,nstation-1 + diri = diri_root + station(n)+"/" + fili = station(n)+"_"+year_ob(n)+"_monthly.nc" + g = addfile (diri+fili,"r") + + lon_ob(n) = g->lon + lat_ob(n) = g->lat + + data = g->CO2_FLUX + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->RAD_FLUX + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->LH_FLUX + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = g->SH_FLUX + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (g) + end do + +;print (lat_ob) +;print (lon_ob) +;printVarSummary (data_ob) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) +; print (ym(0)) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0) + + delete (data_mod0) + yy!0 = "field" + data_mod = yy(pts|:,field|:,time|:) +; printVarSummary (data_mod) + +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data(1,:) = (/data_mod(n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data(1,:) = (/data_mod(n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data(1,:) = (/data_mod(n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data(1,:) = (/data_mod(n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;******************************************************************* +; for table of site score +;******************************************************************* + + table_length = 0.8 + +; table header name + table_header_name = "Site" + +; column (not including header column) + col_header = (/"Latitude","Longitude","observed" \ + ,"CO2 Flux","Net Radiation","Latent Heat" \ + ,"Sensible Heat","Average" \ + /) + ncol = dimsizes(col_header) + +; row (not including header row) + nrow = nstation + 1 + row_header = new ((/nrow/),string ) + row_header(0:nstation-1) = station(:) + row_header(nrow-1) = "All Sites" + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.800,0.895/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.010 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" + color_fill4(:,ncol-1) = "grey" + color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-2 + text4(n,0) = sprintf("%5.2f", lat_ob(n)) + text4(n,1) = sprintf("%5.2f", lon_ob(n)) + text4(n,2) = year_ob(n) + text4(n,3) = sprintf("%5.2f", M_score(n,0)) ; CO2 Flux + text4(n,4) = sprintf("%5.2f", M_score(n,1)) ; Net Radiation + text4(n,5) = sprintf("%5.2f", M_score(n,2)) ; Latent Heat + text4(n,6) = sprintf("%5.2f", M_score(n,3)) ; Sensible Heat + text4(n,7) = sprintf("%5.2f", avg(M_score(n,:))) ; avg all fields + end do + +; for the last row + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_all = M_co2+ M_rad +M_lh + M_sh + + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = "-" + text4(nrow-1,3) = sprintf("%5.2f", M_co2) ; avg all sites + text4(nrow-1,4) = sprintf("%5.2f", M_rad) ; avg all sites + text4(nrow-1,5) = sprintf("%5.2f", M_lh ) ; avg all sites + text4(nrow-1,6) = sprintf("%5.2f", M_sh ) ; avg all sites + text4(nrow-1,7) = sprintf("%5.2f", M_all) ; avg all sites + + print (M_co2) + print (M_rad) + print (M_lh ) + print (M_sh) + print (M_all) + + M_energy_co2 = sprintf("%.2f", M_co2) + system("sed s#M_energy_co2#"+M_energy_co2+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_energy_co2) + + M_energy_rad = sprintf("%.2f", M_rad) + system("sed s#M_energy_rad#"+M_energy_rad+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_energy_rad) + + M_energy_lh = sprintf("%.2f", M_lh) + system("sed s#M_energy_lh#"+M_energy_lh+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_energy_lh) + + M_energy_sh = sprintf("%.2f", M_sh) + system("sed s#M_energy_sh#"+M_energy_sh+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_energy_sh) +;--------------------------------------------------------------------------- + + plot_name = "table_site_score" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Model " + model_name + " M_Score" + + gsn_text_ndc(wks,title_text,0.50,0.95,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;------------------------------------------------------------------- + temp_name = "energy." + model_name + system("mkdir -p " + temp_name+";"+ \ + "cp "+ html_name + " " +temp_name+"/table.html"+";"+ \ + "mv *.png " + temp_name +";"+ \ + "tar cf "+ temp_name +".tar " + temp_name) +;------------------------------------------------------------------- + +end diff -r 000000000000 -r 0c6405ab2ff4 energy/99.new.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/energy/99.new.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,528 @@ +;************************************************************ +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; using gsn_table for all +; output: line plot for each site (4 fields) +; table for M_score +;************************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************ +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************* +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ + +; model_name = "i01.10cn" + model_name = "i01.10casa" + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile(dirm+film,"r") + + xm = fm->lon + ym = fm->lat +;------------------------------------------------ + nlat = dimsizes(ym) + nlon = dimsizes(xm) + +; for 4 fields, 12-monthly + nmon = 12 + nfield = 4 + + data_mod0 = new ((/nfield,nmon,nlat,nlon/),float) + +; change to unit of observed (u mol/m2/s) +; Model_units [=] gC/m2/s +; 12. = molecular weight of C +; u mol = 1e-6 mol + factor = 1e6 /12. + + ENERGY ="new" + +;************************************************ +; read data: observed +;************************************************ + + station = (/"BOREAS_NSA_OBS" \ + ,"CastelPorziano" \ + ,"Hyytiala" \ + ,"Kaamanen" \ + ,"LBA_Tapajos_KM67" \ + ,"Lethbridge" \ + ,"Tharandt" \ + ,"Vielsalm" \ + /) + + year_ob = (/"1994-2004" \ + ,"1997-2003" \ + ,"1996-2003" \ + ,"2000-2003" \ + ,"2002-2005" \ + ,"1999-2004" \ + ,"1996-2003" \ + ,"1998-2003" \ + /) + + field = (/"CO2 Flux" \ + ,"Net Radiation" \ + ,"Latent Heat" \ + ,"Sensible Heat" \ + /) + + nstation = dimsizes(station) + nmon = 12 + nfield = dimsizes(field) + + data_mod = new ((/nstation, nfield, nmon/),float) + data_ob = new ((/nstation, nfield, nmon/),float) + lat_ob = new ((/nstation/),float) + lon_ob = new ((/nstation/),float) + + diro_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" + dirm_root = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + + do n = 0,nstation-1 + +;------------------------------------------------- +; get ob data + + diro = diro_root + station(n)+"/" + filo = station(n)+"_"+year_ob(n)+"_monthly.nc" + fo = addfile (diro+filo,"r") + + print (filo) + + lon_ob(n) = fo->lon + lat_ob(n) = fo->lat + + data = fo->CO2_FLUX + data_ob(n,0,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->RAD_FLUX + data_ob(n,1,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->LH_FLUX + data_ob(n,2,:) = dim_avg(data(month|:,year|:)) + delete (data) + + data = fo->SH_FLUX + data_ob(n,3,:) = dim_avg(data(month|:,year|:)) + delete (data) + + delete (fo) +;--------------------------------------------------- +; get model data + + film = model_name+"_"+year_ob(n)+"_MONS_climo.nc" + fm = addfile (dirm_root+film,"r") + + print (film) + +if (ENERGY .eq. "old") then + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + +; data = fm->LATENT + data1 = fm->FCEV + data2 = fm->FCTR + data3 = fm->FGEV + data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) + delete (data1) + delete (data2) + delete (data3) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->NETRAD + data1 = fm->FSA + data2 = fm->FIRA + data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:) + delete (data1) + delete (data2) + +else + + data = fm->NEE + data_mod0(0,:,:,:) = data(:,:,:) * factor + delete (data) + + data = fm->NETRAD + data_mod0(1,:,:,:) = data(:,:,:) + delete (data) + + data = fm->LATENT + data_mod0(2,:,:,:) = data(:,:,:) + delete (data) + +; data = fm->SENSIBLE + data = fm->FSH + data_mod0(3,:,:,:) = data(:,:,:) + delete (data) +end if + + delete (fm) + +;************************************************************ +; interpolate model data into observed station +; note: model is 0-360E, 90S-90N +;************************************************************ + +; to be able to handle observation at (-89.98,-24.80) + ym(0) = -90. + + yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0) + +; print (yy) + + data_mod(n,:,:) = yy(:,:,0) + + delete (yy) + + end do +;************************************************************ +; compute correlation coef and M score +;************************************************************ + + score_max = 5. + + ccr = new ((/nstation, nfield/),float) + M_score = new ((/nstation, nfield/),float) + + do n=0,nstation-1 + do m=0,nfield-1 + ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0) + bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:)))) + M_score(n,m) = (1. -(bias/nmon)) * score_max + end do + end do + + M_co2 = avg(M_score(:,0)) + M_rad = avg(M_score(:,1)) + M_lh = avg(M_score(:,2)) + M_sh = avg(M_score(:,3)) + M_all = M_co2+ M_rad +M_lh + M_sh + + M_energy_co2 = sprintf("%.2f", M_co2) + M_energy_rad = sprintf("%.2f", M_rad) + M_energy_lh = sprintf("%.2f", M_lh ) + M_energy_sh = sprintf("%.2f", M_sh ) + M_energy_all = sprintf("%.2f", M_all) + +;******************************************************************* +; for station line plot +;******************************************************************* + +; for x-axis in xyplot + mon = ispan(1,12,1) + mon@long_name = "month" + + res = True ; plot mods desired + res@xyLineThicknesses = (/2.0,2.0/) ; make 2nd lines thicker + res@xyLineColors = (/"blue","red"/) ; line color (ob,model) +;------------------------------------------------------------------------- +; Add a boxed legend using the more simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 +; res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) + res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;------------------------------------------------------------------- +; for panel plot + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page +;------------------------------------------------------------------- + + plot_data = new((/2,12/),float) + plot_data!0 = "case" + plot_data!1 = "month" + + do n = 0,nstation-1 +;---------------------------- +; for observed + + plot_name = station(n)+"_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;---------------------------- +; for model_vs_ob + + plot_name = station(n)+"_model_vs_ob" + title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + plot=new(4,graphic) ; create graphic array + + plot_data(0,:) = (/data_ob (n,0,:)/) + plot_data(1,:) = (/data_mod(n,0,:)/) + plot_data@long_name = field(0) + plot(0)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 1 + + plot_data(0,:) = (/data_ob (n,1,:)/) + plot_data(1,:) = (/data_mod(n,1,:)/) + plot_data@long_name = field(1) + plot(1)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 2 + + plot_data(0,:) = (/data_ob (n,2,:)/) + plot_data(1,:) = (/data_mod(n,2,:)/) + plot_data@long_name = field(2) + plot(2)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 3 + + plot_data(0,:) = (/data_ob (n,3,:)/) + plot_data(1,:) = (/data_mod(n,3,:)/) + plot_data@long_name = field(3) + plot(3)=gsn_csm_xy(wks,mon,plot_data,res) ; create plot 4 + + gsn_panel(wks,plot,(/2,2/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + end do + +;******************************************************************* +; html table of site: observed +;******************************************************************* + output_html = "line_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Observation

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObserved
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;******************************************************************* +; score and line table : model vs observed +;******************************************************************* + output_html = "score+line_vs_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Energy at Site: Model "+model_name+"

" \ + /) + footer = "" + + delete (table_header) + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site NameLatitudeLongitudeObservedCO2 FluxNet RadiationLatent HeatSensible HeatAverage
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +; row of table + + do n = 0,nstation-1 + set_line(lines,nline,row_header) + + txt0 = station(n) + txt1 = sprintf("%5.2f", lat_ob(n)) + txt2 = sprintf("%5.2f", lon_ob(n)) + txt3 = year_ob(n) + txt4 = sprintf("%5.2f", M_score(n,0)) + txt5 = sprintf("%5.2f", M_score(n,1)) + txt6 = sprintf("%5.2f", M_score(n,2)) + txt7 = sprintf("%5.2f", M_score(n,3)) + txt8 = sprintf("%5.2f", avg(M_score(n,:))) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + + set_line(lines,nline,row_footer) + end do + +; last row, summary + set_line(lines,nline,row_header) + + txt0 = "All_"+sprintf("%.0f", nstation) + txt1 = "-" + txt2 = "-" + txt3 = "-" + txt4 = M_energy_co2 + txt5 = M_energy_rad + txt6 = M_energy_lh + txt7 = M_energy_sh + txt8 = M_energy_all + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + + set_line(lines,nline,row_footer) +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + delete (idx) + +;*************************************************************************** +; output plots +;*************************************************************************** + output_dir = model_name+"/energy" + + system("mv *.png *.html " + output_dir) +;*************************************************************************** +end diff -r 000000000000 -r 0c6405ab2ff4 fire/10.1x1_to_1.9.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fire/10.1x1_to_1.9.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,141 @@ +;--------------------------------------------------------------- +; convert from 1x1 to T31/T42 +; +; use model T31/T42 lat and lon +; output model area, too. +; +;------------------------------------------------------------- +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +undef("copyatt") +load "/fis/cgd/cseg/people/jeff/ncl/remap_areaave.ncl" +begin +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/" + filo = "Fire_C_1997-2006_monthly_1.9.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"year",-1,True) + +;****************************************************** +; input grid: 1deg x 1deg, N->S, 180W-180E +;****************************************************** + diri = "/fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/" + fili = "Fire_C_1997-2006_monthly_1x1.nc" + g = addfile (diri+fili,"r") + bi = g->FIRE_C + xi = g->lon + yi = g->lat + + dsizes = dimsizes(bi) + nyear = dsizes(0) + nmonth = dsizes(1) + nlatx = dsizes(2) + nlonx = dsizes(3) + +;=================================================== +; change from 180W-180E, 90N-90S to 0-360E, 90S-90N +;=================================================== + + yi = (/ yi(::-1) /) + bi = (/ bi(:,:,::-1,:) /) + + b2 = bi + x2 = xi + + do i= 0,nlonx-1 + if (i .lt. 180) then + p = i + 180 + xi(p) = x2(i) + 360. + else + p = i - 180 + xi(p) = x2(i) + end if + bi(:,:,:,p)= b2(:,:,:,i) + end do + + bi&lat = yi + bi&lon = xi + + print (xi) + print (yi) + +;================================================== +; edges +;================================================== + + xi_edge = fspan(0.0, 360.0, nlonx+1) + xi_edge@units = "degrees_east" + yi_edge = fspan(-90.0, 90.0, nlatx+1) + yi_edge@units = "degrees_north" + +;================================================== +; area +;================================================== + + deg2rad = 4.0*atan(1.0)/180.0 + earth_rad = 6.37122e6 + dx = earth_rad * deg2rad * (xi_edge(1)-xi_edge(0)) + dsin = sin(deg2rad*yi_edge(1:180)) - sin(deg2rad*yi_edge(0:179)) + area_in = new((/ nlatx, nlonx /), float) + area_in = conform(area_in, earth_rad*dx*dsin,0) + area_in@units = "m^2" + +;************************************************************** +; output grid: (0-360), (90S-90N) +;************************************************************** +; interpolate into model T31/T42, using model lat and lon + + diri = "/fis/cgd/cseg/people/jeff/surface_data/" + fili = "lnd_1.9.nc" + b = addfile(diri+fili,"r") + + yo = b->lat + xo = b->lon + nlat = dimsizes(yo) + nlon = dimsizes(xo) + + xo_edge = fspan(0.0, 360.0, nlon+1) - 0.5*360.0/nlon + xo_edge@units = "degrees_east" + + yo_edge = new(nlat+1, float) + gau_info = gaus(nlat/2) + yo_edge(0) = -90.0 + yo_edge(1:nlat-1) = doubletofloat(0.5*(gau_info(0:nlat-2,0)+gau_info(1:nlat-1,0))) + yo_edge(nlat) = 90.0 + yo_edge@units = "degrees_north" + +; yo = 0.5*(yo_edge(0:nlat-1) + yo_edge(1:nlat)) +; yo@units = yo_edge@units +; xo = 0.5*(xo_edge(0:nlon-1) + xo_edge(1:nlon)) +; xo@units = xo_edge@units + +;=================================================== +; output +;=================================================== + + w = new((/nyear,nmonth,nlat,nlon/),float) + + do m = 0,nyear-1 + do n = 0,nmonth-1 + w(m,n,:,:) = remap_areaave(xi_edge, yi_edge, bi(m,n,:,:), xo_edge, yo_edge) + end do + end do + + w!0 = "year" + w!1 = "month" + w!2 = "lat" + w&lat = yo + w!3 = "lon" + w&lon = xo + w@units = bi@units + w@long_name = bi@long_name + w@_FillValue = bi@_FillValue + + c->FIRE_C = w + c->date = g->date + c->area = b->area + +end diff -r 000000000000 -r 0c6405ab2ff4 fire/10.1x1_to_T31.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fire/10.1x1_to_T31.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,140 @@ +;--------------------------------------------------------------- +; convert from 1x1 to T31/T42 +; +; use model T31/T42 lat and lon +; output model area, too. +; +;------------------------------------------------------------- +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +undef("copyatt") +load "/fis/cgd/cseg/people/jeff/ncl/remap_areaave.ncl" +begin +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/" + filo = "Fire_C_1997-2006_monthly_T31.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"year",-1,True) + +;****************************************************** +; input grid: 1deg x 1deg, N->S, 180W-180E +;****************************************************** + diri = "/fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/" + fili = "Fire_C_1997-2006_monthly_1x1.nc" + g = addfile (diri+fili,"r") + bi = g->FIRE_C + xi = g->lon + yi = g->lat + + dsizes = dimsizes(bi) + nyear = dsizes(0) + nmonth = dsizes(1) + nlatx = dsizes(2) + nlonx = dsizes(3) + +;=================================================== +; change from 180W-180E, 90N-90S to 0-360E, 90S-90N +;=================================================== + + yi = (/ yi(::-1) /) + bi = (/ bi(:,:,::-1,:) /) + + b2 = bi + x2 = xi + + do i= 0,nlonx-1 + if (i .lt. 180) then + p = i + 180 + xi(p) = x2(i) + 360. + else + p = i - 180 + xi(p) = x2(i) + end if + bi(:,:,:,p)= b2(:,:,:,i) + end do + + bi&lat = yi + bi&lon = xi + + print (xi) + print (yi) + +;================================================== +; edges +;================================================== + + xi_edge = fspan(0.0, 360.0, nlonx+1) + xi_edge@units = "degrees_east" + yi_edge = fspan(-90.0, 90.0, nlatx+1) + yi_edge@units = "degrees_north" + +;================================================== +; area +;================================================== + + deg2rad = 4.0*atan(1.0)/180.0 + earth_rad = 6.37122e6 + dx = earth_rad * deg2rad * (xi_edge(1)-xi_edge(0)) + dsin = sin(deg2rad*yi_edge(1:180)) - sin(deg2rad*yi_edge(0:179)) + area_in = new((/ nlatx, nlonx /), float) + area_in = conform(area_in, earth_rad*dx*dsin,0) + area_in@units = "m^2" + +;************************************************************** +; output grid: (0-360), (90S-90N) +;************************************************************** +; interpolate into model T31/T42, using model data + diri = "/fis/cgd/cseg/people/jeff/fire_data/model/" + fili = "b30.061n_1980-1990_ANN_climo.nc" + b = addfile(diri+fili,"r") + + yo = b->lat + xo = b->lon + nlat = dimsizes(yo) + nlon = dimsizes(xo) + + xo_edge = fspan(0.0, 360.0, nlon+1) - 0.5*360.0/nlon + xo_edge@units = "degrees_east" + + yo_edge = new(nlat+1, float) + gau_info = gaus(nlat/2) + yo_edge(0) = -90.0 + yo_edge(1:nlat-1) = doubletofloat(0.5*(gau_info(0:nlat-2,0)+gau_info(1:nlat-1,0))) + yo_edge(nlat) = 90.0 + yo_edge@units = "degrees_north" + +; yo = 0.5*(yo_edge(0:nlat-1) + yo_edge(1:nlat)) +; yo@units = yo_edge@units +; xo = 0.5*(xo_edge(0:nlon-1) + xo_edge(1:nlon)) +; xo@units = xo_edge@units + +;=================================================== +; output +;=================================================== + + w = new((/nyear,nmonth,nlat,nlon/),float) + + do m = 0,nyear-1 + do n = 0,nmonth-1 + w(m,n,:,:) = remap_areaave(xi_edge, yi_edge, bi(m,n,:,:), xo_edge, yo_edge) + end do + end do + + w!0 = "year" + w!1 = "month" + w!2 = "lat" + w&lat = yo + w!3 = "lon" + w&lon = xo + w@units = bi@units + w@long_name = bi@long_name + w@_FillValue = bi@_FillValue + + c->FIRE_C = w + c->date = g->date + c->area = b->area + +end diff -r 000000000000 -r 0c6405ab2ff4 fire/10.1x1_to_T42.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fire/10.1x1_to_T42.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,141 @@ +;--------------------------------------------------------------- +; convert from 1x1 to T31/T42 +; +; use model T31/T42 lat and lon +; output model area, too. +; +;------------------------------------------------------------- +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +undef("copyatt") +load "/fis/cgd/cseg/people/jeff/ncl/remap_areaave.ncl" +begin +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/" + filo = "Fire_C_1997-2006_monthly_T42.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"year",-1,True) + +;****************************************************** +; input grid: 1deg x 1deg, N->S, 180W-180E +;****************************************************** + diri = "/fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/" + fili = "Fire_C_1997-2006_monthly_1x1.nc" + g = addfile (diri+fili,"r") + bi = g->FIRE_C + xi = g->lon + yi = g->lat + + dsizes = dimsizes(bi) + nyear = dsizes(0) + nmonth = dsizes(1) + nlatx = dsizes(2) + nlonx = dsizes(3) + +;=================================================== +; change from 180W-180E, 90N-90S to 0-360E, 90S-90N +;=================================================== + + yi = (/ yi(::-1) /) + bi = (/ bi(:,:,::-1,:) /) + + b2 = bi + x2 = xi + + do i= 0,nlonx-1 + if (i .lt. 180) then + p = i + 180 + xi(p) = x2(i) + 360. + else + p = i - 180 + xi(p) = x2(i) + end if + bi(:,:,:,p)= b2(:,:,:,i) + end do + + bi&lat = yi + bi&lon = xi + + print (xi) + print (yi) + +;================================================== +; edges +;================================================== + + xi_edge = fspan(0.0, 360.0, nlonx+1) + xi_edge@units = "degrees_east" + yi_edge = fspan(-90.0, 90.0, nlatx+1) + yi_edge@units = "degrees_north" + +;================================================== +; area +;================================================== + + deg2rad = 4.0*atan(1.0)/180.0 + earth_rad = 6.37122e6 + dx = earth_rad * deg2rad * (xi_edge(1)-xi_edge(0)) + dsin = sin(deg2rad*yi_edge(1:180)) - sin(deg2rad*yi_edge(0:179)) + area_in = new((/ nlatx, nlonx /), float) + area_in = conform(area_in, earth_rad*dx*dsin,0) + area_in@units = "m^2" + +;************************************************************** +; output grid: (0-360), (90S-90N) +;************************************************************** +; interpolate into model T31/T42, using model lat and lon + + diri = "/fis/cgd/cseg/people/jeff/surface_data/" + fili = "lnd_T42.nc" + b = addfile(diri+fili,"r") + + yo = b->lat + xo = b->lon + nlat = dimsizes(yo) + nlon = dimsizes(xo) + + xo_edge = fspan(0.0, 360.0, nlon+1) - 0.5*360.0/nlon + xo_edge@units = "degrees_east" + + yo_edge = new(nlat+1, float) + gau_info = gaus(nlat/2) + yo_edge(0) = -90.0 + yo_edge(1:nlat-1) = doubletofloat(0.5*(gau_info(0:nlat-2,0)+gau_info(1:nlat-1,0))) + yo_edge(nlat) = 90.0 + yo_edge@units = "degrees_north" + +; yo = 0.5*(yo_edge(0:nlat-1) + yo_edge(1:nlat)) +; yo@units = yo_edge@units +; xo = 0.5*(xo_edge(0:nlon-1) + xo_edge(1:nlon)) +; xo@units = xo_edge@units + +;=================================================== +; output +;=================================================== + + w = new((/nyear,nmonth,nlat,nlon/),float) + + do m = 0,nyear-1 + do n = 0,nmonth-1 + w(m,n,:,:) = remap_areaave(xi_edge, yi_edge, bi(m,n,:,:), xo_edge, yo_edge) + end do + end do + + w!0 = "year" + w!1 = "month" + w!2 = "lat" + w&lat = yo + w!3 = "lon" + w&lon = xo + w@units = bi@units + w@long_name = bi@long_name + w@_FillValue = bi@_FillValue + + c->FIRE_C = w + c->date = g->date + c->area = b->area + +end diff -r 000000000000 -r 0c6405ab2ff4 fire/21.table+tseries.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fire/21.table+tseries.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,258 @@ +;******************************************************** +;using model biome vlass +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;--------------------------------------------------- +; model name and grid + + model_grid = "T42" + + model_name = "cn" + model_name1 = "i01.06cn" + model_name2 = "i01.10cn" + +;--------------------------------------------------- +; get biome data: model + + biome_name_mod = "Model PFT Class" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "class_pft_"+model_grid+".nc" + fm = addfile(dirm+film,"r") + + classmod = fm->CLASS_PFT + + delete (fm) + +; model data has 17 land-type classes + + nclass_mod = 17 + +;-------------------------------------------------- +; get model data: landfrac and area + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile (dirm+film,"r") + + landmask = fm->landmask + landfrac = fm->landfrac + area = fm->area + + delete (fm) + +; change area from km**2 to m**2 + area = area * 1.e6 + +;---------------------------------------------------- +; read data: time series, model + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name2 + "_Fire_C_1979-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + data_mod = fm->COL_FIRE_CLOSS(18:25,:,:,:) + + delete (fm) + +; Units for these variables are: +; g C/m^2/s + +; change unit to g C/m^2/month + + nsec_per_month = 60*60*24*30 + + data_mod = data_mod * nsec_per_month + + data_mod@unit = "gC/m2/month" +;---------------------------------------------------- +; read data: time series, observed + + dirm = "/fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/" + film = "Fire_C_1997-2006_monthly_"+ model_grid+".nc" + fm = addfile (dirm+film,"r") + + data_ob = fm->FIRE_C(0:7,:,:,:) + + delete (fm) + + ob_name = "GFEDv2" + +; Units for these variables are: +; g C/m^2/month + +;--------------------------------------------------- +; take into account landfrac + + data_mod = data_mod * conform(data_mod, landfrac, (/2,3/)) + data_ob = data_ob * conform(data_ob, landfrac, (/2,3/)) + +;--------------------------------------------------- +; get time-mean + + x = dim_avg_Wrap(data_mod(lat|:,lon|:,month|:,year|:)) + data_mod_m = dim_avg_Wrap( x(lat|:,lon|:,month|:)) + delete (x) + + x = dim_avg_Wrap( data_ob(lat|:,lon|:,month|:,year|:)) + data_ob_m = dim_avg_Wrap( x(lat|:,lon|:,month|:)) + delete (x) + +; printVarSummary(y) + +;---------------------------------------------------- +; compute correlation coef + + landmask_1d = ndtooned(landmask) + data_mod_1d = ndtooned(data_mod_m) + data_ob_1d = ndtooned(data_ob_m) + + good = ind(landmask_1d .gt. 0.) +; print (dimsizes(good)) + + cc = esccr(data_mod_1d(good),data_ob_1d(good),0) +; print (cc) + + delete (landmask_1d) + delete (data_mod_1d) + delete (data_ob_id) + +;---------------------------------------------------- +; compute M_global + + score_max = 1. + + Mscore = cc * cc * score_max + + M_global = sprintf("%.2f", Mscore) + +;---------------------------------------------------- +; global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + +;---------------------------------------------------- +; global contour: model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") + + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;---------------------- +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%.2f", cc)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) + +;----------------------- +; plot ob + + data_ob_m = where(landmask .gt. 0., data_ob_m, data_ob_m@_FillValue) + + title = ob_name + resg@tiMainString = title + + resg@cnMinLevelValF = 1. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + plot(0) = gsn_csm_contour_map_ce(wks,data_ob_m,resg) + +;----------------------- +; plot model + + data_mod_m = where(landmask .gt. 0., data_mod_m, data_mod_m@_FillValue) + + title = "Model "+ model_name + resg@tiMainString = title + + resg@cnMinLevelValF = 1. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + plot(1) = gsn_csm_contour_map_ce(wks,data_mod_m,resg) + +;----------------------- +; plot model-ob + + resg@cnMinLevelValF = -8. + resg@cnMaxLevelValF = 2. + resg@cnLevelSpacingF = 1. + + zz = data_ob_m + zz = data_mod_m - data_ob_m + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + +; plot panel + + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + +exit + +; system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ +; "rm "+plot_name+"."+plot_type) + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + + clear (wks) + delete (plot) + + delete (data_ob_m) + delete (data_mod_m) + delete (zz) + + resg@gsnFrame = True ; Do advance frame + resg@gsnDraw = True ; Do draw plot + +end + diff -r 000000000000 -r 0c6405ab2ff4 fire/22.table+tseries.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fire/22.table+tseries.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,554 @@ +;******************************************************** +;using model biome vlass +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;--------------------------------------------------- +; model name and grid + + model_grid = "T42" + + model_name = "cn" + model_name1 = "i01.06cn" + model_name2 = "i01.10cn" + +;--------------------------------------------------- +; get biome data: model + + biome_name_mod = "Model PFT Class" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "class_pft_"+model_grid+".nc" + fm = addfile(dirm+film,"r") + + classmod = fm->CLASS_PFT + + delete (fm) + +; model data has 17 land-type classes + + nclass_mod = 17 + +;-------------------------------------------------- +; get model data: landmask, landfrac and area + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile (dirm+film,"r") + + landmask = fm->landmask + landfrac = fm->landfrac + area = fm->area + + delete (fm) + +; change area from km**2 to m**2 + area = area * 1.e6 + +;---------------------------------------------------- +; read data: time series, model + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name2 + "_Fire_C_1979-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + data_mod = fm->COL_FIRE_CLOSS(18:25,:,:,:) + + delete (fm) + +; Units for these variables are: +; g C/m^2/s + +; change unit to g C/m^2/month + + nsec_per_month = 60*60*24*30 + + data_mod = data_mod * nsec_per_month + + data_mod@unit = "gC/m2/month" +;---------------------------------------------------- +; read data: time series, observed + + dirm = "/fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/" + film = "Fire_C_1997-2006_monthly_"+ model_grid+".nc" + fm = addfile (dirm+film,"r") + + data_ob = fm->FIRE_C(0:7,:,:,:) + + delete (fm) + + ob_name = "GFEDv2" + +; Units for these variables are: +; g C/m^2/month + +;--------------------------------------------------- +; take into account landfrac + + area = area * landfrac + data_mod = data_mod * conform(data_mod, landfrac, (/2,3/)) + data_ob = data_ob * conform(data_ob, landfrac, (/2,3/)) + + delete (landfrac) + +;------------------------------------------------------------- +; html table1 data + +; column (not including header column) + + col_head = (/"Model Fire_Flux (PgC/yr)" \ + ,"Observed Fire_Flux (PgC/yr)" \ + ,"Correlation Coefficient" \ + ,"Ratio model/observed" \ + ,"M_score" \ + ,"Timeseries plot" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + +;***************************************************************** +; (A) get time-mean +;***************************************************************** + + x = dim_avg_Wrap(data_mod(lat|:,lon|:,month|:,year|:)) + data_mod_m = dim_avg_Wrap( x(lat|:,lon|:,month|:)) + delete (x) + + x = dim_avg_Wrap( data_ob(lat|:,lon|:,month|:,year|:)) + data_ob_m = dim_avg_Wrap( x(lat|:,lon|:,month|:)) + delete (x) + +;---------------------------------------------------- +; compute correlation coef + + landmask_1d = ndtooned(landmask) + data_mod_1d = ndtooned(data_mod_m) + data_ob_1d = ndtooned(data_ob_m) + + good = ind(landmask_1d .gt. 0.) +; print (dimsizes(good)) + + cc = esccr(data_mod_1d(good),data_ob_1d(good),0) +; print (cc) + + delete (landmask_1d) + delete (data_mod_1d) + delete (data_ob_1d) + delete (good) + +;---------------------------------------------------- +; compute M_global + + score_max = 1. + + Mscore = cc * cc * score_max + + M_global = sprintf("%.2f", Mscore) + +;---------------------------------------------------- +; global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + +;---------------------------------------------------- +; global contour: model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") + + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;---------------------- +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%.2f", cc)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) + +;----------------------- +; plot ob + + data_ob_m = where(landmask .gt. 0., data_ob_m, data_ob_m@_FillValue) + + title = ob_name + resg@tiMainString = title + + resg@cnMinLevelValF = 1. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + plot(0) = gsn_csm_contour_map_ce(wks,data_ob_m,resg) + +;----------------------- +; plot model + + data_mod_m = where(landmask .gt. 0., data_mod_m, data_mod_m@_FillValue) + + title = "Model "+ model_name + resg@tiMainString = title + + resg@cnMinLevelValF = 1. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + plot(1) = gsn_csm_contour_map_ce(wks,data_mod_m,resg) + +;----------------------- +; plot model-ob + + resg@cnMinLevelValF = -8. + resg@cnMaxLevelValF = 2. + resg@cnLevelSpacingF = 1. + + zz = data_ob_m + zz = data_mod_m - data_ob_m + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + +; plot panel + + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + +; system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ +; "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + delete (data_ob_m) + delete (data_mod_m) + delete (zz) + + resg@gsnFrame = True ; Do advance frame + resg@gsnDraw = True ; Do draw plot + +;******************************************************************* +; (B) Time series : per biome +;******************************************************************* + + data_n = 2 + + dsizes = dimsizes(data_mod) + nyear = dsizes(0) + nmonth = dsizes(1) + ntime = nyear * nmonth + + year_start = 1997 + year_end = 2004 + +;------------------------------------------- +; Calculate "nice" bins for binning the data + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; print (range) +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;------------------------------------------- +; put data into bins + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + +; output + + area_bin = new((/nx/),float) + yvalues = new((/ntime,data_n,nx/),float) + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if +;--------------------- +; for area + + data = ndtooned(area) + + if (.not.any(ismissing(idx))) then + area_bin(i) = sum(data(idx)) + else + area_bin(i) = area_bin@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + area_bin(i) = area_bin@_FillValue + end if +;############################################################# + + delete (data) + +;--------------------- +; for data_mod and data_ob + + do n = 0,data_n-1 + + t = -1 + do m = 0,nyear-1 + do k = 0,nmonth-1 + + t = t + 1 + + if (n.eq.0) then + data = ndtooned(data_ob(m,k,:,:)) + end if + + if (n.eq.1) then + data = ndtooned(data_mod(m,k,:,:)) + end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(t,n,i) = avg(data(idx)) + else + yvalues(t,n,i) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(t,n,i) = yvalues@_FillValue + end if +;############################################################# + + end do + end do + + delete(data) + end do + + delete(idx) + end do + + delete (base) + delete (data_mod) + delete (data_ob) + +;---------------------------------------------------------------- +; get area_good + + good = ind(.not.ismissing(area_bin)) + + area_g = area_bin(good) + + n_biome = dimsizes(good) + +;---------------------------------------------------------------- +; data for tseries plot + + yvalues_g = new((/ntime,data_n,n_biome/),float) + + yvalues_g@units = "TgC/month" + +; change unit to Tg C/month +; change unit from g to Tg (Tera gram) + factor_unit = 1.e-12 + + yvalues_g = yvalues(:,:,good) * conform(yvalues_g,area_g,2) * factor_unit + +;------------------------------------------------------------------- +; general settings for line plot + + res = True + res@xyDashPatterns = (/0,0/) ; make lines solid + res@xyLineThicknesses = (/2.0,2.0/) ; make lines thicker + res@xyLineColors = (/"blue","red"/) ; line color + + res@trXMinF = year_start + res@trXMaxF = year_end + 1 + + res@vpHeightF = 0.4 ; change aspect ratio of plot +; res@vpWidthF = 0.8 + res@vpWidthF = 0.75 + + res@tiMainFontHeightF = 0.025 ; size of title + + res@tmXBFormat = "f" ; not to add trailing zeros + +; res@gsnMaximize = True + +;---------------------------------------------- +; Add a boxed legend using the simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + res@pmLegendParallelPosF = 0.73 ;(rightward) + res@pmLegendParallelPosF = 0.83 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) + +;******************************************************************* +; (A) time series plot: monthly ( 2 lines per plot) +;******************************************************************* + +; x-axis in time series plot + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_start + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + plot_data@long_name = "TgC/month" + +;---------------------------------------------- +; time series : per biome + + do m = 0, n_biome-1 + + plot_name = "monthly_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = "Fire : "+ row_head(m) + res@tiMainString = title + + plot_data(0,:) = yvalues_g(:,0,m) + plot_data(1,:) = yvalues_g(:,1,m) + + plot = gsn_csm_xy(wks,timeF,plot_data,res) + +; system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ +; "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + end do + +;-------------------------------------------- +; time series: global + + plot_name = "monthly_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = "Fire : "+ row_head(n_biome) + res@tiMainString = title + + do k = 0,ntime-1 + plot_data(0,k) = sum(yvalues_g(k,0,:)) + plot_data(1,k) = sum(yvalues_g(k,1,:)) + end do + + plot = gsn_csm_xy(wks,timeF,plot_data,res) + +; system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ +; "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +end + diff -r 000000000000 -r 0c6405ab2ff4 fire/23.table+tseries.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fire/23.table+tseries.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,692 @@ +;******************************************************** +;using model biome vlass +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;--------------------------------------------------- +; model name and grid + + model_grid = "T42" + + model_name = "cn" + model_name1 = "i01.06cn" + model_name2 = "i01.10cn" + +;--------------------------------------------------- +; get biome data: model + + biome_name_mod = "Model PFT Class" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "class_pft_"+model_grid+".nc" + fm = addfile(dirm+film,"r") + + classmod = fm->CLASS_PFT + + delete (fm) + +; model data has 17 land-type classes + + nclass_mod = 17 + +;-------------------------------------------------- +; get model data: landmask, landfrac and area + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile (dirm+film,"r") + + landmask = fm->landmask + landfrac = fm->landfrac + area = fm->area + + delete (fm) + +; change area from km**2 to m**2 + area = area * 1.e6 + +;---------------------------------------------------- +; read data: time series, model + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name2 + "_Fire_C_1979-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + data_mod = fm->COL_FIRE_CLOSS(18:25,:,:,:) + + delete (fm) + +; Units for these variables are: +; g C/m^2/s + +; change unit to g C/m^2/month + + nsec_per_month = 60*60*24*30 + + data_mod = data_mod * nsec_per_month + + data_mod@unit = "gC/m2/month" +;---------------------------------------------------- +; read data: time series, observed + + dirm = "/fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/" + film = "Fire_C_1997-2006_monthly_"+ model_grid+".nc" + fm = addfile (dirm+film,"r") + + data_ob = fm->FIRE_C(0:7,:,:,:) + + delete (fm) + + ob_name = "GFEDv2" + +; Units for these variables are: +; g C/m^2/month + +;--------------------------------------------------- +; take into account landfrac + + area = area * landfrac + data_mod = data_mod * conform(data_mod, landfrac, (/2,3/)) + data_ob = data_ob * conform(data_ob, landfrac, (/2,3/)) + + delete (landfrac) + +;------------------------------------------------------------- +; html table1 data + +; column (not including header column) + + col_head = (/"Observed Fire_Flux (PgC/yr)" \ + ,"Model Fire_Flux (PgC/yr)" \ + ,"Correlation Coefficient" \ + ,"Ratio model/observed" \ + ,"M_score" \ + ,"Timeseries plot" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + +;***************************************************************** +; (A) get time-mean +;***************************************************************** + + x = dim_avg_Wrap(data_mod(lat|:,lon|:,month|:,year|:)) + data_mod_m = dim_avg_Wrap( x(lat|:,lon|:,month|:)) + delete (x) + + x = dim_avg_Wrap( data_ob(lat|:,lon|:,month|:,year|:)) + data_ob_m = dim_avg_Wrap( x(lat|:,lon|:,month|:)) + delete (x) + +;---------------------------------------------------- +; compute correlation coef + + landmask_1d = ndtooned(landmask) + data_mod_1d = ndtooned(data_mod_m) + data_ob_1d = ndtooned(data_ob_m) + + good = ind(landmask_1d .gt. 0.) + + cc = esccr(data_mod_1d(good),data_ob_1d(good),0) + + delete (landmask_1d) + delete (data_mod_1d) + delete (data_ob_1d) + delete (good) + +;---------------------------------------------------- +; compute M_global + + score_max = 1. + + Mscore1 = cc * cc * score_max + + M_global = sprintf("%.2f", Mscore1) + +;---------------------------------------------------- +; global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + +;---------------------------------------------------- +; global contour: model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") + + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;---------------------- +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%.2f", cc)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) + +;----------------------- +; plot ob + + data_ob_m = where(landmask .gt. 0., data_ob_m, data_ob_m@_FillValue) + + title = ob_name + resg@tiMainString = title + + resg@cnMinLevelValF = 1. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + plot(0) = gsn_csm_contour_map_ce(wks,data_ob_m,resg) + +;----------------------- +; plot model + + data_mod_m = where(landmask .gt. 0., data_mod_m, data_mod_m@_FillValue) + + title = "Model "+ model_name + resg@tiMainString = title + + resg@cnMinLevelValF = 1. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + plot(1) = gsn_csm_contour_map_ce(wks,data_mod_m,resg) + +;----------------------- +; plot model-ob + + resg@cnMinLevelValF = -8. + resg@cnMaxLevelValF = 2. + resg@cnLevelSpacingF = 1. + + zz = data_ob_m + zz = data_mod_m - data_ob_m + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + +; plot panel + + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + delete (data_ob_m) + delete (data_mod_m) + delete (zz) + + resg@gsnFrame = True ; Do advance frame + resg@gsnDraw = True ; Do draw plot + +;******************************************************************* +; (B) Time series : per biome +;******************************************************************* + + data_n = 2 + + dsizes = dimsizes(data_mod) + nyear = dsizes(0) + nmonth = dsizes(1) + ntime = nyear * nmonth + + year_start = 1997 + year_end = 2004 + +;------------------------------------------- +; Calculate "nice" bins for binning the data + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;------------------------------------------- +; put data into bins + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + +; output + + area_bin = new((/nx/),float) + yvalues = new((/ntime,data_n,nx/),float) + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if +;--------------------- +; for area + + data = ndtooned(area) + + if (.not.any(ismissing(idx))) then + area_bin(i) = sum(data(idx)) + else + area_bin(i) = area_bin@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + area_bin(i) = area_bin@_FillValue + end if +;############################################################# + + delete (data) + +;--------------------- +; for data_mod and data_ob + + do n = 0,data_n-1 + + t = -1 + do m = 0,nyear-1 + do k = 0,nmonth-1 + + t = t + 1 + + if (n.eq.0) then + data = ndtooned(data_ob(m,k,:,:)) + end if + + if (n.eq.1) then + data = ndtooned(data_mod(m,k,:,:)) + end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(t,n,i) = avg(data(idx)) + else + yvalues(t,n,i) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(t,n,i) = yvalues@_FillValue + end if +;############################################################# + + end do + end do + + delete(data) + end do + + delete(idx) + end do + + delete (base) + delete (data_mod) + delete (data_ob) + +;---------------------------------------------------------------- +; get area_good + + good = ind(.not.ismissing(area_bin)) + + area_g = area_bin(good) + + n_biome = dimsizes(good) + +;---------------------------------------------------------------- +; data for tseries plot + + yvalues_g = new((/ntime,data_n,n_biome/),float) + + yvalues_g@units = "TgC/month" + +; change unit to Tg C/month +; change unit from g to Tg (Tera gram) + factor_unit = 1.e-12 + + yvalues_g = yvalues(:,:,good) * conform(yvalues_g,area_g,2) * factor_unit + + delete (good) + +;------------------------------------------------------------------- +; general settings for line plot + + res = True + res@xyDashPatterns = (/0,0/) ; make lines solid + res@xyLineThicknesses = (/2.0,2.0/) ; make lines thicker + res@xyLineColors = (/"blue","red"/) ; line color + + res@trXMinF = year_start + res@trXMaxF = year_end + 1 + + res@vpHeightF = 0.4 ; change aspect ratio of plot +; res@vpWidthF = 0.8 + res@vpWidthF = 0.75 + + res@tiMainFontHeightF = 0.025 ; size of title + + res@tmXBFormat = "f" ; not to add trailing zeros + +; res@gsnMaximize = True + +;---------------------------------------------- +; Add a boxed legend using the simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + res@pmLegendParallelPosF = 0.73 ;(rightward) + res@pmLegendParallelPosF = 0.83 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) + +;******************************************************************* +; (A) time series plot: monthly ( 2 lines per plot) +;******************************************************************* + +; x-axis in time series plot + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_start + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + plot_data@long_name = "TgC/month" + +;---------------------------------------------- +; time series plot : per biome + + do m = 0, n_biome-1 + + plot_name = "monthly_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = "Fire : "+ row_head(m) + res@tiMainString = title + + plot_data(0,:) = yvalues_g(:,0,m) + plot_data(1,:) = yvalues_g(:,1,m) + + plot = gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + end do + +;------------------------------------------ +; data for table : per biome + +; unit change from TgC/month to PgC/month + unit_factor = 1.e-3 + + score_max = 1. + + tmp_ob = new((/ntime/),float) + tmp_mod = new((/ntime/),float) + + total_ob = new((/n_biome/),float) + total_mod = new((/n_biome/),float) + Mscore2 = new((/n_biome/),float) + + do m = 0, n_biome-1 + + tmp_ob = yvalues_g(:,0,m) + tmp_mod = yvalues_g(:,1,m) + + total_ob(m) = avg(month_to_annual(tmp_ob, 0)) * unit_factor + total_mod(m) = avg(month_to_annual(tmp_mod,0)) * unit_factor + + cc = esccr(tmp_mod,tmp_ob,0) + + ratio = total_mod(m)/total_ob(m) + + good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.) + + bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) ) + Mscore2(m) = (1.- (bias/dimsizes(good)))*score_max + + delete (good) + + text(m,0) = sprintf("%.2f",total_ob(m)) + text(m,1) = sprintf("%.2f",total_mod(m)) + text(m,2) = sprintf("%.2f",cc) + text(m,3) = sprintf("%.2f",ratio) + text(m,4) = sprintf("%.2f",Mscore2(m)) + text(m,5) = "model_vs_ob" + end do + + delete (tmp_ob) + delete (tmp_mod) + +;-------------------------------------------- +; time series plot: all biome + + plot_name = "monthly_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = "Fire : "+ row_head(n_biome) + res@tiMainString = title + + do k = 0,ntime-1 + plot_data(0,k) = sum(yvalues_g(k,0,:)) + plot_data(1,k) = sum(yvalues_g(k,1,:)) + end do + + plot = gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + +;------------------------------------------ +; data for table : global + + tmp_ob = ndtooned(yvalues_g(:,0,:)) + tmp_mod = ndtooned(yvalues_g(:,1,:)) + + cc = esccr(tmp_mod,tmp_ob,0) + + ratio = sum(total_mod)/sum(total_ob) + + text(nrow-1,0) = sprintf("%.2f",sum(total_ob)) + text(nrow-1,1) = sprintf("%.2f",sum(total_mod)) + text(nrow-1,2) = sprintf("%.2f",cc) + text(nrow-1,3) = sprintf("%.2f",ratio) + text(nrow-1,4) = sprintf("%.2f",avg(Mscore2)) + text(nrow-1,5) = "model_vs_ob" + +;************************************************** +; create html table +;************************************************** + + header_text = "

Fire Emission (1997-2004): Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text(n,0) + txt2 = text(n,1) + txt3 = text(n,2) + txt4 = text(n,3) + txt5 = text(n,4) + txt6 = text(n,5) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_fire.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + +end + diff -r 000000000000 -r 0c6405ab2ff4 fire/24.table+tseries.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fire/24.table+tseries.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,717 @@ +;******************************************************** +; landfrac applied to area only. +; using model biome class +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;--------------------------------------------------- +; model name and grid + + model_grid = "T42" + + model_name = "cn" + model_name1 = "i01.06cn" + model_name2 = "i01.10cn" + +;--------------------------------------------------- +; get biome data: model + + biome_name_mod = "Model PFT Class" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "class_pft_"+model_grid+".nc" + fm = addfile(dirm+film,"r") + + classmod = fm->CLASS_PFT + + delete (fm) + +; model data has 17 land-type classes + + nclass_mod = 17 + +;-------------------------------------------------- +; get model data: landmask, landfrac and area + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile (dirm+film,"r") + + landmask = fm->landmask + landfrac = fm->landfrac + area = fm->area + + delete (fm) + +; change area from km**2 to m**2 + area = area * 1.e6 + +;--------------------------------------------------- +; take into account landfrac + + area = area * landfrac + +;---------------------------------------------------- +; read data: time series, model + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name2 + "_Fire_C_1979-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + data_mod = fm->COL_FIRE_CLOSS(18:25,:,:,:) + + delete (fm) + +; Units for these variables are: +; g C/m^2/s + +; change unit to g C/m^2/month + + nsec_per_month = 60*60*24*30 + + data_mod = data_mod * nsec_per_month + + data_mod@unit = "gC/m2/month" +;---------------------------------------------------- +; read data: time series, observed + + dirm = "/fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/" + film = "Fire_C_1997-2006_monthly_"+ model_grid+".nc" + fm = addfile (dirm+film,"r") + + data_ob = fm->FIRE_C(0:7,:,:,:) + + delete (fm) + + ob_name = "GFEDv2" + +; Units for these variables are: +; g C/m^2/month + +;------------------------------------------------------------- +; html table1 data + +; column (not including header column) + + col_head = (/"Observed Fire_Flux (PgC/yr)" \ + ,"Model Fire_Flux (PgC/yr)" \ + ,"Correlation Coefficient" \ + ,"Ratio model/observed" \ + ,"M_score" \ + ,"Timeseries plot" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + +;***************************************************************** +; (A) get time-mean +;***************************************************************** + + x = dim_avg_Wrap(data_mod(lat|:,lon|:,month|:,year|:)) + data_mod_m = dim_avg_Wrap( x(lat|:,lon|:,month|:)) + delete (x) + + x = dim_avg_Wrap( data_ob(lat|:,lon|:,month|:,year|:)) + data_ob_m = dim_avg_Wrap( x(lat|:,lon|:,month|:)) + delete (x) + +;---------------------------------------------------- +; compute correlation coef: space + + landmask_1d = ndtooned(landmask) + data_mod_1d = ndtooned(data_mod_m) + data_ob_1d = ndtooned(data_ob_m ) + area_1d = ndtooned(area) + landfrac_1d = ndtooned(landfrac) + + good = ind(landmask_1d .gt. 0.) + + global_mod = sum(data_mod_1d(good)*area_1d(good)) * 1.e-15 * 12. + global_ob = sum(data_ob_1d(good) *area_1d(good)) * 1.e-15 * 12. + print (global_mod) + print (global_ob) + + global_area= sum(area_1d) + global_land= sum(area_1d(good)) + print (global_area) + print (global_land) + + cc_space = esccr(data_mod_1d(good)*landfrac_1d(good),data_ob_1d(good)*landfrac_1d(good),0) + + delete (landmask_1d) + delete (landfrac_1d) +; delete (area_1d) + delete (data_mod_1d) + delete (data_ob_1d) + delete (good) + +;---------------------------------------------------- +; compute M_global + + score_max = 1. + + Mscore1 = cc_space * cc_space * score_max + + M_global = sprintf("%.2f", Mscore1) + +;---------------------------------------------------- +; global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + +;---------------------------------------------------- +; global contour: model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") + + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;---------------------- +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%.2f", cc_space)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) + +;----------------------- +; plot ob + + data_ob_m = where(landmask .gt. 0., data_ob_m, data_ob_m@_FillValue) + + title = ob_name + resg@tiMainString = title + + resg@cnMinLevelValF = 1. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + plot(0) = gsn_csm_contour_map_ce(wks,data_ob_m,resg) + +;----------------------- +; plot model + + data_mod_m = where(landmask .gt. 0., data_mod_m, data_mod_m@_FillValue) + + title = "Model "+ model_name + resg@tiMainString = title + + resg@cnMinLevelValF = 1. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + plot(1) = gsn_csm_contour_map_ce(wks,data_mod_m,resg) + +;----------------------- +; plot model-ob + + resg@cnMinLevelValF = -8. + resg@cnMaxLevelValF = 2. + resg@cnLevelSpacingF = 1. + + zz = data_ob_m + zz = data_mod_m - data_ob_m + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + +; plot panel + + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + delete (data_ob_m) + delete (data_mod_m) + delete (zz) + + resg@gsnFrame = True ; Do advance frame + resg@gsnDraw = True ; Do draw plot + +;******************************************************************* +; (B) Time series : per biome +;******************************************************************* + + data_n = 2 + + dsizes = dimsizes(data_mod) + nyear = dsizes(0) + nmonth = dsizes(1) + ntime = nyear * nmonth + + year_start = 1997 + year_end = 2004 + +;------------------------------------------- +; Calculate "nice" bins for binning the data + +; using model biome class + nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;------------------------------------------- +; put data into bins + +; using observed biome class +; base = ndtooned(classob) +; using model biome class + base = ndtooned(classmod) + +; output + + area_bin = new((/nx/),float) + yvalues = new((/ntime,data_n,nx/),float) + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if +;--------------------- +; for area + + if (.not.any(ismissing(idx))) then + area_bin(i) = sum(area_1d(idx)) + else + area_bin(i) = area_bin@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + area_bin(i) = area_bin@_FillValue + end if +;############################################################# + +;--------------------- +; for data_mod and data_ob + + do n = 0,data_n-1 + + t = -1 + do m = 0,nyear-1 + do k = 0,nmonth-1 + + t = t + 1 + + if (n.eq.0) then + data = ndtooned(data_ob(m,k,:,:)) + end if + + if (n.eq.1) then + data = ndtooned(data_mod(m,k,:,:)) + end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(t,n,i) = sum(data(idx)*area_1d(idx)) + else + yvalues(t,n,i) = yvalues@_FillValue + end if + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(t,n,i) = yvalues@_FillValue + end if +;############################################################# + + end do + end do + + delete(data) + end do + + delete(idx) + end do + + delete (base) + delete (data_mod) + delete (data_ob) + + global_bin = sum(area_bin) + print (global_bin) + +;---------------------------------------------------------------- +; get area_good + + good = ind(.not.ismissing(area_bin)) + + area_g = area_bin(good) + + n_biome = dimsizes(good) + + global_good = sum(area_g) + print (global_good) + +;---------------------------------------------------------------- +; data for tseries plot + + yvalues_g = new((/ntime,data_n,n_biome/),float) + + yvalues_g@units = "TgC/month" + +; change unit to Tg C/month +; change unit from g to Tg (Tera gram) + factor_unit = 1.e-12 + + yvalues_g = yvalues(:,:,good) * factor_unit + + delete (good) + +;------------------------------------------------------------------- +; general settings for line plot + + res = True + res@xyDashPatterns = (/0,0/) ; make lines solid + res@xyLineThicknesses = (/2.0,2.0/) ; make lines thicker + res@xyLineColors = (/"blue","red"/) ; line color + + res@trXMinF = year_start + res@trXMaxF = year_end + 1 + + res@vpHeightF = 0.4 ; change aspect ratio of plot +; res@vpWidthF = 0.8 + res@vpWidthF = 0.75 + + res@tiMainFontHeightF = 0.025 ; size of title + + res@tmXBFormat = "f" ; not to add trailing zeros + +; res@gsnMaximize = True + +;---------------------------------------------- +; Add a boxed legend using the simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + res@pmLegendParallelPosF = 0.73 ;(rightward) + res@pmLegendParallelPosF = 0.83 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) + +;******************************************************************* +; (A) time series plot: monthly ( 2 lines per plot) +;******************************************************************* + +; x-axis in time series plot + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_start + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + plot_data@long_name = "TgC/month" + +;---------------------------------------------- +; time series plot : per biome + + do m = 0, n_biome-1 + + plot_name = "monthly_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = "Fire : "+ row_head(m) + res@tiMainString = title + + plot_data(0,:) = yvalues_g(:,0,m) + plot_data(1,:) = yvalues_g(:,1,m) + + plot = gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + end do + +;------------------------------------------ +; data for table : per biome + +; unit change from TgC/month to PgC/month + unit_factor = 1.e-3 + + score_max = 1. + + tmp_ob = new((/ntime/),float) + tmp_mod = new((/ntime/),float) + + total_ob = new((/n_biome/),float) + total_mod = new((/n_biome/),float) + Mscore2 = new((/n_biome/),float) + + do m = 0, n_biome-1 + + tmp_ob = yvalues_g(:,0,m) + tmp_mod = yvalues_g(:,1,m) + + total_ob(m) = avg(month_to_annual(tmp_ob, 0)) * unit_factor + total_mod(m) = avg(month_to_annual(tmp_mod,0)) * unit_factor + + cc_time = esccr(tmp_mod,tmp_ob,0) + + ratio = total_mod(m)/total_ob(m) + + good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.) + + bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) ) + Mscore2(m) = (1.- (bias/dimsizes(good)))*score_max + + delete (good) + + text(m,0) = sprintf("%.2f",total_ob(m)) + text(m,1) = sprintf("%.2f",total_mod(m)) + text(m,2) = sprintf("%.2f",cc_time) + text(m,3) = sprintf("%.2f",ratio) + text(m,4) = sprintf("%.2f",Mscore2(m)) + text(m,5) = "model_vs_ob" + end do + + delete (tmp_ob) + delete (tmp_mod) + +;-------------------------------------------- +; time series plot: all biome + + plot_name = "monthly_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = "Fire : "+ row_head(n_biome) + res@tiMainString = title + + do k = 0,ntime-1 + plot_data(0,k) = sum(yvalues_g(k,0,:)) + plot_data(1,k) = sum(yvalues_g(k,1,:)) + end do + + plot = gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + +;------------------------------------------ +; data for table : global + + score_max = 1. + + tmp_ob = ndtooned(yvalues_g(:,0,:)) + tmp_mod = ndtooned(yvalues_g(:,1,:)) + + cc_time = esccr(tmp_mod,tmp_ob,0) + + ratio = sum(total_mod)/sum(total_ob) + + good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.) + + bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) ) + Mscore3 = (1.- (bias/dimsizes(good)))*score_max + + print (Mscore3) + + delete (good) + + text(nrow-1,0) = sprintf("%.2f",sum(total_ob)) + text(nrow-1,1) = sprintf("%.2f",sum(total_mod)) + text(nrow-1,2) = sprintf("%.2f",cc_time) + text(nrow-1,3) = sprintf("%.2f",ratio) +; text(nrow-1,4) = sprintf("%.2f",avg(Mscore2)) + text(nrow-1,4) = sprintf("%.2f", Mscore3) + text(nrow-1,5) = "model_vs_ob" + +;************************************************** +; create html table +;************************************************** + + header_text = "

Fire Emission (1997-2004): Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text(n,0) + txt2 = text(n,1) + txt3 = text(n,2) + txt4 = text(n,3) + txt5 = text(n,4) + txt6 = text(n,5) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_fire.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + +end + diff -r 000000000000 -r 0c6405ab2ff4 fire/24x.table+tseries.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fire/24x.table+tseries.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,784 @@ +;******************************************************** +; using observed biome class +; landfrac applied to area only. +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;--------------------------------------------------- +; model name and grid + + model_grid = "T42" + + model_name = "cn" + model_name1 = "i01.06cn" + model_name2 = "i01.10cn" + +;------------------------------------------------ +; read biome data: observed + + biome_name_ob = "MODIS LandCover" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "land_class_"+model_grid+".nc" + + fo = addfile(diro+filo,"r") + + classob = tofloat(fo->LAND_CLASS) + + delete (fo) + +; observed data has 20 land-type classes + + nclass_ob = 20 + +;--------------------------------------------------- +; get biome data: model + + biome_name_mod = "Model PFT Class" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "class_pft_"+model_grid+".nc" + fm = addfile(dirm+film,"r") + + classmod = fm->CLASS_PFT + + delete (fm) + +; model data has 17 land-type classes + + nclass_mod = 17 + +;-------------------------------------------------- +; get model data: landmask, landfrac and area + + dirm = "/fis/cgd/cseg/people/jeff/surface_data/" + film = "lnd_T42.nc" + fm = addfile (dirm+film,"r") + + landmask = fm->landmask + landfrac = fm->landfrac + area = fm->area + + delete (fm) + +; change area from km**2 to m**2 + area = area * 1.e6 + +;--------------------------------------------------- +; take into account landfrac + + area = area * landfrac + +;---------------------------------------------------- +; read data: time series, model + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name2 + "_Fire_C_1979-2004_monthly.nc" + fm = addfile (dirm+film,"r") + + data_mod = fm->COL_FIRE_CLOSS(18:25,:,:,:) + + delete (fm) + +; Units for these variables are: +; g C/m^2/s + +; change unit to g C/m^2/month + + nsec_per_month = 60*60*24*30 + + data_mod = data_mod * nsec_per_month + + data_mod@unit = "gC/m2/month" +;---------------------------------------------------- +; read data: time series, observed + + dirm = "/fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/" + film = "Fire_C_1997-2006_monthly_"+ model_grid+".nc" + fm = addfile (dirm+film,"r") + + data_ob = fm->FIRE_C(0:7,:,:,:) + + delete (fm) + + ob_name = "GFEDv2" + +; Units for these variables are: +; g C/m^2/month + +;------------------------------------------------------------- +; html table1 data + +; column (not including header column) + + col_head = (/"Observed Fire_Flux (PgC/yr)" \ + ,"Model Fire_Flux (PgC/yr)" \ + ,"Correlation Coefficient" \ + ,"Ratio model/observed" \ + ,"M_score" \ + ,"Timeseries plot" \ + /) + + ncol = dimsizes(col_head) + +; row (not including header row) + +;---------------------------------------------------- +; using observed biome class: + row_head = (/"Evergreen Needleleaf Forests" \ + ,"Evergreen Broadleaf Forests" \ + ,"Deciduous Needleleaf Forest" \ + ,"Deciduous Broadleaf Forests" \ + ,"Mixed Forests" \ + ,"Closed Bushlands" \ + ,"Open Bushlands" \ + ,"Woody Savannas (S. Hem.)" \ + ,"Savannas (S. Hem.)" \ + ,"Grasslands" \ + ,"Permanent Wetlands" \ + ,"Croplands" \ + ,"Cropland/Natural Vegetation Mosaic" \ + ,"Barren or Sparsely Vegetated" \ + ,"Woody Savannas (N. Hem.)" \ + ,"Savannas (N. Hem.)" \ + ,"All Biome" \ + /) + + +; using model biome class: +; row_head = (/"Not Vegetated" \ +; ,"Needleleaf Evergreen Temperate Tree" \ +; ,"Needleleaf Evergreen Boreal Tree" \ +;; ,"Needleleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Tropical Tree" \ +; ,"Broadleaf Evergreen Temperate Tree" \ +; ,"Broadleaf Deciduous Tropical Tree" \ +; ,"Broadleaf Deciduous Temperate Tree" \ +;; ,"Broadleaf Deciduous Boreal Tree" \ +;; ,"Broadleaf Evergreen Shrub" \ +; ,"Broadleaf Deciduous Temperate Shrub" \ +; ,"Broadleaf Deciduous Boreal Shrub" \ +; ,"C3 Arctic Grass" \ +; ,"C3 Non-Arctic Grass" \ +; ,"C4 Grass" \ +; ,"Corn" \ +;; ,"Wheat" \ +; ,"All Biome" \ +; /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text = new ((/nrow, ncol/),string ) + +;***************************************************************** +; (A) get time-mean +;***************************************************************** + + x = dim_avg_Wrap(data_mod(lat|:,lon|:,month|:,year|:)) + data_mod_m = dim_avg_Wrap( x(lat|:,lon|:,month|:)) + delete (x) + + x = dim_avg_Wrap( data_ob(lat|:,lon|:,month|:,year|:)) + data_ob_m = dim_avg_Wrap( x(lat|:,lon|:,month|:)) + delete (x) + +;---------------------------------------------------- +; compute correlation coef: space + + landmask_1d = ndtooned(landmask) + data_mod_1d = ndtooned(data_mod_m) + data_ob_1d = ndtooned(data_ob_m ) + area_1d = ndtooned(area) + landfrac_1d = ndtooned(landfrac) + + good = ind(landmask_1d .gt. 0.) + + global_mod = sum(data_mod_1d(good)*area_1d(good)) * 1.e-15 * 12. + global_ob = sum(data_ob_1d(good) *area_1d(good)) * 1.e-15 * 12. + + print (global_mod) + print (global_ob) + + global_area= sum(area_1d) + global_land= sum(area_1d(good)) + print (global_area) + print (global_land) + + cc_space = esccr(data_mod_1d(good)*landfrac_1d(good),data_ob_1d(good)*landfrac_1d(good),0) + + delete (landmask_1d) + delete (landfrac_1d) +; delete (area_1d) + delete (data_mod_1d) + delete (data_ob_1d) + delete (good) + +;---------------------------------------------------- +; compute M_global + + score_max = 1. + + Mscore1 = cc_space * cc_space * score_max + + M_global = sprintf("%.2f", Mscore1) + +;---------------------------------------------------- +; global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + +;---------------------------------------------------- +; global contour: model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") + + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;---------------------- +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%.2f", cc_space)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) + +;----------------------- +; plot ob + + data_ob_m = where(landmask .gt. 0., data_ob_m, data_ob_m@_FillValue) + + title = ob_name + resg@tiMainString = title + + resg@cnMinLevelValF = 1. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + plot(0) = gsn_csm_contour_map_ce(wks,data_ob_m,resg) + +;----------------------- +; plot model + + data_mod_m = where(landmask .gt. 0., data_mod_m, data_mod_m@_FillValue) + + title = "Model "+ model_name + resg@tiMainString = title + + resg@cnMinLevelValF = 1. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + plot(1) = gsn_csm_contour_map_ce(wks,data_mod_m,resg) + +;----------------------- +; plot model-ob + + resg@cnMinLevelValF = -8. + resg@cnMaxLevelValF = 2. + resg@cnLevelSpacingF = 1. + + zz = data_ob_m + zz = data_mod_m - data_ob_m + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + +; plot panel + + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + delete (data_ob_m) + delete (data_mod_m) + delete (zz) + + resg@gsnFrame = True ; Do advance frame + resg@gsnDraw = True ; Do draw plot + +;******************************************************************* +; (B) Time series : per biome +;******************************************************************* + + data_n = 2 + + dsizes = dimsizes(data_mod) + nyear = dsizes(0) + nmonth = dsizes(1) + ntime = nyear * nmonth + + year_start = 1997 + year_end = 2004 + +;------------------------------------------- +; Calculate "nice" bins for binning the data + +; using ob biome class + nclass = nclass_ob +; using model biome class +; nclass = nclass_mod + + range = fspan(0,nclass,nclass+1) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nx = dimsizes(range) - 1 + +;------------------------------------------- +; put data into bins + +; using observed biome class + base = ndtooned(classob) +; using model biome class +; base = ndtooned(classmod) + +; output + + area_bin = new((/nx/),float) + yvalues = new((/ntime,data_n,nx/),float) + +; Loop through each range, using base. + + do i=0,nx-1 + + if (i.ne.(nx-1)) then + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else + idx = ind(base.ge.range(i)) + end if +;--------------------- +; for area + + if (.not.any(ismissing(idx))) then + area_bin(i) = sum(area_1d(idx)) + else + area_bin(i) = area_bin@_FillValue + end if + +;############################################################# +;using observed biome class: +; set the following 4 classes to _FillValue: +; Water Bodies(0), Urban and Build-Up(13), +; Permenant Snow and Ice(15), Unclassified(17) + + if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then + area_bin(i) = yvalues@_FillValue + end if +;############################################################# + + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + +; if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then +; area_bin(i) = area_bin@_FillValue +; end if +;############################################################# + +;--------------------- +; for data_mod and data_ob + + do n = 0,data_n-1 + + t = -1 + do m = 0,nyear-1 + do k = 0,nmonth-1 + + t = t + 1 + + if (n.eq.0) then + data = ndtooned(data_ob(m,k,:,:)) + end if + + if (n.eq.1) then + data = ndtooned(data_mod(m,k,:,:)) + end if + +; Calculate average + + if (.not.any(ismissing(idx))) then + yvalues(t,n,i) = sum(data(idx)*area_1d(idx)) + else + yvalues(t,n,i) = yvalues@_FillValue + end if + +;############################################################# +;using observed biome class: +; set the following 4 classes to _FillValue: +; Water Bodies(0), Urban and Build-Up(13), +; Permenant Snow and Ice(15), Unclassified(17) + + if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then + yvalues(t,n,i) = yvalues@_FillValue + end if +;############################################################# + + +;############################################################# +; using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + +; if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then +; yvalues(t,n,i) = yvalues@_FillValue +; end if +;############################################################# + + end do + end do + + delete(data) + end do + + delete(idx) + end do + + delete (base) + delete (data_mod) + delete (data_ob) + + global_bin = sum(area_bin) + print (global_bin) + +;---------------------------------------------------------------- +; get area_good + + good = ind(.not.ismissing(area_bin)) + + area_g = area_bin(good) + + n_biome = dimsizes(good) + + global_good = sum(area_g) + print (global_good) + +;---------------------------------------------------------------- +; data for tseries plot + + yvalues_g = new((/ntime,data_n,n_biome/),float) + + yvalues_g@units = "TgC/month" + +; change unit to Tg C/month +; change unit from g to Tg (Tera gram) + factor_unit = 1.e-12 + + yvalues_g = yvalues(:,:,good) * factor_unit + + delete (good) + +;------------------------------------------------------------------- +; general settings for line plot + + res = True + res@xyDashPatterns = (/0,0/) ; make lines solid + res@xyLineThicknesses = (/2.0,2.0/) ; make lines thicker + res@xyLineColors = (/"blue","red"/) ; line color + + res@trXMinF = year_start + res@trXMaxF = year_end + 1 + + res@vpHeightF = 0.4 ; change aspect ratio of plot +; res@vpWidthF = 0.8 + res@vpWidthF = 0.75 + + res@tiMainFontHeightF = 0.025 ; size of title + + res@tmXBFormat = "f" ; not to add trailing zeros + +; res@gsnMaximize = True + +;---------------------------------------------- +; Add a boxed legend using the simple method + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.06 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendOrthogonalPosF = -0.30 ;(downward) + +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + res@pmLegendParallelPosF = 0.73 ;(rightward) + res@pmLegendParallelPosF = 0.83 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) + +;******************************************************************* +; (A) time series plot: monthly ( 2 lines per plot) +;******************************************************************* + +; x-axis in time series plot + + timeI = new((/ntime/),integer) + timeF = new((/ntime/),float) + timeI = ispan(1,ntime,1) + timeF = year_start + (timeI-1)/12. + timeF@long_name = "year" + + plot_data = new((/2,ntime/),float) + plot_data@long_name = "TgC/month" + +;---------------------------------------------- +; time series plot : per biome + + do m = 0, n_biome-1 + + plot_name = "monthly_biome_"+ m + + wks = gsn_open_wks (plot_type,plot_name) + + title = "Fire : "+ row_head(m) + res@tiMainString = title + + plot_data(0,:) = yvalues_g(:,0,m) + plot_data(1,:) = yvalues_g(:,1,m) + + plot = gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + + end do + +;------------------------------------------ +; data for table : per biome + +; unit change from TgC/month to PgC/month + unit_factor = 1.e-3 + + score_max = 1. + + tmp_ob = new((/ntime/),float) + tmp_mod = new((/ntime/),float) + + total_ob = new((/n_biome/),float) + total_mod = new((/n_biome/),float) + Mscore2 = new((/n_biome/),float) + + do m = 0, n_biome-1 + + tmp_ob = yvalues_g(:,0,m) + tmp_mod = yvalues_g(:,1,m) + + total_ob(m) = avg(month_to_annual(tmp_ob, 0)) * unit_factor + total_mod(m) = avg(month_to_annual(tmp_mod,0)) * unit_factor + + cc_time = esccr(tmp_mod,tmp_ob,0) + + ratio = total_mod(m)/total_ob(m) + + good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.) + + bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) ) + Mscore2(m) = (1.- (bias/dimsizes(good)))*score_max + + delete (good) + + text(m,0) = sprintf("%.2f",total_ob(m)) + text(m,1) = sprintf("%.2f",total_mod(m)) + text(m,2) = sprintf("%.2f",cc_time) + text(m,3) = sprintf("%.2f",ratio) + text(m,4) = sprintf("%.2f",Mscore2(m)) + text(m,5) = "model_vs_ob" + end do + + delete (tmp_ob) + delete (tmp_mod) + +;-------------------------------------------- +; time series plot: all biome + + plot_name = "monthly_global" + + wks = gsn_open_wks (plot_type,plot_name) + + title = "Fire : "+ row_head(n_biome) + res@tiMainString = title + + do k = 0,ntime-1 + plot_data(0,k) = sum(yvalues_g(k,0,:)) + plot_data(1,k) = sum(yvalues_g(k,1,:)) + end do + + plot = gsn_csm_xy(wks,timeF,plot_data,res) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) + +;------------------------------------------ +; data for table : global + + score_max = 1. + + tmp_ob = ndtooned(yvalues_g(:,0,:)) + tmp_mod = ndtooned(yvalues_g(:,1,:)) + + cc_time = esccr(tmp_mod,tmp_ob,0) + + ratio = sum(total_mod)/sum(total_ob) + + good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.) + + bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) ) + Mscore3 = (1.- (bias/dimsizes(good)))*score_max + + print (Mscore3) + + delete (good) + + text(nrow-1,0) = sprintf("%.2f",sum(total_ob)) + text(nrow-1,1) = sprintf("%.2f",sum(total_mod)) + text(nrow-1,2) = sprintf("%.2f",cc_time) + text(nrow-1,3) = sprintf("%.2f",ratio) +; text(nrow-1,4) = sprintf("%.2f",avg(Mscore2)) + text(nrow-1,4) = sprintf("%.2f", Mscore3) + text(nrow-1,5) = "model_vs_ob" + +;************************************************** +; create html table +;************************************************** + + header_text = "

Fire Emission (1997-2004): Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Type"+col_head(0)+""+col_head(1)+""+col_head(2)+""+col_head(3)+""+col_head(4)+""+col_head(5)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt0 = row_head(n) + txt1 = text(n,0) + txt2 = text(n,1) + txt3 = text(n,2) + txt4 = text(n,3) + txt5 = text(n,4) + txt6 = text(n,5) + + set_line(lines,nline,""+txt0+"") + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + + output_html = "table_fire.html" + + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) + +end + diff -r 000000000000 -r 0c6405ab2ff4 fire/note.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fire/note.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,6 @@ +observed data in /fis/cgd/cseg/people/jeff/fire_data/ob/GFEDv2_C/ + Fire_C_1997-2006_monthly_T42.nc + +model data in /fis/cgd/cseg/people/jeff/clamp_data/model + i01.10cn_Fire_C_1979-2004_monthly.nc + i01.10casa_Fire_C_1979-2004_monthly.nc \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/01.read.land_class.ascii.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/01.read.land_class.ascii.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,55 @@ +;************************************************ +; Read ascii, Write nc +; output: lat: N->S lon: -180W->180E +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;--------------------------------------------------- +; final data + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" + filo = "land_class_0.25deg.nc" + c = addfile(diro+filo,"c") +; filedimdef(c,"time",-1,True) + + nlat = 180*4 + nlon = 360*4 + + t = new((/nlat,nlon/),integer) + lon = new((/nlon/),float) + lat = new((/nlat/),float) +;--------------------------------------------------- +; input data + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/modis_landcover_qdeg/" + fili = "modis_landcover_class_qd.asc" + b = diri+fili + + lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north") + lat = (/ lat(::-1) /) ; make N->S + lon = lonGlobeFo(nlon, "lon", "longitude", "degrees_east") + lon = (/ lon - 180. /) ; subtract 180 from all values + lon&lon = lon ; update coordinates + lat&lat = lat ; update coordinates + +;============================= +; name dimensions of t and assign coordinate variables +;============================ + t!0 = "lat" + t!1 = "lon" + t&lat = lat + t&lon = lon + t@long_name = "landcover class" + t@units = "" + t@_FillValue= -9999 + t@missing_value= -9999 + + t = asciiread(b,(/nlat,nlon/),"integer") + + c->LAND_CLASS = t + c->lat = lat + c->lon = lon + + print (min(t) + "/" + max(t)) +end diff -r 000000000000 -r 0c6405ab2ff4 lai/01.read.land_class.split.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/01.read.land_class.split.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,67 @@ +;************************************************ +; Read ascii, Write nc +; output: lat: N->S lon: -180W->180E +; class 8 split into class 8 = woody savanna (S. Hem.) +; 18 = woody savanna (N. Hem.) +; class 8 split into class 9 = savanna (S. Hem.) +; 19 = savanna (N. Hem.) +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;--------------------------------------------------- +; final data + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" + filo = "land_class_0.25deg_new.nc" + c = addfile(diro+filo,"c") +; filedimdef(c,"time",-1,True) + + nlat = 180*4 + nlon = 360*4 + + t = new((/nlat,nlon/),integer) + lon = new((/nlon/),float) + lat = new((/nlat/),float) +;--------------------------------------------------- +; input data + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/modis_landcover_qdeg/" + fili = "modis_landcover_class_qd.asc" + b = diri+fili + + lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north") + lat = (/ lat(::-1) /) ; make N->S + lon = lonGlobeFo(nlon, "lon", "longitude", "degrees_east") + lon = (/ lon - 180. /) ; subtract 180 from all values + lon&lon = lon ; update coordinates + lat&lat = lat ; update coordinates + +;============================= +; name dimensions of t and assign coordinate variables +;============================ + t!0 = "lat" + t!1 = "lon" + t&lat = lat + t&lon = lon + t@long_name = "landcover class" + t@units = "" + t@_FillValue= -9999 + t@missing_value= -9999 + + t = asciiread(b,(/nlat,nlon/),"integer") + + nlat = dimsizes(lat) + ny2 = nlat/2 + + do j = 0,ny2-1 + t(j,:) = where((t(j,:) .eq. 8),18,t(j,:)) + t(j,:) = where((t(j,:) .eq. 9),19,t(j,:)) + end do + + c->LAND_CLASS = t + c->lat = lat + c->lon = lon + + print (min(t) + "/" + max(t)) +end diff -r 000000000000 -r 0c6405ab2ff4 lai/02.read_byte_LAI.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/02.read_byte_LAI.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,40 @@ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +begin + nlat = 3600 + mlon = 7200 + + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" + fili = "MOD15A2_GEO_2000001.nc" + a = addfile(diri+fili,"r") + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/" + filo = "LAI_2000001_3.nc" + c = addfile(diro+filo,"c") + + y = a->Lai_0_05deg + + y@_FillValue = inttobyte(253) + y@_FillValue = inttobyte(255) + + x = byte2flt(y) + +; x@_FillValue = -17281 ; orig fill + x@_FillValue = 1.e+36 ; new fill + + lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north") + lat = (/ lat(::-1) /) ; make N->S + lon = lonGlobeFo(mlon, "lon", "longitude", "degrees_east") + lon = (/ lon - 180. /) ; subtract 180 from all values + lon&lon = lon ; update coordinates + + x!0 = "lat" + x!1 = "lon" + x&lat= lat + x&lon= lon + + c->LAI = x +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/02.read_byte_LAI.ncl.x --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/02.read_byte_LAI.ncl.x Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,54 @@ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +begin + nlat = 3600 + mlon = 7200 + + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" + fili = "MOD15A2_GEO_2000001.nc" + a = addfile(diri+fili,"r") + + y = a->Lai_0_05deg ; byte + y@_FillValue = inttobyte(253) + y@_FillValue = inttobyte(255) + + x = byte2flt(y) + + x@_FillValue = 1.e+36 ; new fill + + lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north") + lat = (/ lat(::-1) /) ; make N->S + lon = lonGlobeFo(mlon, "lon", "longitude", "degrees_east") + lon = (/ lon - 180. /) ; subtract 180 from all values + lon&lon = lon ; update coordinates + + x!0 = "lat" + x!1 = "lon" + x&lat= lat + x&lon= lon + + y!0 = "lat" + y!1 = "lon" + y&lat= lat + y&lon= lon + + iy = new (dimsizes(y), "integer", -999) + iy = y + + iy!0 = "lat" + iy!1 = "lon" + iy&lat= lat + iy&lon= lon + + print(y(:,{130})+" "+ iy(:,{130})+" "+x(:,{130})) + + + +; diro = "/fis/cgd/cseg/people/jeff/clamp_data/" +; filo = "LAI_2000001_2.nc" +; c = addfile(diro+filo,"c") +; c->LAI = x +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/02.read_byte_LAI.note --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/02.read_byte_LAI.note Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,3 @@ +on tempest, convert to netcdf +> ncl_convert2nc *.hdf + \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/02.read_lai_avg.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/02.read_lai_avg.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,91 @@ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +begin +;---------------------------------------------------------- + year = "2004" + + nlat = 3600 + mlon = 7200 + month_in_year = 12 +;---------------------------------------------------------- + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" + diro = "/fis/cgd/cseg/people/jeff/clamp_data/" + filo = "MOD15A2_LAI_" + year + "_monthly.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + + day = (/"001","009","017","025","033","041","049","057","065","073", \ + "081","089","097","105","113","121","129","137","145","153", \ + "161","169","177","185","193","201","209","217","225","233", \ + "241","249","257","265","273","281","289","297","305","313", \ + "321","329","337","345","353","361"/) + + file_index_L = (/0,3,7 ,11,15,18,22,26,30,34,38,41/) + file_index_R = (/3,7,11,14,18,22,26,30,34,37,41,45/) + scale_L = (/8,1,5,6,8,1,3,4,5,7,8,2/) + scale_R = (/7,3,2,8,7,5,4,3,1,8,6,5/) + +; dayI = stringtointeger(day) +; print (dayI) + + x = new((/12,nlat,mlon/),float) + x = 0. + x@_FillValue = 1.e+36 + + do m = 0,month_in_year-1 + nday = 0 ; number of day in a month + do n = file_index_L(m),file_index_R(m) + fili = "MOD15A2_GEO_" + year + day(n) + ".hdf" + print (fili) + a = addfile(diri+fili,"r") + y = a->Lai_0_05deg + + y@_FillValue = inttobyte(253) ; special missing value? + y@_FillValue = inttobyte(255) ; missing value + + z = byte2flt(y) + + z@_FillValue = 1.e+36 + +; weighted by day, data is 8-day average + scale = 8 + if (n .eq. file_index_L(m)) then + scale = scale_L(m) + end if + if (n .eq. file_index_R(m)) then + scale = scale_R(m) + end if + + nday = nday + scale + + x(m,:,:) = where(ismissing(z),1.e+36,x(m,:,:)+z(:,:)*scale) + + delete (a) + delete (y) + delete (z) + end do + x(m,:,:) = where(ismissing(x(m,:,:)),1.e+36,x(m,:,:)/nday) + print (nday) + print (min(x) + "/" + max(x)) + end do + + lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north") + lat = (/ lat(::-1) /) ; make N->S + lon = lonGlobeFo(mlon, "lon", "longitude", "degrees_east") + lon = (/ lon - 180. /) ; subtract 180 from all values + lon&lon = lon ; update coordinates + + x!0 = "time" + x!1 = "lat" + x!2 = "lon" + x&time= ispan(1,month_in_year,1) + x&lat= lat + x&lon= lon + x@units = "none" + x@long_name = "Leaf Area Index" + + c->LAI = x +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/022.lai_ensemble.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/022.lai_ensemble.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,50 @@ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +begin +;---------------------------------------------------------- + year_start = 2000 + year_end = 2005 +;---------------------------------------------------------- + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" + diro = "/fis/cgd/cseg/people/jeff/clamp_data/" + filo1 = "LAI_"+year_start+"-"+year_end+"_ensemble_T42.nc" + filo2 = "LAI_"+year_start+"-"+year_end+"_mean_T42.nc" + c = addfile(diro+filo1,"c") + d = addfile(diro+filo2,"c") + + nyear = year_end - year_start + 1 + + do n = year_start,year_end + +; fili = "LAI_" + n + "_monthly.nc" + fili = "LAI_" + n + "_monthly_T42.nc" + print (fili) + + a = addfile(diri+fili,"r") + x = a->LAI + + if (n .eq. year_start) then + y = x + printVarSummary (x) + else + y = y + x + end if + + delete (a) + delete (x) + delete (fili) + end do + + y = y/nyear + printVarSummary (y) + + c->LAI = y + + z = dim_avg_Wrap(y(lat|:,lon|:,time|:)) + printVarSummary (z) + + d->LAI = z +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/022.lai_ensemble.ncl.x --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/022.lai_ensemble.ncl.x Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,45 @@ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +begin +;---------------------------------------------------------- + year_start = 2000 + year_end = 2005 +;---------------------------------------------------------- + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" + diro = "/fis/cgd/cseg/people/jeff/clamp_data/" + filo1 = "LAI_"+year_start+"-"+year_end+"_ensemble.nc" + filo2 = "LAI_"+year_start+"-"+year_end+"_mean.nc" + c = addfile(diro+filo1,"c") + d = addfile(diro+filo2,"c") + + nyear = year_end - year_start + 1 + + files = new((/nyear/),"string") + + do n = year_start,year_end + i = n - year_start + files(i)= diri + "LAI_" + n + "_monthly.nc" + end do +; print (files) + + file_list = addfiles(files,"r") + ListSetType(file_list,"join") + x = addfiles_GetVar(file_list, files, "LAI") + print (files) + + x!0 = "case" + x!1 = "time" + x!2 = "lat" + x!3 = "lon" + + y = dim_avg(x(time|:,lat|:,lon|:,case|:)) + print (files) + c->LAI = y + print (files) + + z = dim_avg(y(lat|:,lon|:,time|:)) + d->LAI = z +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/03.2.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.2.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,132 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + year = 2001 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "LAI_" + year + "_monthly_1.9.nc" + + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + fili = "LAI_" + year + "_monthly.nc" + + g = addfile (diri+fili,"r") + bi = g->LAI + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(:,::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,:,p)= b2(:,:,i) + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "newcn05_ncep_1i_MONS_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = new((/12,nlat,nlon/),float) + + do m = 0,11 + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + bo(m,j,i) = avg(bi(m,{LATS:LATN},{LONL:LONR})) + end do + end do + end do + + bo!0 = "time" + bo!1 = "lat" + bo!2 = "lon" + bo&time= bi&time + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name + bo@_FillValue = bi@_FillValue + + c->LAI = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.3.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.3.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,132 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + year = 2002 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "LAI_" + year + "_monthly_1.9.nc" + + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + fili = "LAI_" + year + "_monthly.nc" + + g = addfile (diri+fili,"r") + bi = g->LAI + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(:,::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,:,p)= b2(:,:,i) + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "newcn05_ncep_1i_MONS_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = new((/12,nlat,nlon/),float) + + do m = 0,11 + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + bo(m,j,i) = avg(bi(m,{LATS:LATN},{LONL:LONR})) + end do + end do + end do + + bo!0 = "time" + bo!1 = "lat" + bo!2 = "lon" + bo&time= bi&time + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name + bo@_FillValue = bi@_FillValue + + c->LAI = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.4.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.4.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,132 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + year = 2003 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "LAI_" + year + "_monthly_1.9.nc" + + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + fili = "LAI_" + year + "_monthly.nc" + + g = addfile (diri+fili,"r") + bi = g->LAI + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(:,::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,:,p)= b2(:,:,i) + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "newcn05_ncep_1i_MONS_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = new((/12,nlat,nlon/),float) + + do m = 0,11 + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + bo(m,j,i) = avg(bi(m,{LATS:LATN},{LONL:LONR})) + end do + end do + end do + + bo!0 = "time" + bo!1 = "lat" + bo!2 = "lon" + bo&time= bi&time + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name + bo@_FillValue = bi@_FillValue + + c->LAI = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.5.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.5.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,132 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + year = 2004 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "LAI_" + year + "_monthly_1.9.nc" + + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + fili = "LAI_" + year + "_monthly.nc" + + g = addfile (diri+fili,"r") + bi = g->LAI + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(:,::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,:,p)= b2(:,:,i) + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "newcn05_ncep_1i_MONS_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = new((/12,nlat,nlon/),float) + + do m = 0,11 + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + bo(m,j,i) = avg(bi(m,{LATS:LATN},{LONL:LONR})) + end do + end do + end do + + bo!0 = "time" + bo!1 = "lat" + bo!2 = "lon" + bo&time= bi&time + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name + bo@_FillValue = bi@_FillValue + + c->LAI = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.6.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.6.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,132 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + year = 2005 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "LAI_" + year + "_monthly_1.9.nc" + + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + fili = "LAI_" + year + "_monthly.nc" + + g = addfile (diri+fili,"r") + bi = g->LAI + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(:,::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,:,p)= b2(:,:,i) + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "newcn05_ncep_1i_MONS_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = new((/12,nlat,nlon/),float) + + do m = 0,11 + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + bo(m,j,i) = avg(bi(m,{LATS:LATN},{LONL:LONR})) + end do + end do + end do + + bo!0 = "time" + bo!1 = "lat" + bo!2 = "lon" + bo&time= bi&time + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name + bo@_FillValue = bi@_FillValue + + c->LAI = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.lai_ob_to_0.25deg.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.lai_ob_to_0.25deg.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,154 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + year = 2000 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" +; filo = "LAI_" + year + "_monthly_0.25deg.nc" + filo = "LAI_2000-2005_mean_0.25deg.nc" +; filo = "LAI_2000-2005_ensemble_0.25deg.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" +; fili = "LAI_" + year + "_monthly.nc" + fili = "LAI_2000-2005_mean_0.05deg.nc" +; fili = "LAI_2000-2005_ensemble_0.05deg.nc" + g = addfile (diri+fili,"r") + bi = g->LAI + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +; Observed NPP*scale_factor +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(:,::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,:,p)= b2(:,:,i) + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) +;exit + +;************************************************ +; create 0.25deg lat and lon +;************************************************ + nlon = 360*4 + nlat = 180*4 + + lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north") ; S->N +; lat = (/ lat(::-1) /) ; N->S + lat&lat = lat + lon = lonGlobeFo(nlon, "lon", "longitude", "degrees_east") ; 0->360 +; lon = (/ lon - 180. /) ; subtract 180 from all values ; 180W-180E + lon&lon = lon ; update coordinates + +; print (lon) +; print (lat) + +; rad = 4.*atan(1.)/180. +; clat = lat +; clat = cos(lat*rad) +; clat@long_name = "cos(latitude)" +; delete(clat@units) +; printVarSummary(clat) + +;bo = new((/12,nlat,nlon/),float) + bo = new((/1,nlat,nlon/),float) + +;do m = 0,11 + do m = 0,0 + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + +; CLAT = clat({LATS:LATN}) ; do once for *slight* efficiency +; TEMP = bi(:,{LATS:LATN},:) ; 2D [lat,lon] + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + bo(m,j,i) = avg(bi(m,{LATS:LATN},{LONL:LONR})) +; bo(m,j,i) = wgt_areaave(TEMP(m,{LONL:LONR}), CLAT, 1.0, 0) + end do + +; delete(CLAT) +; delete(TEMP) + end do + end do + + bo!0 = "time" + bo!1 = "lat" + bo!2 = "lon" + bo&time= bi&time +; bo&time= 1 + bo&lat = lat + bo&lon = lon +; bo@units = bi@units +; bo@long_name = bi@long_name + bo@units = "none" + bo@long_name = "Leaf Area Index" + bo@_FillValue = bi@_FillValue + + c->LAI = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.lai_ob_to_0.25deg.ncl.0 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.lai_ob_to_0.25deg.ncl.0 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,157 @@ +; *********************************************** +; interpolate into 0.25degree +; no change in lat and lon, to be in consistent with +; land class data +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + year = 2003 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" + filo = "LAI_2000-2005_mean_0.25.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" +; fili = "LAI_2000-2005_mean_0.05deg.nc" + fili = "LAI_2000-2005_ensemble_0.05deg.nc" + g = addfile (diri+fili,"r") + bi = g->LAI + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +; Observed NPP*scale_factor +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(:,::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,:,p)= b2(:,:,i) + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) +;exit + +;************************************************ +; read in model data +;************************************************ +;fili2 = "i01.03cn_1545-1569_ANN_climo.nc" + fili2 = "" + f = addfile (diri+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + +;(A) +;bo = linint2_Wrap(xi,yi,bi,True,xo,yo,0) + +;(B) + +; rad = 4.*atan(1.)/180. +; clat = lat +; clat = cos(lat*rad) +; clat@long_name = "cos(latitude)" +; delete(clat@units) +; printVarSummary(clat) + + bo = new((/12,nlat,nlon/),float) +;bo = new((/1,nlat,nlon/),float) + do m = 0,11 + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + +; CLAT = clat({LATS:LATN}) ; do once for *slight* efficiency +; TEMP = bi(:,{LATS:LATN},:) ; 2D [lat,lon] + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) +; bo(:,j,i) = avg(bi(:,{LATS:LATN},{LONL:LONR})) + bo(m,j,i) = avg(bi(m,{LATS:LATN},{LONL:LONR})) +; bo(:,j,i) = wgt_areaave(TEMP(:,{LONL:LONR}), CLAT, 1.0, 0) + end do + +; delete(CLAT) +; delete(TEMP) + end do + end do + + bo!0 = "time" + bo!1 = "lat" + bo!2 = "lon" + bo&time= bi&time +; bo&time= 1 + bo&lat = lat + bo&lon = lon +; bo@units = bi@units +; bo@long_name = bi@long_name + bo@units = "none" + bo@long_name = "Leaf Area Index" + bo@_FillValue = bi@_FillValue + + c->LAI = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.lai_ob_to_1.9.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.lai_ob_to_1.9.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,132 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + year = 2000 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "LAI_" + year + "_monthly_1.9.nc" + + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + fili = "LAI_" + year + "_monthly.nc" + + g = addfile (diri+fili,"r") + bi = g->LAI + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(:,::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,:,p)= b2(:,:,i) + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "newcn05_ncep_1i_MONS_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = new((/12,nlat,nlon/),float) + + do m = 0,11 + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + bo(m,j,i) = avg(bi(m,{LATS:LATN},{LONL:LONR})) + end do + end do + end do + + bo!0 = "time" + bo!1 = "lat" + bo!2 = "lon" + bo&time= bi&time + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name + bo@_FillValue = bi@_FillValue + + c->LAI = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.lai_ob_to_T31.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.lai_ob_to_T31.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,133 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + year = 2000 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "LAI_" + year + "_monthly_T31.nc" + + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + fili = "LAI_" + year + "_monthly.nc" + + g = addfile (diri+fili,"r") + bi = g->LAI + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +; Observed NPP*scale_factor +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(:,::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,:,p)= b2(:,:,i) + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "b30.061n_1995-2004_MONS_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = new((/12,nlat,nlon/),float) + + do m = 0,11 + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + bo(m,j,i) = avg(bi(m,{LATS:LATN},{LONL:LONR})) + end do + end do + end do + + bo!0 = "time" + bo!1 = "lat" + bo!2 = "lon" + bo&time= bi&time + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name + bo@_FillValue = bi@_FillValue + + c->LAI = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.lai_ob_to_T31.ncl.x --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.lai_ob_to_T31.ncl.x Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,128 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "LAI_2000-2005_ensemble_T31.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + fili = "LAI_2000-2005_ensemble_0.05deg.nc" + g = addfile (diri+fili,"r") + bi = g->LAI + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(:,::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,:,p)= b2(:,:,i) + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "b30.061n_1995-2004_MONS_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = new((/12,nlat,nlon/),float) + + do m = 0,11 + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + bo(m,j,i) = avg(bi(m,{LATS:LATN},{LONL:LONR})) + end do + end do + end do + + bo!0 = "time" + bo!1 = "lat" + bo!2 = "lon" + bo&time= bi&time + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name + bo@_FillValue = bi@_FillValue +; bo@units = "none" +; bo@long_name = "Leaf Area Index" + + c->LAI = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.lai_ob_to_T42.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.lai_ob_to_T42.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,158 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + year = 2003 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/" +; filo = "LAI_" + year + "_monthly_T42.nc" +; filo = "LAI_2000-2005_mean_T42.nc" + filo = "LAI_2000-2005_ensemble_T42.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"time",-1,True) + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" +; fili = "LAI_" + year + "_monthly.nc" +; fili = "LAI_2000-2005_mean_0.05deg.nc" + fili = "LAI_2000-2005_ensemble_0.05deg.nc" + g = addfile (diri+fili,"r") + bi = g->LAI + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +; Observed NPP*scale_factor +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(:,::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,:,p)= b2(:,:,i) + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) +;exit + +;************************************************ +; read in model data +;************************************************ +;fili2 = "i01.04casa_1605-1629_ANN_climo.nc" + fili2 = "i01.03cn_1545-1569_ANN_climo.nc" + f = addfile (diri+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + +;(A) +;bo = linint2_Wrap(xi,yi,bi,True,xo,yo,0) + +;(B) + +; rad = 4.*atan(1.)/180. +; clat = lat +; clat = cos(lat*rad) +; clat@long_name = "cos(latitude)" +; delete(clat@units) +; printVarSummary(clat) + + bo = new((/12,nlat,nlon/),float) +;bo = new((/1,nlat,nlon/),float) + do m = 0,11 + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + +; CLAT = clat({LATS:LATN}) ; do once for *slight* efficiency +; TEMP = bi(:,{LATS:LATN},:) ; 2D [lat,lon] + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) +; bo(:,j,i) = avg(bi(:,{LATS:LATN},{LONL:LONR})) + bo(m,j,i) = avg(bi(m,{LATS:LATN},{LONL:LONR})) +; bo(:,j,i) = wgt_areaave(TEMP(:,{LONL:LONR}), CLAT, 1.0, 0) + end do + +; delete(CLAT) +; delete(TEMP) + end do + end do + + bo!0 = "time" + bo!1 = "lat" + bo!2 = "lon" + bo&time= bi&time +; bo&time= 1 + bo&lat = lat + bo&lon = lon +; bo@units = bi@units +; bo@long_name = bi@long_name + bo@units = "none" + bo@long_name = "Leaf Area Index" + bo@_FillValue = bi@_FillValue + + c->LAI = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.land_class_to_1.9.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.land_class_to_1.9.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,139 @@ +; *********************************************** +; interpolate into model grids (T42) +; output: lat: S->N lon: 0->360 +; input : lat: N->S lon: -180->180 +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + nclass = 20 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "land_class_1.9.nc" + c = addfile(diro+filo,"c") + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + fili = "land_class_0.25deg_new.nc" + g = addfile (diri+fili,"r") + bi = g->LAND_CLASS + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + nx2 = nx/2 + + do i= 0,nx-1 + if (i .lt. nx2) then + p = i + nx2 + xi(p) = x2(i) + 360. + else + p = i - nx2 + xi(p) = x2(i) + end if + bi(:,p)= b2(:,i) + end do + + bi&lat = yi + bi&lon = xi + + print (xi) + print (yi) +;exit + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "newcn05_ncep_1i_MONS_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = new((/nlat,nlon/),integer) + count = new((/nclass/),integer) + + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + count = 0 + + do n = 0,nclass-1 + count(n) = num (bi({LATS:LATN},{LONL:LONR}).eq.n) + end do + + bo(j,i) = maxind(count) + end do + end do + + bo!0 = "lat" + bo!1 = "lon" + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name + bo@_FillValue = bi@_FillValue + + print (min(bo) + "/" + max(bo)) + + c->LAND_CLASS = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.land_class_to_T31.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.land_class_to_T31.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,139 @@ +; *********************************************** +; interpolate into model grids (T42) +; output: lat: S->N lon: 0->360 +; input : lat: N->S lon: -180->180 +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + nclass = 20 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "land_class_T31.nc" + c = addfile(diro+filo,"c") + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + fili = "land_class_0.25deg_new.nc" + g = addfile (diri+fili,"r") + bi = g->LAND_CLASS + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + nx2 = nx/2 + + do i= 0,nx-1 + if (i .lt. nx2) then + p = i + nx2 + xi(p) = x2(i) + 360. + else + p = i - nx2 + xi(p) = x2(i) + end if + bi(:,p)= b2(:,i) + end do + + bi&lat = yi + bi&lon = xi + + print (xi) + print (yi) +;exit + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "b30.061n_1995-2004_ANN_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = new((/nlat,nlon/),integer) + count = new((/nclass/),integer) + + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + count = 0 + + do n = 0,nclass-1 + count(n) = num (bi({LATS:LATN},{LONL:LONR}).eq.n) + end do + + bo(j,i) = maxind(count) + end do + end do + + bo!0 = "lat" + bo!1 = "lon" + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name + bo@_FillValue = bi@_FillValue + + print (min(bo) + "/" + max(bo)) + + c->LAND_CLASS = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/03.land_class_to_T42.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/03.land_class_to_T42.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,141 @@ +; *********************************************** +; interpolate into model grids (T42) +; output: lat: S->N lon: 0->360 +; input : lat: N->S lon: -180->180 +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + nclass = 20 + +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" +; filo = "land_class_T42.nc" + filo = "land_class_T42_new.nc" + c = addfile(diro+filo,"c") + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" + fili = "land_class_0.25deg.nc" + fili = "land_class_0.25deg_new.nc" + g = addfile (diri+fili,"r") + bi = g->LAND_CLASS + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +;************************************************ + + yi = (/ yi(::-1) /) + bi = (/ bi(::-1,:) /) + printVarSummary(bi) + + b2 = bi + x2 = xi + + nx = dimsizes(xi) + nx2 = nx/2 + + do i= 0,nx-1 + if (i .lt. nx2) then + p = i + nx2 + xi(p) = x2(i) + 360. + else + p = i - nx2 + xi(p) = x2(i) + end if + bi(:,p)= b2(:,i) + end do + + bi&lat = yi + bi&lon = xi + + print (xi) + print (yi) +;exit + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "i01.03cn_1545-1569_ANN_climo.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = new((/nlat,nlon/),integer) + count = new((/nclass/),integer) + + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + count = 0 + + do n = 0,nclass-1 + count(n) = num (bi({LATS:LATN},{LONL:LONR}).eq.n) + end do + + bo(j,i) = maxind(count) + end do + end do + + bo!0 = "lat" + bo!1 = "lon" + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name + bo@_FillValue = bi@_FillValue + + print (min(bo) + "/" + max(bo)) + + c->LAND_CLASS = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/04.lai_ensemble.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/04.lai_ensemble.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,43 @@ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +begin +;---------------------------------------------------------- + year_start = 2000 + year_end = 2005 +;---------------------------------------------------------- + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" + diro = "/fis/cgd/cseg/people/jeff/clamp_data/" + filo1 = "MOD15A2_LAI_"+year_start+"-"+year_end+"_ensemble.nc" + filo2 = "MOD15A2_LAI_"+year_start+"-"+year_end+"_mean.nc" + c = addfile(diro+filo1,"c") + d = addfile(diro+filo2,"c") + + nyear = year_end - year_start + 1 + + files = new((/nyear/),"string") + + do n = year_start,year_end + i = n - year_start +; files(i)= diri + "MOD15A2_LAI_" + n + "_monthly.nc" + files(i)= diri + "MOD15A2_LAI_" + n + "_monthly_T42.nc" + end do + print (files) + + file_list = addfiles(files,"r") + ListSetType(file_list,"join") + x = addfiles_GetVar(file_list, files, "LAI") + printVarSummary (x) + + y = dim_avg_Wrap(x(time|:,lat|:,lon|:,case|:)) + printVarSummary (y) + + c->LAI = y + + z = dim_avg_Wrap(y(lat|:,lon|:,time|:)) + printVarSummary (z) + + d->LAI = z +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/04.lai_ensemble_1.9.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/04.lai_ensemble_1.9.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,46 @@ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +begin +;---------------------------------------------------------- + year_start = 2000 + year_end = 2005 +;---------------------------------------------------------- + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo1 = "LAI_"+year_start+"-"+year_end+"_MONS_1.9.nc" + filo2 = "LAI_"+year_start+"-"+year_end+"_ANN_1.9.nc" + c = addfile(diro+filo1,"c") + d = addfile(diro+filo2,"c") + + nyear = year_end - year_start + 1 + + files = new((/nyear/),"string") + + do n = year_start,year_end + i = n - year_start + files(i)= diri + "LAI_" + n + "_monthly_1.9.nc" + end do + print (files) + + file_list = addfiles(files,"r") + ListSetType(file_list,"join") + x = addfiles_GetVar(file_list, files, "LAI") + printVarSummary (x) + x@_FillValue = 1.e+36 + + y = dim_avg_Wrap(x(time|:,lat|:,lon|:,case|:)) + printVarSummary (y) + y@_FillValue = 1.e+36 + + c->LAI = y + + z = dim_avg_Wrap(y(lat|:,lon|:,time|:)) + printVarSummary (z) + z@_FillValue = 1.e+36 + + d->LAI = z +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/04.lai_ensemble_T31.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/04.lai_ensemble_T31.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,46 @@ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +begin +;---------------------------------------------------------- + year_start = 2000 + year_end = 2005 +;---------------------------------------------------------- + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo1 = "LAI_"+year_start+"-"+year_end+"_MONS_T31_3.nc" + filo2 = "LAI_"+year_start+"-"+year_end+"_ANN_T31_3.nc" + c = addfile(diro+filo1,"c") + d = addfile(diro+filo2,"c") + + nyear = year_end - year_start + 1 + + files = new((/nyear/),"string") + + do n = year_start,year_end + i = n - year_start + files(i)= diri + "LAI_" + n + "_monthly_T31.nc" + end do + print (files) + + file_list = addfiles(files,"r") + ListSetType(file_list,"join") + x = addfiles_GetVar(file_list, files, "LAI") + printVarSummary (x) + x@_FillValue = 1.e+36 + + y = dim_avg_Wrap(x(time|:,lat|:,lon|:,case|:)) + printVarSummary (y) + y@_FillValue = 1.e+36 + + c->LAI = y + + z = dim_avg_Wrap(y(lat|:,lon|:,time|:)) + printVarSummary (z) + z@_FillValue = 1.e+36 + + d->LAI = z +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/04.lai_ensemble_T42.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/04.lai_ensemble_T42.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,45 @@ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +begin +;---------------------------------------------------------- + year_start = 2000 + year_end = 2005 +;---------------------------------------------------------- + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" + diro = "/fis/cgd/cseg/people/jeff/clamp_data/" +; filo1 = "LAI_"+year_start+"-"+year_end+"_ensemble.nc" +; filo2 = "LAI_"+year_start+"-"+year_end+"_mean.nc" + filo1 = "LAI_"+year_start+"-"+year_end+"_ensemble_T42.nc" + filo2 = "LAI_"+year_start+"-"+year_end+"_mean_T42.nc" + c = addfile(diro+filo1,"c") + d = addfile(diro+filo2,"c") + + nyear = year_end - year_start + 1 + + files = new((/nyear/),"string") + + do n = year_start,year_end + i = n - year_start +; files(i)= diri + "LAI_" + n + "_monthly.nc" + files(i)= diri + "LAI_" + n + "_monthly_T42.nc" + end do + print (files) + + file_list = addfiles(files,"r") + ListSetType(file_list,"join") + x = addfiles_GetVar(file_list, files, "LAI") + printVarSummary (x) + + y = dim_avg_Wrap(x(time|:,lat|:,lon|:,case|:)) + printVarSummary (y) + + c->LAI = y + + z = dim_avg_Wrap(y(lat|:,lon|:,time|:)) + printVarSummary (z) + + d->LAI = z +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/04.lai_ensemble_T42.ncl.x --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/04.lai_ensemble_T42.ncl.x Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,82 @@ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +begin +;---------------------------------------------------------- + year_start = 2000 + year_end = 2005 +;---------------------------------------------------------- + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" + diro = "/fis/cgd/cseg/people/jeff/clamp_data/" + filo1 = "MOD15A2_LAI_"+year_start+"-"+year_end+"_ensemble.nc" + filo2 = "MOD15A2_LAI_"+year_start+"-"+year_end+"_mean.nc" + c = addfile(diro+filo1,"c") + d = addfile(diro+filo2,"c") + + nyear = year_end - year_start + 1 + + files = new((/nyear/),"string") + + do n = year_start,year_end + i = n - year_start +; files(i)= diri + "MOD15A2_LAI_" + n + "_monthly.nc" + files(i)= diri + "MOD15A2_LAI_" + n + "_monthly_T42.nc" + end do + print (files) + + file_list = addfiles(files,"r") + ListSetType(file_list,"join") + x = addfiles_GetVar(file_list, files, "LAI") + printVarSummary (x) + + y = addfiles_GetVar(file_list, files, "time") + time = y(0,:) + delete(time@case) + delete(y) + printVarSummary (time) + + y = addfiles_GetVar(file_list, files, "lat") + lat = y(0,:) + delete(lat@case) + delete(y) + printVarSummary (lat) + + y = addfiles_GetVar(file_list, files, "lon") + lon = y(0,:) + delete(lon@case) + delete(y) + printVarSummary (lon) + + x!0 = "case" + x!1 = "time" + x!2 = "lat" + x!3 = "lon" + + y = dim_avg(x(time|:,lat|:,lon|:,case|:)) + + y!0 = "time" + y!1 = "lat" + y!2 = "lon" + y&time = time + y&lat = lat + y&lon = lon + y@units = "none" + y@long_name = "Leaf Area Index" + printVarSummary (y) + + c->LAI = y + + z = dim_avg(y(lat|:,lon|:,time|:)) + + z!0 = "lat" + z!1 = "lon" + z&lat = lat + z&lon = lon + z@units = "none" + z@long_name = "Leaf Area Index" + printVarSummary (z) + + d->LAI = z +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/24.histogram+bias_mean.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/24.histogram+bias_mean.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,293 @@ +;******************************************************** +; histogram normalized by rain and compute correleration +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; +; Main code. +; +begin + +;nclass = 18 + nclass = 20 + +;************************************************ +; read in data: observed +;************************************************ + diri1 = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" +;fili1 = "land_class_T42.nc" + fili1 = "land_class_T42_new.nc" + fili2 = "LAI_2000-2005_mean_T42.nc" + data_file_ob1 = addfile(diri1+fili1,"r") + data_file_ob2 = addfile(diri1+fili2,"r") + + RAIN1 = tofloat(data_file_ob1->LAND_CLASS) + NPP1 = data_file_ob2->LAI +;************************************************ +; read in data: model +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +;fili3 = "i01.03cn_1545-1569_ANN_climo.nc" + fili3 = "i01.04casa_1605-1629_ANN_climo.nc" + data_file_model = addfile(diri2+fili3,"r") + + NPP2 = data_file_model->TLAI +;************************************************ +; print min/max and unit +;************************************************ + pminmax(RAIN1,"RAIN1") + pminmax(NPP1,"NPP1") + pminmax(NPP2,"NPP2") + + RAIN1_1D = ndtooned(RAIN1) + NPP1_1D = ndtooned(NPP1) + NPP2_1D = ndtooned(NPP2) +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + +; nbins = nclass + 1 ; Number of bins to use. +; nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,False) +; nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) +; range = fspan(nicevals(0),nicevals(1),nvals) + + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) + +; print (nicevals) +; print (nvals) + print (range) +; exit + +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN1_1D + npp_data = NPP2_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then + print("") + print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else + print("") + print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; + print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) + print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do + +; +; Start the graphics. +; + wks = gsn_open_wks("ps","xy") + + res = True + res@gsnMaximize = True + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 + res@xyMarkerColors = (/"Brown","Blue"/) +; res@trYMinF = min(mn_yvalues) - 10. +; res@trYMaxF = max(mx_yvalues) + 10. + res@trYMinF = min(mn_yvalues) - 2 + res@trYMaxF = max(mx_yvalues) + 4 + +; res@tiMainString = "Observed vs i01.03cn" + res@tiMainString = "Observed vs i01.04casa" + + res@tiYAxisString = "Mean LAI (Leaf Area Index)" + res@tiXAxisString = "Land Cover Type" +; +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. +; + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 +; res@xyExplicitLegendLabels = (/"observed","model_i01.03cn"/) + res@xyExplicitLegendLabels = (/"observed","model_i01.04casa"/) + + xy = gsn_csm_xy(wks,xvalues,yvalues,res) + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + + line_colors = (/"brown","blue"/) + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + +; +; Here's how to do the legend by hand. +; +; mkres = True ; Marker resources +; txres = True ; Text resources +; mkres@gsMarkerIndex = 16 +; mkres@gsMarkerSizeF = 0.02 +; txres@txFontHeightF = 0.02 +; txres@txJust = "CenterLeft" +; +; Change these values if you want to move the marker legend location. +; These values are in the same data space as the plot. +; +; xlg1_cen = 0.2 +; ylg1_cen = 900. + +; xlg2_cen = 0.2 +; ylg2_cen = 760. + +; mkres@gsMarkerColor = "brown" +; lnres@gsLineColor = "brown" + +; lg_mark_legend1 = gsn_add_polymarker(wks,xy,xlg1_cen,ylg1_cen,mkres) +; lg_line_legend1 = gsn_add_polyline(wks,xy,(/xlg1_cen,xlg1_cen/), \ +; (/ylg1_cen-60,ylg1_cen+60/),lnres) +; lg_cap_legend11 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen-60,ylg1_cen-60/),lnres) +; lg_cap_legend12 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen+60,ylg1_cen+60/),lnres) + +; tx_legend1 = gsn_add_text(wks,xy,"observed",xlg1_cen+0.15,ylg1_cen,txres) + +; mkres@gsMarkerColor = "blue" +; lnres@gsLineColor = "blue" + +; lg_mark_legend2 = gsn_add_polymarker(wks,xy,xlg2_cen,ylg2_cen,mkres) +; lg_line_legend2 = gsn_add_polyline(wks,xy,(/xlg2_cen,xlg2_cen/), \ +; (/ylg2_cen-60,ylg2_cen+60/),lnres) +; lg_cap_legend21 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen-60,ylg2_cen-60/),lnres) +; lg_cap_legend22 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen+60,ylg2_cen+60/),lnres) +; tx_legend2 = gsn_add_text(wks,xy,"model_i01.03cn",xlg2_cen+0.15,ylg2_cen,txres) + + draw(xy) + frame(wks) + system("convert xy.ps xy.png") + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + nz = dimsizes(uu) + print (nz) + + ccr = esccr(uu,vv,0) + print (ccr) + +;old eq +;bias = sum(((vv-uu)/uu)^2) +;M = (1.- sqrt(bias/nz))*5. + +;new eq + bias = sum(abs(vv-uu)/(vv+uu)) + M = (1.- (bias/nz))*5. + print (bias) + print (M) + +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/25.histogram+bias_max.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/25.histogram+bias_max.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,340 @@ +;******************************************************** +; histogram normalized by rain and compute correleration +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; +; Main code. +; +begin + +;nclass = 18 + nclass = 20 + +;************************************************ +; read in data: observed +;************************************************ + diri1 = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" +;fili1 = "land_class_T42.nc" + fili1 = "land_class_T42_new.nc" + fili2 = "LAI_2000-2005_ensemble_T42.nc" + data_file_ob1 = addfile(diri1+fili1,"r") + data_file_ob2 = addfile(diri1+fili2,"r") + + RAIN1 = tofloat(data_file_ob1->LAND_CLASS) + + z = data_file_ob2->LAI + y = z(0,:,:) + y@long_name = "Leaf Area Index Max" + s = z(:,0,0) + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = z(:,j,i) + y(j,i) = max(s) + end do + end do + + print (min(y)+"/"+max(y)) + + NPP1 = y + + delete (z) + delete (s) + delete (y) +;************************************************ +; read in data: model +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili3 = "i01.03cn_1545-1569_MONS_climo.nc" +;fili3 = "i01.04casa_1605-1629_MONS_climo.nc" + data_file_model = addfile(diri2+fili3,"r") + + z = data_file_model->TLAI + y = z(0,:,:) + y@long_name = "Leaf Area Index Max" + s = z(:,0,0) + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = z(:,j,i) + y(j,i) = max(s) + end do + end do + + print (min(y)+"/"+max(y)) + + NPP2 = y + + delete (z) + delete (s) + delete (y) +;************************************************ +; print min/max and unit +;************************************************ + pminmax(RAIN1,"RAIN1") + pminmax(NPP1,"NPP1") + pminmax(NPP2,"NPP2") + + RAIN1_1D = ndtooned(RAIN1) + NPP1_1D = ndtooned(NPP1) + NPP2_1D = ndtooned(NPP2) +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + +; nbins = nclass + 1 ; Number of bins to use. +; nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,False) +; nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) +; range = fspan(nicevals(0),nicevals(1),nvals) + + nclass = nclass + 1 + range = fspan(0,nclass-1,nclass) + +; print (nicevals) +; print (nvals) + print (range) +; exit + +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN1_1D + npp_data = NPP2_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then + print("") + print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else + print("") + print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; + print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) + print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do + +; +; Start the graphics. +; + wks = gsn_open_wks("ps","xy") + + res = True + res@gsnMaximize = True + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 + res@xyMarkerColors = (/"Brown","Blue"/) +; res@trYMinF = min(mn_yvalues) - 10. +; res@trYMaxF = max(mx_yvalues) + 10. + res@trYMinF = min(mn_yvalues) - 2 + res@trYMaxF = max(mx_yvalues) + 4 + + res@tiMainString = "Observed vs i01.03cn" +; res@tiMainString = "Observed vs i01.04casa" + + res@tiYAxisString = "Max LAI (Leaf Area Index)" + res@tiXAxisString = "Land Cover Type" +; +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. +; + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed","model_i01.03cn"/) +; res@xyExplicitLegendLabels = (/"observed","model_i01.04casa"/) + + xy = gsn_csm_xy(wks,xvalues,yvalues,res) + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + + line_colors = (/"brown","blue"/) + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + +; +; Here's how to do the legend by hand. +; +; mkres = True ; Marker resources +; txres = True ; Text resources +; mkres@gsMarkerIndex = 16 +; mkres@gsMarkerSizeF = 0.02 +; txres@txFontHeightF = 0.02 +; txres@txJust = "CenterLeft" +; +; Change these values if you want to move the marker legend location. +; These values are in the same data space as the plot. +; +; xlg1_cen = 0.2 +; ylg1_cen = 900. + +; xlg2_cen = 0.2 +; ylg2_cen = 760. + +; mkres@gsMarkerColor = "brown" +; lnres@gsLineColor = "brown" + +; lg_mark_legend1 = gsn_add_polymarker(wks,xy,xlg1_cen,ylg1_cen,mkres) +; lg_line_legend1 = gsn_add_polyline(wks,xy,(/xlg1_cen,xlg1_cen/), \ +; (/ylg1_cen-60,ylg1_cen+60/),lnres) +; lg_cap_legend11 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen-60,ylg1_cen-60/),lnres) +; lg_cap_legend12 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen+60,ylg1_cen+60/),lnres) + +; tx_legend1 = gsn_add_text(wks,xy,"observed",xlg1_cen+0.15,ylg1_cen,txres) + +; mkres@gsMarkerColor = "blue" +; lnres@gsLineColor = "blue" + +; lg_mark_legend2 = gsn_add_polymarker(wks,xy,xlg2_cen,ylg2_cen,mkres) +; lg_line_legend2 = gsn_add_polyline(wks,xy,(/xlg2_cen,xlg2_cen/), \ +; (/ylg2_cen-60,ylg2_cen+60/),lnres) +; lg_cap_legend21 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen-60,ylg2_cen-60/),lnres) +; lg_cap_legend22 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen+60,ylg2_cen+60/),lnres) +; tx_legend2 = gsn_add_text(wks,xy,"model_i01.03cn",xlg2_cen+0.15,ylg2_cen,txres) + + draw(xy) + frame(wks) + system("convert xy.ps xy.png") + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + nz = dimsizes(uu) + print (nz) + + ccr = esccr(uu,vv,0) + print (ccr) + +;old eq +;bias = sum(((vv-uu)/uu)^2) +;M = (1.- sqrt(bias/nz))*5. + +;new eq + bias = sum(abs(vv-uu)/(vv+uu)) + M = (1.- (bias/nz))*5. + print (bias) + print (M) + +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/26.histogram+bias_phase.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/26.histogram+bias_phase.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,341 @@ +;******************************************************** +; histogram normalized by rain and compute correleration +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; +; Main code. +; +begin + +;nclass = 18 + nclass = 20 + +;************************************************ +; read in data: observed +;************************************************ + diri1 = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" +;fili1 = "land_class_T42.nc" + fili1 = "land_class_T42_new.nc" + fili2 = "LAI_2000-2005_ensemble_T42.nc" + data_file_ob1 = addfile(diri1+fili1,"r") + data_file_ob2 = addfile(diri1+fili2,"r") + + RAIN1 = tofloat(data_file_ob1->LAND_CLASS) + + z = data_file_ob2->LAI + y = z(0,:,:) + y@long_name = "Leaf Area Index Max Month" + s = z(:,0,0) + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = z(:,j,i) + y(j,i) = maxind(s) + 1 + end do + end do + + print (min(y)+"/"+max(y)) + + NPP1 = y + + delete (z) + delete (s) + delete (y) +;************************************************ +; read in data: model +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +;fili3 = "i01.03cn_1545-1569_MONS_climo.nc" + fili3 = "i01.04casa_1605-1629_MONS_climo.nc" + data_file_model = addfile(diri2+fili3,"r") + + z = data_file_model->TLAI + y = z(0,:,:) + y@long_name = "Leaf Area Index Max Month" + s = z(:,0,0) + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = z(:,j,i) + y(j,i) = maxind(s) + 1 + end do + end do + + print (min(y)+"/"+max(y)) + + NPP2 = y + + delete (z) + delete (s) + delete (y) +;************************************************ +; print min/max and unit +;************************************************ + pminmax(RAIN1,"RAIN1") + pminmax(NPP1,"NPP1") + pminmax(NPP2,"NPP2") + + RAIN1_1D = ndtooned(RAIN1) + NPP1_1D = ndtooned(NPP1) + NPP2_1D = ndtooned(NPP2) +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + +; nbins = nclass + 1 ; Number of bins to use. +; nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,False) +; nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) +; range = fspan(nicevals(0),nicevals(1),nvals) + + nclass = nclass + 1 + range = fspan(0,nclass-1,nclass) + +; print (nicevals) +; print (nvals) + print (range) +; exit + +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN1_1D + npp_data = NPP2_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then + print("") + print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else + print("") + print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; + print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) + print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do + +; +; Start the graphics. +; + wks = gsn_open_wks("ps","xy") + + res = True + res@gsnMaximize = True + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 + res@xyMarkerColors = (/"Brown","Blue"/) +; res@trYMinF = min(mn_yvalues) - 10. +; res@trYMaxF = max(mx_yvalues) + 10. + res@trYMinF = min(mn_yvalues) - 2 + res@trYMaxF = max(mx_yvalues) + 4 + +; res@tiMainString = "Observed vs i01.03cn" + res@tiMainString = "Observed vs i01.04casa" + + res@tiYAxisString = "Max LAI (Leaf Area Index) Month" + res@tiXAxisString = "Land Cover Type" +; +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. +; + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 +; res@xyExplicitLegendLabels = (/"observed","model_i01.03cn"/) + res@xyExplicitLegendLabels = (/"observed","model_i01.04casa"/) + + xy = gsn_csm_xy(wks,xvalues,yvalues,res) + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + + line_colors = (/"brown","blue"/) + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + +; +; Here's how to do the legend by hand. +; +; mkres = True ; Marker resources +; txres = True ; Text resources +; mkres@gsMarkerIndex = 16 +; mkres@gsMarkerSizeF = 0.02 +; txres@txFontHeightF = 0.02 +; txres@txJust = "CenterLeft" +; +; Change these values if you want to move the marker legend location. +; These values are in the same data space as the plot. +; +; xlg1_cen = 0.2 +; ylg1_cen = 900. + +; xlg2_cen = 0.2 +; ylg2_cen = 760. + +; mkres@gsMarkerColor = "brown" +; lnres@gsLineColor = "brown" + +; lg_mark_legend1 = gsn_add_polymarker(wks,xy,xlg1_cen,ylg1_cen,mkres) +; lg_line_legend1 = gsn_add_polyline(wks,xy,(/xlg1_cen,xlg1_cen/), \ +; (/ylg1_cen-60,ylg1_cen+60/),lnres) +; lg_cap_legend11 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen-60,ylg1_cen-60/),lnres) +; lg_cap_legend12 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen+60,ylg1_cen+60/),lnres) + +; tx_legend1 = gsn_add_text(wks,xy,"observed",xlg1_cen+0.15,ylg1_cen,txres) + +; mkres@gsMarkerColor = "blue" +; lnres@gsLineColor = "blue" + +; lg_mark_legend2 = gsn_add_polymarker(wks,xy,xlg2_cen,ylg2_cen,mkres) +; lg_line_legend2 = gsn_add_polyline(wks,xy,(/xlg2_cen,xlg2_cen/), \ +; (/ylg2_cen-60,ylg2_cen+60/),lnres) +; lg_cap_legend21 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen-60,ylg2_cen-60/),lnres) +; lg_cap_legend22 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen+60,ylg2_cen+60/),lnres) +; tx_legend2 = gsn_add_text(wks,xy,"model_i01.03cn",xlg2_cen+0.15,ylg2_cen,txres) + + draw(xy) + frame(wks) + system("convert xy.ps xy.png") + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + nz = dimsizes(uu) + print (nz) + + ccr = esccr(uu,vv,0) + print (ccr) + +;old eq +;bias = sum(((vv-uu)/uu)^2) +;M = (1.- sqrt(bias/nz))*5. + +;new eq + bias = abs(avg(vv)-avg(uu)) + bias = where((bias.gt. 6.),12.-bias,bias) + M = ((6. - bias)/6.)*5. + print (bias) + print (M) + +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/27.histogram+bias_grow.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/27.histogram+bias_grow.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,347 @@ +;******************************************************** +; histogram normalized by rain and compute correleration +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; +; Main code. +; +begin + +;nclass = 18 + nclass = 20 + day_of_data = (/31,28,31,30,31,30,31,31,30,31,30,31/) + +;************************************************ +; read in data: observed +;************************************************ + diri1 = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" +;fili1 = "land_class_T42.nc" + fili1 = "land_class_T42_new.nc" + fili2 = "LAI_2000-2005_ensemble_T42.nc" + data_file_ob1 = addfile(diri1+fili1,"r") + data_file_ob2 = addfile(diri1+fili2,"r") + + RAIN1 = tofloat(data_file_ob1->LAND_CLASS) + + z = data_file_ob2->LAI + y = z(0,:,:) + y@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(z(k,j,i)) .and. z(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + y(j,i) = nday + end do + end do + + print (min(y)+"/"+max(y)) + + NPP1 = y + + delete (z) + delete (y) +;************************************************ +; read in data: model +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +;fili3 = "i01.03cn_1545-1569_MONS_climo.nc" + fili3 = "i01.04casa_1605-1629_MONS_climo.nc" + data_file_model = addfile(diri2+fili3,"r") + + z = data_file_model->TLAI + y = z(0,:,:) + y@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(z(k,j,i)) .and. z(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + y(j,i) = nday + end do + end do + + print (min(y)+"/"+max(y)) + + NPP2 = y + + delete (z) + delete (y) +;************************************************ +; print min/max and unit +;************************************************ + pminmax(RAIN1,"RAIN1") + pminmax(NPP1,"NPP1") + pminmax(NPP2,"NPP2") + + RAIN1_1D = ndtooned(RAIN1) + NPP1_1D = ndtooned(NPP1) + NPP2_1D = ndtooned(NPP2) +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + +; nbins = nclass + 1 ; Number of bins to use. +; nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,False) +; nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) +; range = fspan(nicevals(0),nicevals(1),nvals) + + nclass = nclass + 1 + range = fspan(0,nclass-1,nclass) + +; print (nicevals) +; print (nvals) + print (range) +; exit + +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN1_1D + npp_data = NPP2_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then + print("") + print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else + print("") + print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; + print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) + print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do + +; +; Start the graphics. +; + wks = gsn_open_wks("ps","xy") + + res = True + res@gsnMaximize = True + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 + res@xyMarkerColors = (/"Brown","Blue"/) +; res@trYMinF = min(mn_yvalues) - 10. +; res@trYMaxF = max(mx_yvalues) + 10. + res@trYMinF = min(mn_yvalues) - 20. + res@trYMaxF = max(mx_yvalues) + 100. + +; res@tiMainString = "Observed vs i01.03cn" + res@tiMainString = "Observed vs i01.04casa" + + res@tiYAxisString = "Days of Growing season" + res@tiXAxisString = "Land Cover Type" +; +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. +; + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 +; res@xyExplicitLegendLabels = (/"observed","model_i01.03cn"/) + res@xyExplicitLegendLabels = (/"observed","model_i01.04casa"/) + + xy = gsn_csm_xy(wks,xvalues,yvalues,res) + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + + line_colors = (/"brown","blue"/) + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + +; +; Here's how to do the legend by hand. +; +; mkres = True ; Marker resources +; txres = True ; Text resources +; mkres@gsMarkerIndex = 16 +; mkres@gsMarkerSizeF = 0.02 +; txres@txFontHeightF = 0.02 +; txres@txJust = "CenterLeft" +; +; Change these values if you want to move the marker legend location. +; These values are in the same data space as the plot. +; +; xlg1_cen = 0.2 +; ylg1_cen = 900. + +; xlg2_cen = 0.2 +; ylg2_cen = 760. + +; mkres@gsMarkerColor = "brown" +; lnres@gsLineColor = "brown" + +; lg_mark_legend1 = gsn_add_polymarker(wks,xy,xlg1_cen,ylg1_cen,mkres) +; lg_line_legend1 = gsn_add_polyline(wks,xy,(/xlg1_cen,xlg1_cen/), \ +; (/ylg1_cen-60,ylg1_cen+60/),lnres) +; lg_cap_legend11 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen-60,ylg1_cen-60/),lnres) +; lg_cap_legend12 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen+60,ylg1_cen+60/),lnres) + +; tx_legend1 = gsn_add_text(wks,xy,"observed",xlg1_cen+0.15,ylg1_cen,txres) + +; mkres@gsMarkerColor = "blue" +; lnres@gsLineColor = "blue" + +; lg_mark_legend2 = gsn_add_polymarker(wks,xy,xlg2_cen,ylg2_cen,mkres) +; lg_line_legend2 = gsn_add_polyline(wks,xy,(/xlg2_cen,xlg2_cen/), \ +; (/ylg2_cen-60,ylg2_cen+60/),lnres) +; lg_cap_legend21 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen-60,ylg2_cen-60/),lnres) +; lg_cap_legend22 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen+60,ylg2_cen+60/),lnres) +; tx_legend2 = gsn_add_text(wks,xy,"model_i01.03cn",xlg2_cen+0.15,ylg2_cen,txres) + + draw(xy) + frame(wks) + system("convert xy.ps xy.png") + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + nz = dimsizes(uu) + print (nz) + + ccr = esccr(uu,vv,0) + print (ccr) +;old eq +;bias = sum(((vv-uu)/uu)^2) +;M = (1.- sqrt(bias/nz))*5. + +;new eq + bias = sum(abs(vv-uu)/(vv+uu)) + M = (1.- (bias/nz))*5. + + print (bias) + print (M) + +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/31.contour_model.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/31.contour_model.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,47 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read in model data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" + fili = "i01.03cn_1545-1569_ANN_climo.nc" +; fili = "i01.04casa_1605-1629_ANN_climo.nc" + + g = addfile(diri+fili,"r") + x = g->TLAI + print (max(x)) + print (min(x)) + +;************************************************ +; create default plot +;************************************************ + + wks = gsn_open_wks("ps","xy") ; open a ps file +; gsn_define_colormap(wks,"wgne15") ; choose colormap + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill +; res@tiMainString = "Observed MODIS MOD 15A2" + res@tiMainString = "Model i01.03cn" +; res@tiMainString = "Model i01.04casa" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 10. ; Max level + res@cnLevelSpacingF = 1. ; interval + + plot = gsn_csm_contour_map_ce(wks,x(0,:,:),res) ; for model + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/31.contour_ob_grow.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/31.contour_ob_grow.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,81 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" + fili = "LAI_2000-2005_ensemble_T42.nc" + f = addfile(diri+fili,"r") + + z = f->LAI + y = z(0,:,:) + y@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + day_of_data = (/31,28,31,30,31,30,31,31,30,31,30,31/) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(z(k,j,i)) .and. z(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + y(j,i) = nday + end do + end do + + print (min(y)+"/"+max(y)) + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "i01.03cn_1545-1569_ANN_climo.nc" + g = addfile(diri2+fili2,"r") + x = g->TLAI + + delta = 0.000001 + x0 = x(0,:,:) + y = where(ismissing(y).and.(ismissing(x0).or.(x0.lt.delta)),y@_FillValue,y) +;************************************************ +; create default plot +;************************************************ + + wks = gsn_open_wks("ps","xy") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@tiMainString = "MODIS MOD 15A2 2000-2005" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 390. ; Max level + res@cnLevelSpacingF = 30. ; interval + +; pres = True ; panel plot mods desired +; pres@gsnMaximize = True ; fill the page + + plot = gsn_csm_contour_map_ce(wks,y,res) ; for observed + +; gsn_panel(wks,plot,(/1,1/),pres) ; create panel plot + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/31.contour_ob_lai_max.ncl.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/31.contour_ob_lai_max.ncl.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,95 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" +; fili = "LAI_2000-2005_ensemble_T42.nc" + fili = "2000-2005_ensemble_T42.nc" + f = addfile(diri+fili,"r") + + z = f->LAI + y = z(0,:,:) + y@long_name = "Leaf Area Index Max" + p = z(0,:,:) + p@long_name = "Leaf Area Index Max Month" + s = z(:,0,0) +; printVarSummary(s) + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = z(:,j,i) + y(j,i) = max(s) + p(j,i) = maxind(s)+ 1 + +; iMax = ind(s.eq.y(j,i)) + 1 ; may be multiple max +; if (.not.ismissing(iMax(0))) then +; p(j,i) = iMax(0) ; no meta data +; end if +; delete(iMax) + + end do + end do + +; printVarSummary(p) + print (min(y)+"/"+max(y)) + print (min(p)+"/"+max(p)) +exit +;************************************************ +; read in model data +;************************************************ + fili2 = "i01.03cn_1545-1569_ANN_climo.nc" + g = addfile(diri+fili2,"r") + x = g->TLAI + + delta = 0.00000000001 + x0 = x(0,:,:) + y = where(ismissing(y).and.(ismissing(x0).or.(x0.lt.delta)),0.,y) +;************************************************ +; create default plot +;************************************************ + +; setvalues NhlGetWorkspaceObjectId() +; "wsMaximumSize" : 199999999 +; end setvalues + + wks = gsn_open_wks("ps","xy") ; open a ps file +; gsn_define_colormap(wks,"wgne15") ; choose colormap + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@tiMainString = "MODIS MOD 15A2 2000-2005" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 12. ; Max level + res@cnLevelSpacingF = 1. ; interval + +; pres = True ; panel plot mods desired +; pres@gsnMaximize = True ; fill the page + + plot = gsn_csm_contour_map_ce(wks,y,res) ; for observed + + plot = gsn_csm_contour_map_ce(wks,p,res) ; for observed + +; gsn_panel(wks,plot,(/1,1/),pres) ; create panel plot + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/31.contour_ob_max.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/31.contour_ob_max.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,98 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" + fili = "LAI_2000-2005_ensemble_T42.nc" +; fili = "LAI_2000_monthly_T42.nc" + f = addfile(diri+fili,"r") + + z = f->LAI + y = z(0,:,:) + y@long_name = "Leaf Area Index Max" + p = z(0,:,:) + p@long_name = "Leaf Area Index Max Month" + s = z(:,0,0) +; printVarSummary(s) + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = z(:,j,i) + y(j,i) = max(s) + p(j,i) = maxind(s)+ 1 + +; iMax = ind(s.eq.y(j,i)) + 1 ; may be multiple max +; if (.not.ismissing(iMax(0))) then +; p(j,i) = iMax(0) ; no meta data +; end if +; delete(iMax) + + end do + end do + +; printVarSummary(p) + print (min(y)+"/"+max(y)) + print (min(p)+"/"+max(p)) + +;************************************************ +; read in model data +;************************************************ + fili2 = "i01.03cn_1545-1569_ANN_climo.nc" + g = addfile(diri+fili2,"r") + x = g->TLAI + + delta = 0.00000000001 + x0 = x(0,:,:) + y = where(ismissing(y).and.(ismissing(x0).or.(x0.lt.delta)),0.,y) +;************************************************ +; create default plot +;************************************************ + +; setvalues NhlGetWorkspaceObjectId() +; "wsMaximumSize" : 199999999 +; end setvalues + + wks = gsn_open_wks("ps","xy") ; open a ps file +; gsn_define_colormap(wks,"wgne15") ; choose colormap + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@tiMainString = "MODIS MOD 15A2 2000-2005" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 10. ; Max level + res@cnLevelSpacingF = 1. ; interval + +; pres = True ; panel plot mods desired +; pres@gsnMaximize = True ; fill the page + + plot = gsn_csm_contour_map_ce(wks,y,res) ; for observed + + res@cnMinLevelValF = 1. ; Min level + res@cnMaxLevelValF = 12. ; Max level + res@cnLevelSpacingF = 1. ; interval + plot = gsn_csm_contour_map_ce(wks,p,res) ; for observed + +; gsn_panel(wks,plot,(/1,1/),pres) ; create panel plot + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/31.contour_ob_mean.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/31.contour_ob_mean.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,65 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" + fili = "LAI_2000-2005_mean_T42.nc" + f = addfile(diri+fili,"r") + + y = f->LAI + printVarSummary(y) + + print (min(y)+"/"+max(y)) + +;************************************************ +; read in model data +;************************************************ + fili2 = "i01.03cn_1545-1569_ANN_climo.nc" + g = addfile(diri+fili2,"r") + x = g->LAISUN + + delta = 0.0000001 + x0 = x(0,:,:) + y = where(ismissing(y).and.(ismissing(x0).or.(x0.lt.delta)),0.,y) +; y = where((y.gt.1000.),1.e+36,y) + printVarSummary(y) + print (min(y)+"/"+max(y)) +;************************************************ +; create default plot +;************************************************ + +; setvalues NhlGetWorkspaceObjectId() +; "wsMaximumSize" : 199999999 +; end setvalues + + wks = gsn_open_wks("ps","xy") ; open a ps file +; gsn_define_colormap(wks,"wgne15") ; choose colormap + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@tiMainString = "MODIS MOD 15A2 2000-2005" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 10. ; Max level + res@cnLevelSpacingF = 1. ; interval + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + plot = gsn_csm_contour_map_ce(wks,y,res) ; for observed + gsn_panel(wks,plot,(/1,1/),pres) ; create panel plot + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/32.contour_diff.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/32.contour_diff.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,87 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + f = addfile ("Npp_T42_mean.nc","r") + y = f->NPP +;************************************************ +; read in model data +;************************************************ + g = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") +;g = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + x = g->NPP + + nsec_per_year = 86400.*365. + x = x * nsec_per_year + + x@units = "gC/m^2/year" +;************************************************ +;fill ob missing grid the same as model +;************************************************ + delta = 0.00001 + x0 = x(0,:,:) + y = where(ismissing(y).and.(ismissing(x0).or.(x0.lt.delta)),0.,y) + + y@units = "gC/m^2/year" +;************************************************ +;model - observed +;************************************************ + z = x + z = x(0,:,:) - y(:,:) +;************************************************ +; create 3 plots +;************************************************ + wks = gsn_open_wks("ps","xy") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@tiMainString = "Observed MODIS MOD 17" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 2200. ; Max level + res@cnLevelSpacingF = 200. ; interval + + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + plot=new(3,graphic) ; create graphic array + + plot(0) = gsn_csm_contour_map_ce(wks,y,res) ; for observed + + res@tiMainString = "Model i01.03cn" +; res@tiMainString = "Model i01.04casa" + plot(1) = gsn_csm_contour_map_ce(wks,x(0,:,:),res) ; for model + + res@cnMinLevelValF = -500 ; Min level + res@cnMaxLevelValF = 500. ; Max level + res@cnLevelSpacingF = 50. ; interval + res@tiMainString = "(Model i01.03cn) - (observed)" +; res@tiMainString = "(Model i01.04casa) - (observed)" + plot(2) = gsn_csm_contour_map_ce(wks,z(0,:,:),res) ; for model - ob + +;*********************************************** +; create panel plot +;*********************************************** + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/32.contour_land_class.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/32.contour_land_class.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,54 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" +; fili = "land_class_0.25deg.nc" + fili = "land_class_T42_new.nc" + f = addfile(diri+fili,"r") + print (f) + +; y = f->LAND_CLASS(::10,::10) ; for 0.25deg +; y = (/ y(::-1,:) /) ; for 0.25deg + + y = f->LAND_CLASS + printVarSummary(y) + + y = where(y.eq.0,y@_FillValue,y) + + printVarSummary(y) + print (min(y)+"/"+max(y)) +;************************************************ +; create default plot +;************************************************ + wks = gsn_open_wks("ps","xy") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@tiMainString = "MODIS LAND CLASS T42" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 1. ; Min level + res@cnMaxLevelValF = 19. ; Max level + res@cnLevelSpacingF = 1. ; interval + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + plot = gsn_csm_contour_map_ce(wks,y,res) ; for observed + gsn_panel(wks,plot,(/1,1/),pres) ; create panel plot + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/33.contour_diff_grow.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/33.contour_diff_grow.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,128 @@ +;************************************************* +; 3 plots, model - ob +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + day_of_data = (/31,28,31,30,31,30,31,31,30,31,30,31/) + +;************************************************ +; read in observed data +;************************************************ + diri1 = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" + fili1 = "LAI_2000-2005_ensemble_T42.nc" + f = addfile(diri1+fili1,"r") + + z = f->LAI + y = z(0,:,:) + y@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(z(k,j,i)) .and. z(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + if (nday .ne. 0.) then + y(j,i) = nday + end if + end do + end do + +; printVarSummary(y) + print (min(y)+"/"+max(y)) + + delete (z) +;************************************************ +; read in data: model +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +;fili3 = "i01.03cn_1545-1569_MONS_climo.nc" + fili3 = "i01.04casa_1605-1629_MONS_climo.nc" + data_file_model = addfile(diri2+fili3,"r") + + z = data_file_model->TLAI + x = z(0,:,:) + x@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(z(k,j,i)) .and. z(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + if (nday .ne. 0.) then + x(j,i) = nday + end if + end do + end do + + print (min(x)+"/"+max(x)) + + d = x + d = x - y + print (min(d)+"/"+max(d)) + + delete (z) + + delta = 0.000001 + y = where(ismissing(y).and.(ismissing(x).or.(x.lt.delta)),0.,y) +;************************************************ +; create default plot +;************************************************ + wks = gsn_open_wks("ps","xy") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 365. ; Max level + res@cnLevelSpacingF = 30. ; interval + + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + plot=new(3,graphic) ; create graphic array + + res@tiMainString = "MODIS MOD 15A2 2000-2005" + plot(0) = gsn_csm_contour_map_ce(wks,y,res) + +; res@tiMainString = "Model i01.03cn" + res@tiMainString = "Model i01.04casa" + plot(1) = gsn_csm_contour_map_ce(wks,x,res) + +; res@tiMainString = "(Model i01.03cn) - (Observed)" + res@tiMainString = "(Model i01.04casa) - (Observed)" + res@cnMinLevelValF = -120. ; Min level + res@cnMaxLevelValF = 120. ; Max level + res@cnLevelSpacingF = 20. ; interval + plot(2) = gsn_csm_contour_map_ce(wks,d,res) ; for observed + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/33.contour_diff_max.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/33.contour_diff_max.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,114 @@ +;************************************************* +; 3 plots, model - ob +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + diri1 = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" + fili1 = "LAI_2000-2005_ensemble_T42.nc" + f = addfile(diri1+fili1,"r") + + z = f->LAI + y = z(0,:,:) + y@long_name = "Leaf Area Index Max" + s = z(:,0,0) + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = z(:,j,i) + y(j,i) = max(s) + end do + end do + +; printVarSummary(y) + print (min(y)+"/"+max(y)) + + delete (s) + delete (z) +;************************************************ +; read in data: model +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +;fili3 = "i01.03cn_1545-1569_MONS_climo.nc" + fili3 = "i01.04casa_1605-1629_MONS_climo.nc" + data_file_model = addfile(diri2+fili3,"r") + + z = data_file_model->TLAI + x = z(0,:,:) + x@long_name = "Leaf Area Index Max" + s = z(:,0,0) + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = z(:,j,i) + x(j,i) = max(s) + end do + end do + + print (min(x)+"/"+max(x)) + d = x + d = x - y + print (min(d)+"/"+max(d)) + + delete (z) + delete (s) + + delta = 0.000001 + y = where(ismissing(y).and.(ismissing(x).or.(x.lt.delta)),0.,y) +;************************************************ +; create default plot +;************************************************ + wks = gsn_open_wks("ps","xy") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 10. ; Max level + res@cnLevelSpacingF = 1. ; interval + + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + plot=new(3,graphic) ; create graphic array + + res@tiMainString = "MODIS MOD 15A2 2000-2005" + plot(0) = gsn_csm_contour_map_ce(wks,y,res) + +; res@tiMainString = "Model i01.03cn" + res@tiMainString = "Model i01.04casa" + plot(1) = gsn_csm_contour_map_ce(wks,x,res) + +; res@tiMainString = "(Model i01.03cn) - (Observed)" + res@tiMainString = "(Model i01.04casa) - (Observed)" + res@cnMinLevelValF = -6. ; Min level + res@cnMaxLevelValF = 6. ; Max level + res@cnLevelSpacingF = 1. ; interval + plot(2) = gsn_csm_contour_map_ce(wks,d,res) ; for observed + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/33.contour_diff_mean.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/33.contour_diff_mean.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,114 @@ +;************************************************* +; 3 plots, model - ob +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + diri1 = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" + fili1 = "LAI_2000-2005_ensemble_T42.nc" + f = addfile(diri1+fili1,"r") + + z = f->LAI + y = z(0,:,:) + y@long_name = "Leaf Area Index Mean" + s = z(:,0,0) + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = z(:,j,i) + y(j,i) = avg(s) + end do + end do + +; printVarSummary(y) + print (min(y)+"/"+max(y)) + + delete (s) + delete (z) +;************************************************ +; read in data: model +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili3 = "i01.03cn_1545-1569_MONS_climo.nc" +;fili3 = "i01.04casa_1605-1629_MONS_climo.nc" + data_file_model = addfile(diri2+fili3,"r") + + z = data_file_model->TLAI + x = z(0,:,:) + x@long_name = "Leaf Area Index Mean" + s = z(:,0,0) + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = z(:,j,i) + x(j,i) = avg(s) + end do + end do + + print (min(x)+"/"+max(x)) + d = x + d = x - y + print (min(d)+"/"+max(d)) + + delete (z) + delete (s) + + delta = 0.000001 + y = where(ismissing(y).and.(ismissing(x).or.(x.lt.delta)),0.,y) +;************************************************ +; create default plot +;************************************************ + wks = gsn_open_wks("ps","xy") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 6. ; Max level + res@cnLevelSpacingF = 0.5 ; interval + + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + plot=new(3,graphic) ; create graphic array + + res@tiMainString = "MODIS MOD 15A2 2000-2005" + plot(0) = gsn_csm_contour_map_ce(wks,y,res) + + res@tiMainString = "Model i01.03cn" +; res@tiMainString = "Model i01.04casa" + plot(1) = gsn_csm_contour_map_ce(wks,x,res) + + res@tiMainString = "(Model i01.03cn) - (Observed)" +; res@tiMainString = "(Model i01.04casa) - (Observed)" + res@cnMinLevelValF = -2. ; Min level + res@cnMaxLevelValF = 2. ; Max level + res@cnLevelSpacingF = 0.4 ; interval + plot(2) = gsn_csm_contour_map_ce(wks,d,res) ; for observed + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/33.contour_diff_phase.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/33.contour_diff_phase.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,116 @@ +;************************************************* +; 3 plots, model - ob +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + diri1 = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" + fili1 = "LAI_2000-2005_ensemble_T42.nc" + f = addfile(diri1+fili1,"r") + + z = f->LAI + y = z(0,:,:) + y@long_name = "Month of Leaf Area Index Max" + s = z(:,0,0) + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = z(:,j,i) + y(j,i) = maxind(s) + 1 + end do + end do + +; printVarSummary(y) + print (min(y)+"/"+max(y)) + + delete (s) + delete (z) +;************************************************ +; read in data: model +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili3 = "i01.03cn_1545-1569_MONS_climo.nc" +;fili3 = "i01.04casa_1605-1629_MONS_climo.nc" + data_file_model = addfile(diri2+fili3,"r") + + z = data_file_model->TLAI + x = z(0,:,:) + x@long_name = "Month of Leaf Area Index Max" + s = z(:,0,0) + + dsizes_z = dimsizes(z) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = z(:,j,i) + x(j,i) = maxind(s) + 1 + end do + end do + + print (min(x)+"/"+max(x)) + d = x + d = x - y + d = where((d .gt. 6.),12.-d,d) + d = where((d .lt. -6.),-12.-d,d) + print (min(d)+"/"+max(d)) + + delete (z) + delete (s) + + delta = 0.000001 + y = where(ismissing(y).and.(ismissing(x).or.(x.lt.delta)),0.,y) +;************************************************ +; create default plot +;************************************************ + wks = gsn_open_wks("ps","xy") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 1. ; Min level + res@cnMaxLevelValF = 12. ; Max level + res@cnLevelSpacingF = 1. ; interval + + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + plot=new(3,graphic) ; create graphic array + + res@tiMainString = "MODIS MOD 15A2 2000-2005" + plot(0) = gsn_csm_contour_map_ce(wks,y,res) + + res@tiMainString = "Model i01.03cn" +; res@tiMainString = "Model i01.04casa" + plot(1) = gsn_csm_contour_map_ce(wks,x,res) + + res@tiMainString = "(Model i01.03cn) - (Observed)" +; res@tiMainString = "(Model i01.04casa) - (Observed)" + res@cnMinLevelValF = -6. ; Min level + res@cnMaxLevelValF = 6. ; Max level + res@cnLevelSpacingF = 1. ; interval + plot(2) = gsn_csm_contour_map_ce(wks,d,res) ; for observed + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 lai/41.table_mean.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/41.table_mean.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,166 @@ +;******************************************************** +; histogram normalized by rain and compute correleration +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; +; Main code. +; +begin + +;nclass = 18 + nclass = 20 + +;************************************************ +; read in data: observed +;************************************************ + diri1 = "/fis/cgd/cseg/people/jeff/clamp_data/lai/" +;fili1 = "land_class_T42.nc" + fili1 = "land_class_T42_new.nc" + fili2 = "LAI_2000-2005_mean_T42.nc" + data_file_ob1 = addfile(diri1+fili1,"r") + data_file_ob2 = addfile(diri1+fili2,"r") + + RAIN1 = tofloat(data_file_ob1->LAND_CLASS) + NPP1 = data_file_ob2->LAI +;************************************************ +; read in data: model +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" +;fili3 = "i01.03cn_1545-1569_ANN_climo.nc" + fili3 = "i01.04casa_1605-1629_ANN_climo.nc" + data_file_model = addfile(diri2+fili3,"r") + + NPP2 = data_file_model->TLAI +;************************************************ +; print min/max and unit +;************************************************ + pminmax(RAIN1,"RAIN1") + pminmax(NPP1,"NPP1") + pminmax(NPP2,"NPP2") + + RAIN1_1D = ndtooned(RAIN1) + NPP1_1D = ndtooned(NPP1) + NPP2_1D = ndtooned(NPP2) +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + +; nbins = nclass + 1 ; Number of bins to use. +; nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,False) +; nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) +; range = fspan(nicevals(0),nicevals(1),nvals) + + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) + +; print (nicevals) +; print (nvals) + print (range) +; exit + +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN1_1D + npp_data = NPP2_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then + print("") + print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else + print("") + print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; + print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) + print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do + +; +; Start the graphics. +; + + u = yvalues(0,:) + v = yvalues(1,:) + print (u) + print (v) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + nz = dimsizes(uu) + print (nz) + + ccr = esccr(uu,vv,0) + print (ccr) + +;new eq + bias = sum(abs(vv-uu)/(vv+uu)) + M = (1.- (bias/nz))*5. + print (bias) + print (M) + +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/99.all.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/99.all.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1739 @@ +;******************************************************** +; histogram normalized by rain and compute correleration +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; Main code. +begin + + nclass = 20 + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read in data: model +;************************************************ +;film = "b30.061n_1995-2004_MONS_climo_lnd.nc" +;model_name = "b30.061n" +;model_grid = "T31" + +;film = "newcn05_ncep_1i_MONS_climo_lnd.nc" +;model_name = "newcn" +;model_grid = "1.9" + +;film = "i01.06cn_1798-2004_MONS_climo.nc" +;model_name = "06cn" +;model_grid = "T42" + +;film = "i01.06casa_1798-2004_MONS_climo.nc" +;model_name = "06casa" +;model_grid = "T42" + + film = "i01.10cn_1948-2004_MONS_climo.nc" + model_name = "10cn" + model_grid = "T42" + +;film = "i01.10casa_1948-2004_MONS_climo.nc" +;model_name = "10casa" +;model_grid = "T42" + + html_name = "table.html." + model_name + html_new = html_name +".new" + system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) +;------------------------------------------------ + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile(dirm+film,"r") + + laimod = fm->TLAI + +;************************************************ +; read in data: observed +;************************************************ + + ob_name = "MODIS MOD 15A2 2000-2005" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo1 = "land_class_"+model_grid+".nc" + filo2 = "LAI_2000-2005_MONS_"+model_grid+".nc" + + fo1 = addfile(diro+filo1,"r") + fo2 = addfile(diro+filo2,"r") + + classob = tofloat(fo1->LAND_CLASS) + laiob = fo2->LAI + +;******************************************************************* +; for plotting table +;******************************************************************* +; table header name + table_header_name = "LAI" + +; column (not including header column) + + col_header1 = (/"Mean","Max","Phase","Growth"/) + col_header2 = (/"ob","model","M" \ + ,"ob","model","M" \ + ,"ob","model","M" \ + ,"ob","model","M" \ + /) + + ncol1 = dimsizes(col_header1) + ncol2 = dimsizes(col_header2) + ncol = ncol2 + +; row (not including header row) + row_header = (/"Water Bodies" \ + ,"Evergreen Needleleaf Forests" \ + ,"Evergreen Broadleaf Forests" \ + ,"Deciduous Needleleaf Forest" \ + ,"Deciduous Broadleaf Forests" \ + ,"Mixed Forests" \ + ,"Closed Bushlands" \ + ,"Open Bushlands" \ + ,"Woody Savannas (S. Hem.)" \ + ,"Savannas (S. Hem.)" \ + ,"Grasslands" \ + ,"Permanent Wetlands" \ + ,"Croplands" \ + ,"Urban and Built-Up" \ + ,"Cropland/Natural Vegetation Mosaic" \ + ,"Permanent Snow and Ice" \ + ,"Barren or Sparsely Vegetated" \ + ,"Unclassified" \ + ,"Woody Savannas (N. Hem.)" \ + ,"Savannas (N. Hem.)" \ + ,"All biome average" \ + /) + nrow = dimsizes(row_header) + +; arrays to be passed to table. + value = new ((/nrow, ncol/),string ) + + table_length = 0.995 + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + xx1 = (/0.005,0.25/) ; Start and end X + yy1 = (/0.900,0.995/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr21 = (/1,ncol1/) ; 1 rows, 4 columns + xx21 = (/xx1(1),0.995/) ; start from end of x1 + yy21 = (/0.9475,0.995/) ; half of y1 + text21 = col_header1 + res21 = True + res21@txFontHeightF = 0.015 + res21@gsFillColor = "Gray" + + ncr22 = (/1,ncol2/) ; 1 rows, 12 columns + xx22 = xx21 ; start from end of x1 + yy22 = (/0.900,0.9475/) ; half of y1 + text22 = col_header2 + res22 = True + res22@txFontHeightF = 0.015 + res22@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; 20 rows, 1 columns + xx3 = xx1 ; same as x1 + yy3 = (/1.0-table_length,0.900/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.01 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; 5 rows, 5 columns + xx4 = xx21 ; Start and end x + yy4 = yy3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" + color_fill4(nrow-1,:) = "CornFlowerBlue" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +;************************************************ +; plot global land class: observed +;************************************************ +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 1. ; Min level + resg@cnMaxLevelValF = 19. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + classob@_FillValue = 1.e+36 + classob = where(classob.eq.0,classob@_FillValue,classob) + + plot_name = "global_class_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,classob,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. +;----------------------------------------------------------------- +;(A) mean +;-------------------------------------------------------------------- +; get data + + laiob_mean = dim_avg_Wrap(laiob(lat|:,lon|:,time|:)) + laimod_mean = dim_avg_Wrap(laimod(lat|:,lon|:,time|:)) + + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_mean) + DATA22_1D = ndtooned(laimod_mean) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((data_ob.ge.range(i)).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(data_ob.ge.range(i)) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrMean = esccr(uu,vv,0) +; print (ccrMean) + +; new eq + bias = sum(abs(vv-uu)/(vv+uu)) + Mmean = (1.- (bias/dimsizes(uu)))*5. + + M_lai_mean = sprintf("%.2f", Mmean) + system("sed s#M_lai_mean#"+M_lai_mean+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_lai_mean) + + do i=0,nrow-2 + text4(i,0) = sprintf("%5.2f",u(i)) + text4(i,1) = sprintf("%5.2f",v(i)) + text4(i,2) = "-" + end do + text4(nrow-1,0) = sprintf("%5.2f",avg(u)) + text4(nrow-1,1) = sprintf("%5.2f",avg(v)) + text4(nrow-1,2) = sprintf("%5.2f",Mmean) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Mean LAI (Leaf Area Index)" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_mean" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMean)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + + delta = 0.00001 + laiob_mean = where(ismissing(laiob_mean).and.(ismissing(laimod_mean).or.(laimod_mean.lt.delta)),0.,laiob_mean) + + plot_name = "global_mean_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laiob_mean,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_mean_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laimod_mean,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) +;----------------------------------------------------------------- +;(B) max +;-------------------------------------------------------------------- +; get data + +; observed + laiob_max = laiob(0,:,:) + s = laiob(:,0,0) + laiob_max@long_name = "Leaf Area Index Max" + + dsizes_z = dimsizes(laiob) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laiob(:,j,i) + laiob_max(j,i) = max(s) + end do + end do + +; print (min(y)+"/"+max(y)) + delete (s) + delete (dsizes_z) +;------------------------- +; model + laimod_max = laimod(0,:,:) + s = laimod(:,0,0) + laimod_max@long_name = "Leaf Area Index Max" + + dsizes_z = dimsizes(laimod) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laimod(:,j,i) + laimod_max(j,i) = max(s) + end do + end do + +; print (min(laimod_max)+"/"+max(laimod_max)) + delete (s) + delete (dsizes_z) +;------------------------ + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_max) + DATA22_1D = ndtooned(laimod_max) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data_ob).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data_ob) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrMax = esccr(uu,vv,0) +; print (ccrMax) + +; new eq + bias = sum(abs(vv-uu)/(vv+uu)) + Mmax = (1.- (bias/dimsizes(uu)))*5. + + M_lai_max = sprintf("%.2f", Mmax) + system("sed s#M_lai_max#"+M_lai_max+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_lai_max) + + do i=0,nrow-2 + text4(i,3) = sprintf("%5.2f",u(i)) + text4(i,4) = sprintf("%5.2f",v(i)) + text4(i,5) = "-" + end do + text4(nrow-1,3) = sprintf("%5.2f",avg(u)) + text4(nrow-1,4) = sprintf("%5.2f",avg(v)) + text4(nrow-1,5) = sprintf("%5.2f",Mmax) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Max LAI (Leaf Area Index)" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_max" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMax)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + + delta = 0.00001 + laiob_max = where(ismissing(laiob_max).and.(ismissing(laimod_max).or.(laimod_max.lt.delta)),0.,laiob_max) + + plot_name = "global_max_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot_max = gsn_csm_contour_map_ce(wks,laiob_max,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_max_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot_max = gsn_csm_contour_map_ce(wks,laimod_max,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) +;------------------------------------------------------------------------ +;(C) phase +;-------------------------------------------------------------------- +; get data + +; observed + laiob_phase = laiob(0,:,:) + s = laiob(:,0,0) + laiob_phase@long_name = "Leaf Area Index Max Month" + + dsizes_z = dimsizes(laiob) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laiob(:,j,i) + laiob_phase(j,i) = maxind(s) + 1 + end do + end do + +; print (min(laiob_phase)+"/"+max(laiob_phase)) + delete (s) + delete (dsizes_z) +;------------------------- +; model + laimod_phase = laimod(0,:,:) + s = laimod(:,0,0) + laimod_phase@long_name = "Leaf Area Index Max Month" + + dsizes_z = dimsizes(laimod) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laimod(:,j,i) + laimod_phase(j,i) = maxind(s) + 1 + end do + end do + +; print (min(laimod_phase)+"/"+max(laimod_phase)) + delete (s) + delete (dsizes_z) +;------------------------ + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_phase) + DATA22_1D = ndtooned(laimod_phase) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data_ob).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data_ob) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrPhase = esccr(uu,vv,0) +; print (ccrPhase) + +; old eq +; bias = abs(avg(vv)-avg(uu)) +; new eq + bias = avg(abs(vv-uu)) + + bias = where((bias.gt. 6.),12.-bias,bias) + Mphase = ((6. - bias)/6.)*5. + + M_lai_phase = sprintf("%.2f", Mphase) + system("sed s#M_lai_phase#"+M_lai_phase+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_lai_phase) + + do i=0,nrow-2 + text4(i,6) = sprintf("%5.2f",u(i)) + text4(i,7) = sprintf("%5.2f",v(i)) + text4(i,8) = "-" + end do + text4(nrow-1,6) = sprintf("%5.2f",avg(u)) + text4(nrow-1,7) = sprintf("%5.2f",avg(v)) + text4(nrow-1,8) = sprintf("%5.2f",Mphase) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Max LAI (Leaf Area Index) Month" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_phase" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrPhase)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 1. ; Min level + resg@cnMaxLevelValF = 12. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + + delta = 0.00001 + laiob_phase = where(ismissing(laiob_phase).and.(ismissing(laimod_phase).or.(laimod_phase.lt.delta)),0.,laiob_phase) + + plot_name = "global_phase_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laiob_phase,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_phase_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot = gsn_csm_contour_map_ce(wks,laimod_phase,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) +;----------------------------------------------------------------- +;(D) grow day +;-------------------------------------------------------------------- +; get data + + day_of_data = (/31,28,31,30,31,30,31,31,30,31,30,31/) + +; observed + laiob_grow = laiob(0,:,:) + laiob_grow@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(laiob) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(laiob(k,j,i)) .and. laiob(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + + laiob_grow(j,i) = nday + end do + end do + +; print (min(laiob_grow)+"/"+max(laiob_grow)) +;------------------------- +; model + laimod_grow = laimod(0,:,:) + laimod_grow@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(laimod) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(laimod(k,j,i)) .and. laimod(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + + laimod_grow(j,i) = nday + end do + end do + +; print (min(laimod_grow)+"/"+max(laimod_grow)) +;------------------------ + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_grow) + DATA22_1D = ndtooned(laimod_grow) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data_ob).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data_ob) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrGrow = esccr(uu,vv,0) +; print (ccrGrow) + +; new eq + bias = sum(abs(vv-uu)/(vv+uu)) + Mgrow = (1.- (bias/dimsizes(uu)))*5. + + M_lai_grow = sprintf("%.2f", Mgrow) + system("sed s#M_lai_grow#"+M_lai_grow+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_lai_grow) + + do i=0,nrow-2 + text4(i,9) = sprintf("%5.2f",u(i)) + text4(i,10) = sprintf("%5.2f",v(i)) + text4(i,11) = "-" + end do + text4(nrow-1,9) = sprintf("%5.2f",avg(u)) + text4(nrow-1,10) = sprintf("%5.2f",avg(v)) + text4(nrow-1,11) = sprintf("%5.2f",Mgrow) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Days of Growing season" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_grow" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrGrow)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 60. ; Min level + resg@cnMaxLevelValF = 360. ; Max level + resg@cnLevelSpacingF = 20. ; interval + +;global contour ob + + laiob_grow@_FillValue = 1.e+36 + laiob_grow = where(laiob_grow .lt. 10.,laiob_grow@_FillValue,laiob_grow) + + plot_name = "global_grow_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laiob_grow,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + laimod_grow@_FillValue = 1.e+36 + laimod_grow = where(laimod_grow .lt. 10.,laimod_grow@_FillValue,laimod_grow) + + plot_name = "global_grow_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot = gsn_csm_contour_map_ce(wks,laimod_grow,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model vs ob + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + plot_name = "global_mean_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMean)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_mean,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_mean,resg) + +;(c) model-ob + + zz = laimod_mean + zz = laimod_mean - laiob_mean + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -2. ; Min level + resg@cnMaxLevelValF = 2. ; Max level + resg@cnLevelSpacingF = 0.4 ; interval + + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;----------------------------------------------------------------- +;global contour model vs ob + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + plot_name = "global_max_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + +; delete(plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMax)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_max,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_max,resg) + +;(c) model-ob + + delete (zz) + zz = laimod_max + zz = laimod_max - laiob_max + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -6. ; Min level + resg@cnMaxLevelValF = 6. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;----------------------------------------------------------------- +;global contour model vs ob + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 1. ; Min level + resg@cnMaxLevelValF = 12. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + plot_name = "global_phase_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + +; delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrPhase)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_phase,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_phase,resg) + +;(c) model-ob + + delete (zz) + zz = laimod_phase + zz = laimod_phase - laiob_phase + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -6. ; Min level + resg@cnMaxLevelValF = 6. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;------------------------------------------------------------------ +;global contour model vs ob + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 60. ; Min level + resg@cnMaxLevelValF = 360. ; Max level + resg@cnLevelSpacingF = 20. ; interval + + plot_name = "global_grow_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + +; delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrGrow)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_grow,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_grow,resg) + +;(c) model-ob + + delete (zz) + zz = laimod_grow + zz = laimod_grow - laiob_grow + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -100. ; Min level + resg@cnMaxLevelValF = 100. ; Max level + resg@cnLevelSpacingF = 20. ; interval + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + clear (wks) + delete (plot) +;************************************************** +; plot lai table +;************************************************** + + plot_name = "table_lai" + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + gsn_table(wks,ncr1,xx1,yy1,text1,res1) + gsn_table(wks,ncr21,xx21,yy21,text21,res21) + gsn_table(wks,ncr22,xx22,yy22,text22,res22) + gsn_table(wks,ncr3,xx3,yy3,text3,res3) + gsn_table(wks,ncr4,xx4,yy4,text4,res4) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;------------------------------------------------------------------- + temp_name = "lai." + model_name + system("mkdir -p " + temp_name+";"+ \ + "cp "+ html_name + " " +temp_name+"/table.html"+";"+ \ + "mv *.png " + temp_name +";"+ \ + "tar cf "+ temp_name +".tar " + temp_name) +;------------------------------------------------------------------- +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/99.all.ncl.0 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/99.all.ncl.0 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1747 @@ +;******************************************************** +; histogram normalized by rain and compute correleration +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; Main code. +begin + + nclass = 20 + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read in data: model +;************************************************ +;film = "b30.061n_1995-2004_MONS_climo_lnd.nc" +;model_name = "b30.061n" +;model_grid = "T31" + +;film = "newcn05_ncep_1i_MONS_climo_lnd.nc" +;model_name = "newcn" +;model_grid = "1.9" + +;film = "i01.06cn_1798-2004_MONS_climo.nc" +;model_name = "06cn" +;model_grid = "T42" + +;film = "i01.06casa_1798-2004_MONS_climo.nc" +;model_name = "06casa" +;model_grid = "T42" + +;film = "i01.10cn_1948-2004_MONS_climo.nc" +;model_name = "10cn" +;model_grid = "T42" + + film = "i01.10casa_1948-2004_MONS_climo.nc" + model_name = "10casa" + model_grid = "T42" +;------------------------------------------------ + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile(dirm+film,"r") + + laimod = fm->TLAI + +;************************************************ +; read in data: observed +;************************************************ + + ob_name = "MODIS MOD 15A2 2000-2005" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo1 = "land_class_"+model_grid+".nc" + filo2 = "LAI_2000-2005_MONS_"+model_grid+".nc" + + fo1 = addfile(diro+filo1,"r") + fo2 = addfile(diro+filo2,"r") + + classob = tofloat(fo1->LAND_CLASS) + laiob = fo2->LAI + +;******************************************************************* +; for plotting table +;******************************************************************* +; table header name + table_header_name = "LAI" + +; column (not including header column) + + col_header1 = (/"Mean","Max","Phase","Growth"/) + col_header2 = (/"ob","model","M" \ + ,"ob","model","M" \ + ,"ob","model","M" \ + ,"ob","model","M" \ + /) + + ncol1 = dimsizes(col_header1) + ncol2 = dimsizes(col_header2) + ncol = ncol2 + +; row (not including header row) + row_header = (/"Water Bodies" \ + ,"Evergreen Needleleaf Forests" \ + ,"Evergreen Broadleaf Forests" \ + ,"Deciduous Needleleaf Forest" \ + ,"Deciduous Broadleaf Forests" \ + ,"Mixed Forests" \ + ,"Closed Bushlands" \ + ,"Open Bushlands" \ + ,"Woody Savannas (S. Hem.)" \ + ,"Savannas (S. Hem.)" \ + ,"Grasslands" \ + ,"Permanent Wetlands" \ + ,"Croplands" \ + ,"Urban and Built-Up" \ + ,"Cropland/Natural Vegetation Mosaic" \ + ,"Permanent Snow and Ice" \ + ,"Barren or Sparsely Vegetated" \ + ,"Unclassified" \ + ,"Woody Savannas (N. Hem.)" \ + ,"Savannas (N. Hem.)" \ + ,"All biome average" \ + /) + nrow = dimsizes(row_header) + +; arrays to be passed to table. + value = new ((/nrow, ncol/),string ) + + table_length = 0.995 + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + xx1 = (/0.005,0.25/) ; Start and end X + yy1 = (/0.900,0.995/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr21 = (/1,ncol1/) ; 1 rows, 4 columns + xx21 = (/xx1(1),0.995/) ; start from end of x1 + yy21 = (/0.9475,0.995/) ; half of y1 + text21 = col_header1 + res21 = True + res21@txFontHeightF = 0.015 + res21@gsFillColor = "Gray" + + ncr22 = (/1,ncol2/) ; 1 rows, 12 columns + xx22 = xx21 ; start from end of x1 + yy22 = (/0.900,0.9475/) ; half of y1 + text22 = col_header2 + res22 = True + res22@txFontHeightF = 0.015 + res22@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; 20 rows, 1 columns + xx3 = xx1 ; same as x1 + yy3 = (/1.0-table_length,0.900/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.01 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; 5 rows, 5 columns + xx4 = xx21 ; Start and end x + yy4 = yy3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" + color_fill4(nrow-1,:) = "CornFlowerBlue" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +;************************************************ +; plot global land class: observed +;************************************************ +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 1. ; Min level + resg@cnMaxLevelValF = 19. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + classob@_FillValue = 1.e+36 + classob = where(classob.eq.0,classob@_FillValue,classob) + + plot_name = "global_class_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,classob,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. +;----------------------------------------------------------------- +;(A) mean +;-------------------------------------------------------------------- +; get data + + laiob_mean = dim_avg_Wrap(laiob(lat|:,lon|:,time|:)) + laimod_mean = dim_avg_Wrap(laimod(lat|:,lon|:,time|:)) + + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_mean) + DATA22_1D = ndtooned(laimod_mean) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((data_ob.ge.range(i)).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(data_ob.ge.range(i)) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrMean = esccr(uu,vv,0) +; print (ccrMean) + +; new eq + bias = sum(abs(vv-uu)/(vv+uu)) + Mmean = (1.- (bias/dimsizes(uu)))*5. + + print (Mmean) + + do i=0,nrow-2 + text4(i,0) = sprintf("%5.2f",u(i)) + text4(i,1) = sprintf("%5.2f",v(i)) + text4(i,2) = "-" + end do + text4(nrow-1,0) = sprintf("%5.2f",avg(u)) + text4(nrow-1,1) = sprintf("%5.2f",avg(v)) + text4(nrow-1,2) = sprintf("%5.2f",Mmean) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Mean LAI (Leaf Area Index)" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_mean" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMean)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + + delta = 0.00001 + laiob_mean = where(ismissing(laiob_mean).and.(ismissing(laimod_mean).or.(laimod_mean.lt.delta)),0.,laiob_mean) + + plot_name = "global_mean_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laiob_mean,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_mean_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laimod_mean,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;----------------------------------------------------------------- +;(B) max +;-------------------------------------------------------------------- +; get data + +; observed + laiob_max = laiob(0,:,:) + s = laiob(:,0,0) + laiob_max@long_name = "Leaf Area Index Max" + + dsizes_z = dimsizes(laiob) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laiob(:,j,i) + laiob_max(j,i) = max(s) + end do + end do + +; print (min(y)+"/"+max(y)) + delete (s) + delete (dsizes_z) +;------------------------- +; model + laimod_max = laimod(0,:,:) + s = laimod(:,0,0) + laimod_max@long_name = "Leaf Area Index Max" + + dsizes_z = dimsizes(laimod) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laimod(:,j,i) + laimod_max(j,i) = max(s) + end do + end do + +; print (min(laimod_max)+"/"+max(laimod_max)) + delete (s) + delete (dsizes_z) +;------------------------ + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_max) + DATA22_1D = ndtooned(laimod_max) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data_ob).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data_ob) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrMax = esccr(uu,vv,0) +; print (ccrMax) + +; new eq + bias = sum(abs(vv-uu)/(vv+uu)) + Mmax = (1.- (bias/dimsizes(uu)))*5. + + print (Mmax) + + do i=0,nrow-2 + text4(i,3) = sprintf("%5.2f",u(i)) + text4(i,4) = sprintf("%5.2f",v(i)) + text4(i,5) = "-" + end do + text4(nrow-1,3) = sprintf("%5.2f",avg(u)) + text4(nrow-1,4) = sprintf("%5.2f",avg(v)) + text4(nrow-1,5) = sprintf("%5.2f",Mmax) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Max LAI (Leaf Area Index)" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_max" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMax)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + + delta = 0.00001 + laiob_max = where(ismissing(laiob_max).and.(ismissing(laimod_max).or.(laimod_max.lt.delta)),0.,laiob_max) + + plot_name = "global_max_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot_max = gsn_csm_contour_map_ce(wks,laiob_max,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_max_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot_max = gsn_csm_contour_map_ce(wks,laimod_max,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;(C) phase +;-------------------------------------------------------------------- +; get data + +; observed + laiob_phase = laiob(0,:,:) + s = laiob(:,0,0) + laiob_phase@long_name = "Leaf Area Index Max Month" + + dsizes_z = dimsizes(laiob) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laiob(:,j,i) + laiob_phase(j,i) = maxind(s) + 1 + end do + end do + +; print (min(laiob_phase)+"/"+max(laiob_phase)) + delete (s) + delete (dsizes_z) +;------------------------- +; model + laimod_phase = laimod(0,:,:) + s = laimod(:,0,0) + laimod_phase@long_name = "Leaf Area Index Max Month" + + dsizes_z = dimsizes(laimod) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laimod(:,j,i) + laimod_phase(j,i) = maxind(s) + 1 + end do + end do + +; print (min(laimod_phase)+"/"+max(laimod_phase)) + delete (s) + delete (dsizes_z) +;------------------------ + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_phase) + DATA22_1D = ndtooned(laimod_phase) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data_ob).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data_ob) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrPhase = esccr(uu,vv,0) +; print (ccrPhase) + +; old eq +; bias = abs(avg(vv)-avg(uu)) +; new eq + bias = avg(abs(vv-uu)) + + bias = where((bias.gt. 6.),12.-bias,bias) + Mphase = ((6. - bias)/6.)*5. + + print (Mphase) + + do i=0,nrow-2 + text4(i,6) = sprintf("%5.2f",u(i)) + text4(i,7) = sprintf("%5.2f",v(i)) + text4(i,8) = "-" + end do + text4(nrow-1,6) = sprintf("%5.2f",avg(u)) + text4(nrow-1,7) = sprintf("%5.2f",avg(v)) + text4(nrow-1,8) = sprintf("%5.2f",Mphase) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Max LAI (Leaf Area Index) Month" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_phase" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrPhase)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 1. ; Min level + resg@cnMaxLevelValF = 12. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + + delta = 0.00001 + laiob_phase = where(ismissing(laiob_phase).and.(ismissing(laimod_phase).or.(laimod_phase.lt.delta)),0.,laiob_phase) + + plot_name = "global_phase_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laiob_phase,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_phase_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot = gsn_csm_contour_map_ce(wks,laimod_phase,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;----------------------------------------------------------------- +;(D) grow day +;-------------------------------------------------------------------- +; get data + + day_of_data = (/31,28,31,30,31,30,31,31,30,31,30,31/) + +; observed + laiob_grow = laiob(0,:,:) + laiob_grow@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(laiob) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(laiob(k,j,i)) .and. laiob(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + + laiob_grow(j,i) = nday + end do + end do + +; print (min(laiob_grow)+"/"+max(laiob_grow)) +;------------------------- +; model + laimod_grow = laimod(0,:,:) + laimod_grow@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(laimod) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(laimod(k,j,i)) .and. laimod(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + + laimod_grow(j,i) = nday + end do + end do + +; print (min(laimod_grow)+"/"+max(laimod_grow)) +;------------------------ + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_grow) + DATA22_1D = ndtooned(laimod_grow) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data_ob).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data_ob) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrGrow = esccr(uu,vv,0) +; print (ccrGrow) + +; new eq + bias = sum(abs(vv-uu)/(vv+uu)) + Mgrow = (1.- (bias/dimsizes(uu)))*5. + + print (Mgrow) + + do i=0,nrow-2 + text4(i,9) = sprintf("%5.2f",u(i)) + text4(i,10) = sprintf("%5.2f",v(i)) + text4(i,11) = "-" + end do + text4(nrow-1,9) = sprintf("%5.2f",avg(u)) + text4(nrow-1,10) = sprintf("%5.2f",avg(v)) + text4(nrow-1,11) = sprintf("%5.2f",Mgrow) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Days of Growing season" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_grow" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrGrow)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 60. ; Min level + resg@cnMaxLevelValF = 360. ; Max level + resg@cnLevelSpacingF = 20. ; interval + +;global contour ob + + laiob_grow@_FillValue = 1.e+36 + laiob_grow = where(laiob_grow .lt. 10.,laiob_grow@_FillValue,laiob_grow) + + plot_name = "global_grow_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laiob_grow,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + laimod_grow@_FillValue = 1.e+36 + laimod_grow = where(laimod_grow .lt. 10.,laimod_grow@_FillValue,laimod_grow) + + plot_name = "global_grow_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot = gsn_csm_contour_map_ce(wks,laimod_grow,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model vs ob + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + plot_name = "global_mean_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMean)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_mean,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_mean,resg) + +;(c) model-ob + + zz = laimod_mean + zz = laimod_mean - laiob_mean + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -2. ; Min level + resg@cnMaxLevelValF = 2. ; Max level + resg@cnLevelSpacingF = 0.4 ; interval + + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +;----------------------------------------------------------------- +;global contour model vs ob + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + plot_name = "global_max_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + +; delete(plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMax)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_max,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_max,resg) + +;(c) model-ob + + delete (zz) + zz = laimod_max + zz = laimod_max - laiob_max + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -6. ; Min level + resg@cnMaxLevelValF = 6. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +;----------------------------------------------------------------- +;global contour model vs ob + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 1. ; Min level + resg@cnMaxLevelValF = 12. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + plot_name = "global_phase_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + +; delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrPhase)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_phase,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_phase,resg) + +;(c) model-ob + + delete (zz) + zz = laimod_phase + zz = laimod_phase - laiob_phase + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -6. ; Min level + resg@cnMaxLevelValF = 6. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + +; pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel +; pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +;------------------------------------------------------------------ +;global contour model vs ob + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 60. ; Min level + resg@cnMaxLevelValF = 360. ; Max level + resg@cnLevelSpacingF = 20. ; interval + + plot_name = "global_grow_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + +; delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrGrow)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_grow,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_grow,resg) + +;(c) model-ob + + delete (zz) + zz = laimod_grow + zz = laimod_grow - laiob_grow + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -100. ; Min level + resg@cnMaxLevelValF = 100. ; Max level + resg@cnLevelSpacingF = 20. ; interval + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +;************************************************** +; plot lai table +;************************************************** + + plot_name = "table_lai" + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + gsn_table(wks,ncr1,xx1,yy1,text1,res1) + gsn_table(wks,ncr21,xx21,yy21,text21,res21) + gsn_table(wks,ncr22,xx22,yy22,text22,res22) + gsn_table(wks,ncr3,xx3,yy3,text3,res3) + gsn_table(wks,ncr4,xx4,yy4,text4,res4) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) +;------------------------------------------------------------------- + temp_name = "temp." + model_name + system("mkdir -p " + temp_name) + system("mv *.png " + temp_name) + system("tar cf "+ temp_name +".tar " + temp_name) +;------------------------------------------------------------------- +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/99.all.ncl.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/99.all.ncl.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1763 @@ +;******************************************************** +; histogram normalized by rain and compute correleration +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; Main code. +begin + + nclass = 20 + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read in data: model +;************************************************ +;film = "b30.061n_1995-2004_MONS_climo_lnd.nc" +;model_name = "b30.061n" +;model_grid = "T31" + +;film = "newcn05_ncep_1i_MONS_climo_lnd.nc" +;model_name = "newcn" +;model_grid = "1.9" + +;film = "i01.06cn_1798-2004_MONS_climo.nc" +;model_name = "06cn" +;model_grid = "T42" + +;film = "i01.06casa_1798-2004_MONS_climo.nc" +;model_name = "06casa" +;model_grid = "T42" + + film = "i01.10cn_1948-2004_MONS_climo.nc" + model_name = "10cn" + model_grid = "T42" + +;film = "i01.10casa_1948-2004_MONS_climo.nc" +;model_name = "10casa" +;model_grid = "T42" + + system("sed s#model_name#"+model_name+"# table.html > table.html.new") + system("mv -f table.html.new table.html") +;------------------------------------------------ + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile(dirm+film,"r") + + laimod = fm->TLAI + +;************************************************ +; read in data: observed +;************************************************ + + ob_name = "MODIS MOD 15A2 2000-2005" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo1 = "land_class_"+model_grid+".nc" + filo2 = "LAI_2000-2005_MONS_"+model_grid+".nc" + + fo1 = addfile(diro+filo1,"r") + fo2 = addfile(diro+filo2,"r") + + classob = tofloat(fo1->LAND_CLASS) + laiob = fo2->LAI + +;******************************************************************* +; for plotting table +;******************************************************************* +; table header name + table_header_name = "LAI" + +; column (not including header column) + + col_header1 = (/"Mean","Max","Phase","Growth"/) + col_header2 = (/"ob","model","M" \ + ,"ob","model","M" \ + ,"ob","model","M" \ + ,"ob","model","M" \ + /) + + ncol1 = dimsizes(col_header1) + ncol2 = dimsizes(col_header2) + ncol = ncol2 + +; row (not including header row) + row_header = (/"Water Bodies" \ + ,"Evergreen Needleleaf Forests" \ + ,"Evergreen Broadleaf Forests" \ + ,"Deciduous Needleleaf Forest" \ + ,"Deciduous Broadleaf Forests" \ + ,"Mixed Forests" \ + ,"Closed Bushlands" \ + ,"Open Bushlands" \ + ,"Woody Savannas (S. Hem.)" \ + ,"Savannas (S. Hem.)" \ + ,"Grasslands" \ + ,"Permanent Wetlands" \ + ,"Croplands" \ + ,"Urban and Built-Up" \ + ,"Cropland/Natural Vegetation Mosaic" \ + ,"Permanent Snow and Ice" \ + ,"Barren or Sparsely Vegetated" \ + ,"Unclassified" \ + ,"Woody Savannas (N. Hem.)" \ + ,"Savannas (N. Hem.)" \ + ,"All biome average" \ + /) + nrow = dimsizes(row_header) + +; arrays to be passed to table. + value = new ((/nrow, ncol/),string ) + + table_length = 0.995 + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + xx1 = (/0.005,0.25/) ; Start and end X + yy1 = (/0.900,0.995/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.03 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr21 = (/1,ncol1/) ; 1 rows, 4 columns + xx21 = (/xx1(1),0.995/) ; start from end of x1 + yy21 = (/0.9475,0.995/) ; half of y1 + text21 = col_header1 + res21 = True + res21@txFontHeightF = 0.015 + res21@gsFillColor = "Gray" + + ncr22 = (/1,ncol2/) ; 1 rows, 12 columns + xx22 = xx21 ; start from end of x1 + yy22 = (/0.900,0.9475/) ; half of y1 + text22 = col_header2 + res22 = True + res22@txFontHeightF = 0.015 + res22@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; 20 rows, 1 columns + xx3 = xx1 ; same as x1 + yy3 = (/1.0-table_length,0.900/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.01 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; 5 rows, 5 columns + xx4 = xx21 ; Start and end x + yy4 = yy3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" + color_fill4(nrow-1,:) = "CornFlowerBlue" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +;************************************************ +; plot global land class: observed +;************************************************ +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 1. ; Min level + resg@cnMaxLevelValF = 19. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + classob@_FillValue = 1.e+36 + classob = where(classob.eq.0,classob@_FillValue,classob) + + plot_name = "global_class_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,classob,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. +;----------------------------------------------------------------- +;(A) mean +;-------------------------------------------------------------------- +; get data + + laiob_mean = dim_avg_Wrap(laiob(lat|:,lon|:,time|:)) + laimod_mean = dim_avg_Wrap(laimod(lat|:,lon|:,time|:)) + + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_mean) + DATA22_1D = ndtooned(laimod_mean) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((data_ob.ge.range(i)).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(data_ob.ge.range(i)) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrMean = esccr(uu,vv,0) +; print (ccrMean) + +; new eq + bias = sum(abs(vv-uu)/(vv+uu)) + Mmean = (1.- (bias/dimsizes(uu)))*5. + + M_lai_mean = sprintf("%.2f", Mmean) + system("sed s#M_lai_mean#"+M_lai_mean+"# table.html > table.html.new") + system("mv -f table.html.new table.html") + print (M_lai_mean) + + do i=0,nrow-2 + text4(i,0) = sprintf("%5.2f",u(i)) + text4(i,1) = sprintf("%5.2f",v(i)) + text4(i,2) = "-" + end do + text4(nrow-1,0) = sprintf("%5.2f",avg(u)) + text4(nrow-1,1) = sprintf("%5.2f",avg(v)) + text4(nrow-1,2) = sprintf("%5.2f",Mmean) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Mean LAI (Leaf Area Index)" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_mean" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMean)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + + delta = 0.00001 + laiob_mean = where(ismissing(laiob_mean).and.(ismissing(laimod_mean).or.(laimod_mean.lt.delta)),0.,laiob_mean) + + plot_name = "global_mean_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laiob_mean,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_mean_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laimod_mean,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;----------------------------------------------------------------- +;(B) max +;-------------------------------------------------------------------- +; get data + +; observed + laiob_max = laiob(0,:,:) + s = laiob(:,0,0) + laiob_max@long_name = "Leaf Area Index Max" + + dsizes_z = dimsizes(laiob) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laiob(:,j,i) + laiob_max(j,i) = max(s) + end do + end do + +; print (min(y)+"/"+max(y)) + delete (s) + delete (dsizes_z) +;------------------------- +; model + laimod_max = laimod(0,:,:) + s = laimod(:,0,0) + laimod_max@long_name = "Leaf Area Index Max" + + dsizes_z = dimsizes(laimod) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laimod(:,j,i) + laimod_max(j,i) = max(s) + end do + end do + +; print (min(laimod_max)+"/"+max(laimod_max)) + delete (s) + delete (dsizes_z) +;------------------------ + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_max) + DATA22_1D = ndtooned(laimod_max) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data_ob).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data_ob) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrMax = esccr(uu,vv,0) +; print (ccrMax) + +; new eq + bias = sum(abs(vv-uu)/(vv+uu)) + Mmax = (1.- (bias/dimsizes(uu)))*5. + + M_lai_max = sprintf("%.2f", Mmax) + system("sed s#M_lai_max#"+M_lai_max+"# table.html > table.html.new") + system("mv -f table.html.new table.html") + print (M_lai_max) + + do i=0,nrow-2 + text4(i,3) = sprintf("%5.2f",u(i)) + text4(i,4) = sprintf("%5.2f",v(i)) + text4(i,5) = "-" + end do + text4(nrow-1,3) = sprintf("%5.2f",avg(u)) + text4(nrow-1,4) = sprintf("%5.2f",avg(v)) + text4(nrow-1,5) = sprintf("%5.2f",Mmax) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Max LAI (Leaf Area Index)" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_max" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMax)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + + delta = 0.00001 + laiob_max = where(ismissing(laiob_max).and.(ismissing(laimod_max).or.(laimod_max.lt.delta)),0.,laiob_max) + + plot_name = "global_max_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot_max = gsn_csm_contour_map_ce(wks,laiob_max,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_max_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot_max = gsn_csm_contour_map_ce(wks,laimod_max,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;(C) phase +;-------------------------------------------------------------------- +; get data + +; observed + laiob_phase = laiob(0,:,:) + s = laiob(:,0,0) + laiob_phase@long_name = "Leaf Area Index Max Month" + + dsizes_z = dimsizes(laiob) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laiob(:,j,i) + laiob_phase(j,i) = maxind(s) + 1 + end do + end do + +; print (min(laiob_phase)+"/"+max(laiob_phase)) + delete (s) + delete (dsizes_z) +;------------------------- +; model + laimod_phase = laimod(0,:,:) + s = laimod(:,0,0) + laimod_phase@long_name = "Leaf Area Index Max Month" + + dsizes_z = dimsizes(laimod) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laimod(:,j,i) + laimod_phase(j,i) = maxind(s) + 1 + end do + end do + +; print (min(laimod_phase)+"/"+max(laimod_phase)) + delete (s) + delete (dsizes_z) +;------------------------ + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_phase) + DATA22_1D = ndtooned(laimod_phase) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data_ob).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data_ob) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrPhase = esccr(uu,vv,0) +; print (ccrPhase) + +; old eq +; bias = abs(avg(vv)-avg(uu)) +; new eq + bias = avg(abs(vv-uu)) + + bias = where((bias.gt. 6.),12.-bias,bias) + Mphase = ((6. - bias)/6.)*5. + + M_lai_phase = sprintf("%.2f", Mphase) + system("sed s#M_lai_phase#"+M_lai_phase+"# table.html > table.html.new") + system("mv -f table.html.new table.html") + print (M_lai_phase) + + do i=0,nrow-2 + text4(i,6) = sprintf("%5.2f",u(i)) + text4(i,7) = sprintf("%5.2f",v(i)) + text4(i,8) = "-" + end do + text4(nrow-1,6) = sprintf("%5.2f",avg(u)) + text4(nrow-1,7) = sprintf("%5.2f",avg(v)) + text4(nrow-1,8) = sprintf("%5.2f",Mphase) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Max LAI (Leaf Area Index) Month" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_phase" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrPhase)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 1. ; Min level + resg@cnMaxLevelValF = 12. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + + delta = 0.00001 + laiob_phase = where(ismissing(laiob_phase).and.(ismissing(laimod_phase).or.(laimod_phase.lt.delta)),0.,laiob_phase) + + plot_name = "global_phase_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laiob_phase,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_phase_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot = gsn_csm_contour_map_ce(wks,laimod_phase,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;----------------------------------------------------------------- +;(D) grow day +;-------------------------------------------------------------------- +; get data + + day_of_data = (/31,28,31,30,31,30,31,31,30,31,30,31/) + +; observed + laiob_grow = laiob(0,:,:) + laiob_grow@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(laiob) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(laiob(k,j,i)) .and. laiob(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + + laiob_grow(j,i) = nday + end do + end do + +; print (min(laiob_grow)+"/"+max(laiob_grow)) +;------------------------- +; model + laimod_grow = laimod(0,:,:) + laimod_grow@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(laimod) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(laimod(k,j,i)) .and. laimod(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + + laimod_grow(j,i) = nday + end do + end do + +; print (min(laimod_grow)+"/"+max(laimod_grow)) +;------------------------ + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_grow) + DATA22_1D = ndtooned(laimod_grow) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data_ob).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data_ob) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrGrow = esccr(uu,vv,0) +; print (ccrGrow) + +; new eq + bias = sum(abs(vv-uu)/(vv+uu)) + Mgrow = (1.- (bias/dimsizes(uu)))*5. + + M_lai_grow = sprintf("%.2f", Mgrow) + system("sed s#M_lai_grow#"+M_lai_grow+"# table.html > table.html.new") + system("mv -f table.html.new table.html") + print (M_lai_grow) + + do i=0,nrow-2 + text4(i,9) = sprintf("%5.2f",u(i)) + text4(i,10) = sprintf("%5.2f",v(i)) + text4(i,11) = "-" + end do + text4(nrow-1,9) = sprintf("%5.2f",avg(u)) + text4(nrow-1,10) = sprintf("%5.2f",avg(v)) + text4(nrow-1,11) = sprintf("%5.2f",Mgrow) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Days of Growing season" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_grow" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrGrow)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 60. ; Min level + resg@cnMaxLevelValF = 360. ; Max level + resg@cnLevelSpacingF = 20. ; interval + +;global contour ob + + laiob_grow@_FillValue = 1.e+36 + laiob_grow = where(laiob_grow .lt. 10.,laiob_grow@_FillValue,laiob_grow) + + plot_name = "global_grow_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laiob_grow,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + laimod_grow@_FillValue = 1.e+36 + laimod_grow = where(laimod_grow .lt. 10.,laimod_grow@_FillValue,laimod_grow) + + plot_name = "global_grow_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot = gsn_csm_contour_map_ce(wks,laimod_grow,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model vs ob + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + plot_name = "global_mean_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMean)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_mean,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_mean,resg) + +;(c) model-ob + + zz = laimod_mean + zz = laimod_mean - laiob_mean + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -2. ; Min level + resg@cnMaxLevelValF = 2. ; Max level + resg@cnLevelSpacingF = 0.4 ; interval + + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +;----------------------------------------------------------------- +;global contour model vs ob + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + plot_name = "global_max_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + +; delete(plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMax)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_max,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_max,resg) + +;(c) model-ob + + delete (zz) + zz = laimod_max + zz = laimod_max - laiob_max + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -6. ; Min level + resg@cnMaxLevelValF = 6. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +;----------------------------------------------------------------- +;global contour model vs ob + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 1. ; Min level + resg@cnMaxLevelValF = 12. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + plot_name = "global_phase_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + +; delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrPhase)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_phase,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_phase,resg) + +;(c) model-ob + + delete (zz) + zz = laimod_phase + zz = laimod_phase - laiob_phase + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -6. ; Min level + resg@cnMaxLevelValF = 6. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + +; pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel +; pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +;------------------------------------------------------------------ +;global contour model vs ob + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 60. ; Min level + resg@cnMaxLevelValF = 360. ; Max level + resg@cnLevelSpacingF = 20. ; interval + + plot_name = "global_grow_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + +; delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrGrow)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_grow,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_grow,resg) + +;(c) model-ob + + delete (zz) + zz = laimod_grow + zz = laimod_grow - laiob_grow + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -100. ; Min level + resg@cnMaxLevelValF = 100. ; Max level + resg@cnLevelSpacingF = 20. ; interval + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +;************************************************** +; plot lai table +;************************************************** + + plot_name = "table_lai" + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + gsn_table(wks,ncr1,xx1,yy1,text1,res1) + gsn_table(wks,ncr21,xx21,yy21,text21,res21) + gsn_table(wks,ncr22,xx22,yy22,text22,res22) + gsn_table(wks,ncr3,xx3,yy3,text3,res3) + gsn_table(wks,ncr4,xx4,yy4,text4,res4) + + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) +;------------------------------------------------------------------- + temp_name = "lai." + model_name + system("mkdir -p " + temp_name) + system("cp table.html " + temp_name) + system("mv *.png " + temp_name) + system("tar cf "+ temp_name +".tar " + temp_name) +;------------------------------------------------------------------- +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/99.all.ncl.new --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/99.all.ncl.new Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,735 @@ +;************************************************************* +; remove histogram plots. +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read data: model +;************************************************ + +;film = "b30.061n_1995-2004_MONS_climo_lnd.nc" +;model_name = "b30.061n" +;model_grid = "T31" + +;film = "newcn05_ncep_1i_MONS_climo_lnd.nc" +;model_name = "newcn" +;model_grid = "1.9" + +;film = "i01.06cn_1798-2004_MONS_climo.nc" +;model_name = "06cn" +;model_grid = "T42" + +;film = "i01.06casa_1798-2004_MONS_climo.nc" +;model_name = "06casa" +;model_grid = "T42" + + film = "i01.10cn_1948-2004_MONS_climo.nc" + model_name = "10cn" + model_grid = "T42" + +;film = "i01.10casa_1948-2004_MONS_climo.nc" +;model_name = "10casa" +;model_grid = "T42" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile(dirm+film,"r") + + laimod = fm->TLAI + +;************************************************ +; read data: observed +;************************************************ + + ob_name = "MODIS MOD 15A2 2000-2005" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo1 = "land_class_"+model_grid+".nc" + filo2 = "LAI_2000-2005_MONS_"+model_grid+".nc" + + fo1 = addfile(diro+filo1,"r") + fo2 = addfile(diro+filo2,"r") + + classob = tofloat(fo1->LAND_CLASS) + laiob = fo2->LAI + +; input observed data has 20 land-type classes + nclass = 20 + +;************************************************ +; global res +;************************************************ + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + +;************************************************ +; plot global land class: observed +;************************************************ + + resg@cnMinLevelValF = 1. ; Min level + resg@cnMaxLevelValF = 19. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +; global contour ob + classob@_FillValue = 1.e+36 + classob = where(classob.eq.0,classob@_FillValue,classob) + + plot_name = "global_class_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,classob,resg) + frame(wks) + + clear (wks) + +;******************************************************************* +; for html table : all 4 components (Mean, Max, Phase, Growth) +;******************************************************************* + +; column (not including header column) + + component = (/"Mean","Max","Phase","Growth"/) + col_head2 = (/"observed",model_name,"M_score" \ + ,"observed",model_name,"M_score" \ + ,"observed",model_name,"M_score" \ + ,"observed",model_name,"M_score" \ + /) + + n_comp = dimsizes(component) + ncol = dimsizes(col_head2) + +; row (not including header row) + row_head = (/"Evergreen Needleleaf Forests" \ + ,"Evergreen Broadleaf Forests" \ + ,"Deciduous Needleleaf Forest" \ + ,"Deciduous Broadleaf Forests" \ + ,"Mixed Forests" \ + ,"Closed Bushlands" \ + ,"Open Bushlands" \ + ,"Woody Savannas (S. Hem.)" \ + ,"Savannas (S. Hem.)" \ + ,"Grasslands" \ + ,"Permanent Wetlands" \ + ,"Croplands" \ + ,"Cropland/Natural Vegetation Mosaic" \ + ,"Barren or Sparsely Vegetated" \ + ,"Woody Savannas (N. Hem.)" \ + ,"Savannas (N. Hem.)" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + +; M_comp + M_comp = (/"M_lai_mean","M_lai_max","M_lai_phase","M_lai_grow"/) + +; total M_score + M_total = 0. + +;******************************************************************** +; use land-type class to bin the data in equally spaced ranges +;******************************************************************** + + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + +;************************************************************************ +; go through all components +;************************************************************************ + + do n = 0,n_comp-1 + +;=================== +; get data: +;=================== +; (A) Mean + + if (n .eq. 0) then + data_ob = dim_avg_Wrap(laiob (lat|:,lon|:,time|:)) + data_mod = dim_avg_Wrap(laimod(lat|:,lon|:,time|:)) + end if + +; (B) Max + + if (n .eq. 1) then + +; observed + data_ob = laiob(0,:,:) + s = laiob(:,0,0) + data_ob@long_name = "Leaf Area Index Max" + + dsizes_z = dimsizes(laiob) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laiob(:,j,i) + data_ob(j,i) = max(s) + end do + end do + + delete (s) + delete (dsizes_z) + +; model + data_mod = laimod(0,:,:) + s = laimod(:,0,0) + data_mod@long_name = "Leaf Area Index Max" + + dsizes_z = dimsizes(laimod) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laimod(:,j,i) + data_mod(j,i) = max(s) + end do + end do + + delete (s) + delete (dsizes_z) + end if + +; (C) phase + + if (n .eq. 2) then + +; observed + data_ob = laiob(0,:,:) + s = laiob(:,0,0) + data_ob@long_name = "Leaf Area Index Max Month" + + dsizes_z = dimsizes(laiob) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laiob(:,j,i) + data_ob(j,i) = maxind(s) + 1 + end do + end do + + delete (s) + delete (dsizes_z) + +; model + data_mod = laimod(0,:,:) + s = laimod(:,0,0) + data_mod@long_name = "Leaf Area Index Max Month" + + dsizes_z = dimsizes(laimod) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laimod(:,j,i) + data_mod(j,i) = maxind(s) + 1 + end do + end do + + delete (s) + delete (dsizes_z) + end if + +; (D) grow day + + if (n .eq. 3) then + + day_of_data = (/31,28,31,30,31,30,31,31,30,31,30,31/) + +; observed + data_ob = laiob(0,:,:) + data_ob@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(laiob) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(laiob(k,j,i)) .and. laiob(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + + data_ob(j,i) = nday + end do + end do + + delete (dsizes_z) + +; model + data_mod = laimod(0,:,:) + data_mod@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(laimod) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(laimod(k,j,i)) .and. laimod(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + + data_mod(j,i) = nday + end do + end do + + delete (dsizes_z) + end if + +;============================== +; put data into bins +;============================== + + base_1D = ndtooned(classob) + data1_1D = ndtooned(data_ob) + data2_1D = ndtooned(data_mod) + +; output for data in bins + + yvalues = new((/2,nx/),float) + count = new((/2,nx/),float) + +; put data into bins + + do nd=0,1 + +; See if we are doing data1 (nd=0) or data2 (nd=1). + + base = base_1D + + if(nd.eq.0) then + data = data1_1D + else + data = data2_1D + end if + +; Loop through each range, using base. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(base.ge.range(i)) + end if + +; Calculate average + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data(idx)) + count(nd,i) = dimsizes(idx) + else + yvalues(nd,i) = yvalues@_FillValue + count(nd,i) = 0 + end if + +;############################################################# +; set the following 4 classes to _FillValue: +; Water Bodies(0), Urban and Build-Up(13), +; Permenant Snow and Ice(15), Unclassified(17) + + if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then + yvalues(nd,i) = yvalues@_FillValue + count(nd,i) = 0 + end if +;############################################################# + +; print(nd + ": " + count(nd,i) + " points, avg = " + yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + + delete(data) + end do + + delete (base) + delete (base_1D) + delete (data1_1D) + delete (data2_1D) + +;===================================== +; compute correlation coef and M score +;===================================== + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + +; compute correlation coef + cc = esccr(uu,vv,0) + + if (n .eq. 2) then + bias = avg(abs(vv-uu)) + bias = where((bias.gt. 6.),12.-bias,bias) + Mscore = ((6. - bias)/6.)*5. + M_score = sprintf("%.2f", Mscore) + else + bias = sum(abs(vv-uu)/abs(vv+uu)) + Mscore = (1.- (bias/dimsizes(uu)))*5. + M_score = sprintf("%.2f", Mscore) + end if + +; compute M_total + + M_total = M_total + Mscore + +;================== +; output M_score +;================== + + print (Mscore) +;======================= +; output to html table +;======================= + + nn = n*3 + + do i=0,nrow-2 + text4(i,nn) = sprintf("%.2f",u(i)) + text4(i,nn+1) = sprintf("%.2f",v(i)) + text4(i,nn+2) = "-" + end do + text4(nrow-1,nn) = sprintf("%.2f",avg(u)) + text4(nrow-1,nn+1) = sprintf("%.2f",avg(v)) + text4(nrow-1,nn+2) = M_score + + delete (u) + delete (v) + delete (uu) + delete (vv) + delete (yvalues) + delete (good) + +;======================================== +; global res changes for each component +;======================================== + delta = 0.00001 + + if (n .eq. 0) then + resg@cnMinLevelValF = 0. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob) + end if + + if (n .eq. 1) then + resg@cnMinLevelValF = 0. + resg@cnMaxLevelValF = 10. + resg@cnLevelSpacingF = 1. + + data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob) + end if + + if (n .eq. 2) then + resg@cnMinLevelValF = 1. + resg@cnMaxLevelValF = 12. + resg@cnLevelSpacingF = 1. + + data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob) + end if + + if (n .eq. 3) then + resg@cnMinLevelValF = 60. + resg@cnMaxLevelValF = 360. + resg@cnLevelSpacingF = 20. + + data_ob@_FillValue = 1.e+36 + data_ob = where(data_ob .lt. 10.,data_ob@_FillValue,data_ob) + + data_mod@_FillValue = 1.e+36 + data_mod = where(data_mod .lt. 10.,data_mod@_FillValue,data_mod) + end if + +;========================= +; global contour : ob +;========================= + + plot_name = "global_"+component(n)+"_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,data_ob,resg) + frame(wks) + + clear (wks) + delete (plot) + +;============================ +; global contour : model +;============================ + + plot_name = "global_"+component(n)+"_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") + + plot = gsn_csm_contour_map_ce(wks,data_mod,resg) + frame(wks) + + clear (wks) + delete (plot) + +;================================ +; global contour: model vs ob +;================================ + + plot_name = "global_"+component(n)+"_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") + + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%.2f", cc)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) + +; plot ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,data_ob,resg) + +; plot model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,data_mod,resg) + +; plot model-ob + + if (n .eq. 0) then + resg@cnMinLevelValF = -2. + resg@cnMaxLevelValF = 2. + resg@cnLevelSpacingF = 0.4 + end if + + if (n .eq. 1) then + resg@cnMinLevelValF = -6. + resg@cnMaxLevelValF = 6. + resg@cnLevelSpacingF = 1. + end if + + if (n .eq. 2) then + resg@cnMinLevelValF = -6. + resg@cnMaxLevelValF = 6. + resg@cnLevelSpacingF = 1. + end if + + if (n .eq. 3) then + resg@cnMinLevelValF = -100. + resg@cnMaxLevelValF = 100. + resg@cnLevelSpacingF = 20. + end if + + zz = data_mod + zz = data_mod - data_ob + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + +; plot panel + + pres = True ; panel plot mods desired + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + clear (wks) + delete (plot) + + end do +;************************************************** +; html table +;************************************************** + output_html = "table_model_vs_ob.html" + + header_text = "

LAI: Model "+model_name+" vs Observed

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Class"+component(0)+""+component(1)+""+component(2)+""+component(3)+"
observed"+model_name+"M_scoreobserved"+model_name+"M_scoreobserved"+model_name+"M_scoreobserved"+model_name+"M_score
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + txt5 = text4(n,3) + txt6 = text4(n,4) + txt7 = text4(n,5) + txt8 = text4(n,6) + txt9 = text4(n,7) + txt10 = text4(n,8) + txt11 = text4(n,9) + txt12 = text4(n,10) + txt13 = text4(n,11) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + set_line(lines,nline,""+txt8+"") + set_line(lines,nline,""+txt9+"") + set_line(lines,nline,""+txt10+"") + set_line(lines,nline,""+txt11+"") + set_line(lines,nline,""+txt12+"") + set_line(lines,nline,""+txt13+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +;*************************************************************************** +; write total score to file +;*************************************************************************** + + asciiwrite("M_save.lai", M_total) + +;*************************************************************************** +end + diff -r 000000000000 -r 0c6405ab2ff4 lai/99.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lai/99.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1185 @@ +;******************************************************** +; histogram normalized by rain and compute correleration +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; Main code. +begin + +;nclass = 18 + nclass = 20 + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read in data: model +;************************************************ + + model_name = "b30.061n" + model_grid = "T31" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "b30.061n_1995-2004_MONS_climo_lnd.nc" +;film = "i01.03cn_1545-1569_MONS_climo.nc" + fm = addfile(dirm+film,"r") + + laimod = fm->TLAI + +;************************************************ +; read in data: observed +;************************************************ + + ob_name = "MODIS MOD 15A2 2000-2005" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo1 = "land_class_"+model_grid+".nc" + filo2 = "LAI_2000-2005_MONS_"+model_grid+".nc" + + fo1 = addfile(diro+filo1,"r") + fo2 = addfile(diro+filo2,"r") + + classob = tofloat(fo1->LAND_CLASS) + laiob = fo2->LAI +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. +;----------------------------------------------------------------- + +;----------------------------------------------------------------- +;(B) max +;-------------------------------------------------------------------- +; get data + +; observed + laiob_max = laiob(0,:,:) + s = laiob(:,0,0) + laiob_max@long_name = "Leaf Area Index Max" + + dsizes_z = dimsizes(laiob) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laiob(:,j,i) + laiob_max(j,i) = max(s) + end do + end do + +; print (min(y)+"/"+max(y)) + delete (s) + delete (dsizes_z) +;------------------------- +; model + laimod_max = laimod(0,:,:) + s = laimod(:,0,0) + laimod_max@long_name = "Leaf Area Index Max" + + dsizes_z = dimsizes(laimod) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laimod(:,j,i) + laimod_max(j,i) = max(s) + end do + end do + +; print (min(laimod_max)+"/"+max(laimod_max)) + delete (s) + delete (dsizes_z) +;------------------------ + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_max) + DATA22_1D = ndtooned(laimod_max) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data_ob).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data_ob) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrMax = esccr(uu,vv,0) +; print (ccrMax) + +; new eq + bias = sum(abs(vv-uu)/(vv+uu)) + Mmax = (1.- (bias/dimsizes(uu)))*5. + + print (Mmax) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Max LAI (Leaf Area Index)" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_max" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMax)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 10. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + + delta = 0.00001 + laiob_max = where(ismissing(laiob_max).and.(ismissing(laimod_max).or.(laimod_max.lt.delta)),0.,laiob_max) + + plot_name = "global_max_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laiob_max,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_max_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot = gsn_csm_contour_map_ce(wks,laimod_max,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model vs ob + + plot_name = "global_max_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrMax)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_max,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_max,resg) + +;(c) model-ob + + zz = laimod_max + zz = laimod_max - laiob_max + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -6. ; Min level + resg@cnMaxLevelValF = 6. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +;----------------------------------------------------------------- +;(C) phase +;-------------------------------------------------------------------- +; get data + +; observed + laiob_phase = laiob(0,:,:) + s = laiob(:,0,0) + laiob_phase@long_name = "Leaf Area Index Max Month" + + dsizes_z = dimsizes(laiob) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laiob(:,j,i) + laiob_phase(j,i) = maxind(s) + 1 + end do + end do + +; print (min(laiob_phase)+"/"+max(laiob_phase)) + delete (s) + delete (dsizes_z) +;------------------------- +; model + laimod_phase = laimod(0,:,:) + s = laimod(:,0,0) + laimod_phase@long_name = "Leaf Area Index Max Month" + + dsizes_z = dimsizes(laimod) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + s = laimod(:,j,i) + laimod_phase(j,i) = maxind(s) + 1 + end do + end do + +; print (min(laimod_phase)+"/"+max(laimod_phase)) + delete (s) + delete (dsizes_z) +;------------------------ + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_phase) + DATA22_1D = ndtooned(laimod_phase) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data_ob).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data_ob) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrPhase = esccr(uu,vv,0) +; print (ccrPhase) + +; old eq +; bias = abs(avg(vv)-avg(uu)) +; new eq + bias = avg(abs(vv-uu)) + + bias = where((bias.gt. 6.),12.-bias,bias) + Mphase = ((6. - bias)/6.)*5. + + print (Mphase) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Max LAI (Leaf Area Index) Month" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_phase" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrPhase)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 1. ; Min level + resg@cnMaxLevelValF = 12. ; Max level + resg@cnLevelSpacingF = 1. ; interval + +;global contour ob + + delta = 0.00001 + laiob_phase = where(ismissing(laiob_phase).and.(ismissing(laimod_phase).or.(laimod_phase.lt.delta)),0.,laiob_phase) + + plot_name = "global_phase_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laiob_phase,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_phase_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot = gsn_csm_contour_map_ce(wks,laimod_phase,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model vs ob + + plot_name = "global_phase_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrPhase)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_phase,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_phase,resg) + +;(c) model-ob + + delete (zz) + zz = laimod_phase + zz = laimod_phase - laiob_phase + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -6. ; Min level + resg@cnMaxLevelValF = 6. ; Max level + resg@cnLevelSpacingF = 1. ; interval + + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + +; pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel +; pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +;----------------------------------------------------------------- +;(D) grow day +;-------------------------------------------------------------------- +; get data + + day_of_data = (/31,28,31,30,31,30,31,31,30,31,30,31/) + +; observed + laiob_grow = laiob(0,:,:) + laiob_grow@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(laiob) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(laiob(k,j,i)) .and. laiob(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + + laiob_grow(j,i) = nday + end do + end do + +; print (min(laiob_grow)+"/"+max(laiob_grow)) +;------------------------- +; model + laimod_grow = laimod(0,:,:) + laimod_grow@long_name = "Days of Growing Season" + + dsizes_z = dimsizes(laimod) + ntime = dsizes_z(0) + nlat = dsizes_z(1) + nlon = dsizes_z(2) + + do j = 0,nlat-1 + do i = 0,nlon-1 + nday = 0. + do k = 0,ntime-1 + if (.not. ismissing(laimod(k,j,i)) .and. laimod(k,j,i) .gt. 1.0) then + nday = nday + day_of_data(k) + end if + end do + + laimod_grow(j,i) = nday + end do + end do + +; print (min(laimod_grow)+"/"+max(laimod_grow)) +;------------------------ + DATA11_1D = ndtooned(classob) + DATA12_1D = ndtooned(laiob_grow) + DATA22_1D = ndtooned(laimod_grow) + + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data_ob = DATA11_1D + data_mod = DATA12_1D + else + data_ob = DATA11_1D + data_mod = DATA22_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data_ob).and.(data_ob.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data_ob) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data_mod(idx)) + mn_yvalues(nd,i) = min(data_mod(idx)) + mx_yvalues(nd,i) = max(data_mod(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data_ob) + delete(data_mod) + end do +;----------------------------------------------------------------- +; compute correlation coef and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccrGrow = esccr(uu,vv,0) +; print (ccrGrow) + +; new eq + bias = sum(abs(vv-uu)/(vv+uu)) + Mgrow = (1.- (bias/dimsizes(uu)))*5. + + print (Mgrow) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;-------------------------------------------------------------------- +; histogram res + + resm = True + resm@gsnMaximize = True + resm@gsnDraw = False + resm@gsnFrame = False + resm@xyMarkLineMode = "Markers" + resm@xyMarkerSizeF = 0.014 + resm@xyMarker = 16 + resm@xyMarkerColors = (/"Brown","Blue"/) +; resm@trYMinF = min(mn_yvalues) - 10. +; resm@trYMaxF = max(mx_yvalues) + 10. + resm@trYMinF = min(mn_yvalues) - 2 + resm@trYMaxF = max(mx_yvalues) + 4 + + resm@tiYAxisString = "Days of Growing season" + resm@tiXAxisString = "Land Cover Type" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;------------------------------------------------------------------ +; Start the graphics. + + plot_name = "histogram_grow" + title = model_name + " vs Observed" + resm@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) +;----------------------------- +; Add a boxed legend using the more simple method + + resm@pmLegendDisplayMode = "Always" +; resm@pmLegendWidthF = 0.1 + resm@pmLegendWidthF = 0.08 + resm@pmLegendHeightF = 0.05 + resm@pmLegendOrthogonalPosF = -1.17 +; resm@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resm@pmLegendParallelPosF = 0.18 + resm@pmLegendParallelPosF = 0.88 ;(rightward) + +; resm@lgPerimOn = False + resm@lgLabelFontHeightF = 0.015 + resm@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrGrow)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resm) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (DATA11_1D) + delete (DATA12_1D) + delete (DATA22_1D) +;delete (range) +;delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;----------------------------------------------------------------- +;global res + + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 360. ; Max level + resg@cnLevelSpacingF = 30. ; interval + +;global contour ob + + delta = 0.00001 + laiob_grow = where(ismissing(laiob_grow).and.(ismissing(laimod_grow).or.(laimod_grow.lt.delta)),0.,laiob_grow) + + plot_name = "global_grow_ob" + title = ob_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,laiob_grow,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_grow_model" + title = "Model " + model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot = gsn_csm_contour_map_ce(wks,laimod_grow,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model vs ob + + plot_name = "global_grow_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrGrow)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = ob_name + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,laiob_grow,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,laimod_grow,resg) + +;(c) model-ob + + delete (zz) + zz = laimod_grow + zz = laimod_grow - laiob_grow + title = "Model_"+model_name+" - Observed" + resg@tiMainString = title + + resg@cnMinLevelValF = -120. ; Min level + resg@cnMaxLevelValF = 120. ; Max level + resg@cnLevelSpacingF = 20. ; interval + + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +end + diff -r 000000000000 -r 0c6405ab2ff4 list.clamp_data --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/list.clamp_data Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,2 @@ +biomass fluxnet model soil_carbon +co2 lai npp diff -r 000000000000 -r 0c6405ab2ff4 list.data --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/list.data Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,2 @@ +biomass fluxnet model soil_carbon +co2 lai npp diff -r 000000000000 -r 0c6405ab2ff4 list.data.model --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/list.data.model Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,35 @@ +T42.clamp.surface-data.060412.nc i01.10casa_1994-2004_ANN_climo.nc +b30.061m_401_425_ANN_climo_atm.nc i01.10casa_1994-2004_MONS_climo.nc +b30.061m_401_425_MONS_climo_atm.nc i01.10casa_1996-2003_ANN_climo.nc +b30.061n_1995-2004_ANN_climo_atm.nc i01.10casa_1996-2003_MONS_climo.nc +b30.061n_1995-2004_ANN_climo_lnd.nc i01.10casa_1997-2003_ANN_climo.nc +b30.061n_1995-2004_MONS_climo_atm.nc i01.10casa_1997-2003_MONS_climo.nc +b30.061n_1995-2004_MONS_climo_lnd.nc i01.10casa_1998-2003_ANN_climo.nc +f02.03casa_1876-1900_ANN_climo.nc i01.10casa_1998-2003_MONS_climo.nc +f02.03casa_1876-1900_ANN_climo_atm.nc i01.10casa_1999-2004_ANN_climo.nc +f02.03casa_1876-1900_MONS_climo.nc i01.10casa_1999-2004_MONS_climo.nc +f02.03casa_1876-1900_MONS_climo_atm.nc i01.10casa_2000-2003_ANN_climo.nc +f02.03cn_1901-1925_ANN_climo.nc i01.10casa_2000-2003_MONS_climo.nc +f02.03cn_1901-1925_ANN_climo_atm.nc i01.10casa_2002-2004_ANN_climo.nc +f02.03cn_1901-1925_MONS_climo.nc i01.10casa_2002-2004_MONS_climo.nc +f02.03cn_1901-1925_MONS_climo_atm.nc i01.10cn_1948-2004_ANN_climo.nc +i01.03cn_1545-1569_ANN_climo.nc i01.10cn_1948-2004_MONS_climo.nc +i01.03cn_1545-1569_MONS_climo.nc i01.10cn_1990-2004_ANN_climo.nc +i01.04casa_1605-1629_ANN_climo.nc i01.10cn_1990-2004_MONS_climo.nc +i01.04casa_1605-1629_MONS_climo.nc i01.10cn_1994-2004_ANN_climo.nc +i01.06casa_1798-2004_ANN_climo.nc i01.10cn_1994-2004_MONS_climo.nc +i01.06casa_1798-2004_MONS_climo.nc i01.10cn_1996-2003_ANN_climo.nc +i01.06casa_1980-2004_ANN_climo.nc i01.10cn_1996-2003_MONS_climo.nc +i01.06casa_1980-2004_MONS_climo.nc i01.10cn_1997-2003_ANN_climo.nc +i01.06cn_1798-2004_ANN_climo.nc i01.10cn_1997-2003_MONS_climo.nc +i01.06cn_1798-2004_MONS_climo.nc i01.10cn_1998-2003_ANN_climo.nc +i01.06cn_1980-2004_ANN_climo.nc i01.10cn_1998-2003_MONS_climo.nc +i01.06cn_1980-2004_MONS_climo.nc i01.10cn_1999-2004_ANN_climo.nc +i01.07casa_1990-2004_ANN_climo.nc i01.10cn_1999-2004_MONS_climo.nc +i01.07casa_1990-2004_MONS_climo.nc i01.10cn_2000-2003_ANN_climo.nc +i01.07cn_1990-2004_ANN_climo.nc i01.10cn_2000-2003_MONS_climo.nc +i01.07cn_1990-2004_MONS_climo.nc i01.10cn_2002-2004_ANN_climo.nc +i01.10casa_1948-2004_ANN_climo.nc i01.10cn_2002-2004_MONS_climo.nc +i01.10casa_1948-2004_MONS_climo.nc newcn05_ncep_1i_ANN_climo_lnd.nc +i01.10casa_1990-2004_ANN_climo.nc newcn05_ncep_1i_MONS_climo_lnd.nc +i01.10casa_1990-2004_MONS_climo.nc surf_co2.clamp.T42.20070208.nc diff -r 000000000000 -r 0c6405ab2ff4 list.fluxnet --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/list.fluxnet Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,4 @@ +BOREAS_NSA_OBS Hyytiala_boreal Lethbridge +BOREAS_NSA_OBS_boreal Kaamanen Lethbridge_c3 +CastelPorziano Kaamanen_c3 Tharandt +Hyytiala LBA_Tapajos_KM67 Vielsalm diff -r 000000000000 -r 0c6405ab2ff4 npp/01.read_81.ncl.x --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/01.read_81.ncl.x Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,271 @@ +;---------------------------------------------------------------------- +; This example reads an ASCII file that is formatted a specific way, and +; writes out the results to a netCDF file. +; +; The first line in the ASCII file must be a header, with each field +; separated by a single character delimiter (like a ","). The rest of +; the file must be such that each row contains all fields, each +; separated by the designated delimiter. +; +; The fields can be integer, float, double, or string. +;---------------------------------------------------------------------- + +;---------------------------------------------------------------------- +; This function returns the index locations of the given delimiter +; in a row or several rows of strings. +;---------------------------------------------------------------------- +function delim_indices(strings,nfields,delimiter) +local cstrings, cdelim +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) ; Convert to characters. + cdelim = stringtochar(delimiter) ; Convert delimiter to character. +; +; Som error checking here. Make sure delimiter is one character. +; + nc = dimsizes(cdelim) + rank = dimsizes(nc) + if(rank.ne.1.or.(rank.eq.1.and.nc.ne.2)) then + print("delim_indices: fatal: the delimiter you've selected") + print("must be a single character. Can't continue.") + exit + end if + +; +; Create array to hold indices of delimiter locations, and then loop +; through each row and find all the delimiters. Make sure each row has +; the correct number of delimiters. +; + ndelims = nfields-1 + cindices = new((/nrows,ndelims/),integer) + do i = 0, nrows-1 + ii = ind(cstrings(i,:).eq.cdelim(0)) +; +; Make sure there were delimiters on this row. If not, we just quit. +; This could probably be modified to do this more gracefully. +; + if(any(ismissing(ii))) then + print("delim_indices: fatal: I didn't find any delimiters") + print("('" + delimiter + "') on row " + i + ". Can't continue.") + exit + end if + if(dimsizes(ii).ne.ndelims) then + print("delim_indices: fatal: I expected to find " + ndelims) + print("delimiters on row " + i + ". Instead, I found " + dimsizes(ii) + ".") + print("Can't continue.") + exit + end if + + cindices(i,:) = ii + + delete(ii) ; For next time through loop + end do + + return(cindices) +end + +;---------------------------------------------------------------------- +; This function reads in a particular field from a string array, +; given the field number to read (fields start at 1 and go to nfield), +; and the indices of the delimiters. +; +; It returns either an integer, float, double, or a string, +; depending on the input flag "return_type". +;---------------------------------------------------------------------- +function read_field(strings,ifield,indices,return_type) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if + +; +; Set up array to return. +; + return_array = new(nrows,return_type) + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if +; +; Here's the code that pulls off the correct string, and converts it +; to float if desired. +; + if(return_type.eq."integer") then + return_array(i) = stringtointeger(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."float") then + return_array(i) = stringtofloat(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."double") then + return_array(i) = stringtodouble(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."string") then + return_array(i) = chartostring(cstrings(i,ibeg:iend)) + end if + end do + + return(return_array) +end + +;---------------------------------------------------------------------- +; Main code. +;---------------------------------------------------------------------- +begin +; +; Set up defaults here. We have to hard-code the field types, +; because we can't really tell otherwise. + + filename = "data.81" ; ASCII" file to read. + cdf_file = filename + ".nc" ; netCDF file to write. + nfields = 22 ; # of fields + delimiter = "," ; field delimiter +; +; In this case, fields #6-#8 are strings, fields #2, #3, and #11 +; are float, and the rest of the fields are integers. +; + var_types = new(nfields,string) + var_types = "integer" ; Most are ints. + var_types(5:7) = "string" ; corresponds to fields 6-8 + var_types(1:2) = "float" + var_types(10) = "float" + + if(isfilepresent(cdf_file)) + print("Warning: '" + cdf_file + "' exists. Will remove it.") + system("/bin/rm " + cdf_file) + end if + +; +; Read in data as strings. This will create a string array that has the +; same number of strings as there are rows in the file. We will then need +; to parse each string later. +; + read_data = asciiread(filename,-1,"string") + header = read_data(0) ; Header. Use for variable names. + data = read_data(1:) ; Get rid of first line which is a header. + nrows = dimsizes(data) ; Number of rows. + +; +; Read in locations of delimiters in each string row. +; + hindices = delim_indices(header,nfields,delimiter) ; header row + dindices = delim_indices(data,nfields,delimiter) ; rest of file + +; +; Read in the field names which will become variable names on +; the netCDF file. +; + var_names = new(nfields,string) + + do i=0,nfields-1 + var_names(i) = read_field(header,i+1,hindices,"string") + end do +; +; Write out this netCDF file efficiently so it will be faster. +; Try to predefine everything before you write to it. +; + f = addfile(cdf_file,"c") + setfileoption(f,"DefineMode",True) ; Enter predefine phase. + +; +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. +; + fAtt = True + fAtt@description = "Data read in from '" + filename + "' ASCII file." + fAtt@creation_date = systemfunc ("date") + fileattdef( f, fAtt ) + +; +; Write dimension name. There's only one here. +; + filedimdef(f,"nvalues",-1,True) + +; +; Define each variable on the file, giving it the dimension name +; we just created above. +; +; Don't deal with variables that are of type string. +; + do i=0,nfields-1 + if(var_types(i).ne."string") then + filevardef(f, var_names(i), var_types(i), "nvalues") + end if + end do + +; +; Loop through each field, read the values for that field, print +; information about the variable, and then write it to the netCDF +; file. +; + do i=0,nfields-1 + ifield = i+1 ; Fields start at #1, not #0. +; +; You can't write strings to a netCDF file, so skip the string fields. +; + if(var_types(i).ne."string") then + tmp_data = read_field(data,ifield,dindices,var_types(i)) +; +; Print some info about the variable. +; + print("") + print("Writing variable " + var_names(i) + " (field #" + ifield + ").") + print("Type is " + var_types(i) + ", min/max = " + min(tmp_data) + \ + "/" + max(tmp_data)) + + if(any(ismissing(tmp_data))) then + print("This variable does contain missing values.") + else + print("This variable doesn't contain missing values.") + end if + + f->$var_names(i)$ = tmp_data ; Write to netCDF file. + + delete(tmp_data) ; Delete for next round. + end if + end do +end diff -r 000000000000 -r 0c6405ab2ff4 npp/01.read_81.ncl.y --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/01.read_81.ncl.y Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,406 @@ +;---------------------------------------------------------------------- +; This example reads an ASCII file that is formatted a specific way, and +; writes out the results to a netCDF file. +; +; The first line in the ASCII file must be a header, with each field +; separated by a single character delimiter (like a ","). The rest of +; the file must be such that each row contains all fields, each +; separated by the designated delimiter. +; +; The fields can be integer, float, double, character, or string. +; String fields cannot be written to a netCDF file. They have to +; be read in as character arrays and written out that way. +;---------------------------------------------------------------------- + +;---------------------------------------------------------------------- +; This function returns the index locations of the given delimiter +; in a row or several rows of strings. +;---------------------------------------------------------------------- +function delim_indices(strings,nfields,delimiter) +local cstrings, cdelim +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) ; Convert to characters. + cdelim = stringtochar(delimiter) ; Convert delimiter to character. +; +; Som error checking here. Make sure delimiter is one character. +; + nc = dimsizes(cdelim) + rank = dimsizes(nc) + if(rank.ne.1.or.(rank.eq.1.and.nc.ne.2)) then + print("delim_indices: fatal: the delimiter you've selected") + print("must be a single character. Can't continue.") + exit + end if + +; +; Create array to hold indices of delimiter locations, and then loop +; through each row and find all the delimiters. Make sure each row has +; the correct number of delimiters. +; + ndelims = nfields-1 + cindices = new((/nrows,ndelims/),integer) + do i = 0, nrows-1 + ii = ind(cstrings(i,:).eq.cdelim(0)) +; +; Make sure there were delimiters on this row. If not, we just quit. +; This could probably be modified to do this more gracefully. +; + if(any(ismissing(ii))) then + print("delim_indices: fatal: I didn't find any delimiters") + print("('" + delimiter + "') on row " + i + ". Can't continue.") + exit + end if + if(dimsizes(ii).ne.ndelims) then + print("delim_indices: fatal: I expected to find " + ndelims) + print("delimiters on row " + i + ". Instead, I found " + dimsizes(ii) + ".") + print("Can't continue.") + exit + end if + + cindices(i,:) = ii + + delete(ii) ; For next time through loop + end do + + return(cindices) +end + +;---------------------------------------------------------------------- +; This function reads in a particular field from a string array, +; given the field number to read (fields start at #1 and go to #nfield), +; and the indices of the delimiters. +; +; It returns either an integer, float, double, character, or a string, +; depending on the input flag "return_type". +;---------------------------------------------------------------------- +function read_field(strings,ifield,indices,return_type) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if + +; +; Set up array to return. For string, int, float, or double arrays, +; we don't have to do anything special. For character arrays, +; however, we do. +; + if(return_type.ne."character") then + return_array = new(nrows,return_type) + else +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + end if + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if +; +; Here's the code that pulls off the correct string, and converts it +; to float if desired. +; + if(return_type.eq."integer") then + return_array(i) = stringtointeger(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."float") then + return_array(i) = stringtofloat(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."double") then + return_array(i) = stringtodouble(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."string") then + return_array(i) = chartostring(cstrings(i,ibeg:iend)) + end if + if(return_type.eq."character") then + if( (iend-ibeg) .gt. max_len) then + max_len = iend-ibeg + end if + tmp_return_array(i,0:iend-ibeg) = cstrings(i,ibeg:iend) + end if + end do + + if(return_type.eq."character") then + return_array = new((/nrows,max_len/),"character") + return_array = tmp_return_array(:,0:max_len-1) + end if + + return(return_array) +end + + +;---------------------------------------------------------------------- +; This function reads in string fields only to get the maximum string +; length. +;---------------------------------------------------------------------- +function get_maxlen(strings,ifield,indices) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if + if( (iend-ibeg) .gt. max_len) then + max_len = iend-ibeg + end if + end do + + return(max_len) +end + +;---------------------------------------------------------------------- +; Main code. +;---------------------------------------------------------------------- +begin +; +; Set up defaults here. We are hard-coding the field types here. +; You can set up this script to try to determine the field types +; automatically, but this is a bit tedious. Maybe later. +; + filename = "data.81" ; ASCII" file to read. + cdf_file = filename + ".nc" ; netCDF file to write. + nfields = 22 ; # of fields + delimiter = "," ; field delimiter +; +; In this case, fields #6-#8 are strings, fields #2, #3, and #11 +; are float, and the rest of the fields are integers. +; + var_types = new(nfields,string) + var_strlens = new(nfields,integer) ; var to hold strlens, just in case. + + var_types = "integer" ; Most are ints. + var_types(5:7) = "character" ; Corresponds to fields 6-8. + var_types(1:2) = "float" + var_types(10) = "float" + + if(isfilepresent(cdf_file)) + print("Warning: '" + cdf_file + "' exists. Will remove it.") + system("/bin/rm " + cdf_file) + end if + +; +; Read in data as strings. This will create a string array that has the +; same number of strings as there are rows in the file. We will then need +; to parse each string later. +; + read_data = asciiread(filename,-1,"string") + header = read_data(0) ; Header. Use for variable names. + data = read_data(1:) ; Get rid of first line which is a header. + nrows = dimsizes(data) ; Number of rows. + +; +; Read in locations of delimiters in each string row. +; + hindices = delim_indices(header,nfields,delimiter) ; header row + dindices = delim_indices(data,nfields,delimiter) ; rest of file + +; +; Read in the field names which will become variable names on +; the netCDF file. +; + var_names = new(nfields,string) + + do i=0,nfields-1 + var_names(i) = read_field(header,i+1,hindices,"string") + end do + +; +; Write out this netCDF file efficiently so it will be faster. +; Try to predefine everything before you write to it. +; + f = addfile(cdf_file,"c") + setfileoption(f,"DefineMode",True) ; Enter predefine phase. + +; +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. +; + fAtt = True + fAtt@description = "Data read in from " + filename + " ASCII file." + fAtt@creation_date = systemfunc ("date") + fileattdef( f, fAtt ) + +; +; Write dimension names to file. If there are no character variables, +; then there's only one dimension name ("nvalues"). +; +; Otherwise, we need to write a dimension name for every character +; variable, which will indicate the maximum string length for that +; variable. +; + indc = ind(var_types.eq."character") + if(.not.any(ismissing(indc))) then +; +; We have to treat the character arrays special here. We need to +; know their sizes so we can write the maximum size of each char +; array to the netCDF file as a dimension name. This means we +; need to read in the character variables once to get the string +; lengths, then we'll read them again later to get the actual values. +; + do i=0,dimsizes(indc)-1 + var_strlens(indc(i)) = get_maxlen(data,indc(i)+1,dindices) + end do + + ndims = dimsizes(indc) + 1 + dimNames = new(ndims,string) + dimSizes = new(ndims,integer) + dimUnlim = new(ndims,logical) + + dimUnlim = False + dimUnlim(0) = True + dimNames(0) = "nvalues" + dimNames(1:ndims-1) = var_names(indc) + "_StrLen" + dimSizes(0) = -1 + dimSizes(1:ndims-1) = var_strlens(indc) + filedimdef(f,dimNames,dimSizes,dimUnlim) + else +; +; No character variables, so just write the one dimension name. +; + filedimdef(f,"nvalues",-1,True) + end if + +; +; Define each variable on the file. +; +; Don't deal with variables that are of type string. +; + do i=0,nfields-1 + if(var_types(i).ne."string") then + if(var_types(i).ne."character") then + filevardef(f, var_names(i), var_types(i), "nvalues") + else + filevardef(f, var_names(i), var_types(i), \ + (/"nvalues",var_names(i)+"_StrLen"/)) + end if + end if + end do + +; +; Loop through each field, read the values for that field, print +; information about the variable, and then write it to the netCDF +; file. +; + do i=0,nfields-1 + ifield = i+1 ; Fields start at #1, not #0. +; +; Note: you can't write strings to a netCDF file, so these have +; to be written out as character arrays. +; + tmp_data = read_field(data,ifield,dindices,var_types(i)) +; +; Print some info about the variable. +; + print("") + print("Writing variable '" + var_names(i) + "' (field #" + ifield + ").") + print("Type is " + var_types(i) + ".") + if(var_types(i).ne."string".and.var_types(i).ne."character") then + print("min/max = " + min(tmp_data) + "/" + max(tmp_data)) + end if + + if(any(ismissing(tmp_data))) then + print("This variable does contain missing values.") + else + print("This variable doesn't contain missing values.") + end if + + f->$var_names(i)$ = tmp_data ; Write to netCDF file. + + delete(tmp_data) ; Delete for next round. + end do +end diff -r 000000000000 -r 0c6405ab2ff4 npp/01.read_ascii_81.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/01.read_ascii_81.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,406 @@ +;---------------------------------------------------------------------- +; This example reads an ASCII file that is formatted a specific way, and +; writes out the results to a netCDF file. +; +; The first line in the ASCII file must be a header, with each field +; separated by a single character delimiter (like a ","). The rest of +; the file must be such that each row contains all fields, each +; separated by the designated delimiter. +; +; The fields can be integer, float, double, character, or string. +; String fields cannot be written to a netCDF file. They have to +; be read in as character arrays and written out that way. +;---------------------------------------------------------------------- + +;---------------------------------------------------------------------- +; This function returns the index locations of the given delimiter +; in a row or several rows of strings. +;---------------------------------------------------------------------- +function delim_indices(strings,nfields,delimiter) +local cstrings, cdelim +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) ; Convert to characters. + cdelim = stringtochar(delimiter) ; Convert delimiter to character. +; +; Som error checking here. Make sure delimiter is one character. +; + nc = dimsizes(cdelim) + rank = dimsizes(nc) + if(rank.ne.1.or.(rank.eq.1.and.nc.ne.2)) then + print("delim_indices: fatal: the delimiter you've selected") + print("must be a single character. Can't continue.") + exit + end if + +; +; Create array to hold indices of delimiter locations, and then loop +; through each row and find all the delimiters. Make sure each row has +; the correct number of delimiters. +; + ndelims = nfields-1 + cindices = new((/nrows,ndelims/),integer) + do i = 0, nrows-1 + ii = ind(cstrings(i,:).eq.cdelim(0)) +; +; Make sure there were delimiters on this row. If not, we just quit. +; This could probably be modified to do this more gracefully. +; + if(any(ismissing(ii))) then + print("delim_indices: fatal: I didn't find any delimiters") + print("('" + delimiter + "') on row " + i + ". Can't continue.") + exit + end if + if(dimsizes(ii).ne.ndelims) then + print("delim_indices: fatal: I expected to find " + ndelims) + print("delimiters on row " + i + ". Instead, I found " + dimsizes(ii) + ".") + print("Can't continue.") + exit + end if + + cindices(i,:) = ii + + delete(ii) ; For next time through loop + end do + + return(cindices) +end + +;---------------------------------------------------------------------- +; This function reads in a particular field from a string array, +; given the field number to read (fields start at #1 and go to #nfield), +; and the indices of the delimiters. +; +; It returns either an integer, float, double, character, or a string, +; depending on the input flag "return_type". +;---------------------------------------------------------------------- +function read_field(strings,ifield,indices,return_type) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if + +; +; Set up array to return. For string, int, float, or double arrays, +; we don't have to do anything special. For character arrays, +; however, we do. +; + if(return_type.ne."character") then + return_array = new(nrows,return_type) + else +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + end if + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if +; +; Here's the code that pulls off the correct string, and converts it +; to float if desired. +; + if(return_type.eq."integer") then + return_array(i) = stringtointeger(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."float") then + return_array(i) = stringtofloat(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."double") then + return_array(i) = stringtodouble(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."string") then + return_array(i) = chartostring(cstrings(i,ibeg:iend)) + end if + if(return_type.eq."character") then + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + tmp_return_array(i,0:iend-ibeg) = cstrings(i,ibeg:iend) + end if + end do + + if(return_type.eq."character") then + return_array = new((/nrows,max_len/),"character") + return_array = tmp_return_array(:,0:max_len-1) + end if + + return(return_array) +end + + +;---------------------------------------------------------------------- +; This function reads in string fields only to get the maximum string +; length. +;---------------------------------------------------------------------- +function get_maxlen(strings,ifield,indices) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + end do + + return(max_len) +end + +;---------------------------------------------------------------------- +; Main code. +;---------------------------------------------------------------------- +begin +; +; Set up defaults here. We are hard-coding the field types here. +; You can set up this script to try to determine the field types +; automatically, but this is a bit tedious. Maybe later. +; + filename = "data.81" ; ASCII" file to read. + cdf_file = filename + ".nc" ; netCDF file to write. + nfields = 22 ; # of fields + delimiter = "," ; field delimiter +; +; In this case, fields #6-#8 are strings, fields #2, #3, and #11 +; are float, and the rest of the fields are integers. +; + var_types = new(nfields,string) + var_strlens = new(nfields,integer) ; var to hold strlens, just in case. + + var_types = "integer" ; Most are ints. + var_types(5:7) = "character" ; Corresponds to fields 6-8. + var_types(1:2) = "float" + var_types(10) = "float" + + if(isfilepresent(cdf_file)) + print("Warning: '" + cdf_file + "' exists. Will remove it.") + system("/bin/rm " + cdf_file) + end if + +; +; Read in data as strings. This will create a string array that has the +; same number of strings as there are rows in the file. We will then need +; to parse each string later. +; + read_data = asciiread(filename,-1,"string") + header = read_data(0) ; Header. Use for variable names. + data = read_data(1:) ; Get rid of first line which is a header. + nrows = dimsizes(data) ; Number of rows. + +; +; Read in locations of delimiters in each string row. +; + hindices = delim_indices(header,nfields,delimiter) ; header row + dindices = delim_indices(data,nfields,delimiter) ; rest of file + +; +; Read in the field names which will become variable names on +; the netCDF file. +; + var_names = new(nfields,string) + + do i=0,nfields-1 + var_names(i) = read_field(header,i+1,hindices,"string") + end do + +; +; Write out this netCDF file efficiently so it will be faster. +; Try to predefine everything before you write to it. +; + f = addfile(cdf_file,"c") + setfileoption(f,"DefineMode",True) ; Enter predefine phase. + +; +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. +; + fAtt = True + fAtt@description = "Data read in from " + filename + " ASCII file." + fAtt@creation_date = systemfunc ("date") + fileattdef( f, fAtt ) + +; +; Write dimension names to file. If there are no character variables, +; then there's only one dimension name ("nvalues"). +; +; Otherwise, we need to write a dimension name for every character +; variable, which will indicate the maximum string length for that +; variable. +; + indc = ind(var_types.eq."character") + if(.not.any(ismissing(indc))) then +; +; We have to treat the character arrays special here. We need to +; know their sizes so we can write the maximum size of each char +; array to the netCDF file as a dimension name. This means we +; need to read in the character variables once to get the string +; lengths, then we'll read them again later to get the actual values. +; + do i=0,dimsizes(indc)-1 + var_strlens(indc(i)) = get_maxlen(data,indc(i)+1,dindices) + end do + + ndims = dimsizes(indc) + 1 + dimNames = new(ndims,string) + dimSizes = new(ndims,integer) + dimUnlim = new(ndims,logical) + + dimUnlim = False + dimUnlim(0) = True + dimNames(0) = "nvalues" + dimNames(1:ndims-1) = var_names(indc) + "_StrLen" + dimSizes(0) = -1 + dimSizes(1:ndims-1) = var_strlens(indc) + filedimdef(f,dimNames,dimSizes,dimUnlim) + else +; +; No character variables, so just write the one dimension name. +; + filedimdef(f,"nvalues",-1,True) + end if + +; +; Define each variable on the file. +; +; Don't deal with variables that are of type string. +; + do i=0,nfields-1 + if(var_types(i).ne."string") then + if(var_types(i).ne."character") then + filevardef(f, var_names(i), var_types(i), "nvalues") + else + filevardef(f, var_names(i), var_types(i), \ + (/"nvalues",var_names(i)+"_StrLen"/)) + end if + end if + end do + +; +; Loop through each field, read the values for that field, print +; information about the variable, and then write it to the netCDF +; file. +; + do i=0,nfields-1 + ifield = i+1 ; Fields start at #1, not #0. +; +; Note: you can't write strings to a netCDF file, so these have +; to be written out as character arrays. +; + tmp_data = read_field(data,ifield,dindices,var_types(i)) +; +; Print some info about the variable. +; + print("") + print("Writing variable '" + var_names(i) + "' (field #" + ifield + ").") + print("Type is " + var_types(i) + ".") + if(var_types(i).ne."string".and.var_types(i).ne."character") then + print("min/max = " + min(tmp_data) + "/" + max(tmp_data)) + end if + + if(any(ismissing(tmp_data))) then + print("This variable does contain missing values.") + else + print("This variable doesn't contain missing values.") + end if + + f->$var_names(i)$ = tmp_data ; Write to netCDF file. + + delete(tmp_data) ; Delete for next round. + end do +end diff -r 000000000000 -r 0c6405ab2ff4 npp/01.read_ascii_933.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/01.read_ascii_933.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,406 @@ +;---------------------------------------------------------------------- +; This example reads an ASCII file that is formatted a specific way, and +; writes out the results to a netCDF file. +; +; The first line in the ASCII file must be a header, with each field +; separated by a single character delimiter (like a ","). The rest of +; the file must be such that each row contains all fields, each +; separated by the designated delimiter. +; +; The fields can be integer, float, double, character, or string. +; String fields cannot be written to a netCDF file. They have to +; be read in as character arrays and written out that way. +;---------------------------------------------------------------------- + +;---------------------------------------------------------------------- +; This function returns the index locations of the given delimiter +; in a row or several rows of strings. +;---------------------------------------------------------------------- +function delim_indices(strings,nfields,delimiter) +local cstrings, cdelim +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) ; Convert to characters. + cdelim = stringtochar(delimiter) ; Convert delimiter to character. +; +; Som error checking here. Make sure delimiter is one character. +; + nc = dimsizes(cdelim) + rank = dimsizes(nc) + if(rank.ne.1.or.(rank.eq.1.and.nc.ne.2)) then + print("delim_indices: fatal: the delimiter you've selected") + print("must be a single character. Can't continue.") + exit + end if + +; +; Create array to hold indices of delimiter locations, and then loop +; through each row and find all the delimiters. Make sure each row has +; the correct number of delimiters. +; + ndelims = nfields-1 + cindices = new((/nrows,ndelims/),integer) + do i = 0, nrows-1 + ii = ind(cstrings(i,:).eq.cdelim(0)) +; +; Make sure there were delimiters on this row. If not, we just quit. +; This could probably be modified to do this more gracefully. +; + if(any(ismissing(ii))) then + print("delim_indices: fatal: I didn't find any delimiters") + print("('" + delimiter + "') on row " + i + ". Can't continue.") + exit + end if + if(dimsizes(ii).ne.ndelims) then + print("delim_indices: fatal: I expected to find " + ndelims) + print("delimiters on row " + i + ". Instead, I found " + dimsizes(ii) + ".") + print("Can't continue.") + exit + end if + + cindices(i,:) = ii + + delete(ii) ; For next time through loop + end do + + return(cindices) +end + +;---------------------------------------------------------------------- +; This function reads in a particular field from a string array, +; given the field number to read (fields start at #1 and go to #nfield), +; and the indices of the delimiters. +; +; It returns either an integer, float, double, character, or a string, +; depending on the input flag "return_type". +;---------------------------------------------------------------------- +function read_field(strings,ifield,indices,return_type) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if + +; +; Set up array to return. For string, int, float, or double arrays, +; we don't have to do anything special. For character arrays, +; however, we do. +; + if(return_type.ne."character") then + return_array = new(nrows,return_type) + else +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + end if + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if +; +; Here's the code that pulls off the correct string, and converts it +; to float if desired. +; + if(return_type.eq."integer") then + return_array(i) = stringtointeger(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."float") then + return_array(i) = stringtofloat(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."double") then + return_array(i) = stringtodouble(chartostring(cstrings(i,ibeg:iend))) + end if + if(return_type.eq."string") then + return_array(i) = chartostring(cstrings(i,ibeg:iend)) + end if + if(return_type.eq."character") then + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + tmp_return_array(i,0:iend-ibeg) = cstrings(i,ibeg:iend) + end if + end do + + if(return_type.eq."character") then + return_array = new((/nrows,max_len/),"character") + return_array = tmp_return_array(:,0:max_len-1) + end if + + return(return_array) +end + + +;---------------------------------------------------------------------- +; This function reads in string fields only to get the maximum string +; length. +;---------------------------------------------------------------------- +function get_maxlen(strings,ifield,indices) +local nstring, cstrings, nf, tmp_str +begin + nrows = dimsizes(strings) +; +; Handle special case if we only have one string. Make sure it +; is put into a 2D array. +; + if(nrows.eq.1) then + cstrings = new((/1,strlen(strings)+1/),character) + end if + + cstrings = stringtochar(strings) + nf = dimsizes(indices(0,:))+1 ; indices is nrows x (nfields-1) + +; +; Error checking. Make sure user has entered a valid field. +; + if(ifield.le.0.or.ifield.gt.nf) then + print("read_field: fatal: you've selected a field that is") + print("out-of-range of the number of fields that you have (" + nf + ").") + exit + end if +; +; We don't know what the biggest character array is at this point, so +; make it bigger than necessary, and then resize later as necessary. +; + tmp_return_array = new((/nrows,dimsizes(cstrings(0,:))/),"character") + + max_len = 0 ; Use to keep track of max lengths of strings. + + do i = 0,nrows-1 +; +; Special case of first field in row. +; + if(ifield.eq.1) then + ibeg = 0 + iend = indices(i,ifield-1)-1 + else +; +; Special case of first field in row. +; + if(ifield.eq.nf) then + ibeg = indices(i,ifield-2)+1 + iend = dimsizes(cstrings(i,:))-1 +; +; Any field between first and last field. +; + else + ibeg = indices(i,ifield-2)+1 + iend = indices(i,ifield-1)-1 + end if + end if + if( (iend-ibeg+1) .gt. max_len) then + max_len = iend-ibeg+1 + end if + end do + + return(max_len) +end + +;---------------------------------------------------------------------- +; Main code. +;---------------------------------------------------------------------- +begin +; +; Set up defaults here. We are hard-coding the field types here. +; You can set up this script to try to determine the field types +; automatically, but this is a bit tedious. Maybe later. +; + filename = "data.933" ; ASCII" file to read. + cdf_file = filename + ".nc" ; netCDF file to write. + nfields = 45 ; # of fields + delimiter = "," ; field delimiter +; +; In this case, fields #6-#8 are strings, fields #2, #3, and #11 +; are float, and the rest of the fields are integers. +; + var_types = new(nfields,string) + var_strlens = new(nfields,integer) ; var to hold strlens, just in case. + + var_types = "integer" ; Most are ints. + var_types(5:7) = "character" ; Corresponds to fields 6-8. + var_types(1:2) = "float" + var_types(10) = "float" + + if(isfilepresent(cdf_file)) + print("Warning: '" + cdf_file + "' exists. Will remove it.") + system("/bin/rm " + cdf_file) + end if + +; +; Read in data as strings. This will create a string array that has the +; same number of strings as there are rows in the file. We will then need +; to parse each string later. +; + read_data = asciiread(filename,-1,"string") + header = read_data(0) ; Header. Use for variable names. + data = read_data(1:) ; Get rid of first line which is a header. + nrows = dimsizes(data) ; Number of rows. + +; +; Read in locations of delimiters in each string row. +; + hindices = delim_indices(header,nfields,delimiter) ; header row + dindices = delim_indices(data,nfields,delimiter) ; rest of file + +; +; Read in the field names which will become variable names on +; the netCDF file. +; + var_names = new(nfields,string) + + do i=0,nfields-1 + var_names(i) = read_field(header,i+1,hindices,"string") + end do + +; +; Write out this netCDF file efficiently so it will be faster. +; Try to predefine everything before you write to it. +; + f = addfile(cdf_file,"c") + setfileoption(f,"DefineMode",True) ; Enter predefine phase. + +; +; Write global attributes to file. It's okay to do this before +; predefining the file's variables. We are still in "define" mode. +; + fAtt = True + fAtt@description = "Data read in from " + filename + " ASCII file." + fAtt@creation_date = systemfunc ("date") + fileattdef( f, fAtt ) + +; +; Write dimension names to file. If there are no character variables, +; then there's only one dimension name ("nvalues"). +; +; Otherwise, we need to write a dimension name for every character +; variable, which will indicate the maximum string length for that +; variable. +; + indc = ind(var_types.eq."character") + if(.not.any(ismissing(indc))) then +; +; We have to treat the character arrays special here. We need to +; know their sizes so we can write the maximum size of each char +; array to the netCDF file as a dimension name. This means we +; need to read in the character variables once to get the string +; lengths, then we'll read them again later to get the actual values. +; + do i=0,dimsizes(indc)-1 + var_strlens(indc(i)) = get_maxlen(data,indc(i)+1,dindices) + end do + + ndims = dimsizes(indc) + 1 + dimNames = new(ndims,string) + dimSizes = new(ndims,integer) + dimUnlim = new(ndims,logical) + + dimUnlim = False + dimUnlim(0) = True + dimNames(0) = "nvalues" + dimNames(1:ndims-1) = var_names(indc) + "_StrLen" + dimSizes(0) = -1 + dimSizes(1:ndims-1) = var_strlens(indc) + filedimdef(f,dimNames,dimSizes,dimUnlim) + else +; +; No character variables, so just write the one dimension name. +; + filedimdef(f,"nvalues",-1,True) + end if + +; +; Define each variable on the file. +; +; Don't deal with variables that are of type string. +; + do i=0,nfields-1 + if(var_types(i).ne."string") then + if(var_types(i).ne."character") then + filevardef(f, var_names(i), var_types(i), "nvalues") + else + filevardef(f, var_names(i), var_types(i), \ + (/"nvalues",var_names(i)+"_StrLen"/)) + end if + end if + end do + +; +; Loop through each field, read the values for that field, print +; information about the variable, and then write it to the netCDF +; file. +; + do i=0,nfields-1 + ifield = i+1 ; Fields start at #1, not #0. +; +; Note: you can't write strings to a netCDF file, so these have +; to be written out as character arrays. +; + tmp_data = read_field(data,ifield,dindices,var_types(i)) +; +; Print some info about the variable. +; + print("") + print("Writing variable '" + var_names(i) + "' (field #" + ifield + ").") + print("Type is " + var_types(i) + ".") + if(var_types(i).ne."string".and.var_types(i).ne."character") then + print("min/max = " + min(tmp_data) + "/" + max(tmp_data)) + end if + + if(any(ismissing(tmp_data))) then + print("This variable does contain missing values.") + else + print("This variable doesn't contain missing values.") + end if + + f->$var_names(i)$ = tmp_data ; Write to netCDF file. + + delete(tmp_data) ; Delete for next round. + end do +end diff -r 000000000000 -r 0c6405ab2ff4 npp/02.read.ascii.ncl.x --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/02.read.ascii.ncl.x Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,83 @@ +;************************************************ +; Read ascii, Write nc +;************************************************ +;load "/fs/cgd/data0/shea/nclGSUN/gsn_code.ncl" +;load "/fs/cgd/data0/shea/nclGSUN/gsn_csm.ncl" +;load "/fs/cgd/data0/shea/nclGSUN/shea_util.ncl" +;************************************************ +begin +;--------------------------------------------------- +; final data + c = addfile("Npp_0.05deg_mean4.nc","c") + filedimdef(c,"time",-1,True) + + nlat = 180*20 + nlon = 360*20 + +;--------------------------------------------------- +; input data + b = "Npp_0.05deg_mean.ASCII2" + + t = new((/1,nlat,nlon/),float) + lon = new((/nlon/),float) + lat = new((/nlat/),float) + time = new((/1/),integer) + +; sam result +; lon = fspan(-180.,179.95,nlon) +; lat = fspan(-90. , 89.95,nlat) + + do i = 0,nlon-1 + lon(i) = -180. + i*(360./nlon) + end do + + do j = 0,nlat-1 + lat(j) = -90. + j*(180./nlat) + end do + + time = 1 + +; print (lon) +; print (lat) +; print (time) +;============================= + ; create lat and long coordinate variables + ;============================ + lon!0 = "lon" + lon@long_name = "lon" + lon@units = "degrees-east" + lon&lon = lon + + lat!0 = "lat" + lat@long_name = "lat" + lat@units = "degrees_north" + lat&lat = lat + ;============================= + ; name dimensions of t and assign coordinate variables + ;============================ + t!0 = "time" + t!1 = "lat" + t!2 = "lon" + t&time = time + t&lat = lat + t&lon = lon + t@long_name = "net primary production" + t@units = "gC/m^2/year" + t@_FillValue= 1.e+36 + t@missing_value= 1.e+36 + + t(0,:,:) = asciiread(b,(/nlat,nlon/),"float") + + c->NPP = t + c->lat = lat + c->lon = lon + c->time = time + + do i = 0,nlon-1 + do j = 0,nlat-1 + if (t(0,j,i) .gt. 0.) then + print (t(0,j,i)) + end if + end do + end do +end diff -r 000000000000 -r 0c6405ab2ff4 npp/02.read_binary.f90.x --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/02.read_binary.f90.x Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,14 @@ +program to_read_int +integer, parameter :: nlat = 180 * 20, nlon = 360 * 20, & + recl = 2*nlat*nlon +integer(2), dimension(nlat,nlon) :: data +open(11,file='Npp_0.05deg_mean.int16',form='unformatted',& + access='direct',recl=recl) +read(11,rec=1)data +close(11) +do i = 1, nlon + do j = 1, nlat + write(*,*)data(j,i) + end do +enddo +end diff -r 000000000000 -r 0c6405ab2ff4 npp/02.read_binary_0.05deg.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/02.read_binary_0.05deg.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,79 @@ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +begin + nlat = 3600 + mlon = 7200 + + diri = "/fis/cgd/cseg/people/jeff/clamp/" + fili = "Npp_0.05deg_mean.int16" + + diro = "/fis/cgd/cseg/people/jeff/clamp/" + filo = "Npp_0.05deg_mean_3.nc" + c = addfile(diro+filo,"c") + +; I think (a) the file is "little endian"; read into short +; (b) the _FillValue is 32700 + + setfileoption("bin","ReadByteOrder","LittleEndian") + xShort= fbindirread(diri+fili,0, (/nlat,mlon/), "short") + xShort@_FillValue= inttoshort(32700) + +;;xShort@scale_factor = ????? +;;xShort@add_offset = ????? + + x = short2flt( xShort ) + +;;print(xShort(:,1800)+" "+x(:,1800)) ; look at the values + delete(xShort) + + x@long_name = "net primary production" + x@units = "gC/m^2/year" +; x@_FillValue = -17281 ; orig fill + x@_FillValue = 1e20 ; new fill + + lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north") + lat = (/ lat(::-1) /) ; make N->S + lon = lonGlobeFo(mlon, "lon", "longitude", "degrees_east") + lon = (/ lon - 180. /) ; subtract 180 from all values + lon&lon = lon ; update coordinates + + x!0 = "lat" + x!1 = "lon" + x&lat= lat + x&lon= lon + + c->NPP = x + + exit + +;************************************************ +; create default plot +;************************************************ + + setvalues NhlGetWorkspaceObjectId() + "wsMaximumSize" : 199999999 + end setvalues + + wks = gsn_open_wks("ps","Npp_rdBinPlt") ; open a ps file + ;gsn_define_colormap(wks,"wgne15") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@cnFillMode = "RasterFill" ; Turn on raster color + res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + ;res@gsnSpreadColors = True ; use full colormap + res@mpFillOn = False ; Turn off map fill + + ;res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + ;res@cnMinLevelValF = ; Min level + ;res@cnMaxLevelValF = ; Max level + ;res@cnLevelSpacingF = ; interval + res@tiMainString = fili + + plot = gsn_csm_contour_map_ce(wks,x,res) + +end + diff -r 000000000000 -r 0c6405ab2ff4 npp/02.read_binary_Npp.ncl.0 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/02.read_binary_Npp.ncl.0 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,94 @@ +;************************************************ +; Read ascii, Write nc +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;--------------------------------------------------- +; final data + c = addfile("Npp_0.05deg_mean_2.nc","c") + filedimdef(c,"time",-1,True) + + nlat = 180*20 + nlon = 360*20 + +;--------------------------------------------------- +; input data + b = "Npp_0.05deg_mean.int16" + + x = new((/nlat*nlon/),float) + t = new((/1,nlat,nlon/),float) + lon = new((/nlon/),float) + lat = new((/nlat/),float) + time = new((/1/),integer) + +; sam result +; lon = fspan(-180.,179.95,nlon) +; lat = fspan(-90. , 89.95,nlat) + + do i = 0,nlon-1 + lon(i) = -180. + i*(360./nlon) + end do + + do j = 0,nlat-1 + lat(j) = -90. + j*(180./nlat) + end do + + time = 1 + +; print (lon) +; print (lat) +; print (time) +;============================= + ; create lat and long coordinate variables + ;============================ + lon!0 = "lon" + lon@long_name = "lon" + lon@units = "degrees-east" + lon&lon = lon + + lat!0 = "lat" + lat@long_name = "lat" + lat@units = "degrees_north" + lat&lat = lat + ;============================= + ; name dimensions of t and assign coordinate variables + ;============================ + t!0 = "time" + t!1 = "lat" + t!2 = "lon" + t&time = time + t&lat = lat + t&lon = lon + t@long_name = "net primary production" + t@units = "gC/m^2/year" + t@_FillValue= 1.e+36 + t@missing_value= 1.e+36 + +; t = fbinrecread(b,0,(/nlat,nlon/),"float") + + do j = 0,nlat-1 +print (j) + do i = 0,nlon-1 + nrec = j*nlon + i + x(nrec) = fbindirread(b,nrec,1,"float") + end do + end do +print (lat) + t = onedtond(x,(/nlat,nlon/)) + + c->NPP = t + c->lat = lat + c->lon = lon + c->time = time + +; do i = 0,nlon-1 +; do j = 0,nlat-1 +; if (t(0,j,i) .gt. 0.) then +; print (t(0,j,i)) +; end if +; end do +; end do +end diff -r 000000000000 -r 0c6405ab2ff4 npp/02.read_uint16_ASCII.c.x --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/02.read_uint16_ASCII.c.x Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,90 @@ +/* purpose: conversion of binary data with little-endian to ASCII + Sep. 8, 2006 by Maosheng Zhao */ + +/* I also accounts for the possible different CPU on different platforms, + and therefore, it should work on different machines without problem */ + +#include +#define COLS 7200 +#define ROWS 3600 +#define DATA_TYPE unsigned short + +/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ +#define IN_FILE_NAME "Npp_0.05deg_mean.int16" +#define OUT_FILE_NAME "Npp_0.05deg_mean.ASCII2" +/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ +int main() +{ + /* definiation of variables will be used */ + FILE *in_f, *out_f; + static DATA_TYPE data_in[ROWS][COLS]; + int i,j; + + /* the follow definition is for determination the type of CPU */ + int is_big_endian=0; + short one=1; + char *cp; + + /* define a buffer pointer to swap bytes if it is big-endian CPU */ + char temp_char[sizeof(DATA_TYPE)]; + DATA_TYPE *buffer_data; + int m; + + /*################################################################*/ + /* main program starts */ + /* open the data file and read all the data */ + in_f = fopen(IN_FILE_NAME,"rb"); + if(in_f == NULL) + { + printf("cannot open %s, exit...\n",IN_FILE_NAME); + exit(0); + } + else /* reading the data */ + { + /* tell the type of CPU */ + cp = (char*)&one; + if(*cp == 0) + is_big_endian = 1; /* yes, this is a big-endian CPU */ + else + is_big_endian = 0; /* this is a little-endian CPU */ + + if(is_big_endian == 0) + { + printf("This is a little-endian CPU, no need to swap bytes\n"); + printf("reading data now, please waiting for...\n"); + fread(data_in,sizeof(DATA_TYPE),COLS*ROWS,in_f); + } + else + { + printf("This is a big-endian CPU, which needs to swap bytes\n"); + printf("reading data now, please waiting for...\n"); + for(i=0;iNPP + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +; Observed NPP*scale_factor +;************************************************ + + scale_factor = 0.1 + + yi = (/ yi(::-1) /) + bi = (/ bi(::-1,:) /) + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,p)= b2(:,i) * scale_factor + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "newcn05_ncep_1i_MONS_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = new((/nlat,nlon/),float) + + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + + bo(j,i) = avg(bi({LATS:LATN},{LONL:LONR})) + end do + end do + + bo!0 = "lat" + bo!1 = "lon" + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name +; bo@_FillValue = bi@_FillValue + bo@_FillValue = 1.e+36 + + c->NPP = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 npp/03.0.05deg_to_T31.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/03.0.05deg_to_T31.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,142 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + filo = "Npp_T31_mean.nc" + c = addfile(diro+filo,"c") + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fili = "Npp_0.05deg_mean.nc" + g = addfile (diri+fili,"r") + bi = g->NPP + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +; Observed NPP*scale_factor +;************************************************ + + scale_factor = 0.1 + + yi = (/ yi(::-1) /) + bi = (/ bi(::-1,:) /) + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,p)= b2(:,i) * scale_factor + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) +;exit + +;************************************************ +; read in model data +;************************************************ + diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fili2 = "b30.061n_1995-2004_ANN_climo_lnd.nc" + f = addfile (diri2+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + +;(A) +;bo = linint2_Wrap(xi,yi,bi,True,xo,yo,0) + +;(B) + + rad = 4.*atan(1.)/180. + clat = lat + clat = cos(lat*rad) + clat@long_name = "cos(latitude)" + delete(clat@units) + printVarSummary(clat) + + bo = new((/nlat,nlon/),float) + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + +; CLAT = clat({LATS:LATN}) ; do once for *slight* efficiency +; TEMP = bi({LATS:LATN},:) ; 2D [lat,lon] + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + bo(j,i) = avg(bi({LATS:LATN},{LONL:LONR})) +; bo(j,i) = wgt_areaave(TEMP(:,{LONL:LONR}), CLAT, 1.0, 0) + end do + +; delete(CLAT) +; delete(TEMP) + end do + + bo!0 = "lat" + bo!1 = "lon" + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name +; bo@_FillValue = bi@_FillValue + bo@_FillValue = 1.e+36 + + c->NPP = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 npp/03.0.05deg_to_T42.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/03.0.05deg_to_T42.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,142 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp_data/" + filo = "Npp_T42_mean.nc" + c = addfile(diro+filo,"c") + +;************************************************ +; read in observed data +;************************************************ + diri = "/fis/cgd/cseg/people/jeff/clamp_data/" + fili = "Npp_0.05deg_mean.nc" + g = addfile (diri+fili,"r") + bi = g->NPP + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +; Observed NPP*scale_factor +;************************************************ + + scale_factor = 0.1 + + yi = (/ yi(::-1) /) + bi = (/ bi(::-1,:) /) + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,p)= b2(:,i) * scale_factor + end do + + bi&lat = yi + bi&lon = xi + +;print (xi) +;print (yi) +;exit + +;************************************************ +; read in model data +;************************************************ +;fili2 = "i01.04casa_1605-1629_ANN_climo.nc" + fili2 = "i01.03cn_1545-1569_ANN_climo.nc" + f = addfile (diri+fili2,"r") + + lon = f->lon + lat = f->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + +;(A) +;bo = linint2_Wrap(xi,yi,bi,True,xo,yo,0) + +;(B) + + rad = 4.*atan(1.)/180. + clat = lat + clat = cos(lat*rad) + clat@long_name = "cos(latitude)" + delete(clat@units) + printVarSummary(clat) + + bo = new((/nlat,nlon/),float) + do j=0,nlat-1 + if (j.eq.0 .or. j.eq.nlat-1) then + if (j.eq.0) then + LATS = -90. + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + if (j.eq.nlat-1) then + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = 90. + end if + else + LATS = lat(j)-0.5*(lat(j)-lat(j-1)) + LATN = lat(j)+0.5*(lat(j+1)-lat(j)) + end if + +; CLAT = clat({LATS:LATN}) ; do once for *slight* efficiency +; TEMP = bi({LATS:LATN},:) ; 2D [lat,lon] + + do i=0,nlon-1 + if (i.eq.0 .or. i.eq.nlon-1) then + if (i.eq.0) then + LONL = 0. + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + if (i.eq.nlon-1) then + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = 360. + end if + else + LONL = lon(i)-0.5*(lon(i)-lon(i-1)) + LONR = lon(i)+0.5*(lon(i+1)-lon(i)) + end if + +;print (LATS) +;print (LATN) +;print (LONL) +;print (LONR) + bo(j,i) = avg(bi({LATS:LATN},{LONL:LONR})) +; bo(j,i) = wgt_areaave(TEMP(:,{LONL:LONR}), CLAT, 1.0, 0) + end do + +; delete(CLAT) +; delete(TEMP) + end do + + bo!0 = "lat" + bo!1 = "lon" + bo&lat = lat + bo&lon = lon + bo@units = bi@units + bo@long_name = bi@long_name +; bo@_FillValue = bi@_FillValue + bo@_FillValue = 1.e+36 + + c->NPP = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 npp/03.0.05deg_to_T42.ncl.0 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/03.0.05deg_to_T42.ncl.0 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,77 @@ +; *********************************************** +; interpolate into model grids (T31) +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; output data +;************************************************ + diro = "/fis/cgd/cseg/people/jeff/clamp/" + filo = "Npp_T31_mean.nc" + c = addfile(diro+filo,"c") + +;************************************************ +; read in observed data +;************************************************ + g = addfile ("Npp_0.05deg_mean.nc","r") + bi = g->NPP + xi = g->lon + yi = g->lat + +;************************************************ +; change into 0-360E, 90S-90N +; Observed NPP*scale_factor +;************************************************ + + scale_factor = 0.1 + + yi = (/ yi(::-1) /) + bi = (/ bi(::-1,:) /) + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,p)= b2(:,i) * scale_factor + end do + +;print (xi) +;print (yi) +;exit + +;************************************************ +; read in model data +;************************************************ + f = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") +;f = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + + xo = f->lon + yo = f->lat + +; print (xi) +; print (yi) +; print (xo) +; print (yo) + + bo = linint2_Wrap(xi,yi,bi,True,xo,yo,0) + + bo!0 = "lat" + bo!1 = "lon" + bo&lat = yo + bo&lon = xo + bo@units = bi@units + bo@long_name = bi@long_name + bo@_FillValue = bi@_FillValue + + c->NPP = bo +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 npp/11.scatter.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/11.scatter.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,53 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read in data +;************************************************ +;f = addfile ("data.81.nc","r") + f = addfile ("data.933.nc","r") + x = f->SITE_ID ; get t data +;y = f->PREC_ANN ; get t data + y = f->TNPP_C ; get t data + + x@long_name = "SITE_ID" +;y@long_name = "PREC_ANN" + y@long_name = "TNPP_C" + +;************************************************ +; plotting parameters +;************************************************ + wks = gsn_open_wks ("png","xy") ; open workstation + + res = True ; plot mods desired +;res@tiMainString = "Observed 81 sites" ; add title + res@tiMainString = "Observed 933 sites" ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + + res@tmLabelAutoStride = True ; nice tick mark labels + +;plot = gsn_csm_xy (wks,t&nvalues,t(:),res) ; create plot + plot = gsn_csm_xy (wks,x,y,res) ; create plot + +;************************************************ +; now create our own markers using NhlNewMarker +; available since ncl version 4.2.0.a030 +;************************************************ +; this example will create filled squares. You will have to play with +; the numbers a but to get the size and shape you desire. On the +; documentation page for NhlNewMarker, there is a table of values for +; the current marker set, to give you an idea of where to start. + +; res@xyMarkerColor = "blue" +; res@tiMainString = "Make your own marker" +; res@xyMarkers = NhlNewMarker(wks, "^", 19, 0.0, 0.0, 1.3125, 1.5, 0.0) +; plot = gsn_csm_xy (wks,x,y,res) + +end diff -r 000000000000 -r 0c6405ab2ff4 npp/12.scatter.linint2_points.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/12.scatter.linint2_points.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,76 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read in data +;************************************************ + g = addfile ("data.81.nc","r") +;g = addfile ("data.933.nc","r") + a = g->SITE_ID ; get ob data + xo = g->LONG_DD ; get ob data + yo = g->LAT_DD ; get ob data + + print (xo) + nx = dimsizes(xo) + do i= 0,nx-1 + if (xo(i) .lt. 0.) then + xo(i) = xo(i)+ 360. + end if + end do + print (xo) + + a@long_name = "SITE_ID" + +;f = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") + f = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + b = f->NPP ; get model data + xi = f->lon ; get model data + yi = f->lat ; get model data + + sec_to_year = 86400.*365. + + bo = linint2_points(xi,yi,b,True,xo,yo,0) * sec_to_year + print (bo) + + bo@long_name = "NPP (gC/m2/year)" + +;************************************************ +; plotting parameters +;************************************************ +;wks = gsn_open_wks ("ps","xy") ; open workstation + wks = gsn_open_wks ("png","xy") + + res = True ; plot mods desired +;res@tiMainString = "Model i01.03cn 81 sites" ; add title +;res@tiMainString = "Model i01.03cn 933 sites" ; add title + res@tiMainString = "Model i01.04casa 81 sites" ; add title +;res@tiMainString = "Model i01.04casa 933 sites" ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + + res@tmLabelAutoStride = True ; nice tick mark labels + +;plot = gsn_csm_xy (wks,t&nvalues,t(:),res) ; create plot + plot = gsn_csm_xy (wks,a,bo,res) ; create plot + +;************************************************ +; now create our own markers using NhlNewMarker +; available since ncl version 4.2.0.a030 +;************************************************ +; this example will create filled squares. You will have to play with +; the numbers a but to get the size and shape you desire. On the +; documentation page for NhlNewMarker, there is a table of values for +; the current marker set, to give you an idea of where to start. + +; res@xyMarkerColor = "blue" +; res@tiMainString = "Make your own marker" +; res@xyMarkers = NhlNewMarker(wks, "^", 19, 0.0, 0.0, 1.3125, 1.5, 0.0) +; plot = gsn_csm_xy (wks,a,bo,res) + +end diff -r 000000000000 -r 0c6405ab2ff4 npp/13.scatter.model-ob.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/13.scatter.model-ob.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,87 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read in data: observed +;************************************************ +;g = addfile ("data.81.nc","r") + g = addfile ("data.933.nc","r") + a = g->TNPP_C +;a = g->ANPP_C +;a = g->BNPP_C + xo = g->LONG_DD + yo = g->LAT_DD + + a@long_name = "TNPP_C (gC/m2/year)" +;a@long_name = "ANPP_C (gC/m2/year)" +;a@long_name = "BNPP_C (gC/m2/year)" + +;print (xo) + nx = dimsizes(xo) + do i= 0,nx-1 + if (xo(i) .lt. 0.) then + xo(i) = xo(i)+ 360. + end if + end do +;print (xo) + +;************************************************ +; read in data: model +;************************************************ + f = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") +;f = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + + b = f->NPP +;b = f->AGNPP +;b = f->BGNPP + xi = f->lon + yi = f->lat + + sec_to_year = 86400.*365. + + bo = linint2_points(xi,yi,b,True,xo,yo,0) * sec_to_year +;print (bo) + + bo@long_name = "NPP (gC/m2/year)" +;bo@long_name = "AGNPP (gC/m2/year)" +;bo@long_name = "BGNPP (gC/m2/year)" + +;************************************************ +; plotting parameters +;************************************************ +;wks = gsn_open_wks ("ps","xy") ; open workstation + wks = gsn_open_wks ("png","xy") + + res = True ; plot mods desired +;res@tiMainString = "Model_i01.03cn vs Observed 81" ; add title + res@tiMainString = "Model_i01.03cn vs Observed 933" ; add title +;res@tiMainString = "Model_i01.04casa vs Observed 81" ; add title +;res@tiMainString = "Model_i01.04casa vs Observed 933" ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,a,bo,res) ; create plot + +;************************************************ +; now create our own markers using NhlNewMarker +; available since ncl version 4.2.0.a030 +;************************************************ +; this example will create filled squares. You will have to play with +; the numbers a but to get the size and shape you desire. On the +; documentation page for NhlNewMarker, there is a table of values for +; the current marker set, to give you an idea of where to start. + +; res@xyMarkerColor = "blue" +; res@tiMainString = "Make your own marker" +; res@xyMarkers = NhlNewMarker(wks, "^", 19, 0.0, 0.0, 1.3125, 1.5, 0.0) +; plot = gsn_csm_xy (wks,a,bo,res) + +end diff -r 000000000000 -r 0c6405ab2ff4 npp/14.scatter_bias.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/14.scatter_bias.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,57 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data +;************************************************ + g = addfile ("data.81.nc","r") +;g = addfile ("data.933.nc","r") + c = g->TNPP_C +;c = g->ANPP_C +;c = g->BNPP_C + xo = g->LONG_DD + yo = g->LAT_DD + +;print (c) + + nx = dimsizes(xo) + do i= 0,nx-1 + if (xo(i) .lt. 0.) then + xo(i) = xo(i)+ 360. + end if + end do +;print (xo) + + f = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") +;f = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + b = f->NPP +;b = f->AGNPP +;b = f->BGNPP + xi = f->lon + yi = f->lat + + sec_to_year = 86400.*365. + + bo = linint2_points(xi,yi,b,True,xo,yo,0) * sec_to_year +;print (bo) + + ccr = esccr(bo,c,0) + print (ccr) + +;old eq +;bias = sum(((bo(0,:)-c(:))/c(:))^2) +;M = (1. - sqrt(bias/nx))*5. + +;new eq + bias = sum(abs(bo(0,:)-c(:))/(bo(0,:)+c(:))) + M = (1. - (bias/nx))*5. + + print (bias) + print (M) + +end diff -r 000000000000 -r 0c6405ab2ff4 npp/15.scatter_bias.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/15.scatter_bias.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,285 @@ +; *********************************************** +; combine all scatter +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read in ob data +;************************************************ + +;(A) plot ob scatter_81 + + dir81 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil81 = "data.81.nc" + f81 = addfile (dir81+fil81,"r") + + x81 = f81->SITE_ID + y81 = f81->TNPP_C + xo81 = f81->LONG_DD + yo81 = f81->LAT_DD + + x81@long_name = "SITE_ID" + y81@long_name = "NPP (gC/m2/year)" + + plot_name = "scatter_ob_81" + title = "Observed 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,x81,y81,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(B) plot ob scatter_933 + + dir933 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil933 = "data.933.nc" + f933 = addfile (dir933+fil933,"r") + + x933 = f933->SITE_ID + y933 = f933->TNPP_C + xo933 = f933->LONG_DD + yo933 = f933->LAT_DD + + x933@long_name = "SITE_ID" + y933@long_name = "NPP (gC/m2/year)" + + plot_name = "scatter_ob_933" + title = "Observed 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,x933,y933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;************************************************ +; read in model data +;************************************************ + +;(C) plot model scatter_81 + + model_name = "b30.061n" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "b30.061n_1995-2004_ANN_climo_lnd.nc" + fm = addfile (dirm+film,"r") + + ymod = fm->NPP + xm = fm->lon + ym = fm->lat + + nx = dimsizes(xo81) + do i= 0,nx-1 + if (xo81(i) .lt. 0.) then + xo81(i) = xo81(i)+ 360. + end if + end do + print (xo81) + + sec_to_year = 86400.*365. + + ymod81 = linint2_points(xm,ym,ymod(0,:,:),True,xo81,yo81,0) * sec_to_year + xmod81 = x81 + + ymod81@long_name = "NPP (gC/m2/year)" + xmod81@long_name = "SITE_ID" +print (ymod81) +print (xmod81) + + plot_name = "scatter_model_81" + title = "Model "+ model_name +" 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,xmod81,ymod81,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(D) plot model scatter_933 + + model_name = "b30.061n" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "b30.061n_1995-2004_ANN_climo_lnd.nc" + fm = addfile (dirm+film,"r") + + ymod = fm->NPP + xm = fm->lon + ym = fm->lat + + nx = dimsizes(xo933) + do i= 0,nx-1 + if (xo933(i) .lt. 0.) then + xo933(i) = xo933(i)+ 360. + end if + end do + print (xo933) + + sec_to_year = 86400.*365. + + ymod933 = linint2_points(xm,ym,ymod(0,:,:),True,xo933,yo933,0) * sec_to_year + xmod933 = x933 + + ymod933@long_name = "NPP (gC/m2/year)" + xmod933@long_name = "SITE_ID" +;print (ymod933) +;print (xmod933) + + plot_name = "scatter_model_933" + title = "Model "+ model_name +" 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,xmod933,ymod933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(E) scatter model vs ob 81 + + ymod81@long_name = "NPP (gC/m2/year)" + y81@long_name = "NPP (gC/m2/year)" +;print (ymod81) +;print (y81) + + plot_name = "scatter_model_vs_ob_81" + title = model_name +" vs ob 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels +;------------------------------- +;compute correlation coef. and M + ccr81 = esccr(ymod81,y81,0) + print (ccr81) + +;new eq + bias = sum(abs(ymod81-y81)/(ymod81+y81)) + M81 = (1. - (bias/dimsizes(y81)))*5. + print (M81) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,y81,ymod81,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(F) scatter model vs ob 933 + + ymod933@long_name = "NPP (gC/m2/year)" + y933@long_name = "NPP (gC/m2/year)" +;print (ymod33) +;print (y933) + + plot_name = "scatter_model_vs_ob_933" + title = model_name +" vs ob 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels +;------------------------------- +;compute correlation coef. and M + ccr933 = esccr(ymod933,y933,0) + print (ccr933) + +;new eq + bias = sum(abs(ymod933-y933)/(ymod933+y933)) + M933 = (1. - (bias/dimsizes(y933)))*5. + print (M933) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,y933,ymod933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +end diff -r 000000000000 -r 0c6405ab2ff4 npp/16.scatter_bias.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/16.scatter_bias.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,840 @@ +; *********************************************** +; combine all scatter +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read in ob data +;************************************************ + dir81 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil81 = "data.81.nc" + f81 = addfile (dir81+fil81,"r") + + id81 = f81->SITE_ID + npp81 = f81->TNPP_C + rain81 = tofloat(f81->PREC_ANN) + x81 = f81->LONG_DD + y81 = f81->LAT_DD + + id81@long_name = "SITE_ID" + npp81@long_name = "NPP (gC/m2/year)" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x81)-1 + if (x81(i) .lt. 0.) then + x81(i) = x81(i)+ 360. + end if + end do +;print (x81) +;------------------------------------- + dir933 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil933 = "data.933.nc" + f933 = addfile (dir933+fil933,"r") + + id933 = f933->SITE_ID + npp933 = f933->TNPP_C + rain933 = f933->PREC + x933 = f933->LONG_DD + y933 = f933->LAT_DD + + id933@long_name = "SITE_ID" + npp933@long_name = "NPP (gC/m2/year)" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x933)-1 + if (x933(i) .lt. 0.) then + x933(i) = x933(i)+ 360. + end if + end do +;print (x933) +;************************************************ +; read in model data +;************************************************ + model_name = "b30.061n" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "b30.061n_1995-2004_ANN_climo_lnd.nc" + fm = addfile (dirm+film,"r") + + nppmod = fm->NPP + rainmod = fm->RAIN + xm = fm->lon + ym = fm->lat + + nppmod81 =linint2_points(xm,ym,nppmod(0,:,:),True,x81,y81,0) + + nppmod933 =linint2_points(xm,ym,nppmod(0,:,:),True,x933,y933,0) + + rainmod81 =linint2_points(xm,ym,rainmod(0,:,:),True,x81,y81,0) + + rainmod933=linint2_points(xm,ym,rainmod(0,:,:),True,x933,y933,0) + +;************************************************ +; Units for these four variables are: +; +; rain81 : mm/year +; rainmod : mm/s +; npp81 : g C/m^2/year +; nppmod81: g C/m^2/s +; +; We want to convert these to "m/year" and "g C/m^2/year". +; + nsec_per_year = 60*60*24*365 + + rain81 = rain81 / 1000. + rainmod81 = (rainmod81/ 1000.) * nsec_per_year + nppmod81 = nppmod81 * nsec_per_year + + rain933 = rain933 / 1000. + rainmod933 = (rainmod933/ 1000.) * nsec_per_year + nppmod933 = nppmod933 * nsec_per_year + + npp81@units = "gC/m^2/yr" + nppmod81@units = "gC/m^2/yr" + npp933@units = "gC/m^2/yr" + nppmod933@units = "gC/m^2/yr" + rain81@units = "m/yr" + rainmod81@units = "m/yr" + rain933@units = "m/yr" + rainmod933@units = "m/yr" + + npp81@long_name = "NPP (gC/m2/year)" + npp933@long_name = "NPP (gC/m2/year)" + nppmod81@long_name = "NPP (gC/m2/year)" + nppmod933@long_name = "NPP (gC/m2/year)" + rain81@long_name = "PREC (m/year)" + rain933@long_name = "PREC (m/year)" + rainmod81@long_name = "PREC (m/year)" + rainmod933@long_name = "PREC (m/year)" + +;(A) plot scatter ob 81 + + plot_name = "scatter_ob_81" + title = "Observed 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id81,npp81,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(B) plot scatter ob 933 + + plot_name = "scatter_ob_933" + title = "Observed 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id933,npp933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(C) plot scatter model 81 + + plot_name = "scatter_model_81" + title = "Model "+ model_name +" 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id81,nppmod81,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(D) plot scatter model 933 + + plot_name = "scatter_model_933" + title = "Model "+ model_name +" 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id933,nppmod933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(E) scatter model vs ob 81 + + plot_name = "scatter_model_vs_ob_81" + title = model_name +" vs ob 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels +;------------------------------- +;compute correlation coef. and M + ccr81 = esccr(nppmod81,npp81,0) + print (ccr81) + +;new eq + bias = sum(abs(nppmod81-npp81)/(nppmod81+npp81)) + M81 = (1. - (bias/dimsizes(y81)))*5. + print (M81) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp81,nppmod81,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(F) scatter model vs ob 933 + + plot_name = "scatter_model_vs_ob_933" + title = model_name +" vs ob 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels +;------------------------------- +;compute correlation coef. and M + ccr933 = esccr(nppmod933,npp933,0) + print (ccr933) + +;new eq + bias = sum(abs(nppmod933-npp933)/(nppmod933+npp933)) + M933 = (1. - (bias/dimsizes(y933)))*5. + print (M933) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp933,nppmod933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;************************************************************************** +;(G) histogram 81 + +;-------------------------------------------------------------------- +;get data + + RAIN1_1D = ndtooned(rain81) + RAIN2_1D = ndtooned(rainmod81) + NPP1_1D = ndtooned(npp81) + NPP2_1D = ndtooned(nppmod81) +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do +;---------------------------------------- +;compute correlation coeff and M score + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr81h = esccr(uu,vv,0) + print (ccr81h) + +;new eq + bias = sum(abs(vv-uu)/(vv+uu)) + M81h = (1.- (bias/dimsizes(uu)))*5. + print (M81h) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + + res = True + res@gsnMaximize = True + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 + res@xyMarkerColors = (/"Brown","Blue"/) + res@trYMinF = min(mn_yvalues) - 10. + res@trYMaxF = max(mx_yvalues) + 10. + + res@tiYAxisString = "NPP (g C/m2/year)" + res@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;================================================================= +; histogram ob 81 site only +; + plot_name = "histogram_ob_81" + title = "Observed 81 site" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),res) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;=========================================================================== +; histogram model vs ob 81 site + + plot_name = "histogram_mod-ob_81" + title = model_name+ " vs Observed 81 site" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81h)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.8,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,res) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +;system("rm "+plot_name+"."+plot_type) +;system("rm "+plot_name+"-1."+plot_type_new) +;system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (RAIN1_1D) + delete (RAIN2_1D) + delete (NPP1_1D) + delete (NPP2_1D) + delete (range) + delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;************************************************************************** +;(H) histogram 933 + +;-------------------------------------------------------------------- +;get data + + RAIN1_1D = ndtooned(rain933) + RAIN2_1D = ndtooned(rainmod933) + NPP1_1D = ndtooned(npp933) + NPP2_1D = ndtooned(nppmod933) +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do +;---------------------------------------- +;compute correlation coeff and M score + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr933h = esccr(uu,vv,0) + print (ccr933h) + +;new eq + bias = sum(abs(vv-uu)/(vv+uu)) + M933h = (1.- (bias/dimsizes(uu)))*5. + print (M933h) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + + res = True + res@gsnMaximize = True + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 + res@xyMarkerColors = (/"Brown","Blue"/) + res@trYMinF = min(mn_yvalues) - 10. + res@trYMaxF = max(mx_yvalues) + 10. + + res@tiYAxisString = "NPP (g C/m2/year)" + res@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;================================================================= +; histogram ob 933 site only +; + plot_name = "histogram_ob_933" + title = "Observed 933 site" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),res) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;=========================================================================== +; histogram model vs ob 933 site + + plot_name = "histogram_mod-ob_933" + title = model_name+ " vs Observed 933 site" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933h)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.8,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,res) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +;system("rm "+plot_name+"."+plot_type) +;system("rm "+plot_name+"-1."+plot_type_new) +;system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ + +end diff -r 000000000000 -r 0c6405ab2ff4 npp/17.scatter_bias.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/17.scatter_bias.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,972 @@ +; *********************************************** +; combine all scatter and all histogram +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read in ob data +;************************************************ +;(1) + dir81 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil81 = "data.81.nc" + f81 = addfile (dir81+fil81,"r") + + id81 = f81->SITE_ID + npp81 = f81->TNPP_C + rain81 = tofloat(f81->PREC_ANN) + x81 = f81->LONG_DD + y81 = f81->LAT_DD + + id81@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x81)-1 + if (x81(i) .lt. 0.) then + x81(i) = x81(i)+ 360. + end if + end do +;print (x81) +;------------------------------------- +;(2) + dir933 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil933 = "data.933.nc" + f933 = addfile (dir933+fil933,"r") + + id933 = f933->SITE_ID + npp933 = f933->TNPP_C + rain933 = f933->PREC + x933 = f933->LONG_DD + y933 = f933->LAT_DD + + id933@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x933)-1 + if (x933(i) .lt. 0.) then + x933(i) = x933(i)+ 360. + end if + end do +;print (x933) +;---------------------------------------- +;(3) + dirglobe = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + filglobe = "Npp_T31_mean.nc" + fglobe = addfile (dirglobe+filglobe,"r") + + nppglobe = fglobe->NPP + +;************************************************ +; read in model data +;************************************************ + model_name = "b30.061n" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "b30.061n_1995-2004_ANN_climo_lnd.nc" + fm = addfile (dirm+film,"r") + + nppmod0 = fm->NPP + rainmod0 = fm->RAIN + xm = fm->lon + ym = fm->lat + + nppmod = nppmod0(0,:,:) + rainmod = rainmod0(0,:,:) + delete (nppmod0) + delete (rainmod0) + + nppmod81 =linint2_points(xm,ym,nppmod,True,x81,y81,0) + + nppmod933 =linint2_points(xm,ym,nppmod,True,x933,y933,0) + + rainmod81 =linint2_points(xm,ym,rainmod,True,x81,y81,0) + + rainmod933=linint2_points(xm,ym,rainmod,True,x933,y933,0) + +;************************************************ +; Units for these variables are: +; +; rain81 : mm/year +; rainmod : mm/s +; npp81 : g C/m^2/year +; nppmod81: g C/m^2/s +; nppglobe: g C/m^2/year +; +; We want to convert these to "m/year" and "g C/m^2/year". +; + nsec_per_year = 60*60*24*365 + + rain81 = rain81 / 1000. + rainmod81 = (rainmod81/ 1000.) * nsec_per_year + nppmod81 = nppmod81 * nsec_per_year + + rain933 = rain933 / 1000. + rainmod933 = (rainmod933/ 1000.) * nsec_per_year + nppmod933 = nppmod933 * nsec_per_year + + nppmod = nppmod * nsec_per_year + + npp81@units = "gC/m^2/yr" + nppmod81@units = "gC/m^2/yr" + npp933@units = "gC/m^2/yr" + nppmod933@units = "gC/m^2/yr" + nppmod@units = "gC/m^2/yr" + nppglobe@units = "gC/m^2/yr" + rain81@units = "m/yr" + rainmod81@units = "m/yr" + rain933@units = "m/yr" + rainmod933@units = "m/yr" + + npp81@long_name = "NPP (gC/m2/year)" + npp933@long_name = "NPP (gC/m2/year)" + nppmod81@long_name = "NPP (gC/m2/year)" + nppmod933@long_name = "NPP (gC/m2/year)" + nppmod@long_name = "NPP (gC/m2/year)" + nppglobe@long_name = "NPP (gC/m2/year)" + rain81@long_name = "PREC (m/year)" + rain933@long_name = "PREC (m/year)" + rainmod81@long_name = "PREC (m/year)" + rainmod933@long_name = "PREC (m/year)" + +;(A) plot scatter ob 81 + + plot_name = "scatter_ob_81" + title = "Observed 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id81,npp81,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(B) plot scatter ob 933 + + plot_name = "scatter_ob_933" + title = "Observed 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id933,npp933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(C) plot scatter model 81 + + plot_name = "scatter_model_81" + title = "Model "+ model_name +" 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id81,nppmod81,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(D) plot scatter model 933 + + plot_name = "scatter_model_933" + title = "Model "+ model_name +" 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id933,nppmod933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(E) scatter model vs ob 81 + + plot_name = "scatter_model_vs_ob_81" + title = model_name +" vs ob 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels +;------------------------------- +;compute correlation coef. and M + ccr81 = esccr(nppmod81,npp81,0) + print (ccr81) + +;new eq + bias = sum(abs(nppmod81-npp81)/(nppmod81+npp81)) + M81 = (1. - (bias/dimsizes(y81)))*5. + print (M81) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp81,nppmod81,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(F) scatter model vs ob 933 + + plot_name = "scatter_model_vs_ob_933" + title = model_name +" vs ob 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels +;------------------------------- +;compute correlation coef. and M + ccr933 = esccr(nppmod933,npp933,0) + print (ccr933) + +;new eq + bias = sum(abs(nppmod933-npp933)/(nppmod933+npp933)) + M933 = (1. - (bias/dimsizes(y933)))*5. + print (M933) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp933,nppmod933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;************************************************************************** +;(G) histogram 81 + +;-------------------------------------------------------------------- +;get data + + RAIN1_1D = ndtooned(rain81) + RAIN2_1D = ndtooned(rainmod81) + NPP1_1D = ndtooned(npp81) + NPP2_1D = ndtooned(nppmod81) +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do +;---------------------------------------- +;compute correlation coeff and M score + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr81h = esccr(uu,vv,0) + print (ccr81h) + +;new eq + bias = sum(abs(vv-uu)/(vv+uu)) + M81h = (1.- (bias/dimsizes(uu)))*5. + print (M81h) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + + res = True + res@gsnMaximize = True + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 + res@xyMarkerColors = (/"Brown","Blue"/) + res@trYMinF = min(mn_yvalues) - 10. + res@trYMaxF = max(mx_yvalues) + 10. + + res@tiYAxisString = "NPP (g C/m2/year)" + res@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;================================================================= +; histogram ob 81 site only +; + plot_name = "histogram_ob_81" + title = "Observed 81 site" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),res) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;=========================================================================== +; histogram model vs ob 81 site + + plot_name = "histogram_mod-ob_81" + title = model_name+ " vs Observed 81 site" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81h)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.8,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,res) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +;system("rm "+plot_name+"."+plot_type) +;system("rm "+plot_name+"-1."+plot_type_new) +;system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (RAIN1_1D) + delete (RAIN2_1D) + delete (NPP1_1D) + delete (NPP2_1D) + delete (range) + delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;************************************************************************** +;(H) histogram 933 + +;-------------------------------------------------------------------- +;get data + + RAIN1_1D = ndtooned(rain933) + RAIN2_1D = ndtooned(rainmod933) + NPP1_1D = ndtooned(npp933) + NPP2_1D = ndtooned(nppmod933) +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do +;---------------------------------------- +;compute correlation coeff and M score + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr933h = esccr(uu,vv,0) + print (ccr933h) + +;new eq + bias = sum(abs(vv-uu)/(vv+uu)) + M933h = (1.- (bias/dimsizes(uu)))*5. + print (M933h) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + + res = True + res@gsnMaximize = True + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 + res@xyMarkerColors = (/"Brown","Blue"/) + res@trYMinF = min(mn_yvalues) - 10. + res@trYMaxF = max(mx_yvalues) + 10. + + res@tiYAxisString = "NPP (g C/m2/year)" + res@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;================================================================= +; histogram ob 933 site only +; + plot_name = "histogram_ob_933" + title = "Observed 933 site" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),res) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;=========================================================================== +; histogram model vs ob 933 site + + plot_name = "histogram_mod-ob_933" + title = model_name+ " vs Observed 933 site" + res@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 + res@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933h)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.8,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,res) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour + +;res + resw = True ; Use plot options + resw@cnFillOn = True ; Turn on color fill + resw@gsnSpreadColors = True ; use full colormap +; resw@cnFillMode = "RasterFill" ; Turn on raster color +; resw@lbLabelAutoStride = True + resw@cnLinesOn = False ; Turn off contourn lines + resw@mpFillOn = False ; Turn off map fill + + resw@gsnSpreadColors = True ; use full colormap + resw@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resw@cnMinLevelValF = 0. ; Min level + resw@cnMaxLevelValF = 2200. ; Max level + resw@cnLevelSpacingF = 200. ; interval +;------------------------------------------------------------------------ +;global contour ob + + delta = 0.00000000001 + nppglobe = where(ismissing(nppglobe).and.(ismissing(nppmod).or.(nppmod.lt.delta)),0.,nppglobe) + + plot_name = "global_ob" + title = "Observed MODIS MOD 17" + resw@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + + plot = gsn_csm_contour_map_ce(wks,nppglobe,resw) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_model" + title = "Model "+ model_name + resw@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppmod,resw) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resw@gsnFrame = False ; Do not draw plot + resw@gsnDraw = False ; Do not advance frame + +;(a) ob + + title = "Observed MODIS MOD 17" + resw@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,nppglobe,resw) ; for observed + +;(b) model + + title = "Model "+ model_name + resw@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,nppmod,resw) ; for model + +;(c) model-ob + + zz = nppmod + zz = nppmod - nppglobe + title = "Model_"+model_name+" - Observed" + + resw@cnMinLevelValF = -500 ; Min level + resw@cnMaxLevelValF = 500. ; Max level + resw@cnLevelSpacingF = 50. ; interval + resw@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resw) + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) +end diff -r 000000000000 -r 0c6405ab2ff4 npp/18.scatter_bias.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/18.scatter_bias.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1096 @@ +; **************************************************** +; combine scatter, histogram, global and zonal plots +; **************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read in ob data +;************************************************ +;(1) + dir81 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil81 = "data.81.nc" + f81 = addfile (dir81+fil81,"r") + + id81 = f81->SITE_ID + npp81 = f81->TNPP_C + rain81 = tofloat(f81->PREC_ANN) + x81 = f81->LONG_DD + y81 = f81->LAT_DD + + id81@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x81)-1 + if (x81(i) .lt. 0.) then + x81(i) = x81(i)+ 360. + end if + end do +;print (x81) +;------------------------------------- +;(2) + dir933 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil933 = "data.933.nc" + f933 = addfile (dir933+fil933,"r") + + id933 = f933->SITE_ID + npp933 = f933->TNPP_C + rain933 = f933->PREC + x933 = f933->LONG_DD + y933 = f933->LAT_DD + + id933@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x933)-1 + if (x933(i) .lt. 0.) then + x933(i) = x933(i)+ 360. + end if + end do +;print (x933) +;---------------------------------------- +;(3) + dirglobe = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + filglobe = "Npp_T31_mean.nc" + fglobe = addfile (dirglobe+filglobe,"r") + + nppglobe0 = fglobe->NPP + nppglobe = nppglobe0 +;************************************************ +; read in model data +;************************************************ + model_name = "b30.061n" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "b30.061n_1995-2004_ANN_climo_lnd.nc" + fm = addfile (dirm+film,"r") + + nppmod0 = fm->NPP + rainmod0 = fm->RAIN + xm = fm->lon + ym = fm->lat + + nppmod = nppmod0(0,:,:) + rainmod = rainmod0(0,:,:) + delete (nppmod0) + delete (rainmod0) + + nppmod81 =linint2_points(xm,ym,nppmod,True,x81,y81,0) + + nppmod933 =linint2_points(xm,ym,nppmod,True,x933,y933,0) + + rainmod81 =linint2_points(xm,ym,rainmod,True,x81,y81,0) + + rainmod933=linint2_points(xm,ym,rainmod,True,x933,y933,0) + +;************************************************ +; Units for these variables are: +; +; rain81 : mm/year +; rainmod : mm/s +; npp81 : g C/m^2/year +; nppmod81: g C/m^2/s +; nppglobe: g C/m^2/year +; +; We want to convert these to "m/year" and "g C/m^2/year". +; + nsec_per_year = 60*60*24*365 + + rain81 = rain81 / 1000. + rainmod81 = (rainmod81/ 1000.) * nsec_per_year + nppmod81 = nppmod81 * nsec_per_year + + rain933 = rain933 / 1000. + rainmod933 = (rainmod933/ 1000.) * nsec_per_year + nppmod933 = nppmod933 * nsec_per_year + + nppmod = nppmod * nsec_per_year + + npp81@units = "gC/m^2/yr" + nppmod81@units = "gC/m^2/yr" + npp933@units = "gC/m^2/yr" + nppmod933@units = "gC/m^2/yr" + nppmod@units = "gC/m^2/yr" + nppglobe@units = "gC/m^2/yr" + rain81@units = "m/yr" + rainmod81@units = "m/yr" + rain933@units = "m/yr" + rainmod933@units = "m/yr" + + npp81@long_name = "NPP (gC/m2/year)" + npp933@long_name = "NPP (gC/m2/year)" + nppmod81@long_name = "NPP (gC/m2/year)" + nppmod933@long_name = "NPP (gC/m2/year)" + nppmod@long_name = "NPP (gC/m2/year)" + nppglobe@long_name = "NPP (gC/m2/year)" + rain81@long_name = "PREC (m/year)" + rain933@long_name = "PREC (m/year)" + rainmod81@long_name = "PREC (m/year)" + rainmod933@long_name = "PREC (m/year)" + +;(A) plot scatter ob 81 + + plot_name = "scatter_ob_81" + title = "Observed 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id81,npp81,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(B) plot scatter ob 933 + + plot_name = "scatter_ob_933" + title = "Observed 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id933,npp933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(C) plot scatter model 81 + + plot_name = "scatter_model_81" + title = "Model "+ model_name +" 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id81,nppmod81,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(D) plot scatter model 933 + + plot_name = "scatter_model_933" + title = "Model "+ model_name +" 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id933,nppmod933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(E) scatter model vs ob 81 + + plot_name = "scatter_model_vs_ob_81" + title = model_name +" vs ob 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels +;------------------------------- +;compute correlation coef. and M + ccr81 = esccr(nppmod81,npp81,0) + print (ccr81) + +;new eq + bias = sum(abs(nppmod81-npp81)/(nppmod81+npp81)) + M81 = (1. - (bias/dimsizes(y81)))*5. + print (M81) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp81,nppmod81,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(F) scatter model vs ob 933 + + plot_name = "scatter_model_vs_ob_933" + title = model_name +" vs ob 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels +;------------------------------- +;compute correlation coef. and M + ccr933 = esccr(nppmod933,npp933,0) + print (ccr933) + +;new eq + bias = sum(abs(nppmod933-npp933)/(nppmod933+npp933)) + M933 = (1. - (bias/dimsizes(y933)))*5. + print (M933) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp933,nppmod933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;************************************************************************** +;(G) histogram 81 + +;-------------------------------------------------------------------- +;get data + + RAIN1_1D = ndtooned(rain81) + RAIN2_1D = ndtooned(rainmod81) + NPP1_1D = ndtooned(npp81) + NPP2_1D = ndtooned(nppmod81) + +; Calculaee "nice" bins for binning the data in equally spaced ranges. + + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; Print out information. + +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data) + delete(npp_data) + end do +;---------------------------------------- +;compute correlation coeff and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr81h = esccr(uu,vv,0) + print (ccr81h) + +;new eq + bias = sum(abs(vv-uu)/(vv+uu)) + M81h = (1.- (bias/dimsizes(uu)))*5. + print (M81h) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + + resh = True + resh@gsnMaximize = True + resh@gsnDraw = False + resh@gsnFrame = False + resh@xyMarkLineMode = "Markers" + resh@xyMarkerSizeF = 0.014 + resh@xyMarker = 16 + resh@xyMarkerColors = (/"Brown","Blue"/) + resh@trYMinF = min(mn_yvalues) - 10. + resh@trYMaxF = max(mx_yvalues) + 10. + + resh@tiYAxisString = "NPP (g C/m2/year)" + resh@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;================================================================= +; histogram ob 81 site only +; + plot_name = "histogram_ob_81" + title = "Observed 81 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;=========================================================================== +; histogram model vs ob 81 site + + plot_name = "histogram_mod-ob_81" + title = model_name+ " vs Observed 81 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + resh@pmLegendDisplayMode = "Always" +; resh@pmLegendWidthF = 0.1 + resh@pmLegendWidthF = 0.08 + resh@pmLegendHeightF = 0.05 + resh@pmLegendOrthogonalPosF = -1.17 +; resh@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resh@pmLegendParallelPosF = 0.18 + resh@pmLegendParallelPosF = 0.88 ;(rightward) + +; resh@lgPerimOn = False + resh@lgLabelFontHeightF = 0.015 + resh@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81h)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resh) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (RAIN1_1D) + delete (RAIN2_1D) + delete (NPP1_1D) + delete (NPP2_1D) + delete (range) + delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;************************************************************************** +;(H) histogram 933 + +;-------------------------------------------------------------------- +;get data + + RAIN1_1D = ndtooned(rain933) + RAIN2_1D = ndtooned(rainmod933) + NPP1_1D = ndtooned(npp933) + NPP2_1D = ndtooned(nppmod933) + +; Calculate "nice" bins for binning the data in equally spaced ranges. + + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; Print out information. + +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data) + delete(npp_data) + end do +;---------------------------------------- +;compute correlation coeff and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr933h = esccr(uu,vv,0) + print (ccr933h) + +;new eq + bias = sum(abs(vv-uu)/(vv+uu)) + M933h = (1.- (bias/dimsizes(uu)))*5. + print (M933h) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + + delete (resh) + resh = True + resh@gsnMaximize = True + resh@gsnDraw = False + resh@gsnFrame = False + resh@xyMarkLineMode = "Markers" + resh@xyMarkerSizeF = 0.014 + resh@xyMarker = 16 + resh@xyMarkerColors = (/"Brown","Blue"/) + resh@trYMinF = min(mn_yvalues) - 10. + resh@trYMaxF = max(mx_yvalues) + 10. + + resh@tiYAxisString = "NPP (g C/m2/year)" + resh@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;================================================================= +; histogram ob 933 site only + + plot_name = "histogram_ob_933" + title = "Observed 933 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + delete (xy) + clear (wks) + +;=========================================================================== +; histogram model vs ob 933 site + + plot_name = "histogram_mod-ob_933" + title = model_name+ " vs Observed 933 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + resh@pmLegendDisplayMode = "Always" +; resh@pmLegendWidthF = 0.1 + resh@pmLegendWidthF = 0.08 + resh@pmLegendHeightF = 0.05 + resh@pmLegendOrthogonalPosF = -1.17 +; resh@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resh@pmLegendParallelPosF = 0.18 + resh@pmLegendParallelPosF = 0.88 ;(rightward) + +; resh@lgPerimOn = False + resh@lgLabelFontHeightF = 0.015 + resh@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933h)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resh) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + delete (xy) + clear (wks) +;------------------------------------------------------------------------ +; global contour + +;res + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@gsnSpreadColors = True ; use full colormap + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 2200. ; Max level + resg@cnLevelSpacingF = 200. ; interval +;------------------------------------------------------------------------ +;global contour ob + + delta = 0.00000000001 + nppglobe = where(ismissing(nppglobe).and.(ismissing(nppmod).or.(nppmod.lt.delta)),0.,nppglobe) + + plot_name = "global_ob" + title = "Observed MODIS MOD 17" + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppglobe,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model + + plot_name = "global_model" + title = "Model "+ model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppmod,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;global contour model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;(d) compute correlation coef and M score + + uu1 = ndtooned(nppmod) + vv1 = ndtooned(nppglobe) + + delete (good) + good = ind(.not.ismissing(uu1) .and. .not.ismissing(vv1)) + + ug = uu1(good) + vg = vv1(good) + + ccrG = esccr(ug,vg,0) + print (ccrG) + + MG = (ccrG*ccrG)* 5.0 + print (MG) + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrG)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = "Observed MODIS MOD 17" + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,nppglobe,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,nppmod,resg) + +;(c) model-ob + + zz = nppmod + zz = nppmod - nppglobe + title = "Model_"+model_name+" - Observed" + + resg@cnMinLevelValF = -500 ; Min level + resg@cnMaxLevelValF = 500. ; Max level + resg@cnLevelSpacingF = 50. ; interval + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +; system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +;--------------------------------------------------------------------- +; zonal line plot ob + + resz = True + + vv = zonalAve(nppglobe) + vv@long_name = nppglobe@long_name + + plot_name = "zonal_ob" + title = "Observed MODIS MOD 17" + resz@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + plot = gsn_csm_xy (wks,ym,vv,resz) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;--------------------------------------------------------------------- +; zonal line plot model vs ob + + s = new ((/2,dimsizes(ym)/), float) + + s(0,:) = zonalAve(nppglobe) + s(1,:) = zonalAve(nppmod) + + s@long_name = nppglobe@long_name +;------------------------------------------- +;(d) compute correlation coef and M score + + ccrZ = esccr(s(1,:), s(0,:),0) + print (ccrZ) + + MZ = (ccrZ*ccrZ)* 5.0 + print (MZ) +;------------------------------------------- + plot_name = "zonal_model_vs_ob" + title = "Zonal Average" + resz@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +; resz@vpHeightF = 0.4 ; change aspect ratio of plot +; resz@vpWidthF = 0.7 + + resz@xyMonoLineColor = "False" ; want colored lines + resz@xyLineColors = (/"black","red"/) ; colors chosen +; resz@xyLineThicknesses = (/3.,3./) ; line thicknesses + resz@xyLineThicknesses = (/2.,2./) ; line thicknesses + resz@xyDashPatterns = (/0.,0./) ; make all lines solid + + resz@tiYAxisString = s@long_name ; add a axis title + resz@txFontHeightF = 0.0195 ; change title font heights + +; Legent + resz@pmLegendDisplayMode = "Always" ; turn on legend + resz@pmLegendSide = "Top" ; Change location of +; resz@pmLegendParallelPosF = .45 ; move units right + resz@pmLegendParallelPosF = .82 ; move units right + resz@pmLegendOrthogonalPosF = -0.4 ; move units down + + resz@pmLegendWidthF = 0.10 ; Change width and + resz@pmLegendHeightF = 0.10 ; height of legend. + resz@lgLabelFontHeightF = .02 ; change font height +; resz@lgTitleOn = True ; turn on legend title +; resz@lgTitleString = "Example" ; create legend title +; resz@lgTitleFontHeightF = .025 ; font of legend title + resz@xyExplicitLegendLabels = (/"Observed",model_name/) ; explicit labels +;-------------------------------------------------------------------- + zRes = True + zRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrZ)+")" + + gsn_text_ndc(wks,correlation_text,0.50,0.77,zRes) +;-------------------------------------------------------------------- + + plot = gsn_csm_xy (wks,ym,s,resz) ; create plot + + frame(wks) ; advance frame + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +end diff -r 000000000000 -r 0c6405ab2ff4 npp/21.histogram.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/21.histogram.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,209 @@ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; +; Main code. +; +begin + data_types = (/ "Obs", "Model" /) + data_names = (/ "data.81.nc", "i01.03cn_1545-1569_ANN_climo.nc" /) +; data_names = (/ "data.81.nc", "i01.04casa_1605-1629_ANN_climo.nc" /) + filevar_names = (/ (/"PREC_ANN","TNPP_C"/), (/"RAIN","NPP"/) /) + ndata_types = dimsizes(data_types) + + data_file_obs = addfile(data_names(0),"r") ; Open obs file + data_file_mod = addfile(data_names(1),"r") ; Open model file + +; +; Read four variables from files. +; + PREC_ANN = tofloat(data_file_obs->PREC_ANN) + TNPP_C = data_file_obs->TNPP_C + RAIN = data_file_mod->RAIN + NPP = data_file_mod->NPP +; +; Units for these four variables are: +; +; PREC_ANN : mm/year +; TNPP_C : g C/m^2/year +; RAIN : mm/s +; NPP : g C/m^2/s +; +; We want to convert these to "m/year" and "g C/m^2/year". +; + nsec_per_year = 60*60*24*365 ; # seconds per year + +; Do the necessary conversions. + PREC_ANN = PREC_ANN / 1000. + RAIN = (RAIN / 1000.) * nsec_per_year + NPP = NPP * nsec_per_year + +; Redo the units. + PREC_ANN@units = "m/yr" + RAIN@units = "m/yr" + NPP@units = "gC/m^2/yr" + TNPP_C@units = "gC/m^2/yr" + + pminmax(PREC_ANN,"PREC_ANN") + pminmax(TNPP_C,"TNPP_C") + pminmax(RAIN,"RAIN") + pminmax(NPP,"NPP") + + RAIN_1D = ndtooned(RAIN) + NPP_1D = ndtooned(NPP) + PREC_ANN_1D = ndtooned(PREC_ANN) + TNPP_C_1D = ndtooned(TNPP_C) + +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN_1D),max(RAIN_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = PREC_ANN_1D + npp_data = TNPP_C_1D + else + data = RAIN_1D + npp_data = NPP_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then + print("") + print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else + print("") + print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; + print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) + print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do + + xvalues@long_name = "Mean Annual precipitation (m/year)" + yvalues@long_name = "NPP (g C/m2/year)" + +; +; Start the graphics. +; +; wks = gsn_open_wks("x11","npp") + wks = gsn_open_wks("png","npp") + + res = True + res@tiMainString = "Observed vs i01.03cn" +; res@tiMainString = "Observed vs i01.04casa" + res@gsnMaximize = False + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 +; res@xyMarkerColors = (/"Gray25","Gray50"/) + res@xyMarkerColors = (/"brown","blue"/) + res@trYMinF = min(mn_yvalues) - 10. + res@trYMaxF = max(mx_yvalues) + 10. + + xy = gsn_csm_xy(wks,xvalues,yvalues,res) + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + + line_colors = (/"brown","blue"/) + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + +end + diff -r 000000000000 -r 0c6405ab2ff4 npp/22.histogram.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/22.histogram.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,238 @@ + +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; +; Main code. +; +begin + data_types = (/ "Obs", "Model" /) + data_names = (/ "data.81.nc", "i01.03cn_1545-1569_ANN_climo.nc" /) +; data_names = (/ "data.81.nc", "i01.04casa_1605-1629_ANN_climo.nc" /) +; filevar_names = (/ (/"PREC_ANN","TNPP_C"/), (/"RAIN","NPP"/) /) + filevar_names = (/ (/"PREC_ANN","ANPP_C"/), (/"RAIN","AGNPP"/) /) + ndata_types = dimsizes(data_types) + + data_file_obs = addfile(data_names(0),"r") ; Open obs file + data_file_mod = addfile(data_names(1),"r") ; Open model file + +;************************************************ +; read in data: observed +;************************************************ + PREC_ANN = tofloat(data_file_obs->PREC_ANN) + TNPP_C = data_file_obs->TNPP_C + xo = data_file_obs->LONG_DD + yo = data_file_obs->LAT_DD + +; change longitude from (-180,180) to (0,360) +;print (xo) + nx = dimsizes(xo) + do i= 0,nx-1 + if (xo(i) .lt. 0.) then + xo(i) = xo(i)+ 360. + end if + end do +;print (xo) + +;************************************************ +; read in data: model +;************************************************ + ai = data_file_mod->RAIN + bi = data_file_mod->NPP + xi = data_file_mod->lon + yi = data_file_mod->lat + +;************************************************ +; interpolate from model grid to observed grid +;************************************************ + RAIN = linint2_points(xi,yi,ai,True,xo,yo,0) + NPP = linint2_points(xi,yi,bi,True,xo,yo,0) + +;************************************************ +; convert unit +;************************************************ +; Units for these four variables are: +; +; PREC_ANN : mm/year +; TNPP_C : g C/m^2/year +; RAIN : mm/s +; NPP : g C/m^2/s +; +; We want to convert these to "m/year" and "g C/m^2/year". +; + nsec_per_year = 60*60*24*365 ; # seconds per year + +; Do the necessary conversions. + PREC_ANN = PREC_ANN / 1000. + RAIN = (RAIN / 1000.) * nsec_per_year + NPP = NPP * nsec_per_year + +; Redo the units. + PREC_ANN@units = "m/yr" + RAIN@units = "m/yr" + NPP@units = "gC/m^2/yr" + TNPP_C@units = "gC/m^2/yr" + +;************************************************ + pminmax(PREC_ANN,"PREC_ANN") + pminmax(TNPP_C,"TNPP_C") + pminmax(RAIN,"RAIN") + pminmax(NPP,"NPP") + + RAIN_1D = ndtooned(RAIN) + NPP_1D = ndtooned(NPP) + PREC_ANN_1D = ndtooned(PREC_ANN) + TNPP_C_1D = ndtooned(TNPP_C) + +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN_1D),max(RAIN_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = PREC_ANN_1D + npp_data = TNPP_C_1D + else + data = RAIN_1D + npp_data = NPP_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then + print("") + print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else + print("") + print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; + print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) + print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do + + xvalues@long_name = "Mean Annual precipitation (m/year)" + yvalues@long_name = "NPP (g C/m2/year)" + +; +; Start the graphics. +; + wks = gsn_open_wks("png","npp") + + res = True + res@gsnMaximize = False + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 +; res@xyMarkerColors = (/"Gray25","Gray50"/) + res@xyMarkerColors = (/"brown","blue"/) + res@trYMinF = min(mn_yvalues) - 10. + res@trYMaxF = max(mx_yvalues) + 10. +; res@tiMainString = "Observed vs i01.03cn_81site" + res@tiMainString = "Observed vs i01.04casa_81site" + + xy = gsn_csm_xy(wks,xvalues,yvalues,res) + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + + line_colors = (/"brown","blue"/) + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + +end + diff -r 000000000000 -r 0c6405ab2ff4 npp/23.histogram.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/23.histogram.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,307 @@ +;******************************************************** +; histogram normalized by rain +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; +; Main code. +; +begin + data_types = (/ "Obs", "Model" /) +; data_names = (/ "data.81.nc" , "i01.03cn_1545-1569_ANN_climo.nc" /) +; data_names = (/ "data.933.nc", "i01.03cn_1545-1569_ANN_climo.nc" /) +; data_names = (/ "data.81.nc" , "i01.04casa_1605-1629_ANN_climo.nc" /) + data_names = (/ "data.933.nc", "i01.04casa_1605-1629_ANN_climo.nc" /) + filevar_names = (/ (/"PREC_ANN","TNPP_C"/), (/"RAIN","NPP"/) /) + ndata_types = dimsizes(data_types) + + data_file_obs = addfile(data_names(0),"r") ; Open obs file + data_file_mod = addfile(data_names(1),"r") ; Open model file + +;************************************************ +; read in data: observed +;************************************************ +;RAIN1 = tofloat(data_file_obs->PREC_ANN) ; for data.81 + RAIN1 = data_file_obs->PREC ; for data.933 + NPP1 = data_file_obs->TNPP_C + xo = data_file_obs->LONG_DD + yo = data_file_obs->LAT_DD + +; change longitude from (-180,180) to (0,360) + print (xo) + nx = dimsizes(xo) + do i= 0,nx-1 + if (xo(i) .lt. 0.) then + xo(i) = xo(i)+ 360. + end if + end do + print (xo) + +;************************************************ +; read in data: model +;************************************************ + ai = data_file_mod->RAIN + bi = data_file_mod->NPP + xi = data_file_mod->lon + yi = data_file_mod->lat + +;************************************************ +; interpolate from model grid to observed grid +;************************************************ + RAIN2 = linint2_points(xi,yi,ai,True,xo,yo,0) + NPP2 = linint2_points(xi,yi,bi,True,xo,yo,0) + +;************************************************ +; convert unit +;************************************************ +; Units for these four variables are: +; +; RAIN1 : mm/year +; RAIN2 : mm/s +; NPP1 : g C/m^2/year +; NPP2 : g C/m^2/s +; +; We want to convert these to "m/year" and "g C/m^2/year". +; + nsec_per_year = 60*60*24*365 ; # seconds per year + +; Do the necessary conversions. + RAIN1 = RAIN1 / 1000. + RAIN2 = (RAIN2/ 1000.) * nsec_per_year + NPP2 = NPP2 * nsec_per_year + +; Redo the units. + RAIN1@units = "m/yr" + RAIN2@units = "m/yr" + NPP1@units = "gC/m^2/yr" + NPP2@units = "gC/m^2/yr" + +;************************************************ +; print min/max and unit +;************************************************ + pminmax(RAIN1,"RAIN1") + pminmax(RAIN2,"RAIN2") + pminmax(NPP1,"NPP1") + pminmax(NPP2,"NPP2") + + RAIN1_1D = ndtooned(RAIN1) + RAIN2_1D = ndtooned(RAIN2) + NPP1_1D = ndtooned(NPP1) + NPP2_1D = ndtooned(NPP2) +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN2_1D),max(RAIN2_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN2_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN2_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN2_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN2_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do + +; +; Start the graphics. +; + wks = gsn_open_wks("png","npp") + + res = True + res@gsnMaximize = True + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 + res@xyMarkerColors = (/"Brown","Blue"/) + res@trYMinF = min(mn_yvalues) - 10. + res@trYMaxF = max(mx_yvalues) + 10. + +; res@tiMainString = "Observerd vs i01.03cn 81site" +; res@tiMainString = "Observerd vs i01.03cn 933site" +; res@tiMainString = "Observerd vs i01.04casa_81site" + res@tiMainString = "Observerd vs i01.04casa 933site" + res@tiYAxisString = "NPP (g C/m2/year)" + res@tiXAxisString = "Precipitation (m/year)" + +; +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. +; + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 +; res@xyExplicitLegendLabels = (/"observed","model_i01.03cn"/) + res@xyExplicitLegendLabels = (/"observed","model_i01.04casa"/) + + xy = gsn_csm_xy(wks,xvalues,yvalues,res) + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + + line_colors = (/"brown","blue"/) + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + +; +; Here's how to do the legend by hand. +; +; mkres = True ; Marker resources +; txres = True ; Text resources +; mkres@gsMarkerIndex = 16 +; mkres@gsMarkerSizeF = 0.02 +; txres@txFontHeightF = 0.02 +; txres@txJust = "CenterLeft" +; +; Change these values if you want to move the marker legend location. +; These values are in the same data space as the plot. +; +; xlg1_cen = 0.2 +; ylg1_cen = 900. + +; xlg2_cen = 0.2 +; ylg2_cen = 760. + +; mkres@gsMarkerColor = "brown" +; lnres@gsLineColor = "brown" + +; lg_mark_legend1 = gsn_add_polymarker(wks,xy,xlg1_cen,ylg1_cen,mkres) +; lg_line_legend1 = gsn_add_polyline(wks,xy,(/xlg1_cen,xlg1_cen/), \ +; (/ylg1_cen-60,ylg1_cen+60/),lnres) +; lg_cap_legend11 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen-60,ylg1_cen-60/),lnres) +; lg_cap_legend12 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen+60,ylg1_cen+60/),lnres) + +; tx_legend1 = gsn_add_text(wks,xy,"observed",xlg1_cen+0.15,ylg1_cen,txres) + +; mkres@gsMarkerColor = "blue" +; lnres@gsLineColor = "blue" + +; lg_mark_legend2 = gsn_add_polymarker(wks,xy,xlg2_cen,ylg2_cen,mkres) +; lg_line_legend2 = gsn_add_polyline(wks,xy,(/xlg2_cen,xlg2_cen/), \ +; (/ylg2_cen-60,ylg2_cen+60/),lnres) +; lg_cap_legend21 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen-60,ylg2_cen-60/),lnres) +; lg_cap_legend22 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen+60,ylg2_cen+60/),lnres) +; tx_legend2 = gsn_add_text(wks,xy,"model_i01.03cn",xlg2_cen+0.15,ylg2_cen,txres) + + draw(xy) + frame(wks) + +end + diff -r 000000000000 -r 0c6405ab2ff4 npp/24.histogram+bias.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/24.histogram+bias.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,329 @@ +;******************************************************** +; histogram normalized by rain and compute correleration +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; +; Main code. +; +begin + data_types = (/ "Obs", "Model" /) + data_names = (/ "data.81.nc" , "i01.03cn_1545-1569_ANN_climo.nc" /) +; data_names = (/ "data.933.nc", "i01.03cn_1545-1569_ANN_climo.nc" /) +; data_names = (/ "data.81.nc" , "i01.04casa_1605-1629_ANN_climo.nc" /) +; data_names = (/ "data.933.nc", "i01.04casa_1605-1629_ANN_climo.nc" /) + filevar_names = (/ (/"PREC_ANN","TNPP_C"/), (/"RAIN","NPP"/) /) + ndata_types = dimsizes(data_types) + + data_file_obs = addfile(data_names(0),"r") ; Open obs file + data_file_mod = addfile(data_names(1),"r") ; Open model file + +;************************************************ +; read in data: observed +;************************************************ + RAIN1 = tofloat(data_file_obs->PREC_ANN) ; for data.81 +;RAIN1 = data_file_obs->PREC ; for data.933 + NPP1 = data_file_obs->TNPP_C + xo = data_file_obs->LONG_DD + yo = data_file_obs->LAT_DD + +; change longitude from (-180,180) to (0,360) + print (xo) + nx = dimsizes(xo) + do i= 0,nx-1 + if (xo(i) .lt. 0.) then + xo(i) = xo(i)+ 360. + end if + end do + print (xo) + +;************************************************ +; read in data: model +;************************************************ + ai = data_file_mod->RAIN + bi = data_file_mod->NPP + xi = data_file_mod->lon + yi = data_file_mod->lat + +;************************************************ +; interpolate from model grid to observed grid +;************************************************ + RAIN2 = linint2_points(xi,yi,ai,True,xo,yo,0) + NPP2 = linint2_points(xi,yi,bi,True,xo,yo,0) + +;************************************************ +; convert unit +;************************************************ +; Units for these four variables are: +; +; RAIN1 : mm/year +; RAIN2 : mm/s +; NPP1 : g C/m^2/year +; NPP2 : g C/m^2/s +; +; We want to convert these to "m/year" and "g C/m^2/year". +; + nsec_per_year = 60*60*24*365 ; # seconds per year + +; Do the necessary conversions. + RAIN1 = RAIN1 / 1000. + RAIN2 = (RAIN2/ 1000.) * nsec_per_year + NPP2 = NPP2 * nsec_per_year + +; Redo the units. + RAIN1@units = "m/yr" + RAIN2@units = "m/yr" + NPP1@units = "gC/m^2/yr" + NPP2@units = "gC/m^2/yr" + +;************************************************ +; print min/max and unit +;************************************************ + pminmax(RAIN1,"RAIN1") + pminmax(RAIN2,"RAIN2") + pminmax(NPP1,"NPP1") + pminmax(NPP2,"NPP2") + + RAIN1_1D = ndtooned(RAIN1) + RAIN2_1D = ndtooned(RAIN2) + NPP1_1D = ndtooned(NPP1) + NPP2_1D = ndtooned(NPP2) +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN2_1D),max(RAIN2_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN2_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN2_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN2_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN2_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do + +; +; Start the graphics. +; + wks = gsn_open_wks("png","xy") + + res = True + res@gsnMaximize = True + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 + res@xyMarkerColors = (/"Brown","Blue"/) + res@trYMinF = min(mn_yvalues) - 10. + res@trYMaxF = max(mx_yvalues) + 10. + +; res@tiMainString = "Observed vs i01.03cn 81 site" +; res@tiMainString = "Observed vs i01.03cn 933 site" + res@tiMainString = "Observed vs i01.04casa 81 site" +; res@tiMainString = "Observed vs i01.04casa 933 site" + res@tiYAxisString = "NPP (g C/m2/year)" + res@tiXAxisString = "Precipitation (m/year)" + +; +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. +; + res@pmLegendDisplayMode = "Always" +; res@pmLegendWidthF = 0.1 + res@pmLegendWidthF = 0.08 + res@pmLegendHeightF = 0.05 + res@pmLegendOrthogonalPosF = -1.17 +; res@pmLegendOrthogonalPosF = -1.00 ;(downward) +; res@pmLegendParallelPosF = 0.18 + res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False + res@lgLabelFontHeightF = 0.015 +; res@xyExplicitLegendLabels = (/"observed","model_i01.03cn"/) + res@xyExplicitLegendLabels = (/"observed","model_i01.04casa"/) + + xy = gsn_csm_xy(wks,xvalues,yvalues,res) + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + + line_colors = (/"brown","blue"/) + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + +; +; Here's how to do the legend by hand. +; +; mkres = True ; Marker resources +; txres = True ; Text resources +; mkres@gsMarkerIndex = 16 +; mkres@gsMarkerSizeF = 0.02 +; txres@txFontHeightF = 0.02 +; txres@txJust = "CenterLeft" +; +; Change these values if you want to move the marker legend location. +; These values are in the same data space as the plot. +; +; xlg1_cen = 0.2 +; ylg1_cen = 900. + +; xlg2_cen = 0.2 +; ylg2_cen = 760. + +; mkres@gsMarkerColor = "brown" +; lnres@gsLineColor = "brown" + +; lg_mark_legend1 = gsn_add_polymarker(wks,xy,xlg1_cen,ylg1_cen,mkres) +; lg_line_legend1 = gsn_add_polyline(wks,xy,(/xlg1_cen,xlg1_cen/), \ +; (/ylg1_cen-60,ylg1_cen+60/),lnres) +; lg_cap_legend11 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen-60,ylg1_cen-60/),lnres) +; lg_cap_legend12 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen+60,ylg1_cen+60/),lnres) + +; tx_legend1 = gsn_add_text(wks,xy,"observed",xlg1_cen+0.15,ylg1_cen,txres) + +; mkres@gsMarkerColor = "blue" +; lnres@gsLineColor = "blue" + +; lg_mark_legend2 = gsn_add_polymarker(wks,xy,xlg2_cen,ylg2_cen,mkres) +; lg_line_legend2 = gsn_add_polyline(wks,xy,(/xlg2_cen,xlg2_cen/), \ +; (/ylg2_cen-60,ylg2_cen+60/),lnres) +; lg_cap_legend21 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen-60,ylg2_cen-60/),lnres) +; lg_cap_legend22 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen+60,ylg2_cen+60/),lnres) +; tx_legend2 = gsn_add_text(wks,xy,"model_i01.03cn",xlg2_cen+0.15,ylg2_cen,txres) + + draw(xy) + frame(wks) + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + nz = dimsizes(uu) + print (nz) + + ccr = esccr(uu,vv,0) + print (ccr) + +;old eq +;bias = sum(((vv-uu)/uu)^2) +;M = (1.- sqrt(bias/nz))*5. + +;new eq + bias = sum(abs(vv-uu)/(vv+uu)) + M = (1.- (bias/nz))*5. + print (bias) + print (M) + +end + diff -r 000000000000 -r 0c6405ab2ff4 npp/24.histogram_ob.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/24.histogram_ob.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,306 @@ +;******************************************************** +; histogram normalized by rain and compute correleration +;******************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" + +procedure pminmax(data:numeric,name:string) +begin + print ("min/max " + name + " = " + min(data) + "/" + max(data)) + if(isatt(data,"units")) then + print (name + " units = " + data@units) + end if +end + +; +; Main code. +; +begin + data_types = (/ "Obs", "Model" /) + data_names = (/ "data.81.nc" , "i01.03cn_1545-1569_ANN_climo.nc" /) +; data_names = (/ "data.933.nc", "i01.03cn_1545-1569_ANN_climo.nc" /) +; data_names = (/ "data.81.nc" , "i01.04casa_1605-1629_ANN_climo.nc" /) +; data_names = (/ "data.933.nc", "i01.04casa_1605-1629_ANN_climo.nc" /) + filevar_names = (/ (/"PREC_ANN","TNPP_C"/), (/"RAIN","NPP"/) /) + ndata_types = dimsizes(data_types) + + data_file_obs = addfile(data_names(0),"r") ; Open obs file + data_file_mod = addfile(data_names(1),"r") ; Open model file + +;************************************************ +; read in data: observed +;************************************************ + RAIN1 = tofloat(data_file_obs->PREC_ANN) ; for data.81 +;RAIN1 = data_file_obs->PREC ; for data.933 + NPP1 = data_file_obs->TNPP_C + xo = data_file_obs->LONG_DD + yo = data_file_obs->LAT_DD + +; change longitude from (-180,180) to (0,360) + print (xo) + nx = dimsizes(xo) + do i= 0,nx-1 + if (xo(i) .lt. 0.) then + xo(i) = xo(i)+ 360. + end if + end do + print (xo) + +;************************************************ +; read in data: model +;************************************************ + ai = data_file_mod->RAIN + bi = data_file_mod->NPP + xi = data_file_mod->lon + yi = data_file_mod->lat + +;************************************************ +; interpolate from model grid to observed grid +;************************************************ + RAIN2 = linint2_points(xi,yi,ai,True,xo,yo,0) + NPP2 = linint2_points(xi,yi,bi,True,xo,yo,0) + +;************************************************ +; convert unit +;************************************************ +; Units for these four variables are: +; +; RAIN1 : mm/year +; RAIN2 : mm/s +; NPP1 : g C/m^2/year +; NPP2 : g C/m^2/s +; +; We want to convert these to "m/year" and "g C/m^2/year". +; + nsec_per_year = 60*60*24*365 ; # seconds per year + +; Do the necessary conversions. + RAIN1 = RAIN1 / 1000. + RAIN2 = (RAIN2/ 1000.) * nsec_per_year + NPP2 = NPP2 * nsec_per_year + +; Redo the units. + RAIN1@units = "m/yr" + RAIN2@units = "m/yr" + NPP1@units = "gC/m^2/yr" + NPP2@units = "gC/m^2/yr" + +;************************************************ +; print min/max and unit +;************************************************ + pminmax(RAIN1,"RAIN1") + pminmax(RAIN2,"RAIN2") + pminmax(NPP1,"NPP1") + pminmax(NPP2,"NPP2") + + RAIN1_1D = ndtooned(RAIN1) + RAIN2_1D = ndtooned(RAIN2) + NPP1_1D = ndtooned(NPP1) + NPP2_1D = ndtooned(NPP2) +; +; Calculate some "nice" bins for binning the data in equally spaced +; ranges. +; + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN2_1D),max(RAIN2_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) +; +; Use this range information to grab all the values in a +; particular range, and then take an average. +; + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),typeof(RAIN2_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + yvalues = new((/2,nx/),typeof(RAIN2_1D)) + mn_yvalues = new((/2,nx/),typeof(RAIN2_1D)) + mx_yvalues = new((/2,nx/),typeof(RAIN2_1D)) + + do nd=0,1 +; +; See if we are doing model or observational data. +; + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if +; +; Loop through each range and check for values. +; + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if +; +; Calculate average, and get min and max. +; + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if +; +; Print out information. +; +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; +; Clean up for next time in loop. +; + delete(idx) + end do + delete(data) + delete(npp_data) + end do + +; +; Start the graphics. +; + wks = gsn_open_wks("png","hist") + + res = True + res@gsnMaximize = True + res@gsnDraw = False + res@gsnFrame = False + res@xyMarkLineMode = "Markers" + res@xyMarkerSizeF = 0.014 + res@xyMarker = 16 + res@xyMarkerColors = (/"Brown","Blue"/) + res@trYMinF = min(mn_yvalues) - 10. + res@trYMaxF = max(mx_yvalues) + 10. + + res@tiMainString = "Observed 81 sites" +; res@tiMainString = "Observed 933 sites" + res@tiYAxisString = "NPP (g C/m2/year)" + res@tiXAxisString = "Precipitation (m/year)" + +; +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. +; +; res@pmLegendDisplayMode = "Always" +;;res@pmLegendWidthF = 0.1 +; res@pmLegendWidthF = 0.08 +; res@pmLegendHeightF = 0.05 +; res@pmLegendOrthogonalPosF = -1.17 +;;res@pmLegendOrthogonalPosF = -1.00 ;(downward) +;;res@pmLegendParallelPosF = 0.18 +; res@pmLegendParallelPosF = 0.23 ;(rightward) + +; res@lgPerimOn = False +; res@lgLabelFontHeightF = 0.015 +; res@xyExplicitLegendLabels = (/"observed","model_i01.03cn"/) +;;res@xyExplicitLegendLabels = (/"observed","model_i01.04casa"/) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),res) + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + + line_colors = (/"brown","blue"/) +; do nd=0,1 + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + +; +; Here's how to do the legend by hand. +; +; mkres = True ; Marker resources +; txres = True ; Text resources +; mkres@gsMarkerIndex = 16 +; mkres@gsMarkerSizeF = 0.02 +; txres@txFontHeightF = 0.02 +; txres@txJust = "CenterLeft" +; +; Change these values if you want to move the marker legend location. +; These values are in the same data space as the plot. +; +; xlg1_cen = 0.2 +; ylg1_cen = 900. + +; xlg2_cen = 0.2 +; ylg2_cen = 760. + +; mkres@gsMarkerColor = "brown" +; lnres@gsLineColor = "brown" + +; lg_mark_legend1 = gsn_add_polymarker(wks,xy,xlg1_cen,ylg1_cen,mkres) +; lg_line_legend1 = gsn_add_polyline(wks,xy,(/xlg1_cen,xlg1_cen/), \ +; (/ylg1_cen-60,ylg1_cen+60/),lnres) +; lg_cap_legend11 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen-60,ylg1_cen-60/),lnres) +; lg_cap_legend12 = gsn_add_polyline(wks,xy,(/xlg1_cen-0.1,xlg1_cen+0.1/), \ +; (/ylg1_cen+60,ylg1_cen+60/),lnres) + +; tx_legend1 = gsn_add_text(wks,xy,"observed",xlg1_cen+0.15,ylg1_cen,txres) + +; mkres@gsMarkerColor = "blue" +; lnres@gsLineColor = "blue" + +; lg_mark_legend2 = gsn_add_polymarker(wks,xy,xlg2_cen,ylg2_cen,mkres) +; lg_line_legend2 = gsn_add_polyline(wks,xy,(/xlg2_cen,xlg2_cen/), \ +; (/ylg2_cen-60,ylg2_cen+60/),lnres) +; lg_cap_legend21 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen-60,ylg2_cen-60/),lnres) +; lg_cap_legend22 = gsn_add_polyline(wks,xy,(/xlg2_cen-0.1,xlg2_cen+0.1/), \ +; (/ylg2_cen+60,ylg2_cen+60/),lnres) +; tx_legend2 = gsn_add_text(wks,xy,"model_i01.03cn",xlg2_cen+0.15,ylg2_cen,txres) + + draw(xy) + frame(wks) + +end + diff -r 000000000000 -r 0c6405ab2ff4 npp/31.contour_model.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/31.contour_model.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,65 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read in netCDF file +;************************************************ +; fili = "Npp_0.05deg_mean.nc" + fili = "Npp_T42_mean.nc" +; fili = "i01.03cn_1545-1569_ANN_climo.nc" +; fili = "i01.04casa_1605-1629_ANN_climo.nc" + + a = addfile(fili,"r") + +;************************************************ +; read in data +;************************************************ +; x = a->NPP(::10,::10) ; for observed 0.05deg + x = a->NPP + + nsec_per_year = 60*60*24*365 + +;scale_factor = nsec_per_year ; for model + scale_factor = 1. ; for observed T42 +;scale_factor = 0.1 ; for observed 0.05deg + + x = x * scale_factor + + x@units = "gC/m^2/year" +;************************************************ +; create default plot +;************************************************ + +; setvalues NhlGetWorkspaceObjectId() +; "wsMaximumSize" : 199999999 +; end setvalues + + wks = gsn_open_wks("png","xy") ; open a ps file +; gsn_define_colormap(wks,"wgne15") ; choose colormap + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@tiMainString = "Observed MODIS MOD 17" +; res@tiMainString = "Model i01.03cn" +; res@tiMainString = "Model i01.04casa" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 2200. ; Max level + res@cnLevelSpacingF = 200. ; interval + + plot = gsn_csm_contour_map_ce(wks,x,res) ; for observed +; plot = gsn_csm_contour_map_ce(wks,x(0,:,:),res) ; for model + +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 npp/31.contour_ob.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/31.contour_ob.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,58 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ +;f = addfile ("Npp_0.05deg_mean.nc","r") +;y = f->NPP(::10,::10) ; for observed 0.05deg + f = addfile ("Npp_T42_mean.nc","r") + y = f->NPP +;************************************************ +; read in model data +;************************************************ + g = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") +;g = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + x = g->NPP + + delta = 0.00000000001 + x0 = x(0,:,:) + y = where(ismissing(y).and.(ismissing(x0).or.(x0.lt.delta)),0.,y) + + y@units = "gC/m^2/year" +;************************************************ +; create default plot +;************************************************ + +; setvalues NhlGetWorkspaceObjectId() +; "wsMaximumSize" : 199999999 +; end setvalues + + wks = gsn_open_wks("png","xy") ; open a ps file +; gsn_define_colormap(wks,"wgne15") ; choose colormap + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@tiMainString = "Observed MODIS MOD 17" +; res@tiMainString = "Model i01.03cn" +; res@tiMainString = "Model i01.04casa" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 2200. ; Max level + res@cnLevelSpacingF = 200. ; interval + + plot = gsn_csm_contour_map_ce(wks,y,res) ; for observed + +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 npp/32.contour_diff.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/32.contour_diff.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,87 @@ +;************************************************* +; ce_1.ncl +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + f = addfile ("Npp_T42_mean.nc","r") + y = f->NPP +;************************************************ +; read in model data +;************************************************ + g = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") +;g = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + x = g->NPP + + nsec_per_year = 86400.*365. + x = x * nsec_per_year + + x@units = "gC/m^2/year" +;************************************************ +;fill ob missing grid the same as model +;************************************************ + delta = 0.00001 + x0 = x(0,:,:) + y = where(ismissing(y).and.(ismissing(x0).or.(x0.lt.delta)),0.,y) + + y@units = "gC/m^2/year" +;************************************************ +;model - observed +;************************************************ + z = x + z = x(0,:,:) - y(:,:) +;************************************************ +; create 3 plots +;************************************************ + wks = gsn_open_wks("ps","xy") ; open a ps file + gsn_define_colormap(wks,"gui_default") ; choose colormap + + res = True ; Use plot options + res@cnFillOn = True ; Turn on color fill + res@gsnSpreadColors = True ; use full colormap +; res@cnFillMode = "RasterFill" ; Turn on raster color +; res@lbLabelAutoStride = True + res@cnLinesOn = False ; Turn off contourn lines + res@mpFillOn = False ; Turn off map fill + res@tiMainString = "Observed MODIS MOD 17" + + res@gsnSpreadColors = True ; use full colormap + res@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + res@cnMinLevelValF = 0. ; Min level + res@cnMaxLevelValF = 2200. ; Max level + res@cnLevelSpacingF = 200. ; interval + + res@gsnFrame = False ; Do not draw plot + res@gsnDraw = False ; Do not advance frame + + plot=new(3,graphic) ; create graphic array + + plot(0) = gsn_csm_contour_map_ce(wks,y,res) ; for observed + + res@tiMainString = "Model i01.03cn" +; res@tiMainString = "Model i01.04casa" + plot(1) = gsn_csm_contour_map_ce(wks,x(0,:,:),res) ; for model + + res@cnMinLevelValF = -500 ; Min level + res@cnMaxLevelValF = 500. ; Max level + res@cnLevelSpacingF = 50. ; interval + res@tiMainString = "(Model i01.03cn) - (observed)" +; res@tiMainString = "(Model i01.04casa) - (observed)" + plot(2) = gsn_csm_contour_map_ce(wks,z(0,:,:),res) ; for model - ob + +;*********************************************** +; create panel plot +;*********************************************** + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert xy.ps xy.png") +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 npp/41.correlation.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/41.correlation.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,49 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +;************************************************ +begin +;************************************************ +; read in data +;************************************************ + g = addfile ("data.81.nc","r") + a = g->SITE_ID + xo = g->LONG_DD + yo = g->LAT_DD +;c = g->TNPP_C +;c = g->ANPP_C + c = g->BNPP_C + + print (xo) + nx = dimsizes(xo) + do i= 0,nx-1 + if (xo(i) .lt. 0.) then + xo(i) = xo(i)+ 360. + end if + end do + print (xo) + + a@long_name = "SITE_ID" + + f = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") +;f = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") +;b = f->NPP +;b = f->AGNPP + b = f->BGNPP + xi = f->lon + yi = f->lat + + sec_to_year = 86400.*365. + + bo = linint2_points(xi,yi,b,True,xo,yo,0) * sec_to_year +;print (bo) + + bo@long_name = "NPP (gC/m2/year)" + + ccr = esccr(bo,c,0) + + print (ccr) + +end diff -r 000000000000 -r 0c6405ab2ff4 npp/41.correlation_zonal.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/41.correlation_zonal.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,31 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data +;************************************************ + g = addfile ("Npp_T31_mean.nc","r") + c = g->NPP + u = zonalAve(c) + +;f = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") + f = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + b = f->NPP + + sec_to_year = 86400.*365. + + b = b * sec_to_year + v = zonalAve(b) + + b@long_name = "NPP (gC/m2/year)" + + ccr = esccr(u,v(0,:),0) + + print (ccr) + +end diff -r 000000000000 -r 0c6405ab2ff4 npp/42.bias_global.nc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/42.bias_global.nc Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,43 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data +;************************************************ + g = addfile ("Npp_T42_mean.nc","r") + c = g->NPP + u = ndtooned(c) + +;f = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") + f = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + b = f->NPP + v = ndtooned(b) + + sec_to_year = 86400.*365. + v = v * sec_to_year + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + nx = dimsizes(uu) +;print (nx) + + do i = 0,nx-1 + if (uu(i) .lt. 1.) then + uu(i) =10. + end if + end do + + ccr = esccr(uu,v(good),0) + print (ccr) +;print (uu) + bias = sum(((v(good)-uu)/uu)^2) + print (bias) + M = 1.- sqrt(bias/nx) + print (M) + +end diff -r 000000000000 -r 0c6405ab2ff4 npp/42.bias_normalized.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/42.bias_normalized.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,60 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data +;************************************************ + g = addfile ("data.81.nc","r") + a = g->SITE_ID + xo = g->LONG_DD + yo = g->LAT_DD + c = g->TNPP_C +;c = g->ANPP_C +;c = g->BNPP_C + cp = g->PREC_ANN + do i= 0,dimsizes(cp)-1 + if (ismissing(cp(i))) then + cp (i) = 100 + end if + end do + d = int2flt(c)/int2flt(cp) + print (d) + + nx = dimsizes(xo) + do i= 0,nx-1 + if (xo(i) .lt. 0.) then + xo(i) = xo(i)+ 360. + end if + end do +;print (xo) + + f = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") +;f = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + b = f->NPP +;b = f->AGNPP +;b = f->BGNPP + xi = f->lon + yi = f->lat + bp = f->RAIN + + sec_to_year = 86400.*365. + + bo = linint2_points(xi,yi,b,True,xo,yo,0) * sec_to_year +;print (bo) + bq = linint2_points(xi,yi,bp,True,xo,yo,0) * sec_to_year + + bo = bo/bq + + ccr = esccr(bo,d,0) + print (ccr) + bias = sum(((bo(0,:)-d(:))/d(:))^2) + print (bias) + M = 1. - sqrt(bias/nx) + print (M) + +end diff -r 000000000000 -r 0c6405ab2ff4 npp/42.bias_zonal.nc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/42.bias_zonal.nc Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,42 @@ +; *********************************************** +; xy_4.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + f = addfile ("Npp_T42_mean.nc","r") + y = f->NPP +;************************************************ +; read in model data +;************************************************ + g = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") +;g = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + x = g->NPP + + delta = 0.00000000001 + x0 = x(0,:,:) + y = where(ismissing(y).and.(ismissing(x0).or.(x0.lt.delta)),0.,y) + + p = zonalAve(y) + + sec_to_year = 86400.*365. + x0 = x0 * sec_to_year + q = zonalAve(x0) + + good = ind(p .ne. 0.) + u = p(good) + v = q(good) + + ccr = esccr(u,v,0) + print (ccr) + bias = sum(((v-u)/u)^2) + print (bias) + M = 1.- sqrt(bias/dimsizes(u)) + print (M) + +end diff -r 000000000000 -r 0c6405ab2ff4 npp/51.zonavg.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/51.zonavg.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,32 @@ +; *********************************************** +; xy_1.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data +;************************************************ +;f = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") + f = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + u = f->NPP + v = zonalAve(u) + + nsec_per_year = 60*60*24*365 + + v = v * nsec_per_year + + v@long_name = "NPP (gC/m2/year)" +;************************************************ +; plotting parameters +;************************************************ + wks = gsn_open_wks ("png","xy") + + res = True +;res@tiMainString = "Model i01.03cn" + res@tiMainString = "Model i01.04casa" + + plot = gsn_csm_xy (wks,v&lat,v(0,:),res) +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 npp/51.zonavg_ob.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/51.zonavg_ob.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,26 @@ +; *********************************************** +; xy_1.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data +;************************************************ + f = addfile ("Npp_T31_mean.nc","r") + u = f->NPP + v = zonalAve(u) + + v@long_name = "NPP (gC/m2/year)" +;************************************************ +; plotting parameters +;************************************************ + wks = gsn_open_wks ("png","xy") + + res = True + res@tiMainString = "Observed" + + plot = gsn_csm_xy (wks,v&lat,v,res) +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 npp/51.zonavg_ob2.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/51.zonavg_ob2.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,49 @@ +; *********************************************** +; xy_1.ncl +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in data +;************************************************ + f = addfile ("Npp_T42_mean.nc","r") + u = f->NPP +;************************************************ +; read in model data +;************************************************ + g = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") + x = g->NPP + lat = g->lat + lon = g->lon + + delta = 0.00000000001 + x0 = x(0,:,:) + u = where(ismissing(u).and.(ismissing(x0).or.(x0.lt.delta)),0.,u) + +; do j = 0,dimsizes(lat)-1 +; do i = 0,dimsizes(lon)-1 +; print(u(j,i)) +; print(x(0,j,i)) +; if (ismissing(u(j,i)) .and. (ismissing(x(0,j,i)).or. \ +; x(0,j,i) .lt. 0.00000000001)) then +; u(j,i) = 0. +; end if +; end do +; end do + + v = zonalAve(u) + + v@long_name = "NPP (gC/m2/year)" +;************************************************ +; plotting parameters +;************************************************ + wks = gsn_open_wks ("png","xy") + + res = True + res@tiMainString = "Observed MODIS MOD 17" + + plot = gsn_csm_xy (wks,v&lat,v,res) +end \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 npp/52.zonavg_to_T31.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/52.zonavg_to_T31.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,62 @@ +; *********************************************** +; zonal average plot +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin +;************************************************ +; read in observed data +;************************************************ + g = addfile ("Npp_0.05deg_mean.nc","r") + bi = g->NPP + xi = g->lon + yi = g->lat + yi = (/ yi(::-1) /) + bi = (/ bi(::-1,:) /) + b2 = bi + x2 = xi + + nx = dimsizes(xi) + do i= 0,nx-1 + if (i .lt. 3600) then + p = i + 3600 + xi(p) = x2(i) + 360. + else + p = i - 3600 + xi(p) = x2(i) + end if + bi(:,p)= b2(:,i) + end do +;print (xi) +;print (yi) +;exit + + f = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") +;f = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + + xo = f->lon + yo = f->lat + + print (xi) + print (yi) + print (xo) + print (yo) + + bo = linint2_Wrap(xi,yi,bi,True,xo,yo,0) + + v = zonalAve(bo) + + v@long_name = "NPP (gC/m2/year)" + +;************************************************ +; plotting parameters +;************************************************ + wks = gsn_open_wks ("png","xy") ; open workstation + + res = True ; plot mods desired + res@tiMainString = "Observed T31" ; add title + + plot = gsn_csm_xy (wks,v&lat,v,res) +end diff -r 000000000000 -r 0c6405ab2ff4 npp/53.zonavg_3line.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/53.zonavg_3line.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,125 @@ +; *********************************************** +; zonal average plot +; *********************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +;************************************************ +; read in observed data +;************************************************ + + a = addfile ("Npp_T42_mean.nc","r") + b = addfile ("i01.03cn_1545-1569_ANN_climo.nc","r") + c = addfile ("i01.04casa_1605-1629_ANN_climo.nc","r") + + ta = a->NPP + tb = b->NPP + tc = c->NPP + + lon = a->lon + lat = a->lat + nlon = dimsizes(lon) + nlat = dimsizes(lat) + + s = new ((/3,nlat/), float) + +;************************************************ +; set value to 0. at missing point of observed +;************************************************ + delta = 0.00000000001 + x0 = tb(0,:,:) + ta = where(ismissing(ta).and.(ismissing(x0).or.(x0.lt.delta)),0.,ta) + + s(0,:) = zonalAve(ta(:,:)) + delete (ta) + +;************************************************ +; for model data +;************************************************ + scale_factor = 86400.*365. + + s(1,:) = zonalAve(tb(0,:,:)) * scale_factor + delete (tb) + + s(2,:) = zonalAve(tc(0,:,:)) * scale_factor + delete (tc) + + s@long_name = "NPP (gC/m2/year)" + +;***************************************************** +; create plot +;***************************************************** + wks = gsn_open_wks("png","xy") ; create plot + i = NhlNewColor(wks,1.0,0.71,0.76) ; add color to colormap + j = NhlNewColor(wks,0.64,0.71,0.8) ; ditto + + res = True ; plot mods desired + res@gsnDraw = False ; don't draw yet + res@gsnFrame = False ; don't advance frame yet + +; res@vpHeightF = 0.4 ; change aspect ratio of plot +; res@vpWidthF = 0.7 + +; res@trXMinF = 1890 ; set x-axis minimum + + res@xyMonoLineColor = "False" ; want colored lines + res@xyLineColors = (/"Red","Blue","Black"/) ; colors chosen +; res@xyLineThicknesses = (/3.,3.,4./) ; line thicknesses + res@xyLineThicknesses = (/2.,2.,2./) ; line thicknesses + res@xyDashPatterns = (/0.,0.,0./) ; make all lines solid + + res@tiMainString = "Zoanl Average" + res@tiYAxisString = "NPP (gC/m2/year)" ; add a axis title + res@txFontHeightF = 0.0195 ; change title font heights + + plot = gsn_csm_xy (wks,lat,s,res) ; create plot + +; plot = fill_xy2(wks,plot(0),time,mnmx(2,:),mnmx(3,:),(/0.64,0.71,0.8/),\ +; (/0.64,0.71,0.8/)) +; plot = fill_xy2(wks,plot(0),time,mnmx(0,:),mnmx(1,:),(/1.0,0.71,0.76/),\ +; (/1.0,0.71,0.76/)) +;***************************************************** +; Manually create legend +;***************************************************** + res_text = True ; text mods desired + res_text@txFontHeightF = 0.015 ; change text size + res_text@txJust = "CenterLeft" ; text justification + + res_lines = True ; polyline mods desired + res_lines@gsLineDashPattern = 0. ; solid line + res_lines@gsLineThicknessF = 5. ; line thicker + res_lines@gsLineColor = "red" ; line color + xx = (/-85.,-75./) + yy = (/1400.,1400./) + gsn_polyline(wks,plot,xx,yy,res_lines) ; add polyline + gsn_text(wks,plot,"Observed",-70.,1400.,res_text); add text + + yy = (/1500.,1500./) + res_lines@gsLineColor = "blue" ; change to blue + gsn_polyline(wks,plot,xx,yy,res_lines) ; add polyline + gsn_text(wks,plot,"Model i01.03cn",-70.,1500.,res_text) ; add text + + yy = (/1600.,1600./) + res_lines@gsLineColor = "black" ; change to black + gsn_polyline(wks,plot,xx,yy,res_lines) ; add poly line + gsn_text(wks,plot,"Model i01.04casa",-70.,1600.,res_text) ; add text +;***************************************************** +; Manually create titles +;***************************************************** +; res_text@txJust = "CenterCenter" ; change justification +; res_text@txFontHeightF = 0.03 ; change font size +; gsn_text_ndc(wks,"Parallel Climate Model Ensembles",0.55,0.90,res_text) + +; res_text@txFontHeightF = 0.02 ; change font size +; gsn_text_ndc(wks,"Global Temperature Anomalies",0.55,0.86,res_text) + +; res_text@txFontHeightF = 0.015 ; change font size +; gsn_text_ndc(wks,"from 1890-1919 average",0.55,0.83,res_text) + + draw(plot) + frame(wks) ; advance frame + +end diff -r 000000000000 -r 0c6405ab2ff4 npp/99.all.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/99.all.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1358 @@ +;***************************************************** +; combine scatter, histogram, global and zonal plots +; compute all correlation coef and M score +; add 1-to-1 line in scatter plots +;***************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;**************************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;**************************************************************************** +procedure get_bin(RAIN1_1D[*]:numeric, NPP1_1D[*]:numeric \ + ,RAIN2_1D[*]:numeric, NPP2_1D[*]:numeric \ + ,xvalues[*][*]:numeric, yvalues[*][*]:numeric \ + ,mn_yvalues[*][*]:numeric, mx_yvalues[*][*]:numeric \ + ,dx4[1]:numeric \ + ) +begin +; Calculaee "nice" bins for binning the data in equally spaced ranges. +; input : RAIN1_1D, RAIN2_1D, NPP1_1D, NPP2_1D +; output: xvalues, yvalues, mn_yvalues, mx_yvalues,dx4 + + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 +; print (nx) + +; xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. +; yvalues = new((/2,nx/),typeof(RAIN1_1D)) +; mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) +; mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; Print out information. +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data) + delete(npp_data) + end do +end +;**************************************************************************** +; Main code. +;**************************************************************************** +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ + +;film = "i01.06cn_1798-2004_ANN_climo.nc" +;model_name = "06cn" +;model_grid = "T42" + +;film = "i01.06casa_1798-2004_ANN_climo.nc" +;model_name = "06casa" +;model_grid = "T42" + +;film = "i01.10casa_1948-2004_ANN_climo.nc" +;model_name = "10casa" +;model_grid = "T42" + + film = "i01.10cn_1948-2004_ANN_climo.nc" + model_name = "10cn" + model_grid = "T42" + + html_name = "table.html." + model_name + html_new = html_name +".new" + system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) +;-------------------------------------------------- + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile (dirm+film,"r") + + nppmod0 = fm->NPP + rainmod0 = fm->RAIN + xm = fm->lon + ym = fm->lat + +;************************************************ +; read ob data +;************************************************ + +;(1) data at 81 sites + dir81 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil81 = "data.81.nc" + f81 = addfile (dir81+fil81,"r") + + id81 = f81->SITE_ID + npp81 = f81->TNPP_C + rain81 = tofloat(f81->PREC_ANN) + x81 = f81->LONG_DD + y81 = f81->LAT_DD + + id81@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x81)-1 + if (x81(i) .lt. 0.) then + x81(i) = x81(i)+ 360. + end if + end do +;print (x81) +;------------------------------------- +;(2) data at 933 sites + dir933 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil933 = "data.933.nc" + f933 = addfile (dir933+fil933,"r") + + id933 = f933->SITE_ID + npp933 = f933->TNPP_C + rain933 = f933->PREC + x933 = f933->LONG_DD + y933 = f933->LAT_DD + + id933@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x933)-1 + if (x933(i) .lt. 0.) then + x933(i) = x933(i)+ 360. + end if + end do +;print (x933) +;---------------------------------------- +;(3) global data, interpolated into model grid + dirglobe = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + filglobe = "Npp_"+model_grid+"_mean.nc" + fglobe = addfile (dirglobe+filglobe,"r") + + nppglobe0 = fglobe->NPP + nppglobe = nppglobe0 + +;*********************************************************************** +; interpolate model data into ob sites +;*********************************************************************** + + nppmod = nppmod0(0,:,:) + rainmod = rainmod0(0,:,:) + delete (nppmod0) + delete (rainmod0) + + nppmod81 =linint2_points(xm,ym,nppmod,True,x81,y81,0) + + nppmod933 =linint2_points(xm,ym,nppmod,True,x933,y933,0) + + rainmod81 =linint2_points(xm,ym,rainmod,True,x81,y81,0) + + rainmod933=linint2_points(xm,ym,rainmod,True,x933,y933,0) + +;********************************************************** +; unified units +;********************************************************** +; Units for these variables are: +; +; rain81 : mm/year +; rainmod : mm/s +; npp81 : g C/m^2/year +; nppmod81: g C/m^2/s +; nppglobe: g C/m^2/year +; +; We want to convert these to "m/year" and "g C/m^2/year". + + nsec_per_year = 60*60*24*365 + + rain81 = rain81 / 1000. + rainmod81 = (rainmod81/ 1000.) * nsec_per_year + nppmod81 = nppmod81 * nsec_per_year + + rain933 = rain933 / 1000. + rainmod933 = (rainmod933/ 1000.) * nsec_per_year + nppmod933 = nppmod933 * nsec_per_year + + nppmod = nppmod * nsec_per_year + + npp81@units = "gC/m^2/yr" + nppmod81@units = "gC/m^2/yr" + npp933@units = "gC/m^2/yr" + nppmod933@units = "gC/m^2/yr" + nppmod@units = "gC/m^2/yr" + nppglobe@units = "gC/m^2/yr" + rain81@units = "m/yr" + rainmod81@units = "m/yr" + rain933@units = "m/yr" + rainmod933@units = "m/yr" + + npp81@long_name = "NPP (gC/m2/year)" + npp933@long_name = "NPP (gC/m2/year)" + nppmod81@long_name = "NPP (gC/m2/year)" + nppmod933@long_name = "NPP (gC/m2/year)" + nppmod@long_name = "NPP (gC/m2/year)" + nppglobe@long_name = "NPP (gC/m2/year)" + rain81@long_name = "PREC (m/year)" + rain933@long_name = "PREC (m/year)" + rainmod81@long_name = "PREC (m/year)" + rainmod933@long_name = "PREC (m/year)" + +;******************************************************************* +;(A)-1 html table of site81 -- observed +;******************************************************************* + output_html = "table_site81_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Observation at 81 sites

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site IDLatitudeLongitudeNPP(gC/m2.year)RAIN(m/year)
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + nrow = dimsizes(id81) + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = sprintf("%5.0f", id81(n)) + txt2 = sprintf("%5.2f", y81(n)) + txt3 = sprintf("%5.2f", x81(n)) + txt4 = sprintf("%5.2f", npp81(n)) + txt5 = sprintf("%5.2f", rain81(n)) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if +;******************************************************************* +;(A)-2 html table of site933 -- observed +;******************************************************************* + output_html = "table_site933_ob.html" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,"

Observation at 933 sites

" \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Site IDLatitudeLongitudeNPP(gC/m2.year)RAIN(m/year)
" + row_header = "" + row_footer = "" + + delete (lines) + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + nrow = dimsizes(id933) + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = sprintf("%5.0f", id933(n)) + txt2 = sprintf("%5.2f", y933(n)) + txt3 = sprintf("%5.2f", x933(n)) + txt4 = sprintf("%5.2f", npp933(n)) + txt5 = sprintf("%5.2f", rain933(n)) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + delete (idx) + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if +;******************************************************************* +;(A)-3 html table of site81 -- model vs ob +;******************************************************************* + output_html = "table_site81_model_vs_ob.html" + + header_text = "

Model "+model_name+" vs Observed at 81 sites

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + delete (table_header) + table_header_text = " "+model_name+"" + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + ,"" \ + ," " \ + , table_header_text \ + ," " \ + , table_header_text \ + ,"" \ + /) + table_footer = "
Site IDLatitudeLongitudeNPP(gC/m2.year)RAIN(m/year)
observedobserved
" + row_header = "" + row_footer = "" + + delete (lines) + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + nrow = dimsizes(id81) + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = sprintf("%5.0f", id81(n)) + txt2 = sprintf("%5.2f", y81(n)) + txt3 = sprintf("%5.2f", x81(n)) + txt4 = sprintf("%5.2f", npp81(n)) + txt5 = sprintf("%5.2f", nppmod81(n)) + txt6 = sprintf("%5.2f", rain81(n)) + txt7 = sprintf("%5.2f", rainmod81(n)) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + delete (idx) + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +;******************************************************************* +;(A)-4 html table of site933 -- model vs ob +;******************************************************************* + output_html = "table_site933_model_vs_ob.html" + + header_text = "

Model "+model_name+" vs Observed at 933 sites

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + delete (table_header) + table_header_text = " "+model_name+"" + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + ,"" \ + ," " \ + , table_header_text \ + ," " \ + , table_header_text \ + ,"" \ + /) + table_footer = "
Site IDLatitudeLongitudeNPP(gC/m2.year)RAIN(m/year)
observedobserved
" + row_header = "" + row_footer = "" + + delete (lines) + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + nrow = dimsizes(id933) + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = sprintf("%5.0f", id933(n)) + txt2 = sprintf("%5.2f", y933(n)) + txt3 = sprintf("%5.2f", x933(n)) + txt4 = sprintf("%5.2f", npp933(n)) + txt5 = sprintf("%5.2f", nppmod933(n)) + txt6 = sprintf("%5.2f", rain933(n)) + txt7 = sprintf("%5.2f", rainmod933(n)) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + set_line(lines,nline,""+txt5+"") + set_line(lines,nline,""+txt6+"") + set_line(lines,nline,""+txt7+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + delete (idx) + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if +;*************************************************************************** +;(A)-5 scatter plot, model vs ob 81 +;*************************************************************************** + + plot_name = "scatter_model_vs_ob_81" + title = model_name +" vs ob 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + res@gsnDraw = False + res@gsnFrame = False ; don't advance frame yet +;------------------------------- +;compute correlation coef. and M + ccr81 = esccr(nppmod81,npp81,0) +;print (ccr81) + +;new eq + bias = sum(abs(nppmod81-npp81)/(abs(nppmod81)+abs(npp81))) + M81 = (1. - (bias/dimsizes(y81)))*5. + + M_npp_S81 = sprintf("%.2f", M81) + system("sed s#M_npp_S81#"+M_npp_S81+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_npp_S81) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp81,nppmod81,res) ; create plot +;------------------------------- +; add polyline + + dum=gsn_add_polyline(wks,plot,(/0,1200/),(/0,1200/),False) +;------------------------------- + draw (plot) + frame(wks) + clear (wks) + delete (dum) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;*************************************************************************** +;(A)-6 scatter plot, model vs ob 933 +;*************************************************************************** + + plot_name = "scatter_model_vs_ob_933" + title = model_name +" vs ob 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + res@gsnDraw = False + res@gsnFrame = False ; don't advance frame yet +;------------------------------- +;compute correlation coef. and M + ccr933 = esccr(nppmod933,npp933,0) +;print (ccr933) + +;new eq + bias = sum(abs(nppmod933-npp933)/(abs(nppmod933)+abs(npp933))) + M933 = (1. - (bias/dimsizes(y933)))*5. + + M_npp_S933 = sprintf("%.2f", M933) + system("sed s#M_npp_S933#"+M_npp_S933+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_npp_S933) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp933,nppmod933,res) ; create plot +;------------------------------- +; add polyline + + dum=gsn_add_polyline(wks,plot,(/0,1500/),(/0,1500/),False) +;------------------------------- + draw (plot) + frame(wks) + clear (wks) + delete (dum) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;************************************************************************** +;(B) histogram 81 +;************************************************************************** +;get data + RAIN1_1D = ndtooned(rain81) + RAIN2_1D = ndtooned(rainmod81) + NPP1_1D = ndtooned(npp81) + NPP2_1D = ndtooned(nppmod81) + +; number of bin + nx = 8 + + xvalues = new((/2,nx/),float) + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + dx4 = new((/1/),float) + + get_bin(RAIN1_1D, NPP1_1D, RAIN2_1D, NPP2_1D \ + ,xvalues,yvalues,mn_yvalues,mx_yvalues,dx4) + +;---------------------------------------- +;compute correlation coeff and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr81h = esccr(uu,vv,0) +;print (ccr81h) + +;new eq + bias = sum(abs(vv-uu)/(abs(vv)+abs(uu))) + M81h = (1.- (bias/dimsizes(uu)))*5. + + M_npp_H81 = sprintf("%.2f", M81h) + system("sed s#M_npp_H81#"+M_npp_H81+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_npp_H81) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + resh = True + resh@gsnMaximize = True + resh@gsnDraw = False + resh@gsnFrame = False + resh@xyMarkLineMode = "Markers" + resh@xyMarkerSizeF = 0.014 + resh@xyMarker = 16 + resh@xyMarkerColors = (/"Brown","Blue"/) + resh@trYMinF = min(mn_yvalues) - 10. + resh@trYMaxF = max(mx_yvalues) + 10. + + resh@tiYAxisString = "NPP (g C/m2/year)" + resh@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) + +;************************************************************************** +;(B)-1 histogram plot, ob 81 site +;************************************************************************** + + plot_name = "histogram_ob_81" + title = "Observed 81 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + plx = (/x1,x1/) + ply = (/y1,y2/) + min_bar(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + + y2 = mx_yvalues(nd,i) + plx = (/x1,x1/) + ply = (/y1,y2/) + max_bar(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + plx = (/x1,x2/) + ply = (/y1,y1/) + min_cap(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + + y1 = mx_yvalues(nd,i) + plx = (/x1,x2/) + ply = (/y1,y1/) + max_cap(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + end if + end do + end do + + draw(xy) + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;**************************************************************************** +;(B)-2 histogram plot, model vs ob 81 site +;**************************************************************************** + + plot_name = "histogram_model_vs_ob_81" + title = model_name+ " vs Observed 81 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + resh@pmLegendDisplayMode = "Always" +; resh@pmLegendWidthF = 0.1 + resh@pmLegendWidthF = 0.08 + resh@pmLegendHeightF = 0.05 + resh@pmLegendOrthogonalPosF = -1.17 +; resh@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resh@pmLegendParallelPosF = 0.18 + resh@pmLegendParallelPosF = 0.88 ;(rightward) + +; resh@lgPerimOn = False + resh@lgLabelFontHeightF = 0.015 + resh@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81h)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resh) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + clear(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) + + delete (RAIN1_1D) + delete (RAIN2_1D) + delete (NPP1_1D) + delete (NPP2_1D) +;delete (range) + delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) + +;************************************************************************** +;(B) histogram 933 +;************************************************************************** + +; get data + RAIN1_1D = ndtooned(rain933) + RAIN2_1D = ndtooned(rainmod933) + NPP1_1D = ndtooned(npp933) + NPP2_1D = ndtooned(nppmod933) + +; number of bin + nx = 10 + + xvalues = new((/2,nx/),float) + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + dx4 = new((/1/),float) + + get_bin(RAIN1_1D, NPP1_1D, RAIN2_1D, NPP2_1D \ + ,xvalues,yvalues,mn_yvalues,mx_yvalues,dx4) + +;---------------------------------------- +;compute correlation coeff and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr933h = esccr(uu,vv,0) +;print (ccr933h) + +;new eq + bias = sum(abs(vv-uu)/(abs(vv)+abs(uu))) + M933h = (1.- (bias/dimsizes(uu)))*5. + + M_npp_H933 = sprintf("%.2f", M933h) + system("sed s#M_npp_H933#"+M_npp_H933+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_npp_H933) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + delete (resh) + resh = True + resh@gsnMaximize = True + resh@gsnDraw = False + resh@gsnFrame = False + resh@xyMarkLineMode = "Markers" + resh@xyMarkerSizeF = 0.014 + resh@xyMarker = 16 + resh@xyMarkerColors = (/"Brown","Blue"/) + resh@trYMinF = min(mn_yvalues) - 10. + resh@trYMaxF = max(mx_yvalues) + 10. + + resh@tiYAxisString = "NPP (g C/m2/year)" + resh@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) + +;************************************************************************** +;(B)-3 histogram plot, ob 933 site +;************************************************************************** + + plot_name = "histogram_ob_933" + title = "Observed 933 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + delete (xy) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;**************************************************************************** +;(B)-4 histogram plot, model vs ob 933 site +;**************************************************************************** + + plot_name = "histogram_model_vs_ob_933" + title = model_name+ " vs Observed 933 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + resh@pmLegendDisplayMode = "Always" +; resh@pmLegendWidthF = 0.1 + resh@pmLegendWidthF = 0.08 + resh@pmLegendHeightF = 0.05 + resh@pmLegendOrthogonalPosF = -1.17 +; resh@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resh@pmLegendParallelPosF = 0.18 + resh@pmLegendParallelPosF = 0.88 ;(rightward) + +; resh@lgPerimOn = False + resh@lgLabelFontHeightF = 0.015 + resh@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933h)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resh) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + delete(xy) + clear(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;*************************************************************************** +;(C) global contour +;*************************************************************************** + +;res + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@gsnSpreadColors = True ; use full colormap + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 2200. ; Max level + resg@cnLevelSpacingF = 200. ; interval + +;**************************************************************************** +;(C)-1 global contour plot, ob +;**************************************************************************** + + delta = 0.00000000001 + nppglobe = where(ismissing(nppglobe).and.(ismissing(nppmod).or.(nppmod.lt.delta)),0.,nppglobe) + + plot_name = "global_ob" + title = "Observed MODIS MOD 17" + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppglobe,resg) + + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;**************************************************************************** +;(C)-2 global contour plot, model +;**************************************************************************** + + plot_name = "global_model" + title = "Model "+ model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppmod,resg) + + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;**************************************************************************** +;(C)-3 global contour plot, model vs ob +;**************************************************************************** + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; compute correlation coef and M score + + uu1 = ndtooned(nppmod) + vv1 = ndtooned(nppglobe) + + delete (good) + good = ind(.not.ismissing(uu1) .and. .not.ismissing(vv1)) + + ug = uu1(good) + vg = vv1(good) + + ccrG = esccr(ug,vg,0) +; print (ccrG) + + MG = (ccrG*ccrG)* 5.0 + + M_npp_G = sprintf("%.2f", MG) + system("sed s#M_npp_G#"+M_npp_G+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_npp_G) + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrG)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = "Observed MODIS MOD 17" + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,nppglobe,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,nppmod,resg) + +;(c) model-ob + + zz = nppmod + zz = nppmod - nppglobe + title = "Model_"+model_name+" - Observed" + + resg@cnMinLevelValF = -500 ; Min level + resg@cnMaxLevelValF = 500. ; Max level + resg@cnLevelSpacingF = 50. ; interval + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + frame (wks) + clear (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;*************************************************************************** +;(D)-1 zonal line plot, ob +;*************************************************************************** + + vv = zonalAve(nppglobe) + vv@long_name = nppglobe@long_name + + plot_name = "zonal_ob" + title = "Observed MODIS MOD 17" + + resz = True + resz@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + plot = gsn_csm_xy (wks,ym,vv,resz) + + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;**************************************************************************** +;(D)-2 zonal line plot, model vs ob +;**************************************************************************** + + s = new ((/2,dimsizes(ym)/), float) + + s(0,:) = zonalAve(nppglobe) + s(1,:) = zonalAve(nppmod) + + s@long_name = nppglobe@long_name +;------------------------------------------- +; compute correlation coef and M score + + ccrZ = esccr(s(1,:), s(0,:),0) +; print (ccrZ) + + MZ = (ccrZ*ccrZ)* 5.0 + + M_npp_Z = sprintf("%.2f", MZ) + system("sed s#M_npp_Z#"+M_npp_Z+"# "+html_name+" > "+html_new+";"+ \ + "mv -f "+html_new+" "+html_name) + print (M_npp_Z) +;------------------------------------------- + plot_name = "zonal_model_vs_ob" + title = "Zonal Average" + resz@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + +; resz@vpHeightF = 0.4 ; change aspect ratio of plot +; resz@vpWidthF = 0.7 + + resz@xyMonoLineColor = "False" ; want colored lines + resz@xyLineColors = (/"black","red"/) ; colors chosen +; resz@xyLineThicknesses = (/3.,3./) ; line thicknesses + resz@xyLineThicknesses = (/2.,2./) ; line thicknesses + resz@xyDashPatterns = (/0.,0./) ; make all lines solid + + resz@tiYAxisString = s@long_name ; add a axis title + resz@txFontHeightF = 0.0195 ; change title font heights + +; Legent + resz@pmLegendDisplayMode = "Always" ; turn on legend + resz@pmLegendSide = "Top" ; Change location of +; resz@pmLegendParallelPosF = .45 ; move units right + resz@pmLegendParallelPosF = .82 ; move units right + resz@pmLegendOrthogonalPosF = -0.4 ; move units down + + resz@pmLegendWidthF = 0.10 ; Change width and + resz@pmLegendHeightF = 0.10 ; height of legend. + resz@lgLabelFontHeightF = .02 ; change font height +; resz@lgTitleOn = True ; turn on legend title +; resz@lgTitleString = "Example" ; create legend title +; resz@lgTitleFontHeightF = .025 ; font of legend title + resz@xyExplicitLegendLabels = (/"Observed",model_name/) ; explicit labels +;-------------------------------------------------------------------- + zRes = True + zRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrZ)+")" + + gsn_text_ndc(wks,correlation_text,0.50,0.77,zRes) +;-------------------------------------------------------------------- + + plot = gsn_csm_xy (wks,ym,s,resz) + + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \ + "mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new+";"+ \ + "rm "+plot_name+"-*."+plot_type_new+";"+ \ + "rm "+plot_name+"."+plot_type) +;*************************************************************************** +; tar up output plots +;*************************************************************************** + + temp_name = "npp." + model_name + system("mkdir -p " + temp_name+";"+ \ + "cp "+ html_name + " " +temp_name+"/table.html"+";"+ \ + "mv table_*.html " + temp_name +";"+ \ + "mv *.png " + temp_name +";"+ \ + "tar cf "+ temp_name +".tar " + temp_name) +;*************************************************************************** +end + diff -r 000000000000 -r 0c6405ab2ff4 npp/99.all.ncl.0 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/99.all.ncl.0 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1683 @@ +; **************************************************** +; combine scatter, histogram, global and zonal plots +; compute all correlation coef and M score +; add 1-to-1 line in scatter plots +; **************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +procedure get_bin(RAIN1_1D[*]:numeric, NPP1_1D[*]:numeric \ + ,RAIN2_1D[*]:numeric, NPP2_1D[*]:numeric \ + ,xvalues[*][*]:numeric, yvalues[*][*]:numeric \ + ,mn_yvalues[*][*]:numeric, mx_yvalues[*][*]:numeric \ + ,dx4[1]:numeric \ + ) +begin +; Calculaee "nice" bins for binning the data in equally spaced ranges. +; input : RAIN1_1D, RAIN2_1D, NPP1_1D, NPP2_1D +; output: xvalues, yvalues, mn_yvalues, mx_yvalues,dx4 + + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 +; print (nx) + +; xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. +; yvalues = new((/2,nx/),typeof(RAIN1_1D)) +; mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) +; mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; Print out information. + +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data) + delete(npp_data) + end do +end + +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" +;************************************************ +; read in model data +;************************************************ +;film = "i01.06cn_1798-2004_ANN_climo.nc" +;model_name = "06cn" +;model_grid = "T42" + +;film = "i01.06casa_1798-2004_ANN_climo.nc" +;model_name = "06casa" +;model_grid = "T42" + + film = "i01.10casa_1948-2004_ANN_climo.nc" + model_name = "10casa" + model_grid = "T42" + +;film = "i01.10cn_1948-2004_ANN_climo.nc" +;model_name = "10cn" +;model_grid = "T42" +;-------------------------------------------------- + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile (dirm+film,"r") + + nppmod0 = fm->NPP + rainmod0 = fm->RAIN + xm = fm->lon + ym = fm->lat + +;************************************************ +; read in ob data +;************************************************ +;(1) + dir81 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil81 = "data.81.nc" + f81 = addfile (dir81+fil81,"r") + + id81 = f81->SITE_ID + npp81 = f81->TNPP_C + rain81 = tofloat(f81->PREC_ANN) + x81 = f81->LONG_DD + y81 = f81->LAT_DD + + id81@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x81)-1 + if (x81(i) .lt. 0.) then + x81(i) = x81(i)+ 360. + end if + end do +;print (x81) +;------------------------------------- +;(2) + dir933 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil933 = "data.933.nc" + f933 = addfile (dir933+fil933,"r") + + id933 = f933->SITE_ID + npp933 = f933->TNPP_C + rain933 = f933->PREC + x933 = f933->LONG_DD + y933 = f933->LAT_DD + + id933@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x933)-1 + if (x933(i) .lt. 0.) then + x933(i) = x933(i)+ 360. + end if + end do +;print (x933) +;---------------------------------------- +;(3) + dirglobe = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + filglobe = "Npp_"+model_grid+"_mean.nc" + fglobe = addfile (dirglobe+filglobe,"r") + + nppglobe0 = fglobe->NPP + nppglobe = nppglobe0 +;*********************************************************************** +; interpolate model data +;*********************************************************************** + nppmod = nppmod0(0,:,:) + rainmod = rainmod0(0,:,:) + delete (nppmod0) + delete (rainmod0) + + nppmod81 =linint2_points(xm,ym,nppmod,True,x81,y81,0) + + nppmod933 =linint2_points(xm,ym,nppmod,True,x933,y933,0) + + rainmod81 =linint2_points(xm,ym,rainmod,True,x81,y81,0) + + rainmod933=linint2_points(xm,ym,rainmod,True,x933,y933,0) + +;************************************************ +; Units for these variables are: +; +; rain81 : mm/year +; rainmod : mm/s +; npp81 : g C/m^2/year +; nppmod81: g C/m^2/s +; nppglobe: g C/m^2/year +; +; We want to convert these to "m/year" and "g C/m^2/year". +; + nsec_per_year = 60*60*24*365 + + rain81 = rain81 / 1000. + rainmod81 = (rainmod81/ 1000.) * nsec_per_year + nppmod81 = nppmod81 * nsec_per_year + + rain933 = rain933 / 1000. + rainmod933 = (rainmod933/ 1000.) * nsec_per_year + nppmod933 = nppmod933 * nsec_per_year + + nppmod = nppmod * nsec_per_year + + npp81@units = "gC/m^2/yr" + nppmod81@units = "gC/m^2/yr" + npp933@units = "gC/m^2/yr" + nppmod933@units = "gC/m^2/yr" + nppmod@units = "gC/m^2/yr" + nppglobe@units = "gC/m^2/yr" + rain81@units = "m/yr" + rainmod81@units = "m/yr" + rain933@units = "m/yr" + rainmod933@units = "m/yr" + + npp81@long_name = "NPP (gC/m2/year)" + npp933@long_name = "NPP (gC/m2/year)" + nppmod81@long_name = "NPP (gC/m2/year)" + nppmod933@long_name = "NPP (gC/m2/year)" + nppmod@long_name = "NPP (gC/m2/year)" + nppglobe@long_name = "NPP (gC/m2/year)" + rain81@long_name = "PREC (m/year)" + rain933@long_name = "PREC (m/year)" + rainmod81@long_name = "PREC (m/year)" + rainmod933@long_name = "PREC (m/year)" + +;(A)-1 plot scatter ob 81 + +;plot_name = "scatter_ob_81" +;title = "Observed 81 sites" + +;wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;res = True ; plot mods desired +;res@tiMainString = title ; add title +;res@xyMarkLineModes = "Markers" ; choose which have markers +;res@xyMarkers = 16 ; choose type of marker +;res@xyMarkerColor = "red" ; Marker color +;res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) +;res@tmLabelAutoStride = True ; nice tick mark labels + +;plot = gsn_csm_xy (wks,id81,npp81,res) ; create plot +;frame(wks) + +;system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +;system("rm "+plot_name+"."+plot_type) +;system("rm "+plot_name+"-1."+plot_type_new) +;system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;clear (wks) +;******************************************************************* +;(A)-2 for table of site(1) (the first 41 sites) +;******************************************************************* + + table_length = 0.95 + +; table header name + table_header_name = "Site ID" + +; column (not including header column) + col_header = (/"Latitude","Longitude","NPP (gC/m2/year)","RAIN (m/year)"/) + ncol = dimsizes(col_header) + +; row (not including header row) + nrow = 41 + row_header = new ((/nrow/),string ) + row_header(0:nrow-1) = id81(0:nrow-1) + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.95/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.015 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" +; color_fill4(:,ncol-1) = "grey" +; color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-1 + text4(n,0) = sprintf("%5.2f", y81(n)) + text4(n,1) = sprintf("%5.2f", x81(n)) + text4(n,2) = sprintf("%5.2f", npp81(n)) + text4(n,3) = sprintf("%5.2f", rain81(n)) + end do +;--------------------------------------------------------------------------- + + plot_name = "table_site81_ob1" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Observation at 81 Sites (1)" + + gsn_text_ndc(wks,title_text,0.50,0.975,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + clear (wks) + + delete (row_header) + delete (res3) + delete (ncr3) + delete (text3) + delete (res4) + delete (ncr4) + delete (text4) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;******************************************************************* +;(A)-3 for table of site(2) (the second 40 sites) +;******************************************************************* + + table_length = 0.95 + +; table header name + table_header_name = "Site ID" + +; column (not including header column) + col_header = (/"Latitude","Longitude","NPP (gC/m2/year)","RAIN (m/year)"/) + ncol = dimsizes(col_header) + +; row (not including header row) + nrow = 40 + row_header = new ((/nrow/),string ) + row_header(0:nrow-1) = id81(41:41+nrow-1) + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.95/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.015 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" +; color_fill4(:,ncol-1) = "grey" +; color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-1 + text4(n,0) = sprintf("%5.2f", y81(n+41)) + text4(n,1) = sprintf("%5.2f", x81(n+41)) + text4(n,2) = sprintf("%5.2f", npp81(n+41)) + text4(n,3) = sprintf("%5.2f", rain81(n+41)) + end do +;--------------------------------------------------------------------------- + + plot_name = "table_site81_ob2" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Observation at 81 Sites (2)" + + gsn_text_ndc(wks,title_text,0.50,0.975,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + clear (wks) + + delete (row_header) + delete (res3) + delete (ncr3) + delete (text3) + delete (res4) + delete (ncr4) + delete (text4) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) +;************************************************************************** +;(A)-4 plot scatter ob 933 + + plot_name = "scatter_ob_933" + title = "Observed 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id933,npp933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(A)-5 plot scatter model 81 + +;plot_name = "scatter_model_81" +;title = "Model "+ model_name +" 81 sites" + +;wks = gsn_open_wks (plot_type,plot_name) ; open workstation +;res = True ; plot mods desired +;res@tiMainString = title ; add title +;res@xyMarkLineModes = "Markers" ; choose which have markers +;res@xyMarkers = 16 ; choose type of marker +;res@xyMarkerColor = "red" ; Marker color +;res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) +;res@tmLabelAutoStride = True ; nice tick mark labels + +;plot = gsn_csm_xy (wks,id81,nppmod81,res) ; create plot +;frame(wks) + +;system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) +;system("rm "+plot_name+"."+plot_type) +;system("rm "+plot_name+"-1."+plot_type_new) +;system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;clear (wks) + +;(A)-6 plot scatter model 933 + + plot_name = "scatter_model_933" + title = "Model "+ model_name +" 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id933,nppmod933,res) ; create plot + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + +;(A)-7 scatter model vs ob 81 + + plot_name = "scatter_model_vs_ob_81" + title = model_name +" vs ob 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + res@gsnDraw = False + res@gsnFrame = False ; don't advance frame yet +;------------------------------- +;compute correlation coef. and M + ccr81 = esccr(nppmod81,npp81,0) +;print (ccr81) + +;new eq + bias = sum(abs(nppmod81-npp81)/(abs(nppmod81)+abs(npp81))) + M81 = (1. - (bias/dimsizes(y81)))*5. + print (M81) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp81,nppmod81,res) ; create plot +;------------------------------- +; add polyline + + dum=gsn_add_polyline(wks,plot,(/0,1200/),(/0,1200/),False) +;------------------------------- + draw (plot) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +;system("rm "+plot_name+"-1."+plot_type_new) +;system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + delete (dum) + +;(A)-8 scatter model vs ob 933 + + plot_name = "scatter_model_vs_ob_933" + title = model_name +" vs ob 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + res@gsnDraw = False + res@gsnFrame = False ; don't advance frame yet +;------------------------------- +;compute correlation coef. and M + ccr933 = esccr(nppmod933,npp933,0) +;print (ccr933) + +;new eq + bias = sum(abs(nppmod933-npp933)/(abs(nppmod933)+abs(npp933))) + M933 = (1. - (bias/dimsizes(y933)))*5. + print (M933) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp933,nppmod933,res) ; create plot +;------------------------------- +; add polyline + + dum=gsn_add_polyline(wks,plot,(/0,1500/),(/0,1500/),False) +;------------------------------- + draw (plot) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +;system("rm "+plot_name+"-1."+plot_type_new) +;system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + delete (dum) + +;******************************************************************* +;(A)-9 for table of site(1) (the first 41 sites), model vs ob +;******************************************************************* + + table_length = 0.95 + +; table header name + table_header_name = "Site ID" + +; row (not including header row) + nrow = 41 + row_header = new ((/nrow/),string ) + row_header(0:nrow-1) = id81(0:nrow-1) + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.85 ,0.95/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.015 + res1@gsFillColor = "CornFlowerBlue" + +; Column header1 (equally space in x2) + + delete (col_header) + delete (ncr2) + delete (text2) + + col_header = (/"Latitude","Longitude"/) + ncol = dimsizes(col_header) + + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.35/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Column header2 (equally space in x2) + + col_header1 = (/"NPP (gC/m2/year)","RAIN (m/year)"/) + col_header2 = (/"ob",model_name \ + ,"ob",model_name \ + /) + + ncol1 = dimsizes(col_header1) + ncol2 = dimsizes(col_header2) + + ncr21 = (/1,ncol1/) ; 1 rows, 4 columns + x21 = (/x2(1),0.995/) ; start from end of x2 + yhalf = (y1(0)+y1(1))*0.5 + y21 = (/yhalf,y1(1)/) ; top half of y1 + text21 = col_header1 + res21 = True + res21@txFontHeightF = 0.015 + res21@gsFillColor = "Gray" + + ncr22 = (/1,ncol2/) ; 1 rows, 12 columns + x22 = x21 ; start from end of x1 + y22 = (/y1(0),yhalf/) ; bottom half of y1 + text22 = col_header2 + res22 = True + res22@txFontHeightF = 0.015 + res22@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body-1 + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" +; color_fill4(:,ncol-1) = "grey" +; color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +; Main table body-2 + ncr42 = (/nrow,ncol2/) ; nrow rows, ncol columns + x42 = x21 ; Start and end x + y42 = y3 ; Start and end Y + text42 = new((/nrow,ncol2/),string) + + color_fill42 = new((/nrow,ncol2/),string) + color_fill42 = "white" +; color_fill42(:,ncol-1) = "grey" +; color_fill42(nrow-1,:) = "green" + + res42 = True ; Set up resource list +; res42@gsnDebug = True ; Useful to print NDC row,col values used. + res42@txFontHeightF = 0.015 + res42@gsFillColor = color_fill42 + + delete (color_fill42) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-1 + text4(n,0) = sprintf("%5.2f", y81(n)) + text4(n,1) = sprintf("%5.2f", x81(n)) + end do + + do n = 0,nrow-1 + text42(n,0) = sprintf("%5.2f", npp81(n)) + text42(n,1) = sprintf("%5.2f", nppmod81(n)) + text42(n,2) = sprintf("%5.2f", rain81(n)) + text42(n,3) = sprintf("%5.2f", rainmod81(n)) + end do +;--------------------------------------------------------------------------- + + plot_name = "table_site81_model_vs_ob1" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Model vs Observation at 81 Sites (1)" + + gsn_text_ndc(wks,title_text,0.50,0.975,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr21,x21,y21,text21,res21) + gsn_table(wks,ncr22,x22,y22,text22,res22) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + gsn_table(wks,ncr42,x42,y42,text42,res42) + + frame(wks) + clear (wks) + + delete (col_header) + delete (row_header) + delete (res1) + delete (ncr1) + delete (text1) + delete (res2) + delete (ncr2) + delete (text2) + delete (res21) + delete (ncr21) + delete (text21) + delete (res22) + delete (ncr22) + delete (text22) + delete (res3) + delete (ncr3) + delete (text3) + delete (res4) + delete (ncr4) + delete (text4) + delete (res42) + delete (ncr42) + delete (text42) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;******************************************************************* +;(A)-10 for table of site(2) (the last 40 sites), model vs ob +;******************************************************************* + + table_length = 0.95 + +; table header name + table_header_name = "Site ID" + +; row (not including header row) + nrow = 40 + row_header = new ((/nrow/),string ) + row_header(0:nrow-1) = id81(41:41+nrow-1) + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.85 ,0.95/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.015 + res1@gsFillColor = "CornFlowerBlue" + +; Column header1 (equally space in x2) + + col_header = (/"Latitude","Longitude"/) + ncol = dimsizes(col_header) + + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.35/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Column header2 (equally space in x2) + +; col_header1 = (/"NPP (gC/m2/year)","RAIN (m/year)"/) + col_header2 = (/"ob",model_name \ + ,"ob",model_name \ + /) + + ncol1 = dimsizes(col_header1) + ncol2 = dimsizes(col_header2) + + ncr21 = (/1,ncol1/) ; 1 rows, 4 columns + x21 = (/x2(1),0.995/) ; start from end of x2 + yhalf = (y1(0)+y1(1))*0.5 + y21 = (/yhalf,y1(1)/) ; top half of y1 + text21 = col_header1 + res21 = True + res21@txFontHeightF = 0.015 + res21@gsFillColor = "Gray" + + ncr22 = (/1,ncol2/) ; 1 rows, 12 columns + x22 = x21 ; start from end of x1 + y22 = (/y1(0),yhalf/) ; bottom half of y1 + text22 = col_header2 + res22 = True + res22@txFontHeightF = 0.015 + res22@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body-1 + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" +; color_fill4(:,ncol-1) = "grey" +; color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +; Main table body-2 + ncr42 = (/nrow,ncol2/) ; nrow rows, ncol columns + x42 = x21 ; Start and end x + y42 = y3 ; Start and end Y + text42 = new((/nrow,ncol2/),string) + + color_fill42 = new((/nrow,ncol2/),string) + color_fill42 = "white" +; color_fill42(:,ncol-1) = "grey" +; color_fill42(nrow-1,:) = "green" + + res42 = True ; Set up resource list +; res42@gsnDebug = True ; Useful to print NDC row,col values used. + res42@txFontHeightF = 0.015 + res42@gsFillColor = color_fill42 + + delete (color_fill42) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-1 + text4(n,0) = sprintf("%5.2f", y81(n+41)) + text4(n,1) = sprintf("%5.2f", x81(n+41)) + end do + + do n = 0,nrow-1 + text42(n,0) = sprintf("%5.2f", npp81(n+41)) + text42(n,1) = sprintf("%5.2f", nppmod81(n+41)) + text42(n,2) = sprintf("%5.2f", rain81(n+41)) + text42(n,3) = sprintf("%5.2f", rainmod81(n+41)) + end do +;--------------------------------------------------------------------------- + + plot_name = "table_site81_model_vs_ob2" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Model vs Observation at 81 Sites (2)" + + gsn_text_ndc(wks,title_text,0.50,0.975,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr21,x21,y21,text21,res21) + gsn_table(wks,ncr22,x22,y22,text22,res22) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + gsn_table(wks,ncr42,x42,y42,text42,res42) + + frame(wks) + clear (wks) + + delete (col_header) + delete (row_header) + delete (res1) + delete (ncr1) + delete (text1) + delete (res2) + delete (ncr2) + delete (text2) + delete (res21) + delete (ncr21) + delete (text21) + delete (res22) + delete (ncr22) + delete (text22) + delete (res3) + delete (ncr3) + delete (text3) + delete (res4) + delete (ncr4) + delete (text4) + delete (res42) + delete (ncr42) + delete (text42) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;************************************************************************** +;(B) histogram 81 +;***********************************************************************- +;get data + + RAIN1_1D = ndtooned(rain81) + RAIN2_1D = ndtooned(rainmod81) + NPP1_1D = ndtooned(npp81) + NPP2_1D = ndtooned(nppmod81) + + nx = 8 + + xvalues = new((/2,nx/),float) + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + dx4 = new((/1/),float) + + get_bin(RAIN1_1D, NPP1_1D, RAIN2_1D, NPP2_1D \ + ,xvalues,yvalues,mn_yvalues,mx_yvalues,dx4) + +;---------------------------------------- +;compute correlation coeff and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr81h = esccr(uu,vv,0) +;print (ccr81h) + +;new eq + bias = sum(abs(vv-uu)/(abs(vv)+abs(uu))) + M81h = (1.- (bias/dimsizes(uu)))*5. + print (M81h) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + + resh = True + resh@gsnMaximize = True + resh@gsnDraw = False + resh@gsnFrame = False + resh@xyMarkLineMode = "Markers" + resh@xyMarkerSizeF = 0.014 + resh@xyMarker = 16 + resh@xyMarkerColors = (/"Brown","Blue"/) + resh@trYMinF = min(mn_yvalues) - 10. + resh@trYMaxF = max(mx_yvalues) + 10. + + resh@tiYAxisString = "NPP (g C/m2/year)" + resh@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;================================================================= +;(B)-1 histogram ob 81 site only +; + plot_name = "histogram_ob_81" + title = "Observed 81 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + delete (x1) + delete (x2) + delete (y1) + delete (y2) + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + plx = (/x1,x1/) + ply = (/y1,y2/) + min_bar(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + + y2 = mx_yvalues(nd,i) + plx = (/x1,x1/) + ply = (/y1,y2/) + max_bar(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + plx = (/x1,x2/) + ply = (/y1,y1/) + min_cap(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + + y1 = mx_yvalues(nd,i) + plx = (/x1,x2/) + ply = (/y1,y1/) + max_cap(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;=========================================================================== +;(B)-2 histogram model vs ob 81 site + + plot_name = "histogram_mod-ob_81" + title = model_name+ " vs Observed 81 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + resh@pmLegendDisplayMode = "Always" +; resh@pmLegendWidthF = 0.1 + resh@pmLegendWidthF = 0.08 + resh@pmLegendHeightF = 0.05 + resh@pmLegendOrthogonalPosF = -1.17 +; resh@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resh@pmLegendParallelPosF = 0.18 + resh@pmLegendParallelPosF = 0.88 ;(rightward) + +; resh@lgPerimOn = False + resh@lgLabelFontHeightF = 0.015 + resh@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81h)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resh) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) + + delete (RAIN1_1D) + delete (RAIN2_1D) + delete (NPP1_1D) + delete (NPP2_1D) +;delete (range) + delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) +;************************************************************************** +;(B) histogram 933 + +;-------------------------------------------------------------------- +;get data + + RAIN1_1D = ndtooned(rain933) + RAIN2_1D = ndtooned(rainmod933) + NPP1_1D = ndtooned(npp933) + NPP2_1D = ndtooned(nppmod933) + + nx = 10 + xvalues = new((/2,nx/),float) + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + dx4 = new((/1/),float) + + get_bin(RAIN1_1D, NPP1_1D, RAIN2_1D, NPP2_1D \ + ,xvalues,yvalues,mn_yvalues,mx_yvalues,dx4) + +;---------------------------------------- +;compute correlation coeff and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr933h = esccr(uu,vv,0) +;print (ccr933h) + +;new eq + bias = sum(abs(vv-uu)/(abs(vv)+abs(uu))) + M933h = (1.- (bias/dimsizes(uu)))*5. + print (M933h) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + + delete (resh) + resh = True + resh@gsnMaximize = True + resh@gsnDraw = False + resh@gsnFrame = False + resh@xyMarkLineMode = "Markers" + resh@xyMarkerSizeF = 0.014 + resh@xyMarker = 16 + resh@xyMarkerColors = (/"Brown","Blue"/) + resh@trYMinF = min(mn_yvalues) - 10. + resh@trYMaxF = max(mx_yvalues) + 10. + + resh@tiYAxisString = "NPP (g C/m2/year)" + resh@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) +;================================================================= +;(B)-3 histogram ob 933 site only + + plot_name = "histogram_ob_933" + title = "Observed 933 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + delete (xy) + clear (wks) + +;=========================================================================== +;(B)-4 histogram model vs ob 933 site + + plot_name = "histogram_mod-ob_933" + title = model_name+ " vs Observed 933 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + resh@pmLegendDisplayMode = "Always" +; resh@pmLegendWidthF = 0.1 + resh@pmLegendWidthF = 0.08 + resh@pmLegendHeightF = 0.05 + resh@pmLegendOrthogonalPosF = -1.17 +; resh@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resh@pmLegendParallelPosF = 0.18 + resh@pmLegendParallelPosF = 0.88 ;(rightward) + +; resh@lgPerimOn = False + resh@lgLabelFontHeightF = 0.015 + resh@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933h)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resh) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + draw(xy) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + delete (xy) + clear (wks) +;***********************************************************************- +; global contour + +;res + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@gsnSpreadColors = True ; use full colormap + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 2200. ; Max level + resg@cnLevelSpacingF = 200. ; interval +;------------------------------------------------------------------------ +;(C)-1 global contour ob + + delta = 0.00000000001 + nppglobe = where(ismissing(nppglobe).and.(ismissing(nppmod).or.(nppmod.lt.delta)),0.,nppglobe) + + plot_name = "global_ob" + title = "Observed MODIS MOD 17" + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppglobe,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;(C)-2 global contour model + + plot_name = "global_model" + title = "Model "+ model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppmod,resg) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ +;(C)-3 global contour model vs ob + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +;(d) compute correlation coef and M score + + uu1 = ndtooned(nppmod) + vv1 = ndtooned(nppglobe) + + delete (good) + good = ind(.not.ismissing(uu1) .and. .not.ismissing(vv1)) + + ug = uu1(good) + vg = vv1(good) + + ccrG = esccr(ug,vg,0) +; print (ccrG) + + MG = (ccrG*ccrG)* 5.0 + print (MG) + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrG)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- + +;(a) ob + + title = "Observed MODIS MOD 17" + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,nppglobe,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,nppmod,resg) + +;(c) model-ob + + zz = nppmod + zz = nppmod - nppglobe + title = "Model_"+model_name+" - Observed" + + resg@cnMinLevelValF = -500 ; Min level + resg@cnMaxLevelValF = 500. ; Max level + resg@cnLevelSpacingF = 50. ; interval + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired + pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) +; system("rm "+plot_name+"-1."+plot_type_new) +; system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + frame (wks) + clear (wks) + + delete (plot) +;********************************************************************** +;(D)-1 zonal line plot ob + + resz = True + + vv = zonalAve(nppglobe) + vv@long_name = nppglobe@long_name + + plot_name = "zonal_ob" + title = "Observed MODIS MOD 17" + resz@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + plot = gsn_csm_xy (wks,ym,vv,resz) + frame(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;--------------------------------------------------------------------- +;(D)-2 zonal line plot model vs ob + + s = new ((/2,dimsizes(ym)/), float) + + s(0,:) = zonalAve(nppglobe) + s(1,:) = zonalAve(nppmod) + + s@long_name = nppglobe@long_name +;------------------------------------------- +;(d) compute correlation coef and M score + + ccrZ = esccr(s(1,:), s(0,:),0) +; print (ccrZ) + + MZ = (ccrZ*ccrZ)* 5.0 + print (MZ) +;------------------------------------------- + plot_name = "zonal_model_vs_ob" + title = "Zonal Average" + resz@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +; resz@vpHeightF = 0.4 ; change aspect ratio of plot +; resz@vpWidthF = 0.7 + + resz@xyMonoLineColor = "False" ; want colored lines + resz@xyLineColors = (/"black","red"/) ; colors chosen +; resz@xyLineThicknesses = (/3.,3./) ; line thicknesses + resz@xyLineThicknesses = (/2.,2./) ; line thicknesses + resz@xyDashPatterns = (/0.,0./) ; make all lines solid + + resz@tiYAxisString = s@long_name ; add a axis title + resz@txFontHeightF = 0.0195 ; change title font heights + +; Legent + resz@pmLegendDisplayMode = "Always" ; turn on legend + resz@pmLegendSide = "Top" ; Change location of +; resz@pmLegendParallelPosF = .45 ; move units right + resz@pmLegendParallelPosF = .82 ; move units right + resz@pmLegendOrthogonalPosF = -0.4 ; move units down + + resz@pmLegendWidthF = 0.10 ; Change width and + resz@pmLegendHeightF = 0.10 ; height of legend. + resz@lgLabelFontHeightF = .02 ; change font height +; resz@lgTitleOn = True ; turn on legend title +; resz@lgTitleString = "Example" ; create legend title +; resz@lgTitleFontHeightF = .025 ; font of legend title + resz@xyExplicitLegendLabels = (/"Observed",model_name/) ; explicit labels +;-------------------------------------------------------------------- + zRes = True + zRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrZ)+")" + + gsn_text_ndc(wks,correlation_text,0.50,0.77,zRes) +;-------------------------------------------------------------------- + + plot = gsn_csm_xy (wks,ym,s,resz) ; create plot + + frame(wks) ; advance frame + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + + clear (wks) +;------------------------------------------------------------------------ + temp_name = "temp." + model_name + system("mkdir -p " + temp_name) + system("mv *.png " + temp_name) + system("tar cf "+ temp_name +".tar " + temp_name) +;------------------------------------------------------------------------ +end + diff -r 000000000000 -r 0c6405ab2ff4 npp/99.all.ncl.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/99.all.ncl.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1667 @@ +;***************************************************** +; combine scatter, histogram, global and zonal plots +; compute all correlation coef and M score +; add 1-to-1 line in scatter plots +;***************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;***************************************************** +procedure get_bin(RAIN1_1D[*]:numeric, NPP1_1D[*]:numeric \ + ,RAIN2_1D[*]:numeric, NPP2_1D[*]:numeric \ + ,xvalues[*][*]:numeric, yvalues[*][*]:numeric \ + ,mn_yvalues[*][*]:numeric, mx_yvalues[*][*]:numeric \ + ,dx4[1]:numeric \ + ) +begin +; Calculaee "nice" bins for binning the data in equally spaced ranges. +; input : RAIN1_1D, RAIN2_1D, NPP1_1D, NPP2_1D +; output: xvalues, yvalues, mn_yvalues, mx_yvalues,dx4 + + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 +; print (nx) + +; xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. +; yvalues = new((/2,nx/),typeof(RAIN1_1D)) +; mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) +; mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; Print out information. + +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data) + delete(npp_data) + end do +end +;**************************************************************************** +; Main code. +;**************************************************************************** +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ + +;film = "i01.06cn_1798-2004_ANN_climo.nc" +;model_name = "06cn" +;model_grid = "T42" + +;film = "i01.06casa_1798-2004_ANN_climo.nc" +;model_name = "06casa" +;model_grid = "T42" + + film = "i01.10casa_1948-2004_ANN_climo.nc" + model_name = "10casa" + model_grid = "T42" + +;film = "i01.10cn_1948-2004_ANN_climo.nc" +;model_name = "10cn" +;model_grid = "T42" +;-------------------------------------------------- + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile (dirm+film,"r") + + nppmod0 = fm->NPP + rainmod0 = fm->RAIN + xm = fm->lon + ym = fm->lat + +;************************************************ +; read ob data +;************************************************ + +;(1) data at 81 sites + dir81 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil81 = "data.81.nc" + f81 = addfile (dir81+fil81,"r") + + id81 = f81->SITE_ID + npp81 = f81->TNPP_C + rain81 = tofloat(f81->PREC_ANN) + x81 = f81->LONG_DD + y81 = f81->LAT_DD + + id81@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x81)-1 + if (x81(i) .lt. 0.) then + x81(i) = x81(i)+ 360. + end if + end do +;print (x81) +;------------------------------------- +;(2) data at 933 sites + dir933 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil933 = "data.933.nc" + f933 = addfile (dir933+fil933,"r") + + id933 = f933->SITE_ID + npp933 = f933->TNPP_C + rain933 = f933->PREC + x933 = f933->LONG_DD + y933 = f933->LAT_DD + + id933@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x933)-1 + if (x933(i) .lt. 0.) then + x933(i) = x933(i)+ 360. + end if + end do +;print (x933) +;---------------------------------------- +;(3) global data, interpolated into model grid + dirglobe = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + filglobe = "Npp_"+model_grid+"_mean.nc" + fglobe = addfile (dirglobe+filglobe,"r") + + nppglobe0 = fglobe->NPP + nppglobe = nppglobe0 + +;*********************************************************************** +; interpolate model data into ob sites +;*********************************************************************** + + nppmod = nppmod0(0,:,:) + rainmod = rainmod0(0,:,:) + delete (nppmod0) + delete (rainmod0) + + nppmod81 =linint2_points(xm,ym,nppmod,True,x81,y81,0) + + nppmod933 =linint2_points(xm,ym,nppmod,True,x933,y933,0) + + rainmod81 =linint2_points(xm,ym,rainmod,True,x81,y81,0) + + rainmod933=linint2_points(xm,ym,rainmod,True,x933,y933,0) + +;********************************************************** +; unified units +;********************************************************** +; Units for these variables are: +; +; rain81 : mm/year +; rainmod : mm/s +; npp81 : g C/m^2/year +; nppmod81: g C/m^2/s +; nppglobe: g C/m^2/year +; +; We want to convert these to "m/year" and "g C/m^2/year". + + nsec_per_year = 60*60*24*365 + + rain81 = rain81 / 1000. + rainmod81 = (rainmod81/ 1000.) * nsec_per_year + nppmod81 = nppmod81 * nsec_per_year + + rain933 = rain933 / 1000. + rainmod933 = (rainmod933/ 1000.) * nsec_per_year + nppmod933 = nppmod933 * nsec_per_year + + nppmod = nppmod * nsec_per_year + + npp81@units = "gC/m^2/yr" + nppmod81@units = "gC/m^2/yr" + npp933@units = "gC/m^2/yr" + nppmod933@units = "gC/m^2/yr" + nppmod@units = "gC/m^2/yr" + nppglobe@units = "gC/m^2/yr" + rain81@units = "m/yr" + rainmod81@units = "m/yr" + rain933@units = "m/yr" + rainmod933@units = "m/yr" + + npp81@long_name = "NPP (gC/m2/year)" + npp933@long_name = "NPP (gC/m2/year)" + nppmod81@long_name = "NPP (gC/m2/year)" + nppmod933@long_name = "NPP (gC/m2/year)" + nppmod@long_name = "NPP (gC/m2/year)" + nppglobe@long_name = "NPP (gC/m2/year)" + rain81@long_name = "PREC (m/year)" + rain933@long_name = "PREC (m/year)" + rainmod81@long_name = "PREC (m/year)" + rainmod933@long_name = "PREC (m/year)" + +;******************************************************************* +;(A)-1 table of site81 (1) (the first 41 sites) +;******************************************************************* + + table_length = 0.95 + +; table header name + table_header_name = "Site ID" + +; column (not including header column) + col_header = (/"Latitude","Longitude","NPP (gC/m2/year)","RAIN (m/year)"/) + ncol = dimsizes(col_header) + +; row (not including header row) + nrow = 41 + row_header = new ((/nrow/),string ) + row_header(0:nrow-1) = id81(0:nrow-1) + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.95/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.015 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" +; color_fill4(:,ncol-1) = "grey" +; color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-1 + text4(n,0) = sprintf("%5.2f", y81(n)) + text4(n,1) = sprintf("%5.2f", x81(n)) + text4(n,2) = sprintf("%5.2f", npp81(n)) + text4(n,3) = sprintf("%5.2f", rain81(n)) + end do +;------------------------------------------------------------------- + + plot_name = "table_site81_ob1" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Observation at 81 Sites (1)" + + gsn_text_ndc(wks,title_text,0.50,0.975,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + clear (wks) + + delete (row_header) + delete (res3) + delete (ncr3) + delete (text3) + delete (res4) + delete (ncr4) + delete (text4) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;******************************************************************* +;(A)-2 table of site81 (2) (the last 40 sites) +;******************************************************************* + + table_length = 0.95 + +; table header name + table_header_name = "Site ID" + +; column (not including header column) + col_header = (/"Latitude","Longitude","NPP (gC/m2/year)","RAIN (m/year)"/) + ncol = dimsizes(col_header) + +; row (not including header row) + nrow = 40 + row_header = new ((/nrow/),string ) + row_header(0:nrow-1) = id81(41:41+nrow-1) + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.95/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.015 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" +; color_fill4(:,ncol-1) = "grey" +; color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-1 + text4(n,0) = sprintf("%5.2f", y81(n+41)) + text4(n,1) = sprintf("%5.2f", x81(n+41)) + text4(n,2) = sprintf("%5.2f", npp81(n+41)) + text4(n,3) = sprintf("%5.2f", rain81(n+41)) + end do +;------------------------------------------------------------------- + + plot_name = "table_site81_ob2" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Observation at 81 Sites (2)" + + gsn_text_ndc(wks,title_text,0.50,0.975,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + clear (wks) + + delete (row_header) + delete (res3) + delete (ncr3) + delete (text3) + delete (res4) + delete (ncr4) + delete (text4) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;************************************************************************** +;(A)-3 scatter plot, ob 933 +;************************************************************************** + + plot_name = "scatter_ob_933" + title = "Observed 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id933,npp933,res) ; create plot + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;************************************************************************** +;(A)-4 scatter plot, model 933 +;************************************************************************** + + plot_name = "scatter_model_933" + title = "Model "+ model_name +" 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id933,nppmod933,res) ; create plot + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;*************************************************************************** +;(A)-5 scatter plot, model vs ob 81 +;*************************************************************************** + + plot_name = "scatter_model_vs_ob_81" + title = model_name +" vs ob 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + res@gsnDraw = False + res@gsnFrame = False ; don't advance frame yet +;------------------------------- +;compute correlation coef. and M + ccr81 = esccr(nppmod81,npp81,0) +;print (ccr81) + +;new eq + bias = sum(abs(nppmod81-npp81)/(abs(nppmod81)+abs(npp81))) + M81 = (1. - (bias/dimsizes(y81)))*5. + print (M81) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp81,nppmod81,res) ; create plot +;------------------------------- +; add polyline + + dum=gsn_add_polyline(wks,plot,(/0,1200/),(/0,1200/),False) +;------------------------------- + draw (plot) + frame(wks) + clear (wks) + delete (dum) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;*************************************************************************** +;(A)-6 scatter plot, model vs ob 933 +;*************************************************************************** + + plot_name = "scatter_model_vs_ob_933" + title = model_name +" vs ob 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + res@gsnDraw = False + res@gsnFrame = False ; don't advance frame yet +;------------------------------- +;compute correlation coef. and M + ccr933 = esccr(nppmod933,npp933,0) +;print (ccr933) + +;new eq + bias = sum(abs(nppmod933-npp933)/(abs(nppmod933)+abs(npp933))) + M933 = (1. - (bias/dimsizes(y933)))*5. + print (M933) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp933,nppmod933,res) ; create plot +;------------------------------- +; add polyline + + dum=gsn_add_polyline(wks,plot,(/0,1500/),(/0,1500/),False) +;------------------------------- + draw (plot) + frame(wks) + clear (wks) + delete (dum) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;******************************************************************* +;(A)-7 table of site81 (1) (the first 41 sites), model vs ob +;******************************************************************* + + table_length = 0.95 + +; table header name + table_header_name = "Site ID" + +; row (not including header row) + nrow = 41 + row_header = new ((/nrow/),string ) + row_header(0:nrow-1) = id81(0:nrow-1) + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.85 ,0.95/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.015 + res1@gsFillColor = "CornFlowerBlue" + +; Column header1 (equally space in x2) + + delete (col_header) + delete (ncr2) + delete (text2) + + col_header = (/"Latitude","Longitude"/) + ncol = dimsizes(col_header) + + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.35/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Column header2 (equally space in x2) + + col_header1 = (/"NPP (gC/m2/year)","RAIN (m/year)"/) + col_header2 = (/"ob",model_name \ + ,"ob",model_name \ + /) + + ncol1 = dimsizes(col_header1) + ncol2 = dimsizes(col_header2) + + ncr21 = (/1,ncol1/) ; 1 rows, 4 columns + x21 = (/x2(1),0.995/) ; start from end of x2 + yhalf = (y1(0)+y1(1))*0.5 + y21 = (/yhalf,y1(1)/) ; top half of y1 + text21 = col_header1 + res21 = True + res21@txFontHeightF = 0.015 + res21@gsFillColor = "Gray" + + ncr22 = (/1,ncol2/) ; 1 rows, 12 columns + x22 = x21 ; start from end of x1 + y22 = (/y1(0),yhalf/) ; bottom half of y1 + text22 = col_header2 + res22 = True + res22@txFontHeightF = 0.015 + res22@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body-1 + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" +; color_fill4(:,ncol-1) = "grey" +; color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +; Main table body-2 + ncr42 = (/nrow,ncol2/) ; nrow rows, ncol columns + x42 = x21 ; Start and end x + y42 = y3 ; Start and end Y + text42 = new((/nrow,ncol2/),string) + + color_fill42 = new((/nrow,ncol2/),string) + color_fill42 = "white" +; color_fill42(:,ncol-1) = "grey" +; color_fill42(nrow-1,:) = "green" + + res42 = True ; Set up resource list +; res42@gsnDebug = True ; Useful to print NDC row,col values used. + res42@txFontHeightF = 0.015 + res42@gsFillColor = color_fill42 + + delete (color_fill42) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-1 + text4(n,0) = sprintf("%5.2f", y81(n)) + text4(n,1) = sprintf("%5.2f", x81(n)) + end do + + do n = 0,nrow-1 + text42(n,0) = sprintf("%5.2f", npp81(n)) + text42(n,1) = sprintf("%5.2f", nppmod81(n)) + text42(n,2) = sprintf("%5.2f", rain81(n)) + text42(n,3) = sprintf("%5.2f", rainmod81(n)) + end do +;--------------------------------------------------------------------------- + + plot_name = "table_site81_model_vs_ob1" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Model vs Observation at 81 Sites (1)" + + gsn_text_ndc(wks,title_text,0.50,0.975,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr21,x21,y21,text21,res21) + gsn_table(wks,ncr22,x22,y22,text22,res22) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + gsn_table(wks,ncr42,x42,y42,text42,res42) + + frame(wks) + clear (wks) + + delete (col_header) + delete (row_header) + delete (res1) + delete (ncr1) + delete (text1) + delete (res2) + delete (ncr2) + delete (text2) + delete (res21) + delete (ncr21) + delete (text21) + delete (res22) + delete (ncr22) + delete (text22) + delete (res3) + delete (ncr3) + delete (text3) + delete (res4) + delete (ncr4) + delete (text4) + delete (res42) + delete (ncr42) + delete (text42) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;******************************************************************* +;(A)-8 table of site81 (2) (the last 40 sites), model vs ob +;******************************************************************* + + table_length = 0.95 + +; table header name + table_header_name = "Site ID" + +; row (not including header row) + nrow = 40 + row_header = new ((/nrow/),string ) + row_header(0:nrow-1) = id81(41:41+nrow-1) + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.85 ,0.95/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.015 + res1@gsFillColor = "CornFlowerBlue" + +; Column header1 (equally space in x2) + + col_header = (/"Latitude","Longitude"/) + ncol = dimsizes(col_header) + + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.35/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Column header2 (equally space in x2) + +; col_header1 = (/"NPP (gC/m2/year)","RAIN (m/year)"/) + col_header2 = (/"ob",model_name \ + ,"ob",model_name \ + /) + + ncol1 = dimsizes(col_header1) + ncol2 = dimsizes(col_header2) + + ncr21 = (/1,ncol1/) ; 1 rows, 4 columns + x21 = (/x2(1),0.995/) ; start from end of x2 + yhalf = (y1(0)+y1(1))*0.5 + y21 = (/yhalf,y1(1)/) ; top half of y1 + text21 = col_header1 + res21 = True + res21@txFontHeightF = 0.015 + res21@gsFillColor = "Gray" + + ncr22 = (/1,ncol2/) ; 1 rows, 12 columns + x22 = x21 ; start from end of x1 + y22 = (/y1(0),yhalf/) ; bottom half of y1 + text22 = col_header2 + res22 = True + res22@txFontHeightF = 0.015 + res22@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body-1 + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" +; color_fill4(:,ncol-1) = "grey" +; color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +; Main table body-2 + ncr42 = (/nrow,ncol2/) ; nrow rows, ncol columns + x42 = x21 ; Start and end x + y42 = y3 ; Start and end Y + text42 = new((/nrow,ncol2/),string) + + color_fill42 = new((/nrow,ncol2/),string) + color_fill42 = "white" +; color_fill42(:,ncol-1) = "grey" +; color_fill42(nrow-1,:) = "green" + + res42 = True ; Set up resource list +; res42@gsnDebug = True ; Useful to print NDC row,col values used. + res42@txFontHeightF = 0.015 + res42@gsFillColor = color_fill42 + + delete (color_fill42) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-1 + text4(n,0) = sprintf("%5.2f", y81(n+41)) + text4(n,1) = sprintf("%5.2f", x81(n+41)) + end do + + do n = 0,nrow-1 + text42(n,0) = sprintf("%5.2f", npp81(n+41)) + text42(n,1) = sprintf("%5.2f", nppmod81(n+41)) + text42(n,2) = sprintf("%5.2f", rain81(n+41)) + text42(n,3) = sprintf("%5.2f", rainmod81(n+41)) + end do +;------------------------------------------------------------------- + + plot_name = "table_site81_model_vs_ob2" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Model vs Observation at 81 Sites (2)" + + gsn_text_ndc(wks,title_text,0.50,0.975,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr21,x21,y21,text21,res21) + gsn_table(wks,ncr22,x22,y22,text22,res22) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + gsn_table(wks,ncr42,x42,y42,text42,res42) + + frame(wks) + clear (wks) + + delete (col_header) + delete (row_header) + delete (res1) + delete (ncr1) + delete (text1) + delete (res2) + delete (ncr2) + delete (text2) + delete (res21) + delete (ncr21) + delete (text21) + delete (res22) + delete (ncr22) + delete (text22) + delete (res3) + delete (ncr3) + delete (text3) + delete (res4) + delete (ncr4) + delete (text4) + delete (res42) + delete (ncr42) + delete (text42) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;************************************************************************** +;(B) histogram 81 +;************************************************************************** +;get data + RAIN1_1D = ndtooned(rain81) + RAIN2_1D = ndtooned(rainmod81) + NPP1_1D = ndtooned(npp81) + NPP2_1D = ndtooned(nppmod81) + +; number of bin + nx = 8 + + xvalues = new((/2,nx/),float) + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + dx4 = new((/1/),float) + + get_bin(RAIN1_1D, NPP1_1D, RAIN2_1D, NPP2_1D \ + ,xvalues,yvalues,mn_yvalues,mx_yvalues,dx4) + +;---------------------------------------- +;compute correlation coeff and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr81h = esccr(uu,vv,0) +;print (ccr81h) + +;new eq + bias = sum(abs(vv-uu)/(abs(vv)+abs(uu))) + M81h = (1.- (bias/dimsizes(uu)))*5. + print (M81h) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + resh = True + resh@gsnMaximize = True + resh@gsnDraw = False + resh@gsnFrame = False + resh@xyMarkLineMode = "Markers" + resh@xyMarkerSizeF = 0.014 + resh@xyMarker = 16 + resh@xyMarkerColors = (/"Brown","Blue"/) + resh@trYMinF = min(mn_yvalues) - 10. + resh@trYMaxF = max(mx_yvalues) + 10. + + resh@tiYAxisString = "NPP (g C/m2/year)" + resh@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) + +;************************************************************************** +;(B)-1 histogram plot, ob 81 site +;************************************************************************** + + plot_name = "histogram_ob_81" + title = "Observed 81 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + delete (x1) + delete (x2) + delete (y1) + delete (y2) + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + plx = (/x1,x1/) + ply = (/y1,y2/) + min_bar(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + + y2 = mx_yvalues(nd,i) + plx = (/x1,x1/) + ply = (/y1,y2/) + max_bar(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + plx = (/x1,x2/) + ply = (/y1,y1/) + min_cap(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + + y1 = mx_yvalues(nd,i) + plx = (/x1,x2/) + ply = (/y1,y1/) + max_cap(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + end if + end do + end do + + draw(xy) + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(B)-2 histogram plot, model vs ob 81 site +;**************************************************************************** + + plot_name = "histogram_model_vs_ob_81" + title = model_name+ " vs Observed 81 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + resh@pmLegendDisplayMode = "Always" +; resh@pmLegendWidthF = 0.1 + resh@pmLegendWidthF = 0.08 + resh@pmLegendHeightF = 0.05 + resh@pmLegendOrthogonalPosF = -1.17 +; resh@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resh@pmLegendParallelPosF = 0.18 + resh@pmLegendParallelPosF = 0.88 ;(rightward) + +; resh@lgPerimOn = False + resh@lgLabelFontHeightF = 0.015 + resh@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81h)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resh) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + clear(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + delete (RAIN1_1D) + delete (RAIN2_1D) + delete (NPP1_1D) + delete (NPP2_1D) +;delete (range) + delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) + +;************************************************************************** +;(B) histogram 933 +;************************************************************************** + +; get data + RAIN1_1D = ndtooned(rain933) + RAIN2_1D = ndtooned(rainmod933) + NPP1_1D = ndtooned(npp933) + NPP2_1D = ndtooned(nppmod933) + +; number of bin + nx = 10 + + xvalues = new((/2,nx/),float) + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + dx4 = new((/1/),float) + + get_bin(RAIN1_1D, NPP1_1D, RAIN2_1D, NPP2_1D \ + ,xvalues,yvalues,mn_yvalues,mx_yvalues,dx4) + +;---------------------------------------- +;compute correlation coeff and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr933h = esccr(uu,vv,0) +;print (ccr933h) + +;new eq + bias = sum(abs(vv-uu)/(abs(vv)+abs(uu))) + M933h = (1.- (bias/dimsizes(uu)))*5. + print (M933h) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + delete (resh) + resh = True + resh@gsnMaximize = True + resh@gsnDraw = False + resh@gsnFrame = False + resh@xyMarkLineMode = "Markers" + resh@xyMarkerSizeF = 0.014 + resh@xyMarker = 16 + resh@xyMarkerColors = (/"Brown","Blue"/) + resh@trYMinF = min(mn_yvalues) - 10. + resh@trYMaxF = max(mx_yvalues) + 10. + + resh@tiYAxisString = "NPP (g C/m2/year)" + resh@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) + +;************************************************************************** +;(B)-3 histogram plot, ob 933 site +;************************************************************************** + + plot_name = "histogram_ob_933" + title = "Observed 933 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + delete (xy) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(B)-4 histogram plot, model vs ob 933 site +;**************************************************************************** + + plot_name = "histogram_model_vs_ob_933" + title = model_name+ " vs Observed 933 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + resh@pmLegendDisplayMode = "Always" +; resh@pmLegendWidthF = 0.1 + resh@pmLegendWidthF = 0.08 + resh@pmLegendHeightF = 0.05 + resh@pmLegendOrthogonalPosF = -1.17 +; resh@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resh@pmLegendParallelPosF = 0.18 + resh@pmLegendParallelPosF = 0.88 ;(rightward) + +; resh@lgPerimOn = False + resh@lgLabelFontHeightF = 0.015 + resh@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933h)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resh) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + delete(xy) + clear(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;*************************************************************************** +;(C) global contour +;*************************************************************************** + +;res + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@gsnSpreadColors = True ; use full colormap + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 2200. ; Max level + resg@cnLevelSpacingF = 200. ; interval + +;**************************************************************************** +;(C)-1 global contour plot, ob +;**************************************************************************** + + delta = 0.00000000001 + nppglobe = where(ismissing(nppglobe).and.(ismissing(nppmod).or.(nppmod.lt.delta)),0.,nppglobe) + + plot_name = "global_ob" + title = "Observed MODIS MOD 17" + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppglobe,resg) + + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(C)-2 global contour plot, model +;**************************************************************************** + + plot_name = "global_model" + title = "Model "+ model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppmod,resg) + + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(C)-3 global contour plot, model vs ob +;**************************************************************************** + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; compute correlation coef and M score + + uu1 = ndtooned(nppmod) + vv1 = ndtooned(nppglobe) + + delete (good) + good = ind(.not.ismissing(uu1) .and. .not.ismissing(vv1)) + + ug = uu1(good) + vg = vv1(good) + + ccrG = esccr(ug,vg,0) +; print (ccrG) + + MG = (ccrG*ccrG)* 5.0 + print (MG) + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrG)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = "Observed MODIS MOD 17" + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,nppglobe,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,nppmod,resg) + +;(c) model-ob + + zz = nppmod + zz = nppmod - nppglobe + title = "Model_"+model_name+" - Observed" + + resg@cnMinLevelValF = -500 ; Min level + resg@cnMaxLevelValF = 500. ; Max level + resg@cnLevelSpacingF = 50. ; interval + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + frame (wks) + clear (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;*************************************************************************** +;(D)-1 zonal line plot, ob +;*************************************************************************** + + vv = zonalAve(nppglobe) + vv@long_name = nppglobe@long_name + + plot_name = "zonal_ob" + title = "Observed MODIS MOD 17" + + resz = True + resz@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + plot = gsn_csm_xy (wks,ym,vv,resz) + + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(D)-2 zonal line plot, model vs ob +;**************************************************************************** + + s = new ((/2,dimsizes(ym)/), float) + + s(0,:) = zonalAve(nppglobe) + s(1,:) = zonalAve(nppmod) + + s@long_name = nppglobe@long_name +;------------------------------------------- +; compute correlation coef and M score + + ccrZ = esccr(s(1,:), s(0,:),0) +; print (ccrZ) + + MZ = (ccrZ*ccrZ)* 5.0 + print (MZ) +;------------------------------------------- + plot_name = "zonal_model_vs_ob" + title = "Zonal Average" + resz@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + +; resz@vpHeightF = 0.4 ; change aspect ratio of plot +; resz@vpWidthF = 0.7 + + resz@xyMonoLineColor = "False" ; want colored lines + resz@xyLineColors = (/"black","red"/) ; colors chosen +; resz@xyLineThicknesses = (/3.,3./) ; line thicknesses + resz@xyLineThicknesses = (/2.,2./) ; line thicknesses + resz@xyDashPatterns = (/0.,0./) ; make all lines solid + + resz@tiYAxisString = s@long_name ; add a axis title + resz@txFontHeightF = 0.0195 ; change title font heights + +; Legent + resz@pmLegendDisplayMode = "Always" ; turn on legend + resz@pmLegendSide = "Top" ; Change location of +; resz@pmLegendParallelPosF = .45 ; move units right + resz@pmLegendParallelPosF = .82 ; move units right + resz@pmLegendOrthogonalPosF = -0.4 ; move units down + + resz@pmLegendWidthF = 0.10 ; Change width and + resz@pmLegendHeightF = 0.10 ; height of legend. + resz@lgLabelFontHeightF = .02 ; change font height +; resz@lgTitleOn = True ; turn on legend title +; resz@lgTitleString = "Example" ; create legend title +; resz@lgTitleFontHeightF = .025 ; font of legend title + resz@xyExplicitLegendLabels = (/"Observed",model_name/) ; explicit labels +;-------------------------------------------------------------------- + zRes = True + zRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrZ)+")" + + gsn_text_ndc(wks,correlation_text,0.50,0.77,zRes) +;-------------------------------------------------------------------- + + plot = gsn_csm_xy (wks,ym,s,resz) + + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;*************************************************************************** +; tar up output plots +;*************************************************************************** + + temp_name = "temp." + model_name + system("mkdir -p " + temp_name) + system("mv *.png " + temp_name) + system("tar cf "+ temp_name +".tar " + temp_name) + +;*************************************************************************** +end + diff -r 000000000000 -r 0c6405ab2ff4 npp/99.all.ncl.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/99.all.ncl.2 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,1695 @@ +;***************************************************** +; combine scatter, histogram, global and zonal plots +; compute all correlation coef and M score +; add 1-to-1 line in scatter plots +;***************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;***************************************************** +procedure get_bin(RAIN1_1D[*]:numeric, NPP1_1D[*]:numeric \ + ,RAIN2_1D[*]:numeric, NPP2_1D[*]:numeric \ + ,xvalues[*][*]:numeric, yvalues[*][*]:numeric \ + ,mn_yvalues[*][*]:numeric, mx_yvalues[*][*]:numeric \ + ,dx4[1]:numeric \ + ) +begin +; Calculaee "nice" bins for binning the data in equally spaced ranges. +; input : RAIN1_1D, RAIN2_1D, NPP1_1D, NPP2_1D +; output: xvalues, yvalues, mn_yvalues, mx_yvalues,dx4 + + nbins = 15 ; Number of bins to use. + + nicevals = nice_mnmxintvl(min(RAIN1_1D),max(RAIN1_1D),nbins,True) + nvals = floattoint((nicevals(1) - nicevals(0))/nicevals(2) + 1) + range = fspan(nicevals(0),nicevals(1),nvals) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 +; print (nx) + +; xvalues = new((/2,nx/),typeof(RAIN1_1D)) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. +; yvalues = new((/2,nx/),typeof(RAIN1_1D)) +; mn_yvalues = new((/2,nx/),typeof(RAIN1_1D)) +; mx_yvalues = new((/2,nx/),typeof(RAIN1_1D)) + + do nd=0,1 + +; See if we are doing model or observational data. + + if(nd.eq.0) then + data = RAIN1_1D + npp_data = NPP1_1D + else + data = RAIN2_1D + npp_data = NPP2_1D + end if + +; Loop through each range and check for values. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((range(i).le.data).and.(data.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(range(i).le.data) + end if + +; Calculate average, and get min and max. + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(npp_data(idx)) + mn_yvalues(nd,i) = min(npp_data(idx)) + mx_yvalues(nd,i) = max(npp_data(idx)) + count = dimsizes(idx) + else + count = 0 + yvalues(nd,i) = yvalues@_FillValue + mn_yvalues(nd,i) = yvalues@_FillValue + mx_yvalues(nd,i) = yvalues@_FillValue + end if + +; Print out information. +; print(data_types(nd) + ": " + count + " points, avg = " + yvalues(nd,i)) +; print("Min/Max: " + mn_yvalues(nd,i) + "/" + mx_yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + delete(data) + delete(npp_data) + end do +end +;**************************************************************************** +; Main code. +;**************************************************************************** +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read model data +;************************************************ + +;film = "i01.06cn_1798-2004_ANN_climo.nc" +;model_name = "06cn" +;model_grid = "T42" + +;film = "i01.06casa_1798-2004_ANN_climo.nc" +;model_name = "06casa" +;model_grid = "T42" + +;film = "i01.10casa_1948-2004_ANN_climo.nc" +;model_name = "10casa" +;model_grid = "T42" + + film = "i01.10cn_1948-2004_ANN_climo.nc" + model_name = "10cn" + model_grid = "T42" + + html_name = "table.html." + model_name + html_new = html_name +".new" + system("sed s#model_name#"+model_name+"# "+html_name+" > "+html_new) + system("mv -f "+html_new+" "+html_name) +;-------------------------------------------------- + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + fm = addfile (dirm+film,"r") + + nppmod0 = fm->NPP + rainmod0 = fm->RAIN + xm = fm->lon + ym = fm->lat + +;************************************************ +; read ob data +;************************************************ + +;(1) data at 81 sites + dir81 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil81 = "data.81.nc" + f81 = addfile (dir81+fil81,"r") + + id81 = f81->SITE_ID + npp81 = f81->TNPP_C + rain81 = tofloat(f81->PREC_ANN) + x81 = f81->LONG_DD + y81 = f81->LAT_DD + + id81@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x81)-1 + if (x81(i) .lt. 0.) then + x81(i) = x81(i)+ 360. + end if + end do +;print (x81) +;------------------------------------- +;(2) data at 933 sites + dir933 = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + fil933 = "data.933.nc" + f933 = addfile (dir933+fil933,"r") + + id933 = f933->SITE_ID + npp933 = f933->TNPP_C + rain933 = f933->PREC + x933 = f933->LONG_DD + y933 = f933->LAT_DD + + id933@long_name = "SITE_ID" + +;change longitude from (-180,180) to (0,360) +;for model data interpolation + + do i= 0,dimsizes(x933)-1 + if (x933(i) .lt. 0.) then + x933(i) = x933(i)+ 360. + end if + end do +;print (x933) +;---------------------------------------- +;(3) global data, interpolated into model grid + dirglobe = "/fis/cgd/cseg/people/jeff/clamp_data/npp/ob/" + filglobe = "Npp_"+model_grid+"_mean.nc" + fglobe = addfile (dirglobe+filglobe,"r") + + nppglobe0 = fglobe->NPP + nppglobe = nppglobe0 + +;*********************************************************************** +; interpolate model data into ob sites +;*********************************************************************** + + nppmod = nppmod0(0,:,:) + rainmod = rainmod0(0,:,:) + delete (nppmod0) + delete (rainmod0) + + nppmod81 =linint2_points(xm,ym,nppmod,True,x81,y81,0) + + nppmod933 =linint2_points(xm,ym,nppmod,True,x933,y933,0) + + rainmod81 =linint2_points(xm,ym,rainmod,True,x81,y81,0) + + rainmod933=linint2_points(xm,ym,rainmod,True,x933,y933,0) + +;********************************************************** +; unified units +;********************************************************** +; Units for these variables are: +; +; rain81 : mm/year +; rainmod : mm/s +; npp81 : g C/m^2/year +; nppmod81: g C/m^2/s +; nppglobe: g C/m^2/year +; +; We want to convert these to "m/year" and "g C/m^2/year". + + nsec_per_year = 60*60*24*365 + + rain81 = rain81 / 1000. + rainmod81 = (rainmod81/ 1000.) * nsec_per_year + nppmod81 = nppmod81 * nsec_per_year + + rain933 = rain933 / 1000. + rainmod933 = (rainmod933/ 1000.) * nsec_per_year + nppmod933 = nppmod933 * nsec_per_year + + nppmod = nppmod * nsec_per_year + + npp81@units = "gC/m^2/yr" + nppmod81@units = "gC/m^2/yr" + npp933@units = "gC/m^2/yr" + nppmod933@units = "gC/m^2/yr" + nppmod@units = "gC/m^2/yr" + nppglobe@units = "gC/m^2/yr" + rain81@units = "m/yr" + rainmod81@units = "m/yr" + rain933@units = "m/yr" + rainmod933@units = "m/yr" + + npp81@long_name = "NPP (gC/m2/year)" + npp933@long_name = "NPP (gC/m2/year)" + nppmod81@long_name = "NPP (gC/m2/year)" + nppmod933@long_name = "NPP (gC/m2/year)" + nppmod@long_name = "NPP (gC/m2/year)" + nppglobe@long_name = "NPP (gC/m2/year)" + rain81@long_name = "PREC (m/year)" + rain933@long_name = "PREC (m/year)" + rainmod81@long_name = "PREC (m/year)" + rainmod933@long_name = "PREC (m/year)" + +;******************************************************************* +;(A)-1 table of site81 (1) (the first 41 sites) +;******************************************************************* + + table_length = 0.95 + +; table header name + table_header_name = "Site ID" + +; column (not including header column) + col_header = (/"Latitude","Longitude","NPP (gC/m2/year)","RAIN (m/year)"/) + ncol = dimsizes(col_header) + +; row (not including header row) + nrow = 41 + row_header = new ((/nrow/),string ) + row_header(0:nrow-1) = id81(0:nrow-1) + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.95/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.015 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" +; color_fill4(:,ncol-1) = "grey" +; color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-1 + text4(n,0) = sprintf("%5.2f", y81(n)) + text4(n,1) = sprintf("%5.2f", x81(n)) + text4(n,2) = sprintf("%5.2f", npp81(n)) + text4(n,3) = sprintf("%5.2f", rain81(n)) + end do +;------------------------------------------------------------------- + + plot_name = "table_site81_ob1" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Observation at 81 Sites (1)" + + gsn_text_ndc(wks,title_text,0.50,0.975,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + clear (wks) + + delete (row_header) + delete (res3) + delete (ncr3) + delete (text3) + delete (res4) + delete (ncr4) + delete (text4) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;******************************************************************* +;(A)-2 table of site81 (2) (the last 40 sites) +;******************************************************************* + + table_length = 0.95 + +; table header name + table_header_name = "Site ID" + +; column (not including header column) + col_header = (/"Latitude","Longitude","NPP (gC/m2/year)","RAIN (m/year)"/) + ncol = dimsizes(col_header) + +; row (not including header row) + nrow = 40 + row_header = new ((/nrow/),string ) + row_header(0:nrow-1) = id81(41:41+nrow-1) + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.900,0.95/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.015 + res1@gsFillColor = "CornFlowerBlue" + +; Column header (equally space in x2) + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.995/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" +; color_fill4(:,ncol-1) = "grey" +; color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-1 + text4(n,0) = sprintf("%5.2f", y81(n+41)) + text4(n,1) = sprintf("%5.2f", x81(n+41)) + text4(n,2) = sprintf("%5.2f", npp81(n+41)) + text4(n,3) = sprintf("%5.2f", rain81(n+41)) + end do +;------------------------------------------------------------------- + + plot_name = "table_site81_ob2" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Observation at 81 Sites (2)" + + gsn_text_ndc(wks,title_text,0.50,0.975,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + + frame(wks) + clear (wks) + + delete (row_header) + delete (res3) + delete (ncr3) + delete (text3) + delete (res4) + delete (ncr4) + delete (text4) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;************************************************************************** +;(A)-3 scatter plot, ob 933 +;************************************************************************** + + plot_name = "scatter_ob_933" + title = "Observed 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id933,npp933,res) ; create plot + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;************************************************************************** +;(A)-4 scatter plot, model 933 +;************************************************************************** + + plot_name = "scatter_model_933" + title = "Model "+ model_name +" 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + plot = gsn_csm_xy (wks,id933,nppmod933,res) ; create plot + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;*************************************************************************** +;(A)-5 scatter plot, model vs ob 81 +;*************************************************************************** + + plot_name = "scatter_model_vs_ob_81" + title = model_name +" vs ob 81 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + res@gsnDraw = False + res@gsnFrame = False ; don't advance frame yet +;------------------------------- +;compute correlation coef. and M + ccr81 = esccr(nppmod81,npp81,0) +;print (ccr81) + +;new eq + bias = sum(abs(nppmod81-npp81)/(abs(nppmod81)+abs(npp81))) + M81 = (1. - (bias/dimsizes(y81)))*5. + + M_npp_S81 = sprintf("%.2f", M81) + system("sed s#M_npp_S81#"+M_npp_S81+"# "+html_name+" > "+html_new) + system("mv -f "+html_new+" "+html_name) + print (M_npp_S81) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp81,nppmod81,res) ; create plot +;------------------------------- +; add polyline + + dum=gsn_add_polyline(wks,plot,(/0,1200/),(/0,1200/),False) +;------------------------------- + draw (plot) + frame(wks) + clear (wks) + delete (dum) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;*************************************************************************** +;(A)-6 scatter plot, model vs ob 933 +;*************************************************************************** + + plot_name = "scatter_model_vs_ob_933" + title = model_name +" vs ob 933 sites" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + res = True ; plot mods desired + res@tiMainString = title ; add title + res@xyMarkLineModes = "Markers" ; choose which have markers + res@xyMarkers = 16 ; choose type of marker + res@xyMarkerColor = "red" ; Marker color + res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01) + res@tmLabelAutoStride = True ; nice tick mark labels + + res@gsnDraw = False + res@gsnFrame = False ; don't advance frame yet +;------------------------------- +;compute correlation coef. and M + ccr933 = esccr(nppmod933,npp933,0) +;print (ccr933) + +;new eq + bias = sum(abs(nppmod933-npp933)/(abs(nppmod933)+abs(npp933))) + M933 = (1. - (bias/dimsizes(y933)))*5. + + M_npp_S933 = sprintf("%.2f", M933) + system("sed s#M_npp_S933#"+M_npp_S933+"# "+html_name+" > "+html_new) + system("mv -f "+html_new+" "+html_name) + print (M_npp_S933) + + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933)+")" + + gsn_text_ndc(wks,correlation_text,0.5,0.95,tRes) +;-------------------------------- + plot = gsn_csm_xy (wks,npp933,nppmod933,res) ; create plot +;------------------------------- +; add polyline + + dum=gsn_add_polyline(wks,plot,(/0,1500/),(/0,1500/),False) +;------------------------------- + draw (plot) + frame(wks) + clear (wks) + delete (dum) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;******************************************************************* +;(A)-7 table of site81 (1) (the first 41 sites), model vs ob +;******************************************************************* + + table_length = 0.95 + +; table header name + table_header_name = "Site ID" + +; row (not including header row) + nrow = 41 + row_header = new ((/nrow/),string ) + row_header(0:nrow-1) = id81(0:nrow-1) + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.85 ,0.95/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.015 + res1@gsFillColor = "CornFlowerBlue" + +; Column header1 (equally space in x2) + + delete (col_header) + delete (ncr2) + delete (text2) + + col_header = (/"Latitude","Longitude"/) + ncol = dimsizes(col_header) + + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.35/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Column header2 (equally space in x2) + + col_header1 = (/"NPP (gC/m2/year)","RAIN (m/year)"/) + col_header2 = (/"ob",model_name \ + ,"ob",model_name \ + /) + + ncol1 = dimsizes(col_header1) + ncol2 = dimsizes(col_header2) + + ncr21 = (/1,ncol1/) ; 1 rows, 4 columns + x21 = (/x2(1),0.995/) ; start from end of x2 + yhalf = (y1(0)+y1(1))*0.5 + y21 = (/yhalf,y1(1)/) ; top half of y1 + text21 = col_header1 + res21 = True + res21@txFontHeightF = 0.015 + res21@gsFillColor = "Gray" + + ncr22 = (/1,ncol2/) ; 1 rows, 12 columns + x22 = x21 ; start from end of x1 + y22 = (/y1(0),yhalf/) ; bottom half of y1 + text22 = col_header2 + res22 = True + res22@txFontHeightF = 0.015 + res22@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body-1 + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" +; color_fill4(:,ncol-1) = "grey" +; color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +; Main table body-2 + ncr42 = (/nrow,ncol2/) ; nrow rows, ncol columns + x42 = x21 ; Start and end x + y42 = y3 ; Start and end Y + text42 = new((/nrow,ncol2/),string) + + color_fill42 = new((/nrow,ncol2/),string) + color_fill42 = "white" +; color_fill42(:,ncol-1) = "grey" +; color_fill42(nrow-1,:) = "green" + + res42 = True ; Set up resource list +; res42@gsnDebug = True ; Useful to print NDC row,col values used. + res42@txFontHeightF = 0.015 + res42@gsFillColor = color_fill42 + + delete (color_fill42) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-1 + text4(n,0) = sprintf("%5.2f", y81(n)) + text4(n,1) = sprintf("%5.2f", x81(n)) + end do + + do n = 0,nrow-1 + text42(n,0) = sprintf("%5.2f", npp81(n)) + text42(n,1) = sprintf("%5.2f", nppmod81(n)) + text42(n,2) = sprintf("%5.2f", rain81(n)) + text42(n,3) = sprintf("%5.2f", rainmod81(n)) + end do +;--------------------------------------------------------------------------- + + plot_name = "table_site81_model_vs_ob1" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Model vs Observation at 81 Sites (1)" + + gsn_text_ndc(wks,title_text,0.50,0.975,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr21,x21,y21,text21,res21) + gsn_table(wks,ncr22,x22,y22,text22,res22) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + gsn_table(wks,ncr42,x42,y42,text42,res42) + + frame(wks) + clear (wks) + + delete (col_header) + delete (row_header) + delete (res1) + delete (ncr1) + delete (text1) + delete (res2) + delete (ncr2) + delete (text2) + delete (res21) + delete (ncr21) + delete (text21) + delete (res22) + delete (ncr22) + delete (text22) + delete (res3) + delete (ncr3) + delete (text3) + delete (res4) + delete (ncr4) + delete (text4) + delete (res42) + delete (ncr42) + delete (text42) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;******************************************************************* +;(A)-8 table of site81 (2) (the last 40 sites), model vs ob +;******************************************************************* + + table_length = 0.95 + +; table header name + table_header_name = "Site ID" + +; row (not including header row) + nrow = 40 + row_header = new ((/nrow/),string ) + row_header(0:nrow-1) = id81(41:41+nrow-1) + +; Table header + ncr1 = (/1,1/) ; 1 row, 1 column + x1 = (/0.005,0.15/) ; Start and end X + y1 = (/0.85 ,0.95/) ; Start and end Y + text1 = table_header_name + res1 = True + res1@txFontHeightF = 0.015 + res1@gsFillColor = "CornFlowerBlue" + +; Column header1 (equally space in x2) + + col_header = (/"Latitude","Longitude"/) + ncol = dimsizes(col_header) + + ncr2 = (/1,ncol/) ; 1 rows, ncol columns + x2 = (/x1(1),0.35/) ; start from end of x1 + y2 = y1 ; same as y1 + text2 = col_header + res2 = True + res2@txFontHeightF = 0.015 + res2@gsFillColor = "Gray" + +; Column header2 (equally space in x2) + +; col_header1 = (/"NPP (gC/m2/year)","RAIN (m/year)"/) + col_header2 = (/"ob",model_name \ + ,"ob",model_name \ + /) + + ncol1 = dimsizes(col_header1) + ncol2 = dimsizes(col_header2) + + ncr21 = (/1,ncol1/) ; 1 rows, 4 columns + x21 = (/x2(1),0.995/) ; start from end of x2 + yhalf = (y1(0)+y1(1))*0.5 + y21 = (/yhalf,y1(1)/) ; top half of y1 + text21 = col_header1 + res21 = True + res21@txFontHeightF = 0.015 + res21@gsFillColor = "Gray" + + ncr22 = (/1,ncol2/) ; 1 rows, 12 columns + x22 = x21 ; start from end of x1 + y22 = (/y1(0),yhalf/) ; bottom half of y1 + text22 = col_header2 + res22 = True + res22@txFontHeightF = 0.015 + res22@gsFillColor = "Gray" + +; Row header (equally space in y2) + ncr3 = (/nrow,1/) ; nrow rows, 1 columns + x3 = x1 ; same as x1 + y3 = (/1.0-table_length,y1(0)/) ; end at start of y1 + text3 = row_header + res3 = True + res3@txFontHeightF = 0.010 + res3@gsFillColor = "Gray" + +; Main table body-1 + ncr4 = (/nrow,ncol/) ; nrow rows, ncol columns + x4 = x2 ; Start and end x + y4 = y3 ; Start and end Y + text4 = new((/nrow,ncol/),string) + + color_fill4 = new((/nrow,ncol/),string) + color_fill4 = "white" +; color_fill4(:,ncol-1) = "grey" +; color_fill4(nrow-1,:) = "green" + + res4 = True ; Set up resource list +; res4@gsnDebug = True ; Useful to print NDC row,col values used. + res4@txFontHeightF = 0.015 + res4@gsFillColor = color_fill4 + + delete (color_fill4) + +; Main table body-2 + ncr42 = (/nrow,ncol2/) ; nrow rows, ncol columns + x42 = x21 ; Start and end x + y42 = y3 ; Start and end Y + text42 = new((/nrow,ncol2/),string) + + color_fill42 = new((/nrow,ncol2/),string) + color_fill42 = "white" +; color_fill42(:,ncol-1) = "grey" +; color_fill42(nrow-1,:) = "green" + + res42 = True ; Set up resource list +; res42@gsnDebug = True ; Useful to print NDC row,col values used. + res42@txFontHeightF = 0.015 + res42@gsFillColor = color_fill42 + + delete (color_fill42) +;------------------------------------------------------------------- +; for table value + + do n = 0,nrow-1 + text4(n,0) = sprintf("%5.2f", y81(n+41)) + text4(n,1) = sprintf("%5.2f", x81(n+41)) + end do + + do n = 0,nrow-1 + text42(n,0) = sprintf("%5.2f", npp81(n+41)) + text42(n,1) = sprintf("%5.2f", nppmod81(n+41)) + text42(n,2) = sprintf("%5.2f", rain81(n+41)) + text42(n,3) = sprintf("%5.2f", rainmod81(n+41)) + end do +;------------------------------------------------------------------- + + plot_name = "table_site81_model_vs_ob2" + + wks = gsn_open_wks (plot_type,plot_name) +;------------------------------------------ +; for table title + + gRes = True + gRes@txFontHeightF = 0.02 +; gRes@txAngleF = 90 + + title_text = "Model vs Observation at 81 Sites (2)" + + gsn_text_ndc(wks,title_text,0.50,0.975,gRes) +;------------------------------------------ + + gsn_table(wks,ncr1,x1,y1,text1,res1) + gsn_table(wks,ncr2,x2,y2,text2,res2) + gsn_table(wks,ncr21,x21,y21,text21,res21) + gsn_table(wks,ncr22,x22,y22,text22,res22) + gsn_table(wks,ncr3,x3,y3,text3,res3) + gsn_table(wks,ncr4,x4,y4,text4,res4) + gsn_table(wks,ncr42,x42,y42,text42,res42) + + frame(wks) + clear (wks) + + delete (col_header) + delete (row_header) + delete (res1) + delete (ncr1) + delete (text1) + delete (res2) + delete (ncr2) + delete (text2) + delete (res21) + delete (ncr21) + delete (text21) + delete (res22) + delete (ncr22) + delete (text22) + delete (res3) + delete (ncr3) + delete (text3) + delete (res4) + delete (ncr4) + delete (text4) + delete (res42) + delete (ncr42) + delete (text42) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + system("rm "+plot_name+"-1."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + +;************************************************************************** +;(B) histogram 81 +;************************************************************************** +;get data + RAIN1_1D = ndtooned(rain81) + RAIN2_1D = ndtooned(rainmod81) + NPP1_1D = ndtooned(npp81) + NPP2_1D = ndtooned(nppmod81) + +; number of bin + nx = 8 + + xvalues = new((/2,nx/),float) + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + dx4 = new((/1/),float) + + get_bin(RAIN1_1D, NPP1_1D, RAIN2_1D, NPP2_1D \ + ,xvalues,yvalues,mn_yvalues,mx_yvalues,dx4) + +;---------------------------------------- +;compute correlation coeff and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr81h = esccr(uu,vv,0) +;print (ccr81h) + +;new eq + bias = sum(abs(vv-uu)/(abs(vv)+abs(uu))) + M81h = (1.- (bias/dimsizes(uu)))*5. + + M_npp_H81 = sprintf("%.2f", M81h) + system("sed s#M_npp_H81#"+M_npp_H81+"# "+html_name+" > "+html_new) + system("mv -f "+html_new+" "+html_name) + print (M_npp_H81) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + resh = True + resh@gsnMaximize = True + resh@gsnDraw = False + resh@gsnFrame = False + resh@xyMarkLineMode = "Markers" + resh@xyMarkerSizeF = 0.014 + resh@xyMarker = 16 + resh@xyMarkerColors = (/"Brown","Blue"/) + resh@trYMinF = min(mn_yvalues) - 10. + resh@trYMaxF = max(mx_yvalues) + 10. + + resh@tiYAxisString = "NPP (g C/m2/year)" + resh@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) + +;************************************************************************** +;(B)-1 histogram plot, ob 81 site +;************************************************************************** + + plot_name = "histogram_ob_81" + title = "Observed 81 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + delete (x1) + delete (x2) + delete (y1) + delete (y2) + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + plx = (/x1,x1/) + ply = (/y1,y2/) + min_bar(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + + y2 = mx_yvalues(nd,i) + plx = (/x1,x1/) + ply = (/y1,y2/) + max_bar(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + plx = (/x1,x2/) + ply = (/y1,y1/) + min_cap(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + + y1 = mx_yvalues(nd,i) + plx = (/x1,x2/) + ply = (/y1,y1/) + max_cap(nd,i) = gsn_add_polyline(wks,xy,plx,ply,lnres) + end if + end do + end do + + draw(xy) + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(B)-2 histogram plot, model vs ob 81 site +;**************************************************************************** + + plot_name = "histogram_model_vs_ob_81" + title = model_name+ " vs Observed 81 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + resh@pmLegendDisplayMode = "Always" +; resh@pmLegendWidthF = 0.1 + resh@pmLegendWidthF = 0.08 + resh@pmLegendHeightF = 0.05 + resh@pmLegendOrthogonalPosF = -1.17 +; resh@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resh@pmLegendParallelPosF = 0.18 + resh@pmLegendParallelPosF = 0.88 ;(rightward) + +; resh@lgPerimOn = False + resh@lgLabelFontHeightF = 0.015 + resh@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr81h)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resh) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + clear(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + + delete (RAIN1_1D) + delete (RAIN2_1D) + delete (NPP1_1D) + delete (NPP2_1D) +;delete (range) + delete (xvalues) + delete (yvalues) + delete (mn_yvalues) + delete (mx_yvalues) + delete (good) + delete (max_bar) + delete (min_bar) + delete (max_cap) + delete (min_cap) + +;************************************************************************** +;(B) histogram 933 +;************************************************************************** + +; get data + RAIN1_1D = ndtooned(rain933) + RAIN2_1D = ndtooned(rainmod933) + NPP1_1D = ndtooned(npp933) + NPP2_1D = ndtooned(nppmod933) + +; number of bin + nx = 10 + + xvalues = new((/2,nx/),float) + yvalues = new((/2,nx/),float) + mn_yvalues = new((/2,nx/),float) + mx_yvalues = new((/2,nx/),float) + dx4 = new((/1/),float) + + get_bin(RAIN1_1D, NPP1_1D, RAIN2_1D, NPP2_1D \ + ,xvalues,yvalues,mn_yvalues,mx_yvalues,dx4) + +;---------------------------------------- +;compute correlation coeff and M score + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + uu = u(good) + vv = v(good) + + ccr933h = esccr(uu,vv,0) +;print (ccr933h) + +;new eq + bias = sum(abs(vv-uu)/(abs(vv)+abs(uu))) + M933h = (1.- (bias/dimsizes(uu)))*5. + + M_npp_H933 = sprintf("%.2f", M933h) + system("sed s#M_npp_H933#"+M_npp_H933+"# "+html_name+" > "+html_new) + system("mv -f "+html_new+" "+html_name) + print (M_npp_H933) + + delete (u) + delete (v) + delete (uu) + delete (vv) +;---------------------------------------------------------------------- +; histogram res + delete (resh) + resh = True + resh@gsnMaximize = True + resh@gsnDraw = False + resh@gsnFrame = False + resh@xyMarkLineMode = "Markers" + resh@xyMarkerSizeF = 0.014 + resh@xyMarker = 16 + resh@xyMarkerColors = (/"Brown","Blue"/) + resh@trYMinF = min(mn_yvalues) - 10. + resh@trYMaxF = max(mx_yvalues) + 10. + + resh@tiYAxisString = "NPP (g C/m2/year)" + resh@tiXAxisString = "Precipitation (m/year)" + + max_bar = new((/2,nx/),graphic) + min_bar = new((/2,nx/),graphic) + max_cap = new((/2,nx/),graphic) + min_cap = new((/2,nx/),graphic) + + lnres = True + line_colors = (/"brown","blue"/) + +;************************************************************************** +;(B)-3 histogram plot, ob 933 site +;************************************************************************** + + plot_name = "histogram_ob_933" + title = "Observed 933 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + + xy = gsn_csm_xy(wks,xvalues(0,:),yvalues(0,:),resh) + +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,0 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then + +; Attach the vertical bar, both above and below the marker. + + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + +; Attach the horizontal cap line, both above and below the marker. + + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + delete (xy) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(B)-4 histogram plot, model vs ob 933 site +;**************************************************************************** + + plot_name = "histogram_model_vs_ob_933" + title = model_name+ " vs Observed 933 site" + resh@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + +;----------------------------- +; Add a boxed legend using the more simple method, which won't have +; vertical lines going through the markers. + + resh@pmLegendDisplayMode = "Always" +; resh@pmLegendWidthF = 0.1 + resh@pmLegendWidthF = 0.08 + resh@pmLegendHeightF = 0.05 + resh@pmLegendOrthogonalPosF = -1.17 +; resh@pmLegendOrthogonalPosF = -1.00 ;(downward) +; resh@pmLegendParallelPosF = 0.18 + resh@pmLegendParallelPosF = 0.88 ;(rightward) + +; resh@lgPerimOn = False + resh@lgLabelFontHeightF = 0.015 + resh@xyExplicitLegendLabels = (/"observed",model_name/) +;----------------------------- + tRes = True + tRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccr933h)+")" + + gsn_text_ndc(wks,correlation_text,0.56,0.85,tRes) + + xy = gsn_csm_xy(wks,xvalues,yvalues,resh) +;------------------------------- +;Attach the vertical bar and the horizontal cap line + + do nd=0,1 + lnres@gsLineColor = line_colors(nd) + do i=0,nx-1 + + if(.not.ismissing(mn_yvalues(nd,i)).and. \ + .not.ismissing(mx_yvalues(nd,i))) then +; +; Attach the vertical bar, both above and below the marker. +; + x1 = xvalues(nd,i) + y1 = yvalues(nd,i) + y2 = mn_yvalues(nd,i) + min_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) + + y2 = mx_yvalues(nd,i) + max_bar(nd,i) = gsn_add_polyline(wks,xy,(/x1,x1/),(/y1,y2/),lnres) +; +; Attach the horizontal cap line, both above and below the marker. +; + x1 = xvalues(nd,i) - dx4 + x2 = xvalues(nd,i) + dx4 + y1 = mn_yvalues(nd,i) + min_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + + y1 = mx_yvalues(nd,i) + max_cap(nd,i) = gsn_add_polyline(wks,xy,(/x1,x2/),(/y1,y1/),lnres) + end if + end do + end do + + draw(xy) + frame(wks) + delete(xy) + clear(wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;*************************************************************************** +;(C) global contour +;*************************************************************************** + +;res + resg = True ; Use plot options + resg@cnFillOn = True ; Turn on color fill + resg@gsnSpreadColors = True ; use full colormap +; resg@cnFillMode = "RasterFill" ; Turn on raster color +; resg@lbLabelAutoStride = True + resg@cnLinesOn = False ; Turn off contourn lines + resg@mpFillOn = False ; Turn off map fill + + resg@gsnSpreadColors = True ; use full colormap + resg@cnLevelSelectionMode = "ManualLevels" ; Manual contour invtervals + resg@cnMinLevelValF = 0. ; Min level + resg@cnMaxLevelValF = 2200. ; Max level + resg@cnLevelSpacingF = 200. ; interval + +;**************************************************************************** +;(C)-1 global contour plot, ob +;**************************************************************************** + + delta = 0.00000000001 + nppglobe = where(ismissing(nppglobe).and.(ismissing(nppmod).or.(nppmod.lt.delta)),0.,nppglobe) + + plot_name = "global_ob" + title = "Observed MODIS MOD 17" + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppglobe,resg) + + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(C)-2 global contour plot, model +;**************************************************************************** + + plot_name = "global_model" + title = "Model "+ model_name + resg@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + plot = gsn_csm_contour_map_ce(wks,nppmod,resg) + + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(C)-3 global contour plot, model vs ob +;**************************************************************************** + + plot_name = "global_model_vs_ob" + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + gsn_define_colormap(wks,"gui_default") ; choose colormap + + delete (plot) + plot=new(3,graphic) ; create graphic array + + resg@gsnFrame = False ; Do not draw plot + resg@gsnDraw = False ; Do not advance frame + +; compute correlation coef and M score + + uu1 = ndtooned(nppmod) + vv1 = ndtooned(nppglobe) + + delete (good) + good = ind(.not.ismissing(uu1) .and. .not.ismissing(vv1)) + + ug = uu1(good) + vg = vv1(good) + + ccrG = esccr(ug,vg,0) +; print (ccrG) + + MG = (ccrG*ccrG)* 5.0 + + M_npp_G = sprintf("%.2f", MG) + system("sed s#M_npp_G#"+M_npp_G+"# "+html_name+" > "+html_new) + system("mv -f "+html_new+" "+html_name) + print (M_npp_G) + +; plot correlation coef + + gRes = True + gRes@txFontHeightF = 0.02 + gRes@txAngleF = 90 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrG)+")" + + gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes) +;-------------------------------------------------------------------- +;(a) ob + + title = "Observed MODIS MOD 17" + resg@tiMainString = title + + plot(0) = gsn_csm_contour_map_ce(wks,nppglobe,resg) + +;(b) model + + title = "Model "+ model_name + resg@tiMainString = title + + plot(1) = gsn_csm_contour_map_ce(wks,nppmod,resg) + +;(c) model-ob + + zz = nppmod + zz = nppmod - nppglobe + title = "Model_"+model_name+" - Observed" + + resg@cnMinLevelValF = -500 ; Min level + resg@cnMaxLevelValF = 500. ; Max level + resg@cnLevelSpacingF = 50. ; interval + resg@tiMainString = title + + plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) + + pres = True ; panel plot mods desired +; pres@gsnPanelYWhiteSpacePercent = 5 ; increase white space around + ; indiv. plots in panel + pres@gsnMaximize = True ; fill the page + + gsn_panel(wks,plot,(/3,1/),pres) ; create panel plot + + frame (wks) + clear (wks) + delete (plot) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;*************************************************************************** +;(D)-1 zonal line plot, ob +;*************************************************************************** + + vv = zonalAve(nppglobe) + vv@long_name = nppglobe@long_name + + plot_name = "zonal_ob" + title = "Observed MODIS MOD 17" + + resz = True + resz@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) ; open workstation + + plot = gsn_csm_xy (wks,ym,vv,resz) + + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;**************************************************************************** +;(D)-2 zonal line plot, model vs ob +;**************************************************************************** + + s = new ((/2,dimsizes(ym)/), float) + + s(0,:) = zonalAve(nppglobe) + s(1,:) = zonalAve(nppmod) + + s@long_name = nppglobe@long_name +;------------------------------------------- +; compute correlation coef and M score + + ccrZ = esccr(s(1,:), s(0,:),0) +; print (ccrZ) + + MZ = (ccrZ*ccrZ)* 5.0 + + M_npp_Z = sprintf("%.2f", MZ) + system("sed s#M_npp_Z#"+M_npp_Z+"# "+html_name+" > "+html_new) + system("mv -f "+html_new+" "+html_name) + print (M_npp_Z) +;------------------------------------------- + plot_name = "zonal_model_vs_ob" + title = "Zonal Average" + resz@tiMainString = title + + wks = gsn_open_wks (plot_type,plot_name) + +; resz@vpHeightF = 0.4 ; change aspect ratio of plot +; resz@vpWidthF = 0.7 + + resz@xyMonoLineColor = "False" ; want colored lines + resz@xyLineColors = (/"black","red"/) ; colors chosen +; resz@xyLineThicknesses = (/3.,3./) ; line thicknesses + resz@xyLineThicknesses = (/2.,2./) ; line thicknesses + resz@xyDashPatterns = (/0.,0./) ; make all lines solid + + resz@tiYAxisString = s@long_name ; add a axis title + resz@txFontHeightF = 0.0195 ; change title font heights + +; Legent + resz@pmLegendDisplayMode = "Always" ; turn on legend + resz@pmLegendSide = "Top" ; Change location of +; resz@pmLegendParallelPosF = .45 ; move units right + resz@pmLegendParallelPosF = .82 ; move units right + resz@pmLegendOrthogonalPosF = -0.4 ; move units down + + resz@pmLegendWidthF = 0.10 ; Change width and + resz@pmLegendHeightF = 0.10 ; height of legend. + resz@lgLabelFontHeightF = .02 ; change font height +; resz@lgTitleOn = True ; turn on legend title +; resz@lgTitleString = "Example" ; create legend title +; resz@lgTitleFontHeightF = .025 ; font of legend title + resz@xyExplicitLegendLabels = (/"Observed",model_name/) ; explicit labels +;-------------------------------------------------------------------- + zRes = True + zRes@txFontHeightF = 0.025 + + correlation_text = "(correlation coef = "+sprintf("%5.2f", ccrZ)+")" + + gsn_text_ndc(wks,correlation_text,0.50,0.77,zRes) +;-------------------------------------------------------------------- + + plot = gsn_csm_xy (wks,ym,s,resz) + + frame(wks) + clear (wks) + + system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new) + system("mv "+plot_name+"-0."+plot_type_new+" "+plot_name+"."+plot_type_new) + system("rm "+plot_name+"-*."+plot_type_new) + system("rm "+plot_name+"."+plot_type) + +;*************************************************************************** +; tar up output plots +;*************************************************************************** + + temp_name = "npp." + model_name + system("mkdir -p " + temp_name) + system("cp "+ html_name + " " +temp_name+"/table.html") + system("mv *.png " + temp_name) + system("tar cf "+ temp_name +".tar " + temp_name) + +;*************************************************************************** +end + diff -r 000000000000 -r 0c6405ab2ff4 npp/note.ob_read --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/note.ob_read Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,7 @@ +(A) for station data + 01.read_ascii_81.ncl + 01.read_ascii_933.ncl + +(B) for global 0.05deg data + 02.read_binary_0.05deg.ncl + 03.0.05deg_to_T42.ncl \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 npp/note.read-binary --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/npp/note.read-binary Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,6 @@ +f90 -64 read-binary.f90 +./a.out > asc.dat & + +wc -l asc.dat +bc -l +ls -tl | head \ No newline at end of file diff -r 000000000000 -r 0c6405ab2ff4 soil_carbon/01.test.read.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/soil_carbon/01.test.read.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,19 @@ +;************************************************ +; Read ascii, Write nc +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + + b = "zot005_45D2_seas.co2" + ncol = 4 + data = readAsciiTable(b, ncol, "float", (/10,17/)) + print (data) + + ncol = 5 + data2 = readAsciiTable(b, ncol, "float", 16) + print (data2) + +end diff -r 000000000000 -r 0c6405ab2ff4 taylor/01.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taylor/01.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,57 @@ +;********************************** +; taylor_3.ncl +;********************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "./taylor_diagram.ncl" +;********************************** +begin +;********************************** +; Assume the following have already been computed: +; _ratio are the ratio: Case_Variance/Reference_Variance +; _cc are the cross correlation coef of Case to Reference +;********************************** + +; Cases [Model] + case = (/ "Case A", "Case B" /) + nCase = dimsizes(case ) ; # of Cases [Cases] + +; variables compared + var = (/ "SLP","Tsfc","Prc","Prc 30S-30N","LW","SW", "U300", "Guess" /) + nVar = dimsizes(var) ; # of Variables + +; "Case A" + CA_ratio = (/1.230, 0.988, 1.092, 1.172, 1.064, 0.966, 1.079, 0.781/) + CA_cc = (/0.958, 0.973, 0.740, 0.743, 0.922, 0.982, 0.952, 0.433/) + +; "Case B" + CB_ratio = (/1.129, 0.996, 1.016, 1.134, 1.023, 0.962, 1.048, 0.852 /) + CB_cc = (/0.963, 0.975, 0.801, 0.814, 0.946, 0.984, 0.968, 0.647 /) + +; arrays to be passed to taylor plot + ratio = new ((/nCase, nVar/),typeof(CA_cc) ) + cc = new ((/nCase, nVar/),typeof(CA_cc) ) + + ratio(0,:) = CA_ratio + ratio(1,:) = CB_ratio + + cc(0,:) = CA_cc + cc(1,:) = CB_cc + +;********************************** +; create plot +;********************************** + + res = True ; default taylor diagram + + res@Markers = (/16, 16/) ; make all solid fill + res@Colors = (/"red", "blue" /) + res@varLabels = var + res@caseLabels = case + + wks = gsn_open_wks("ps","taylor") + plot = taylor_diagram(wks,ratio,cc,res) + + frame(wks) + +end diff -r 000000000000 -r 0c6405ab2ff4 taylor/taylor_diagram.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taylor/taylor_diagram.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,478 @@ +function taylor_diagram (wks:graphic ,RATIO[*][*]:numeric, CC[*][*]:numeric \ + ,rOpts:logical) +;-------------------------------------------------------------------- +; This version of taylor_diagram supports "paneling" +; It requires NCL version 4.2.0.a034 because it uses "gsn_create_legend" +;-------------------------------------------------------------------- + +; +; Generate a Taylor Diagram: +; Generate Multiple Aspects of Model Performance in a Single Diagram +; Taylor, K. E., J. Geophys. Res., 106, D7, 7183-7192, 2001 +; +; An example: +; http://www.grida.no/climate/ipcc_tar/wg1/fig8-4.htm +; +; This expects one or more datasets. The left dimension +; is the number of datasets. The rightmost is the number of pts. +; +; Markers are at: +; http://www.ncl.ucar.edu/Document/Graphics/Resources/gs.shtml +; +; By default, the function can handle up to 10 variable comparisons.. +; To expand ... modify the 'Colors' and 'Markers' attributes. +; The user can change / add some default settings. +; +; The defaults that the user can modify: +; +; rOpts = True +; ; 'made-up' resources +; rOpts@Colors = (/ "blue" , "red", "green", "cyan", "black" \ +; , "torquoise", "brown", "yellow"/) +; rOpts@Markers = (/ 2, 3, 6, 14, 9, 12, 7, 4/) ; Marker Indices +; rOpts@markerTxOffset = 0.0175 ; offset for text above marker +; rOpts@stnRad = (/ 1. /) ; (/ 0.50, 0.75, 1.5 /) +; rOpts@centerDiffRMS = False ; True mean draw additional radii from REF +; rOpts@caseLabelsFontHeightF = 0.05 +; rOpts@varLabelsFontHeightF = 0.013 +; rOpts@varLabelsYloc = 0.65 +; rOpts@legendWidth = 0.015 +; rOpts@legendHeight = 0.030*nCase +; rOpts@taylorDraw = True +; rOpts@taylorFrame = True +; +; ; standard NCL resources +; rOpts@tiMainString = "Taylor" ; not using title makes plot bigger +; rOpts@gsMarkerSizeF = 0.0085 ; marker size +; rOpts@gsMarkerThicknessF = 1.0 +; rOpts@txFontHeightF = 0.0125 ; text size +; rOpts@tiMainFontHeightF = 0.0225 ; tiMainString size +; +; It returns to the user a graphic object containing the +; Taylor background and plotted x/y pts. +; This graphic object contains a simple Taylor background appropriate +; for standardized data and the markers for the datasets. +; ================================================================== +; This version allows paneling: +; The 'cumbersome' "dum" variables were added by +; Adam Phillips to allow paneling via "gsn_add_?". +; ================================================================== +begin + dimR = dimsizes(RATIO) + nCase = dimR(0) ; # of cases [models] + nVar = dimR(1) ; # of variables + + ; x/y coordinates for plotting + X = new ( (/nCase,nVar/) , typeof(RATIO) ) + Y = new ( (/nCase,nVar/) , typeof(RATIO) ) + + do nc=0,nCase-1 + angle = acos( CC(nc,:) ) ; array operation + X(nc,:) = RATIO(nc,:)*cos( angle ) + Y(nc,:) = RATIO(nc,:)*sin( angle ) + end do + + xyMin = 0. + xyOne = 1.00 + xyMax = 1.65 + xyMax_Panel = xyMax+ 0.10 ; paneling purposes + + if (rOpts .and. isatt(rOpts,"txFontHeightF")) then + FontHeightF = rOpts@txFontHeightF ; user wants to specify size + else + FontHeightF = 0.0175 + end if + +; ---------------------------------------------------------------- +; Part 1: +; base plot: Based upon request of Mark Stevens +; basic x-y and draw the 1.0 observed and the outer curve at 1.65 +; ---------------------------------------------------------------- + + rxy = True + rxy@gsnDraw = False + rxy@gsnFrame = False + rxy@vpHeightF = 0.65 + rxy@vpWidthF = 0.65 + rxy@tmYLBorderOn = False + rxy@tmXBBorderOn = False + + rxy@tiYAxisString = "Standardized Deviations (Normalized)" + rxy@tiYAxisFontHeightF= FontHeightF ; default=0.025 + + rxy@tmXBMode = "Explicit" + rxy@tmXBValues = (/0.0,0.25,0.50,0.75,1.00,1.25,1.5/) ; major tm + ; default "OBS" or "REF" + ;rxy@tmXBLabels = (/"0.00","0.25","0.50","0.75","REF" ,"1.25","1.50"/) + rxy@tmXBLabels = (/" ","0.25","0.50","0.75","REF" ,"1.25","1.50"/) + if (rOpts .and. isatt(rOpts,"OneX") ) then ; eg: rOpts@OneX="1.00" + ;rxy@tmXBLabels = (/"0.00","0.25","0.50","0.75",rOpts@OneX,"1.25","1.50"/) + rxy@tmXBLabels = (/" ","0.25","0.50","0.75",rOpts@OneX,"1.25","1.50"/) + end if + + rxy@tmXBMajorLengthF = 0.015 ; default=0.02 for a vpHeightF=0.6 + rxy@tmXBLabelFontHeightF = FontHeightF + rxy@tmXBMinorOn = False + rxy@trXMaxF = xyMax_Panel + + rxy@tmYLMode = "Manual" + rxy@tmYLMinorOn = False + rxy@tmYLMajorLengthF = rxy@tmXBMajorLengthF + rxy@tmYLLabelFontHeightF = FontHeightF + rxy@tmYLMode = "Explicit" + rxy@tmYLValues = (/0.0, .25,0.50, 0.75, 1.00, 1.25, 1.5/) ; major tm + rxy@tmYLLabels = (/"0.00","0.25","0.50","0.75","1.00","1.25","1.50"/) + ;rxy@tmYLLabels = (/" ","0.25","0.50","0.75","1.00","1.25","1.50"/) + rxy@trYMaxF = xyMax_Panel + + rxy@tmYRBorderOn = False + rxy@tmYROn = False ; Turn off right tick marks. + + rxy@tmXTBorderOn = False + rxy@tmXTOn = False ; Turn off right tick marks. + + rxy@xyDashPatterns = (/ 0 /) ; line characteristics (dash,solid) + rxy@xyLineThicknesses = (/ 2./) ; choose line thickness + + rxy@gsnFrame = False ; Don't advance the frame. + + ; create outer 'correlation axis' + npts = 200 ; arbitrary + xx = fspan(xyMin,xyMax,npts) + yy = sqrt(xyMax^2 - xx^2 ) ; outer correlation line (xyMax) + + sLabels = (/"0.0","0.1","0.2","0.3","0.4","0.5","0.6" \ ; correlation labels + ,"0.7","0.8","0.9","0.95","0.99","1.0" /); also, major tm + cLabels = stringtofloat(sLabels) + rad = 4.*atan(1.0)/180. + angC = acos(cLabels)/rad ; angles: correlation labels + + if (rOpts .and. isatt(rOpts,"tiMainString")) then + rxy@tiMainString = rOpts@tiMainString + ;rxy@tiMainOffsetYF = 0.015 ; default 0.0 + if (isatt(rOpts,"tiMainFontHeightF")) then + rxy@tiMainFontHeightF = rOpts@tiMainFontHeightF + else + rxy@tiMainFontHeightF = 0.0225 ; default 0.025 + end if + end if +;;if (rOpts .and. isatt(rOpts,"gsnCenterString")) then +;; rxy@gsnCenterString = rOpts@gsnCenterString ; only gsn_csm_xy +;;end if + + taylor = gsn_xy(wks,xx,yy,rxy) ; Create and draw XY plot. + + rsrRes = True + rsrRes@gsLineThicknessF = rxy@xyLineThicknesses(0) ; line thickness + rsrRes@gsLineDashPattern = 0 ; solid line pattern + ; draw x and y to xyMax + dum0 = gsn_add_polyline(wks,taylor,(/0., 0. /),(/0.,xyMax/), rsrRes) + dum1 = gsn_add_polyline(wks,taylor,(/0.,xyMax/),(/0., 0. /), rsrRes) + + xx = fspan(xyMin, xyOne ,npts) ; draw 1.0 standard radius + yy = sqrt(xyOne - xx^2) + rsrRes@gsLineDashPattern = 1 ; dashed line pattern + rsrRes@gsLineThicknessF = rxy@xyLineThicknesses(0) ; line thickness + dum2 = gsn_add_polyline(wks,taylor,xx,yy, rsrRes) + delete(xx) + delete(yy) + + if (rOpts .and. isatt(rOpts,"stnRad") ) then + rsrRes@gsLineThicknessF = 1 ; rxy@xyLineThicknesses(0) + nStnRad = dimsizes(rOpts@stnRad) + + dum3 = new(nStnRad,graphic) + do n=0,nStnRad-1 + rr = rOpts@stnRad(n) + xx = fspan(xyMin, rr ,npts) + yy = sqrt(rr^2 - xx^2) + dum3(n) = gsn_add_polyline(wks,taylor,xx,yy, rsrRes) + end do + taylor@$unique_string("dum")$ = dum3 + + delete(xx) + delete(yy) + end if + + getvalues taylor ; get style info from taylor + "tmYLLabelFont" : tmYLLabelFont ; use for correlation axis + "tmYLLabelFontHeightF" : tmYLLabelFontHeightF + end getvalues + +; ---------------------------------------------------------------- +; Part 2: +; Correlation labels +; ---------------------------------------------------------------- + radC = xyMax ; for correlation labels + xC = radC*cos(angC*rad) + yC = radC*sin(angC*rad) +; added to get some separation + xC = xC + 0.020*cos(rad*angC) + yC = yC + 0.060*sin(rad*angC) + + txRes = True ; text mods desired + txRes@txFontHeightF = FontHeightF ; match YL + txRes@tmYLLabelFont = tmYLLabelFont ; match YL + txRes@txAngleF = -45. + if (.not.isatt(rOpts,"drawCorLabel") .or. rOpts@drawCorLabel) then + dum4 = gsn_add_text(wks,taylor,"Correlation",1.30,1.30,txRes) + taylor@$unique_string("dum")$ = dum4 + end if + txRes@txAngleF = 0.0 + txRes@txFontHeightF = FontHeightF*0.50 ; bit smaller + +;;dum0 = gsn_add_text(wks,taylor,"OBSERVED",1.00,0.075,txRes) + + plRes = True + plRes@gsLineThicknessF = 2. + + txRes@txJust = "CenterLeft" ; Default="CenterCenter". + txRes@txFontHeightF = FontHeightF ; match YL + ;txRes@txBackgroundFillColor = "white" + + tmEnd = 0.975 + radTM = xyMax*tmEnd ; radius end: major TM + xTM = new( 2 , "float") + yTM = new( 2 , "float") + + dum5 = new(dimsizes(sLabels),graphic) + dum6 = dum5 + + do i=0,dimsizes(sLabels)-1 ; Loop to draw strings + txRes@txAngleF = angC(i) + dum5(i) = gsn_add_text(wks, taylor, sLabels(i),xC(i),yC(i),txRes) ; cor label + xTM(0) = xyMax*cos(angC(i)*rad) ; major tickmarks at + yTM(0) = xyMax*sin(angC(i)*rad) ; correlation labels + xTM(1) = radTM*cos(angC(i)*rad) + yTM(1) = radTM*sin(angC(i)*rad) + dum6(i) = gsn_add_polyline(wks,taylor,xTM,yTM,plRes) + end do + ; minor tm locations + mTM = (/0.05,0.15,0.25,0.35,0.45,0.55,0.65 \ + ,0.75,0.85,0.91,0.92,0.93,0.94,0.96,0.97,0.98 /) + angmTM = acos(mTM)/rad ; angles: correlation labels + radmTM = xyMax*(1.-(1.-tmEnd)*0.5) ; radius end: minor TM + + dum7 = new(dimsizes(mTM),graphic) + + do i=0,dimsizes(mTM)-1 ; manually add tm + xTM(0) = xyMax*cos(angmTM(i)*rad) ; minor tickmarks + yTM(0) = xyMax*sin(angmTM(i)*rad) + xTM(1) = radmTM*cos(angmTM(i)*rad) + yTM(1) = radmTM*sin(angmTM(i)*rad) + dum7(i) = gsn_add_polyline(wks,taylor,xTM,yTM,plRes) + end do + ; added for Wanli + if (rOpts .and. isatt(rOpts,"ccRays") ) then + angRL = acos(rOpts@ccRays)/rad ; angles: radial lines + + rlRes = True + rlRes@xyDashPattern = 4 ; line pattern + rlRes@xyLineThicknessF = 1 ; choose line thickness + + dum8 = new(dimsizes(angRL),graphic) + do i=0,dimsizes(angRL)-1 + xRL = xyMax*cos(angRL(i)*rad) + yRL = xyMax*sin(angRL(i)*rad) + dum8(i) = gsn_add_polyline(wks,taylor,(/0, xRL /),(/0, yRL /),rlRes) + end do + taylor@$unique_string("dum")$ = dum8 + end if + +; ---------------------------------------------------------------- +; Part 3: +; Concentric about 1.0 on XB axis +; I think this is correct. Still test mode. +; ---------------------------------------------------------------- + if (rOpts .and. isatt(rOpts,"centerDiffRMS") \ + .and. rOpts@centerDiffRMS) then + respl = True ; polyline mods desired + respl@gsLineThicknessF = 1.0 ; line thickness + respl@gsLineColor = "Black" ; line color + respl@gsLineDashPattern = 2 ; short dash lines + + dx = 0.25 + ncon = 4 ; 0.75, 0.50, 0.25, 0.0 + npts = 100 ; arbitrary + ang = fspan(180,360,npts)*rad + + dum9 = new(ncon,graphic) + + do n=1,ncon + rr = n*dx ; radius from 1.0 [OBS] abscissa + xx = 1. + rr*cos(ang) + yy = fabs( rr*sin(ang) ) + if (n.le.2) then + dum9(n-1) = gsn_add_polyline(wks,taylor,xx,yy,respl) + end if + if (n.eq.3) then + n3 = floattointeger( 0.77*npts ) + dum9(n-1) = gsn_add_polyline(wks,taylor,xx(0:n3),yy(0:n3),respl) + end if + if (n.eq.4) then + n4 = floattointeger( 0.61*npts ) + dum9(n-1) = gsn_add_polyline(wks,taylor,xx(0:n4),yy(0:n4),respl) + end if + end do + delete(ang) + delete(xx) + delete(yy) + taylor@$unique_string("dum")$ = dum9 + + end if +; --------------------------------------------------------------- +; Part 4: +; generic resources that will be applied to all users data points +; of course, these can be changed +; http://www.ncl.ucar.edu/Document/Graphics/Resources/gs.shtml +; --------------------------------------------------------------- + if (rOpts .and. isatt(rOpts,"Markers")) then + Markers = rOpts@Markers + else + Markers = (/ 4, 6, 8, 0, 9, 12, 7, 2, 11, 16/) ; Marker Indices + end if + + if (rOpts .and. isatt(rOpts,"Colors")) then + Colors = rOpts@Colors + else + Colors = (/ "red", "blue", "green", "cyan", "orange" \ + , "torquoise", "brown", "yellow", "purple", "black"/) + end if + + if (rOpts .and. isatt(rOpts,"gsMarkerThicknessF")) then + gsMarkerThicknessF = rOpts@gsMarkerThicknessF + else + gsMarkerThicknessF = 1.0 + end if + + if (rOpts .and. isatt(rOpts,"gsMarkerSizeF")) then + gsMarkerSizeF = rOpts@gsMarkerSizeF + else + gsMarkerSizeF = 0.0085 ; Default: 0.007 + end if + + gsRes = True + gsRes@gsMarkerThicknessF = gsMarkerThicknessF ; default=1.0 + gsRes@gsMarkerSizeF = gsMarkerSizeF ; Default: 0.007 + + ptRes = True ; text options for points + ptRes@txJust = "BottomCenter"; Default="CenterCenter". + ptRes@txFontThicknessF = 1.2 ; default=1.00 + ptRes@txFontHeightF = 0.0125 ; default=0.05 + if (rOpts .and. isatt(rOpts,"txFontHeightF")) then + ptRes@txFontHeightF = rOpts@txFontHeightF + end if + + markerTxYOffset = 0.0175 ; default + if (rOpts .and. isatt(rOpts,"markerTxYOffset")) then + markerTxYOffset = rOpts@markerTxYOffset ; user defined offset + end if + + dum10 = new((nCase*nVar),graphic) + dum11 = dum10 + + do n=0,nCase-1 + gsRes@gsMarkerIndex = Markers(n) ; marker style (+) + gsRes@gsMarkerColor = Colors(n) ; marker color + ptRes@txFontColor = gsRes@gsMarkerColor + do i=0,nVar-1 + dum10(n*nVar+i) = gsn_add_polymarker(wks,taylor,X(n,i),Y(n,i),gsRes) +; dum11(n*nVar+i) = gsn_add_text(wks,taylor,(i+1),X(n,i),Y(n,i)+markerTxYOffset,ptRes) + end do + end do + +; --------------------------------------------------------------- +; Part 5: ; add case legend and variable labels +; --------------------------------------------------------------- + + if (rOpts .and. isatt(rOpts,"caseLabels")) then + + if (isatt(rOpts,"caseLabelsFontHeightF")) then + caseLabelsFontHeightF = rOpts@caseLabelsFontHeightF + else + caseLabelsFontHeightF = 0.05 + end if + + lgres = True + lgres@lgMarkerColors = Colors ; colors of markers + lgres@lgMarkerIndexes = Markers ; Markers + lgres@lgMarkerSizeF = gsMarkerSizeF ; Marker size + lgres@lgItemType = "Markers" ; draw markers only + lgres@lgLabelFontHeightF = caseLabelsFontHeightF ; font height of legend case labels + + if (isatt(rOpts,"legendWidth")) then + lgres@vpWidthF = rOpts@legendWidth + else + lgres@vpWidthF = 0.15 ; width of legend (NDC) + end if + + if (isatt(rOpts,"legendHeight")) then + lgres@vpHeightF = rOpts@legendHeight + else + lgres@vpHeightF = 0.030*nCase ; height of legend (NDC) + end if + + lgres@lgPerimOn = False ; turn off perimeter + nModel = dimsizes( rOpts@caseLabels ) + lbid = gsn_create_legend(wks,nModel,rOpts@caseLabels,lgres) + + amres = True + amres@amParallelPosF = 0.35 + amres@amOrthogonalPosF = -0.35 + annoid1 = gsn_add_annotation(taylor,lbid,amres) ; add legend to plot + end if + + if (rOpts .and. isatt(rOpts,"varLabels")) then + nVar = dimsizes(rOpts@varLabels) + + if (isatt(rOpts,"varLabelsFontHeightF")) then + varLabelsFontHeightF = rOpts@varLabelsFontHeightF + else + varLabelsFontHeightF = 0.013 + end if + + txres = True + txres@txFontHeightF = varLabelsFontHeightF + txres@txJust = "CenterLeft" ; justify to the center left + + ;delta_y = 0.02 + delta_y = 0.06 + if (rOpts .and. isatt(rOpts,"varLabelsYloc")) then + ys = rOpts@varLabelsYloc ; user specified + else + ys = max( (/nVar*delta_y , 0.30/) ) + end if + + + do i = 1,nVar + if (i.eq.1) then + dum12 = new(nVar,graphic) + end if + + dum12(i-1) = gsn_add_text(wks,taylor,i+" - "+rOpts@varLabels(i-1), .125,ys,txres) + ys = ys- delta_y + end do + + taylor@$unique_string("dum")$ = dum12 + end if + + taylor@$unique_string("dum")$ = dum0 ; x-axis + taylor@$unique_string("dum")$ = dum1 ; y-axis + taylor@$unique_string("dum")$ = dum2 ; 1.0 std curve + taylor@$unique_string("dum")$ = dum5 ; labels [COR] + taylor@$unique_string("dum")$ = dum6 ; major tm [COR] + taylor@$unique_string("dum")$ = dum7 ; minor tm + taylor@$unique_string("dum")$ = dum10 ; markers + taylor@$unique_string("dum")$ = dum11 ; text + + if (.not.isatt(rOpts,"taylorDraw") .or. \ + (isatt(rOpts,"taylorDraw") .and. rOpts@taylorDraw)) then + draw(taylor) + end if + if (.not.isatt(rOpts,"taylorFrame") .or. \ + (isatt(rOpts,"taylorFrame") .and. rOpts@taylorFrame)) then + frame(wks) + end if + return(taylor) +end + diff -r 000000000000 -r 0c6405ab2ff4 taylor/taylor_diagram.ncl.0 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taylor/taylor_diagram.ncl.0 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,478 @@ +function taylor_diagram (wks:graphic ,RATIO[*][*]:numeric, CC[*][*]:numeric \ + ,rOpts:logical) +;-------------------------------------------------------------------- +; This version of taylor_diagram supports "paneling" +; It requires NCL version 4.2.0.a034 because it uses "gsn_create_legend" +;-------------------------------------------------------------------- + +; +; Generate a Taylor Diagram: +; Generate Multiple Aspects of Model Performance in a Single Diagram +; Taylor, K. E., J. Geophys. Res., 106, D7, 7183-7192, 2001 +; +; An example: +; http://www.grida.no/climate/ipcc_tar/wg1/fig8-4.htm +; +; This expects one or more datasets. The left dimension +; is the number of datasets. The rightmost is the number of pts. +; +; Markers are at: +; http://www.ncl.ucar.edu/Document/Graphics/Resources/gs.shtml +; +; By default, the function can handle up to 10 variable comparisons.. +; To expand ... modify the 'Colors' and 'Markers' attributes. +; The user can change / add some default settings. +; +; The defaults that the user can modify: +; +; rOpts = True +; ; 'made-up' resources +; rOpts@Colors = (/ "blue" , "red", "green", "cyan", "black" \ +; , "torquoise", "brown", "yellow"/) +; rOpts@Markers = (/ 2, 3, 6, 14, 9, 12, 7, 4/) ; Marker Indices +; rOpts@markerTxOffset = 0.0175 ; offset for text above marker +; rOpts@stnRad = (/ 1. /) ; (/ 0.50, 0.75, 1.5 /) +; rOpts@centerDiffRMS = False ; True mean draw additional radii from REF +; rOpts@caseLabelsFontHeightF = 0.05 +; rOpts@varLabelsFontHeightF = 0.013 +; rOpts@varLabelsYloc = 0.65 +; rOpts@legendWidth = 0.015 +; rOpts@legendHeight = 0.030*nCase +; rOpts@taylorDraw = True +; rOpts@taylorFrame = True +; +; ; standard NCL resources +; rOpts@tiMainString = "Taylor" ; not using title makes plot bigger +; rOpts@gsMarkerSizeF = 0.0085 ; marker size +; rOpts@gsMarkerThicknessF = 1.0 +; rOpts@txFontHeightF = 0.0125 ; text size +; rOpts@tiMainFontHeightF = 0.0225 ; tiMainString size +; +; It returns to the user a graphic object containing the +; Taylor background and plotted x/y pts. +; This graphic object contains a simple Taylor background appropriate +; for standardized data and the markers for the datasets. +; ================================================================== +; This version allows paneling: +; The 'cumbersome' "dum" variables were added by +; Adam Phillips to allow paneling via "gsn_add_?". +; ================================================================== +begin + dimR = dimsizes(RATIO) + nCase = dimR(0) ; # of cases [models] + nVar = dimR(1) ; # of variables + + ; x/y coordinates for plotting + X = new ( (/nCase,nVar/) , typeof(RATIO) ) + Y = new ( (/nCase,nVar/) , typeof(RATIO) ) + + do nc=0,nCase-1 + angle = acos( CC(nc,:) ) ; array operation + X(nc,:) = RATIO(nc,:)*cos( angle ) + Y(nc,:) = RATIO(nc,:)*sin( angle ) + end do + + xyMin = 0. + xyOne = 1.00 + xyMax = 1.65 + xyMax_Panel = xyMax+ 0.10 ; paneling purposes + + if (rOpts .and. isatt(rOpts,"txFontHeightF")) then + FontHeightF = rOpts@txFontHeightF ; user wants to specify size + else + FontHeightF = 0.0175 + end if + +; ---------------------------------------------------------------- +; Part 1: +; base plot: Based upon request of Mark Stevens +; basic x-y and draw the 1.0 observed and the outer curve at 1.65 +; ---------------------------------------------------------------- + + rxy = True + rxy@gsnDraw = False + rxy@gsnFrame = False + rxy@vpHeightF = 0.65 + rxy@vpWidthF = 0.65 + rxy@tmYLBorderOn = False + rxy@tmXBBorderOn = False + + rxy@tiYAxisString = "Standardized Deviations (Normalized)" + rxy@tiYAxisFontHeightF= FontHeightF ; default=0.025 + + rxy@tmXBMode = "Explicit" + rxy@tmXBValues = (/0.0,0.25,0.50,0.75,1.00,1.25,1.5/) ; major tm + ; default "OBS" or "REF" + ;rxy@tmXBLabels = (/"0.00","0.25","0.50","0.75","REF" ,"1.25","1.50"/) + rxy@tmXBLabels = (/" ","0.25","0.50","0.75","REF" ,"1.25","1.50"/) + if (rOpts .and. isatt(rOpts,"OneX") ) then ; eg: rOpts@OneX="1.00" + ;rxy@tmXBLabels = (/"0.00","0.25","0.50","0.75",rOpts@OneX,"1.25","1.50"/) + rxy@tmXBLabels = (/" ","0.25","0.50","0.75",rOpts@OneX,"1.25","1.50"/) + end if + + rxy@tmXBMajorLengthF = 0.015 ; default=0.02 for a vpHeightF=0.6 + rxy@tmXBLabelFontHeightF = FontHeightF + rxy@tmXBMinorOn = False + rxy@trXMaxF = xyMax_Panel + + rxy@tmYLMode = "Manual" + rxy@tmYLMinorOn = False + rxy@tmYLMajorLengthF = rxy@tmXBMajorLengthF + rxy@tmYLLabelFontHeightF = FontHeightF + rxy@tmYLMode = "Explicit" + rxy@tmYLValues = (/0.0, .25,0.50, 0.75, 1.00, 1.25, 1.5/) ; major tm + rxy@tmYLLabels = (/"0.00","0.25","0.50","0.75","1.00","1.25","1.50"/) + ;rxy@tmYLLabels = (/" ","0.25","0.50","0.75","1.00","1.25","1.50"/) + rxy@trYMaxF = xyMax_Panel + + rxy@tmYRBorderOn = False + rxy@tmYROn = False ; Turn off right tick marks. + + rxy@tmXTBorderOn = False + rxy@tmXTOn = False ; Turn off right tick marks. + + rxy@xyDashPatterns = (/ 0 /) ; line characteristics (dash,solid) + rxy@xyLineThicknesses = (/ 2./) ; choose line thickness + + rxy@gsnFrame = False ; Don't advance the frame. + + ; create outer 'correlation axis' + npts = 200 ; arbitrary + xx = fspan(xyMin,xyMax,npts) + yy = sqrt(xyMax^2 - xx^2 ) ; outer correlation line (xyMax) + + sLabels = (/"0.0","0.1","0.2","0.3","0.4","0.5","0.6" \ ; correlation labels + ,"0.7","0.8","0.9","0.95","0.99","1.0" /); also, major tm + cLabels = stringtofloat(sLabels) + rad = 4.*atan(1.0)/180. + angC = acos(cLabels)/rad ; angles: correlation labels + + if (rOpts .and. isatt(rOpts,"tiMainString")) then + rxy@tiMainString = rOpts@tiMainString + ;rxy@tiMainOffsetYF = 0.015 ; default 0.0 + if (isatt(rOpts,"tiMainFontHeightF")) then + rxy@tiMainFontHeightF = rOpts@tiMainFontHeightF + else + rxy@tiMainFontHeightF = 0.0225 ; default 0.025 + end if + end if +;;if (rOpts .and. isatt(rOpts,"gsnCenterString")) then +;; rxy@gsnCenterString = rOpts@gsnCenterString ; only gsn_csm_xy +;;end if + + taylor = gsn_xy(wks,xx,yy,rxy) ; Create and draw XY plot. + + rsrRes = True + rsrRes@gsLineThicknessF = rxy@xyLineThicknesses(0) ; line thickness + rsrRes@gsLineDashPattern = 0 ; solid line pattern + ; draw x and y to xyMax + dum0 = gsn_add_polyline(wks,taylor,(/0., 0. /),(/0.,xyMax/), rsrRes) + dum1 = gsn_add_polyline(wks,taylor,(/0.,xyMax/),(/0., 0. /), rsrRes) + + xx = fspan(xyMin, xyOne ,npts) ; draw 1.0 standard radius + yy = sqrt(xyOne - xx^2) + rsrRes@gsLineDashPattern = 1 ; dashed line pattern + rsrRes@gsLineThicknessF = rxy@xyLineThicknesses(0) ; line thickness + dum2 = gsn_add_polyline(wks,taylor,xx,yy, rsrRes) + delete(xx) + delete(yy) + + if (rOpts .and. isatt(rOpts,"stnRad") ) then + rsrRes@gsLineThicknessF = 1 ; rxy@xyLineThicknesses(0) + nStnRad = dimsizes(rOpts@stnRad) + + dum3 = new(nStnRad,graphic) + do n=0,nStnRad-1 + rr = rOpts@stnRad(n) + xx = fspan(xyMin, rr ,npts) + yy = sqrt(rr^2 - xx^2) + dum3(n) = gsn_add_polyline(wks,taylor,xx,yy, rsrRes) + end do + taylor@$unique_string("dum")$ = dum3 + + delete(xx) + delete(yy) + end if + + getvalues taylor ; get style info from taylor + "tmYLLabelFont" : tmYLLabelFont ; use for correlation axis + "tmYLLabelFontHeightF" : tmYLLabelFontHeightF + end getvalues + +; ---------------------------------------------------------------- +; Part 2: +; Correlation labels +; ---------------------------------------------------------------- + radC = xyMax ; for correlation labels + xC = radC*cos(angC*rad) + yC = radC*sin(angC*rad) +; added to get some separation + xC = xC + 0.020*cos(rad*angC) + yC = yC + 0.060*sin(rad*angC) + + txRes = True ; text mods desired + txRes@txFontHeightF = FontHeightF ; match YL + txRes@tmYLLabelFont = tmYLLabelFont ; match YL + txRes@txAngleF = -45. + if (.not.isatt(rOpts,"drawCorLabel") .or. rOpts@drawCorLabel) then + dum4 = gsn_add_text(wks,taylor,"Correlation",1.30,1.30,txRes) + taylor@$unique_string("dum")$ = dum4 + end if + txRes@txAngleF = 0.0 + txRes@txFontHeightF = FontHeightF*0.50 ; bit smaller + +;;dum0 = gsn_add_text(wks,taylor,"OBSERVED",1.00,0.075,txRes) + + plRes = True + plRes@gsLineThicknessF = 2. + + txRes@txJust = "CenterLeft" ; Default="CenterCenter". + txRes@txFontHeightF = FontHeightF ; match YL + ;txRes@txBackgroundFillColor = "white" + + tmEnd = 0.975 + radTM = xyMax*tmEnd ; radius end: major TM + xTM = new( 2 , "float") + yTM = new( 2 , "float") + + dum5 = new(dimsizes(sLabels),graphic) + dum6 = dum5 + + do i=0,dimsizes(sLabels)-1 ; Loop to draw strings + txRes@txAngleF = angC(i) + dum5(i) = gsn_add_text(wks, taylor, sLabels(i),xC(i),yC(i),txRes) ; cor label + xTM(0) = xyMax*cos(angC(i)*rad) ; major tickmarks at + yTM(0) = xyMax*sin(angC(i)*rad) ; correlation labels + xTM(1) = radTM*cos(angC(i)*rad) + yTM(1) = radTM*sin(angC(i)*rad) + dum6(i) = gsn_add_polyline(wks,taylor,xTM,yTM,plRes) + end do + ; minor tm locations + mTM = (/0.05,0.15,0.25,0.35,0.45,0.55,0.65 \ + ,0.75,0.85,0.91,0.92,0.93,0.94,0.96,0.97,0.98 /) + angmTM = acos(mTM)/rad ; angles: correlation labels + radmTM = xyMax*(1.-(1.-tmEnd)*0.5) ; radius end: minor TM + + dum7 = new(dimsizes(mTM),graphic) + + do i=0,dimsizes(mTM)-1 ; manually add tm + xTM(0) = xyMax*cos(angmTM(i)*rad) ; minor tickmarks + yTM(0) = xyMax*sin(angmTM(i)*rad) + xTM(1) = radmTM*cos(angmTM(i)*rad) + yTM(1) = radmTM*sin(angmTM(i)*rad) + dum7(i) = gsn_add_polyline(wks,taylor,xTM,yTM,plRes) + end do + ; added for Wanli + if (rOpts .and. isatt(rOpts,"ccRays") ) then + angRL = acos(rOpts@ccRays)/rad ; angles: radial lines + + rlRes = True + rlRes@xyDashPattern = 4 ; line pattern + rlRes@xyLineThicknessF = 1 ; choose line thickness + + dum8 = new(dimsizes(angRL),graphic) + do i=0,dimsizes(angRL)-1 + xRL = xyMax*cos(angRL(i)*rad) + yRL = xyMax*sin(angRL(i)*rad) + dum8(i) = gsn_add_polyline(wks,taylor,(/0, xRL /),(/0, yRL /),rlRes) + end do + taylor@$unique_string("dum")$ = dum8 + end if + +; ---------------------------------------------------------------- +; Part 3: +; Concentric about 1.0 on XB axis +; I think this is correct. Still test mode. +; ---------------------------------------------------------------- + if (rOpts .and. isatt(rOpts,"centerDiffRMS") \ + .and. rOpts@centerDiffRMS) then + respl = True ; polyline mods desired + respl@gsLineThicknessF = 1.0 ; line thickness + respl@gsLineColor = "Black" ; line color + respl@gsLineDashPattern = 2 ; short dash lines + + dx = 0.25 + ncon = 4 ; 0.75, 0.50, 0.25, 0.0 + npts = 100 ; arbitrary + ang = fspan(180,360,npts)*rad + + dum9 = new(ncon,graphic) + + do n=1,ncon + rr = n*dx ; radius from 1.0 [OBS] abscissa + xx = 1. + rr*cos(ang) + yy = fabs( rr*sin(ang) ) + if (n.le.2) then + dum9(n-1) = gsn_add_polyline(wks,taylor,xx,yy,respl) + end if + if (n.eq.3) then + n3 = floattointeger( 0.77*npts ) + dum9(n-1) = gsn_add_polyline(wks,taylor,xx(0:n3),yy(0:n3),respl) + end if + if (n.eq.4) then + n4 = floattointeger( 0.61*npts ) + dum9(n-1) = gsn_add_polyline(wks,taylor,xx(0:n4),yy(0:n4),respl) + end if + end do + delete(ang) + delete(xx) + delete(yy) + taylor@$unique_string("dum")$ = dum9 + + end if +; --------------------------------------------------------------- +; Part 4: +; generic resources that will be applied to all users data points +; of course, these can be changed +; http://www.ncl.ucar.edu/Document/Graphics/Resources/gs.shtml +; --------------------------------------------------------------- + if (rOpts .and. isatt(rOpts,"Markers")) then + Markers = rOpts@Markers + else + Markers = (/ 4, 6, 8, 0, 9, 12, 7, 2, 11, 16/) ; Marker Indices + end if + + if (rOpts .and. isatt(rOpts,"Colors")) then + Colors = rOpts@Colors + else + Colors = (/ "red", "blue", "green", "cyan", "orange" \ + , "torquoise", "brown", "yellow", "purple", "black"/) + end if + + if (rOpts .and. isatt(rOpts,"gsMarkerThicknessF")) then + gsMarkerThicknessF = rOpts@gsMarkerThicknessF + else + gsMarkerThicknessF = 1.0 + end if + + if (rOpts .and. isatt(rOpts,"gsMarkerSizeF")) then + gsMarkerSizeF = rOpts@gsMarkerSizeF + else + gsMarkerSizeF = 0.0085 ; Default: 0.007 + end if + + gsRes = True + gsRes@gsMarkerThicknessF = gsMarkerThicknessF ; default=1.0 + gsRes@gsMarkerSizeF = gsMarkerSizeF ; Default: 0.007 + + ptRes = True ; text options for points + ptRes@txJust = "BottomCenter"; Default="CenterCenter". + ptRes@txFontThicknessF = 1.2 ; default=1.00 + ptRes@txFontHeightF = 0.0125 ; default=0.05 + if (rOpts .and. isatt(rOpts,"txFontHeightF")) then + ptRes@txFontHeightF = rOpts@txFontHeightF + end if + + markerTxYOffset = 0.0175 ; default + if (rOpts .and. isatt(rOpts,"markerTxYOffset")) then + markerTxYOffset = rOpts@markerTxYOffset ; user defined offset + end if + + dum10 = new((nCase*nVar),graphic) + dum11 = dum10 + + do n=0,nCase-1 + gsRes@gsMarkerIndex = Markers(n) ; marker style (+) + gsRes@gsMarkerColor = Colors(n) ; marker color + ptRes@txFontColor = gsRes@gsMarkerColor + do i=0,nVar-1 + dum10(n*nVar+i) = gsn_add_polymarker(wks,taylor,X(n,i),Y(n,i),gsRes) + dum11(n*nVar+i) = gsn_add_text(wks,taylor,(i+1),X(n,i),Y(n,i)+markerTxYOffset,ptRes) + end do + end do + +; --------------------------------------------------------------- +; Part 5: ; add case legend and variable labels +; --------------------------------------------------------------- + + if (rOpts .and. isatt(rOpts,"caseLabels")) then + + if (isatt(rOpts,"caseLabelsFontHeightF")) then + caseLabelsFontHeightF = rOpts@caseLabelsFontHeightF + else + caseLabelsFontHeightF = 0.05 + end if + + lgres = True + lgres@lgMarkerColors = Colors ; colors of markers + lgres@lgMarkerIndexes = Markers ; Markers + lgres@lgMarkerSizeF = gsMarkerSizeF ; Marker size + lgres@lgItemType = "Markers" ; draw markers only + lgres@lgLabelFontHeightF = caseLabelsFontHeightF ; font height of legend case labels + + if (isatt(rOpts,"legendWidth")) then + lgres@vpWidthF = rOpts@legendWidth + else + lgres@vpWidthF = 0.15 ; width of legend (NDC) + end if + + if (isatt(rOpts,"legendHeight")) then + lgres@vpHeightF = rOpts@legendHeight + else + lgres@vpHeightF = 0.030*nCase ; height of legend (NDC) + end if + + lgres@lgPerimOn = False ; turn off perimeter + nModel = dimsizes( rOpts@caseLabels ) + lbid = gsn_create_legend(wks,nModel,rOpts@caseLabels,lgres) + + amres = True + amres@amParallelPosF = 0.35 + amres@amOrthogonalPosF = -0.35 + annoid1 = gsn_add_annotation(taylor,lbid,amres) ; add legend to plot + end if + + if (rOpts .and. isatt(rOpts,"varLabels")) then + nVar = dimsizes(rOpts@varLabels) + + if (isatt(rOpts,"varLabelsFontHeightF")) then + varLabelsFontHeightF = rOpts@varLabelsFontHeightF + else + varLabelsFontHeightF = 0.013 + end if + + txres = True + txres@txFontHeightF = varLabelsFontHeightF + txres@txJust = "CenterLeft" ; justify to the center left + + ;delta_y = 0.02 + delta_y = 0.06 + if (rOpts .and. isatt(rOpts,"varLabelsYloc")) then + ys = rOpts@varLabelsYloc ; user specified + else + ys = max( (/nVar*delta_y , 0.30/) ) + end if + + + do i = 1,nVar + if (i.eq.1) then + dum12 = new(nVar,graphic) + end if + + dum12(i-1) = gsn_add_text(wks,taylor,i+" - "+rOpts@varLabels(i-1), .125,ys,txres) + ys = ys- delta_y + end do + + taylor@$unique_string("dum")$ = dum12 + end if + + taylor@$unique_string("dum")$ = dum0 ; x-axis + taylor@$unique_string("dum")$ = dum1 ; y-axis + taylor@$unique_string("dum")$ = dum2 ; 1.0 std curve + taylor@$unique_string("dum")$ = dum5 ; labels [COR] + taylor@$unique_string("dum")$ = dum6 ; major tm [COR] + taylor@$unique_string("dum")$ = dum7 ; minor tm + taylor@$unique_string("dum")$ = dum10 ; markers + taylor@$unique_string("dum")$ = dum11 ; text + + if (.not.isatt(rOpts,"taylorDraw") .or. \ + (isatt(rOpts,"taylorDraw") .and. rOpts@taylorDraw)) then + draw(taylor) + end if + if (.not.isatt(rOpts,"taylorFrame") .or. \ + (isatt(rOpts,"taylorFrame") .and. rOpts@taylorFrame)) then + frame(wks) + end if + return(taylor) +end + diff -r 000000000000 -r 0c6405ab2ff4 taylor/taylor_diagram.ncl.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taylor/taylor_diagram.ncl.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,479 @@ +function taylor_diagram (wks:graphic ,RATIO[*][*]:numeric, CC[*][*]:numeric \ + ,rOpts:logical) +;-------------------------------------------------------------------- +; This version of taylor_diagram supports "paneling" +; It requires NCL version 4.2.0.a034 because it uses "gsn_create_legend" +;-------------------------------------------------------------------- + +; +; Generate a Taylor Diagram: +; Generate Multiple Aspects of Model Performance in a Single Diagram +; Taylor, K. E., J. Geophys. Res., 106, D7, 7183-7192, 2001 +; +; An example: +; http://www.grida.no/climate/ipcc_tar/wg1/fig8-4.htm +; +; This expects one or more datasets. The left dimension +; is the number of datasets. The rightmost is the number of pts. +; +; Markers are at: +; http://www.ncl.ucar.edu/Document/Graphics/Resources/gs.shtml +; +; By default, the function can handle up to 10 variable comparisons.. +; To expand ... modify the 'Colors' and 'Markers' attributes. +; The user can change / add some default settings. +; +; The defaults that the user can modify: +; +; rOpts = True +; ; 'made-up' resources +; rOpts@Colors = (/ "blue" , "red", "green", "cyan", "black" \ +; , "torquoise", "brown", "yellow"/) +; rOpts@Markers = (/ 2, 3, 6, 14, 9, 12, 7, 4/) ; Marker Indices +; rOpts@markerTxOffset = 0.0175 ; offset for text above marker +; rOpts@stnRad = (/ 1. /) ; (/ 0.50, 0.75, 1.5 /) +; rOpts@centerDiffRMS = False ; True mean draw additional radii from REF +; rOpts@caseLabelsFontHeightF = 0.05 +; rOpts@varLabelsFontHeightF = 0.013 +; rOpts@varLabelsYloc = 0.65 +; rOpts@legendWidth = 0.015 +; rOpts@legendHeight = 0.030*nCase +; rOpts@taylorDraw = True +; rOpts@taylorFrame = True +; +; ; standard NCL resources +; rOpts@tiMainString = "Taylor" ; not using title makes plot bigger +; rOpts@gsMarkerSizeF = 0.0085 ; marker size +; rOpts@gsMarkerThicknessF = 1.0 +; rOpts@txFontHeightF = 0.0125 ; text size +; rOpts@tiMainFontHeightF = 0.0225 ; tiMainString size +; +; It returns to the user a graphic object containing the +; Taylor background and plotted x/y pts. +; This graphic object contains a simple Taylor background appropriate +; for standardized data and the markers for the datasets. +; ================================================================== +; This version allows paneling: +; The 'cumbersome' "dum" variables were added by +; Adam Phillips to allow paneling via "gsn_add_?". +; ================================================================== +begin + dimR = dimsizes(RATIO) + nCase = dimR(0) ; # of cases [models] + nVar = dimR(1) ; # of variables + + ; x/y coordinates for plotting + X = new ( (/nCase,nVar/) , typeof(RATIO) ) + Y = new ( (/nCase,nVar/) , typeof(RATIO) ) + + do nc=0,nCase-1 + angle = acos( CC(nc,:) ) ; array operation + X(nc,:) = RATIO(nc,:)*cos( angle ) + Y(nc,:) = RATIO(nc,:)*sin( angle ) + end do + + xyMin = 0. + xyOne = 1.00 + xyMax = 1.65 + xyMax_Panel = xyMax+ 0.10 ; paneling purposes + + if (rOpts .and. isatt(rOpts,"txFontHeightF")) then + FontHeightF = rOpts@txFontHeightF ; user wants to specify size + else + FontHeightF = 0.0175 + end if + +; ---------------------------------------------------------------- +; Part 1: +; base plot: Based upon request of Mark Stevens +; basic x-y and draw the 1.0 observed and the outer curve at 1.65 +; ---------------------------------------------------------------- + + rxy = True + rxy@gsnDraw = False + rxy@gsnFrame = False + rxy@vpHeightF = 0.65 + rxy@vpWidthF = 0.65 + rxy@tmYLBorderOn = False + rxy@tmXBBorderOn = False + +; rxy@tiYAxisString = "Standardized Deviations (Normalized)" + rxy@tiYAxisString = "Standardized Deviations" + rxy@tiYAxisFontHeightF= FontHeightF ; default=0.025 + + rxy@tmXBMode = "Explicit" + rxy@tmXBValues = (/0.0,0.25,0.50,0.75,1.00,1.25,1.5/) ; major tm + ; default "OBS" or "REF" + ;rxy@tmXBLabels = (/"0.00","0.25","0.50","0.75","REF" ,"1.25","1.50"/) + rxy@tmXBLabels = (/" ","0.25","0.50","0.75","REF" ,"1.25","1.50"/) + if (rOpts .and. isatt(rOpts,"OneX") ) then ; eg: rOpts@OneX="1.00" + ;rxy@tmXBLabels = (/"0.00","0.25","0.50","0.75",rOpts@OneX,"1.25","1.50"/) + rxy@tmXBLabels = (/" ","0.25","0.50","0.75",rOpts@OneX,"1.25","1.50"/) + end if + + rxy@tmXBMajorLengthF = 0.015 ; default=0.02 for a vpHeightF=0.6 + rxy@tmXBLabelFontHeightF = FontHeightF + rxy@tmXBMinorOn = False + rxy@trXMaxF = xyMax_Panel + + rxy@tmYLMode = "Manual" + rxy@tmYLMinorOn = False + rxy@tmYLMajorLengthF = rxy@tmXBMajorLengthF + rxy@tmYLLabelFontHeightF = FontHeightF + rxy@tmYLMode = "Explicit" + rxy@tmYLValues = (/0.0, .25,0.50, 0.75, 1.00, 1.25, 1.5/) ; major tm + rxy@tmYLLabels = (/"0.00","0.25","0.50","0.75","1.00","1.25","1.50"/) + ;rxy@tmYLLabels = (/" ","0.25","0.50","0.75","1.00","1.25","1.50"/) + rxy@trYMaxF = xyMax_Panel + + rxy@tmYRBorderOn = False + rxy@tmYROn = False ; Turn off right tick marks. + + rxy@tmXTBorderOn = False + rxy@tmXTOn = False ; Turn off right tick marks. + + rxy@xyDashPatterns = (/ 0 /) ; line characteristics (dash,solid) + rxy@xyLineThicknesses = (/ 2./) ; choose line thickness + + rxy@gsnFrame = False ; Don't advance the frame. + + ; create outer 'correlation axis' + npts = 200 ; arbitrary + xx = fspan(xyMin,xyMax,npts) + yy = sqrt(xyMax^2 - xx^2 ) ; outer correlation line (xyMax) + + sLabels = (/"0.0","0.1","0.2","0.3","0.4","0.5","0.6" \ ; correlation labels + ,"0.7","0.8","0.9","0.95","0.99","1.0" /); also, major tm + cLabels = stringtofloat(sLabels) + rad = 4.*atan(1.0)/180. + angC = acos(cLabels)/rad ; angles: correlation labels + + if (rOpts .and. isatt(rOpts,"tiMainString")) then + rxy@tiMainString = rOpts@tiMainString + ;rxy@tiMainOffsetYF = 0.015 ; default 0.0 + if (isatt(rOpts,"tiMainFontHeightF")) then + rxy@tiMainFontHeightF = rOpts@tiMainFontHeightF + else + rxy@tiMainFontHeightF = 0.0225 ; default 0.025 + end if + end if +;;if (rOpts .and. isatt(rOpts,"gsnCenterString")) then +;; rxy@gsnCenterString = rOpts@gsnCenterString ; only gsn_csm_xy +;;end if + + taylor = gsn_xy(wks,xx,yy,rxy) ; Create and draw XY plot. + + rsrRes = True + rsrRes@gsLineThicknessF = rxy@xyLineThicknesses(0) ; line thickness + rsrRes@gsLineDashPattern = 0 ; solid line pattern + ; draw x and y to xyMax + dum0 = gsn_add_polyline(wks,taylor,(/0., 0. /),(/0.,xyMax/), rsrRes) + dum1 = gsn_add_polyline(wks,taylor,(/0.,xyMax/),(/0., 0. /), rsrRes) + + xx = fspan(xyMin, xyOne ,npts) ; draw 1.0 standard radius + yy = sqrt(xyOne - xx^2) + rsrRes@gsLineDashPattern = 1 ; dashed line pattern + rsrRes@gsLineThicknessF = rxy@xyLineThicknesses(0) ; line thickness + dum2 = gsn_add_polyline(wks,taylor,xx,yy, rsrRes) + delete(xx) + delete(yy) + + if (rOpts .and. isatt(rOpts,"stnRad") ) then + rsrRes@gsLineThicknessF = 1 ; rxy@xyLineThicknesses(0) + nStnRad = dimsizes(rOpts@stnRad) + + dum3 = new(nStnRad,graphic) + do n=0,nStnRad-1 + rr = rOpts@stnRad(n) + xx = fspan(xyMin, rr ,npts) + yy = sqrt(rr^2 - xx^2) + dum3(n) = gsn_add_polyline(wks,taylor,xx,yy, rsrRes) + end do + taylor@$unique_string("dum")$ = dum3 + + delete(xx) + delete(yy) + end if + + getvalues taylor ; get style info from taylor + "tmYLLabelFont" : tmYLLabelFont ; use for correlation axis + "tmYLLabelFontHeightF" : tmYLLabelFontHeightF + end getvalues + +; ---------------------------------------------------------------- +; Part 2: +; Correlation labels +; ---------------------------------------------------------------- + radC = xyMax ; for correlation labels + xC = radC*cos(angC*rad) + yC = radC*sin(angC*rad) +; added to get some separation + xC = xC + 0.020*cos(rad*angC) + yC = yC + 0.060*sin(rad*angC) + + txRes = True ; text mods desired + txRes@txFontHeightF = FontHeightF ; match YL + txRes@tmYLLabelFont = tmYLLabelFont ; match YL + txRes@txAngleF = -45. + if (.not.isatt(rOpts,"drawCorLabel") .or. rOpts@drawCorLabel) then + dum4 = gsn_add_text(wks,taylor,"Correlation",1.30,1.30,txRes) + taylor@$unique_string("dum")$ = dum4 + end if + txRes@txAngleF = 0.0 + txRes@txFontHeightF = FontHeightF*0.50 ; bit smaller + +;;dum0 = gsn_add_text(wks,taylor,"OBSERVED",1.00,0.075,txRes) + + plRes = True + plRes@gsLineThicknessF = 2. + + txRes@txJust = "CenterLeft" ; Default="CenterCenter". + txRes@txFontHeightF = FontHeightF ; match YL + ;txRes@txBackgroundFillColor = "white" + + tmEnd = 0.975 + radTM = xyMax*tmEnd ; radius end: major TM + xTM = new( 2 , "float") + yTM = new( 2 , "float") + + dum5 = new(dimsizes(sLabels),graphic) + dum6 = dum5 + + do i=0,dimsizes(sLabels)-1 ; Loop to draw strings + txRes@txAngleF = angC(i) + dum5(i) = gsn_add_text(wks, taylor, sLabels(i),xC(i),yC(i),txRes) ; cor label + xTM(0) = xyMax*cos(angC(i)*rad) ; major tickmarks at + yTM(0) = xyMax*sin(angC(i)*rad) ; correlation labels + xTM(1) = radTM*cos(angC(i)*rad) + yTM(1) = radTM*sin(angC(i)*rad) + dum6(i) = gsn_add_polyline(wks,taylor,xTM,yTM,plRes) + end do + ; minor tm locations + mTM = (/0.05,0.15,0.25,0.35,0.45,0.55,0.65 \ + ,0.75,0.85,0.91,0.92,0.93,0.94,0.96,0.97,0.98 /) + angmTM = acos(mTM)/rad ; angles: correlation labels + radmTM = xyMax*(1.-(1.-tmEnd)*0.5) ; radius end: minor TM + + dum7 = new(dimsizes(mTM),graphic) + + do i=0,dimsizes(mTM)-1 ; manually add tm + xTM(0) = xyMax*cos(angmTM(i)*rad) ; minor tickmarks + yTM(0) = xyMax*sin(angmTM(i)*rad) + xTM(1) = radmTM*cos(angmTM(i)*rad) + yTM(1) = radmTM*sin(angmTM(i)*rad) + dum7(i) = gsn_add_polyline(wks,taylor,xTM,yTM,plRes) + end do + ; added for Wanli + if (rOpts .and. isatt(rOpts,"ccRays") ) then + angRL = acos(rOpts@ccRays)/rad ; angles: radial lines + + rlRes = True + rlRes@xyDashPattern = 4 ; line pattern + rlRes@xyLineThicknessF = 1 ; choose line thickness + + dum8 = new(dimsizes(angRL),graphic) + do i=0,dimsizes(angRL)-1 + xRL = xyMax*cos(angRL(i)*rad) + yRL = xyMax*sin(angRL(i)*rad) + dum8(i) = gsn_add_polyline(wks,taylor,(/0, xRL /),(/0, yRL /),rlRes) + end do + taylor@$unique_string("dum")$ = dum8 + end if + +; ---------------------------------------------------------------- +; Part 3: +; Concentric about 1.0 on XB axis +; I think this is correct. Still test mode. +; ---------------------------------------------------------------- + if (rOpts .and. isatt(rOpts,"centerDiffRMS") \ + .and. rOpts@centerDiffRMS) then + respl = True ; polyline mods desired + respl@gsLineThicknessF = 1.0 ; line thickness + respl@gsLineColor = "Black" ; line color + respl@gsLineDashPattern = 2 ; short dash lines + + dx = 0.25 + ncon = 4 ; 0.75, 0.50, 0.25, 0.0 + npts = 100 ; arbitrary + ang = fspan(180,360,npts)*rad + + dum9 = new(ncon,graphic) + + do n=1,ncon + rr = n*dx ; radius from 1.0 [OBS] abscissa + xx = 1. + rr*cos(ang) + yy = fabs( rr*sin(ang) ) + if (n.le.2) then + dum9(n-1) = gsn_add_polyline(wks,taylor,xx,yy,respl) + end if + if (n.eq.3) then + n3 = floattointeger( 0.77*npts ) + dum9(n-1) = gsn_add_polyline(wks,taylor,xx(0:n3),yy(0:n3),respl) + end if + if (n.eq.4) then + n4 = floattointeger( 0.61*npts ) + dum9(n-1) = gsn_add_polyline(wks,taylor,xx(0:n4),yy(0:n4),respl) + end if + end do + delete(ang) + delete(xx) + delete(yy) + taylor@$unique_string("dum")$ = dum9 + + end if +; --------------------------------------------------------------- +; Part 4: +; generic resources that will be applied to all users data points +; of course, these can be changed +; http://www.ncl.ucar.edu/Document/Graphics/Resources/gs.shtml +; --------------------------------------------------------------- + if (rOpts .and. isatt(rOpts,"Markers")) then + Markers = rOpts@Markers + else + Markers = (/ 4, 6, 8, 0, 9, 12, 7, 2, 11, 16/) ; Marker Indices + end if + + if (rOpts .and. isatt(rOpts,"Colors")) then + Colors = rOpts@Colors + else + Colors = (/ "red", "blue", "green", "cyan", "orange" \ + , "torquoise", "brown", "yellow", "purple", "black"/) + end if + + if (rOpts .and. isatt(rOpts,"gsMarkerThicknessF")) then + gsMarkerThicknessF = rOpts@gsMarkerThicknessF + else + gsMarkerThicknessF = 1.0 + end if + + if (rOpts .and. isatt(rOpts,"gsMarkerSizeF")) then + gsMarkerSizeF = rOpts@gsMarkerSizeF + else + gsMarkerSizeF = 0.0085 ; Default: 0.007 + end if + + gsRes = True + gsRes@gsMarkerThicknessF = gsMarkerThicknessF ; default=1.0 + gsRes@gsMarkerSizeF = gsMarkerSizeF ; Default: 0.007 + + ptRes = True ; text options for points + ptRes@txJust = "BottomCenter"; Default="CenterCenter". + ptRes@txFontThicknessF = 1.2 ; default=1.00 + ptRes@txFontHeightF = 0.0125 ; default=0.05 + if (rOpts .and. isatt(rOpts,"txFontHeightF")) then + ptRes@txFontHeightF = rOpts@txFontHeightF + end if + + markerTxYOffset = 0.0175 ; default + if (rOpts .and. isatt(rOpts,"markerTxYOffset")) then + markerTxYOffset = rOpts@markerTxYOffset ; user defined offset + end if + + dum10 = new((nCase*nVar),graphic) + dum11 = dum10 + + do n=0,nCase-1 + gsRes@gsMarkerIndex = Markers(n) ; marker style (+) + gsRes@gsMarkerColor = Colors(n) ; marker color + ptRes@txFontColor = gsRes@gsMarkerColor + do i=0,nVar-1 + dum10(n*nVar+i) = gsn_add_polymarker(wks,taylor,X(n,i),Y(n,i),gsRes) + dum11(n*nVar+i) = gsn_add_text(wks,taylor,(i+1),X(n,i),Y(n,i)+markerTxYOffset,ptRes) + end do + end do + +; --------------------------------------------------------------- +; Part 5: ; add case legend and variable labels +; --------------------------------------------------------------- + + if (rOpts .and. isatt(rOpts,"caseLabels")) then + + if (isatt(rOpts,"caseLabelsFontHeightF")) then + caseLabelsFontHeightF = rOpts@caseLabelsFontHeightF + else + caseLabelsFontHeightF = 0.05 + end if + + lgres = True + lgres@lgMarkerColors = Colors ; colors of markers + lgres@lgMarkerIndexes = Markers ; Markers + lgres@lgMarkerSizeF = gsMarkerSizeF ; Marker size + lgres@lgItemType = "Markers" ; draw markers only + lgres@lgLabelFontHeightF = caseLabelsFontHeightF ; font height of legend case labels + + if (isatt(rOpts,"legendWidth")) then + lgres@vpWidthF = rOpts@legendWidth + else + lgres@vpWidthF = 0.15 ; width of legend (NDC) + end if + + if (isatt(rOpts,"legendHeight")) then + lgres@vpHeightF = rOpts@legendHeight + else + lgres@vpHeightF = 0.030*nCase ; height of legend (NDC) + end if + + lgres@lgPerimOn = False ; turn off perimeter + nModel = dimsizes( rOpts@caseLabels ) + lbid = gsn_create_legend(wks,nModel,rOpts@caseLabels,lgres) + + amres = True + amres@amParallelPosF = 0.35 + amres@amOrthogonalPosF = -0.35 + annoid1 = gsn_add_annotation(taylor,lbid,amres) ; add legend to plot + end if + + if (rOpts .and. isatt(rOpts,"varLabels")) then + nVar = dimsizes(rOpts@varLabels) + + if (isatt(rOpts,"varLabelsFontHeightF")) then + varLabelsFontHeightF = rOpts@varLabelsFontHeightF + else + varLabelsFontHeightF = 0.013 + end if + + txres = True + txres@txFontHeightF = varLabelsFontHeightF + txres@txJust = "CenterLeft" ; justify to the center left + + ;delta_y = 0.02 + delta_y = 0.06 + if (rOpts .and. isatt(rOpts,"varLabelsYloc")) then + ys = rOpts@varLabelsYloc ; user specified + else + ys = max( (/nVar*delta_y , 0.30/) ) + end if + + + do i = 1,nVar + if (i.eq.1) then + dum12 = new(nVar,graphic) + end if + + dum12(i-1) = gsn_add_text(wks,taylor,i+" - "+rOpts@varLabels(i-1), .125,ys,txres) + ys = ys- delta_y + end do + + taylor@$unique_string("dum")$ = dum12 + end if + + taylor@$unique_string("dum")$ = dum0 ; x-axis + taylor@$unique_string("dum")$ = dum1 ; y-axis + taylor@$unique_string("dum")$ = dum2 ; 1.0 std curve + taylor@$unique_string("dum")$ = dum5 ; labels [COR] + taylor@$unique_string("dum")$ = dum6 ; major tm [COR] + taylor@$unique_string("dum")$ = dum7 ; minor tm + taylor@$unique_string("dum")$ = dum10 ; markers + taylor@$unique_string("dum")$ = dum11 ; text + + if (.not.isatt(rOpts,"taylorDraw") .or. \ + (isatt(rOpts,"taylorDraw") .and. rOpts@taylorDraw)) then + draw(taylor) + end if + if (.not.isatt(rOpts,"taylorFrame") .or. \ + (isatt(rOpts,"taylorFrame") .and. rOpts@taylorFrame)) then + frame(wks) + end if + return(taylor) +end + diff -r 000000000000 -r 0c6405ab2ff4 time_series/10.write_ameriflux_casa.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/time_series/10.write_ameriflux_casa.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,167 @@ +;************************************************ +; Read ascii, Write nc +; output: lat: N->S lon: -180W->180E +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +; output + + model_name = "i01.10casa" + + diro = "/ptmp/jeff/" + filo = model_name + "_ameriflux_1990-2004_monthly.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"year",-1,True) + +; input data + + nlat = 64 + nlon = 128 + + year_start = 1990 + year_end = 2004 + + nyear = year_end - year_start + 1 + nmonth = 12 + + data1 = new((/nyear,nmonth,nlat,nlon/),float) + data2 = new((/nyear,nmonth,nlat,nlon/),float) + data3 = new((/nyear,nmonth,nlat,nlon/),float) + data4 = new((/nyear,nmonth,nlat,nlon/),float) + data5 = new((/nyear,nmonth,nlat,nlon/),float) + data6 = new((/nyear,nmonth,nlat,nlon/),float) + data7 = new((/nyear,nmonth,nlat,nlon/),float) + date = new((/nyear,nmonth/),integer) + +; name dimensions and assign coordinate variables + + data1!0 ="year" + data1!1 ="month" + data1!2 = "lat" + data1!3 = "lon" + + data2!0 ="year" + data2!1 ="month" + data2!2 = "lat" + data2!3 = "lon" + + data3!0 ="year" + data3!1 ="month" + data3!2 = "lat" + data3!3 = "lon" + + data4!0 ="year" + data4!1 ="month" + data4!2 = "lat" + data4!3 = "lon" + + data5!0 ="year" + data5!1 ="month" + data5!2 = "lat" + data5!3 = "lon" + + data6!0 ="year" + data6!1 ="month" + data6!2 = "lat" + data6!3 = "lon" + + data7!0 ="year" + data7!1 ="month" + data7!2 = "lat" + data7!3 = "lon" + + date!0 ="year" + date!1 ="month" + date@long_name = "date: yyyymm" + +; input dir + diri = "/ptmp/jeff/"+model_name+"/" + + do m = 0,nyear-1 + year = year_start + m + do n = 0,nmonth-1 + nn = n+1 + date(m,n) = year*100 +nn + +; input file + if (nn .ge. 10) then + fili = model_name+".clm2.h0."+year+"-"+nn+".nc" + else + fili = model_name+".clm2.h0."+year+"-0"+nn+".nc" + end if + + print (fili) + + g = addfile (diri+fili,"r") + + b = g->NEE + data1(m,n,:,:) = (/b(0,:,:)/) + data1@long_name = b@long_name + data1@units = b@units + data1@_FillValue = b@_FillValue + delete (b) + + b = g->GPP + data2(m,n,:,:) = (/b(0,:,:)/) + data2@long_name = b@long_name + data2@units = b@units + data2@_FillValue = b@_FillValue + delete (b) + + b = g->AR + data3(m,n,:,:) = (/b(0,:,:)/) + b = g->HR + data3(m,n,:,:) = data3(m,n,:,:)+(/b(0,:,:)/) + data3@long_name = "total ecosystem respiration, autotrophic + heterotrophic" + data3@units = b@units + data3@_FillValue = b@_FillValue + delete (b) + + b = g->NETRAD + data4(m,n,:,:) = (/b(0,:,:)/) + data4@long_name = b@long_name + data4@units = b@units + data4@_FillValue = b@_FillValue + delete (b) + + b = g->LATENT + data5(m,n,:,:) = (/b(0,:,:)/) + data5@long_name = b@long_name + data5@units = b@units + data5@_FillValue = b@_FillValue + delete (b) + + b = g->FSH + data6(m,n,:,:) = (/b(0,:,:)/) + data6@long_name = b@long_name + data6@units = b@units + data6@_FillValue = b@_FillValue + delete (b) + + b = g->FSDS + data7(m,n,:,:) = (/b(0,:,:)/) + data7@long_name = b@long_name + data7@units = b@units + data7@_FillValue = b@_FillValue + delete (b) + + end do + end do + + c->NEE = data1 + c->GPP = data2 + c->ER = data3 + c->NETRAD = data4 + c->LATENT = data5 + c->FSH = data6 + c->FSDS = data7 + c->date = date + c->area = g->area + + print (date) + +end diff -r 000000000000 -r 0c6405ab2ff4 time_series/10.write_ameriflux_cn.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/time_series/10.write_ameriflux_cn.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,165 @@ +;************************************************ +; Read ascii, Write nc +; output: lat: N->S lon: -180W->180E +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +; output + + model_name = "i01.10cn" + + diro = "/ptmp/jeff/" + filo = model_name + "_ameriflux_1990-2004_monthly.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"year",-1,True) + +; input data + + nlat = 64 + nlon = 128 + + year_start = 1990 + year_end = 2004 + + nyear = year_end - year_start + 1 + nmonth = 12 + + data1 = new((/nyear,nmonth,nlat,nlon/),float) + data2 = new((/nyear,nmonth,nlat,nlon/),float) + data3 = new((/nyear,nmonth,nlat,nlon/),float) + data4 = new((/nyear,nmonth,nlat,nlon/),float) + data5 = new((/nyear,nmonth,nlat,nlon/),float) + data6 = new((/nyear,nmonth,nlat,nlon/),float) + data7 = new((/nyear,nmonth,nlat,nlon/),float) + date = new((/nyear,nmonth/),integer) + +; name dimensions and assign coordinate variables + + data1!0 ="year" + data1!1 ="month" + data1!2 = "lat" + data1!3 = "lon" + + data2!0 ="year" + data2!1 ="month" + data2!2 = "lat" + data2!3 = "lon" + + data3!0 ="year" + data3!1 ="month" + data3!2 = "lat" + data3!3 = "lon" + + data4!0 ="year" + data4!1 ="month" + data4!2 = "lat" + data4!3 = "lon" + + data5!0 ="year" + data5!1 ="month" + data5!2 = "lat" + data5!3 = "lon" + + data6!0 ="year" + data6!1 ="month" + data6!2 = "lat" + data6!3 = "lon" + + data7!0 ="year" + data7!1 ="month" + data7!2 = "lat" + data7!3 = "lon" + + date!0 ="year" + date!1 ="month" + date@long_name = "date: yyyymm" + +; input dir + diri = "/ptmp/jeff/"+model_name+"/" + + do m = 0,nyear-1 + year = year_start + m + do n = 0,nmonth-1 + nn = n+1 + date(m,n) = year*100 +nn + +; input file + if (nn .ge. 10) then + fili = model_name+".clm2.h0."+year+"-"+nn+".nc" + else + fili = model_name+".clm2.h0."+year+"-0"+nn+".nc" + end if + + print (fili) + + g = addfile (diri+fili,"r") + + b = g->NEE + data1(m,n,:,:) = (/b(0,:,:)/) + data1@long_name = b@long_name + data1@units = b@units + data1@_FillValue = b@_FillValue + delete (b) + + b = g->GPP + data2(m,n,:,:) = (/b(0,:,:)/) + data2@long_name = b@long_name + data2@units = b@units + data2@_FillValue = b@_FillValue + delete (b) + + b = g->ER + data3(m,n,:,:) = (/b(0,:,:)/) + data3@long_name = b@long_name + data3@units = b@units + data3@_FillValue = b@_FillValue + delete (b) + + b = g->NETRAD + data4(m,n,:,:) = (/b(0,:,:)/) + data4@long_name = b@long_name + data4@units = b@units + data4@_FillValue = b@_FillValue + delete (b) + + b = g->LATENT + data5(m,n,:,:) = (/b(0,:,:)/) + data5@long_name = b@long_name + data5@units = b@units + data5@_FillValue = b@_FillValue + delete (b) + + b = g->FSH + data6(m,n,:,:) = (/b(0,:,:)/) + data6@long_name = b@long_name + data6@units = b@units + data6@_FillValue = b@_FillValue + delete (b) + + b = g->FSDS + data7(m,n,:,:) = (/b(0,:,:)/) + data7@long_name = b@long_name + data7@units = b@units + data7@_FillValue = b@_FillValue + delete (b) + + end do + end do + + c->NEE = data1 + c->GPP = data2 + c->ER = data3 + c->NETRAD = data4 + c->LATENT = data5 + c->FSH = data6 + c->FSDS = data7 + c->date = date + c->area = g->area + + print (date) + +end diff -r 000000000000 -r 0c6405ab2ff4 time_series/20.write_fire_cn.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/time_series/20.write_fire_cn.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,104 @@ +;************************************************ +; output: lat: N->S lon: -180W->180E +;************************************************ +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************ +begin + +; output + + model_name = "i01.10cn" + + diro = "/ptmp/jeff/" + filo = model_name + "_Fire_C_1979-2004_monthly.nc" + c = addfile(diro+filo,"c") + filedimdef(c,"year",-1,True) + +; input data + + nlat = 64 + nlon = 128 + + year_start = 1979 + year_end = 2004 + + nyear = year_end - year_start + 1 + nmonth = 12 + + data1 = new((/nyear,nmonth,nlat,nlon/),float) + data2 = new((/nyear,nmonth,nlat,nlon/),float) + data3 = new((/nyear,nmonth,nlat,nlon/),float) + date = new((/nyear,nmonth/),integer) + +; input dir + diri = "/ptmp/jeff/"+model_name+"/" + + do m = 0,nyear-1 + year = year_start + m + do n = 0,nmonth-1 + nn = n+1 + date(m,n) = year*100 +nn + +; input file + if (nn .ge. 10) then + fili = model_name+".clm2.h0."+year+"-"+nn+".nc" + else + fili = model_name+".clm2.h0."+year+"-0"+nn+".nc" + end if + +; print (fili) + + g = addfile (diri+fili,"r") + + b1 = g->COL_FIRE_CLOSS + data1(m,n,:,:) = (/b1(0,:,:)/) + + b2 = g->NPP + data2(m,n,:,:) = (/b2(0,:,:)/) + + b3 = g->NEE + data3(m,n,:,:) = (/b3(0,:,:)/) + end do + end do + +; name dimensions and assign coordinate variables + + data1!0 ="year" + data1!1 ="month" + data1!2 = "lat" + data1!3 = "lon" + data1@long_name = b1@long_name + data1@units = b1@units + data1@_FillValue = b1@_FillValue + + data2!0 ="year" + data2!1 ="month" + data2!2 = "lat" + data2!3 = "lon" + data2@long_name = b2@long_name + data2@units = b2@units + data2@_FillValue = b2@_FillValue + + data3!0 ="year" + data3!1 ="month" + data3!2 = "lat" + data3!3 = "lon" + data3@long_name = b3@long_name + data3@units = b3@units + data3@_FillValue = b3@_FillValue + + date!0 ="year" + date!1 ="month" + date@long_name = "date: yyyymm" + + c->COL_FIRE_CLOSS = data1 + c->NPP = data2 + c->NEE = data3 + c->date = date + c->area = g->area + + print (date) + +end diff -r 000000000000 -r 0c6405ab2ff4 turnover/01.biome.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/turnover/01.biome.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,294 @@ +;******************************************************** +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;************************************************ +; read data: model +;************************************************ + + model_grid = "T42" + + model_name = "i01.06cn" +;model_name = "i01.06casa" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name + "_1980-2004_ANN_climo.nc" + + fm = addfile (dirm+film,"r") + + xm = fm->lon + ym = fm->lat + + pool = fm->WOODC + flux = fm->WOODC_ALLOC + +;Units for these variables are: +;pool: g C/m^2 +;flux: g C/m^2/s + + nsec_per_year = 60*60*24*365 + + flux = flux * nsec_per_year + +;************************************************ +; read data: observed-biome +;************************************************ + + ob_name = "MODIS MOD 15A2 2000-2005" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "land_class_"+model_grid+".nc" + + fo = addfile(diro+filo,"r") + + classob = tofloat(fo->LAND_CLASS) + + nclass = 20 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + +; get data + + base_1D = ndtooned(classob) + data1_1D = ndtooned(pool) + data2_1D = ndtooned(flux) + +; output + + yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing data1 (nd=0) or data2 (nd=1). + + base = base_1D + + if(nd.eq.0) then + data = data1_1D + else + data = data2_1D + end if + +; Loop through each range, using base. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(base.ge.range(i)) + end if + +; Calculate average + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data(idx)) + count = dimsizes(idx) + else + yvalues(nd,i) = yvalues@_FillValue + count = 0 + end if + +;############################################################# +; set the following 4 classes to _FillValue: +; Water Bodies(0), Urban and Build-Up(13), +; Permenant Snow and Ice(15), Unclassified(17) + + if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then + yvalues(nd,i) = yvalues@_FillValue + count = 0 + end if +;############################################################# + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + + delete(data) + end do + +;============================ +;compute turnover time +;============================ + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + + uu = u(good) + vv = v(good) + + n_biome = dimsizes(uu) + + t_biome = new((/n_biome/),float) + + t_biome = uu/vv + + t_biome_avg = avg(t_biome) + +;print (t_biome) +;print (t_biome_avg) + +;=========================== +; for html table - biome +;=========================== + + output_html = "table_biome.html" + +; column (not including header column) + + col_head = (/"WOOD Flux","WOOD Pool","WOOD Turnover Time"/) + + ncol = dimsizes(col_head) + +; row (not including header row) +; 4 classes removed: Water Bodies, Urban and Build-Up, +; Unclassified, Permanent Snow and Ice + + row_head = (/"Evergreen Needleleaf Forests" \ + ,"Evergreen Broadleaf Forests" \ + ,"Deciduous Needleleaf Forest" \ + ,"Deciduous Broadleaf Forests" \ + ,"Mixed Forests" \ + ,"Closed Bushlands" \ + ,"Open Bushlands" \ + ,"Woody Savannas (S. Hem.)" \ + ,"Savannas (S. Hem.)" \ + ,"Grasslands" \ + ,"Permanent Wetlands" \ + ,"Croplands" \ + ,"Cropland/Natural Vegetation Mosaic" \ + ,"Barren or Sparsely Vegetated" \ + ,"Woody Savannas (N. Hem.)" \ + ,"Savannas (N. Hem.)" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",vv(i)) + text4(i,1) = sprintf("%.1f",uu(i)) + text4(i,2) = sprintf("%.1f",t_biome(i)) + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = sprintf("%.1f",t_biome_avg) + +;************************************************** +; html table +;************************************************** + + header_text = "

WOOD Turnover Time: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Class"+col_head(0)+""+col_head(1)+""+col_head(2)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + +end + diff -r 000000000000 -r 0c6405ab2ff4 turnover/02.biome.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/turnover/02.biome.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,303 @@ +;******************************************************** +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;components + + component = (/"Leaf","Wood","Fine_Root","Litter","Coarse_Woody_Debris","Soil"/) + n_comp = dimsizes(component) + + field_pool = (/"LEAFC","WOODC","FROOTC","LITTERC","CWDC","SOILC"/) + field_flux = (/"LEAFC_ALLOC","WOODC_ALLOC","FROOTC_ALLOC","LITTERC_LOSS","CWDC_LOSS","SOILC_HR"/) + +;************************************************ +; read data: model +;************************************************ + + model_grid = "T42" + +;model_name = "i01.06cn" + model_name = "i01.06casa" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name + "_1980-2004_ANN_climo.nc" + + fm = addfile (dirm+film,"r") + + do k = 0,n_comp-1 + + pool = fm->$field_pool(k)$ + flux = fm->$field_flux(k)$ + +;Units for these variables are: +;pool: g C/m^2 +;flux: g C/m^2/s + + nsec_per_year = 60*60*24*365 + + flux = flux * nsec_per_year + +;************************************************ +; read data: observed-biome +;************************************************ + + ob_name = "MODIS MOD 15A2 2000-2005" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "land_class_"+model_grid+".nc" + + fo = addfile(diro+filo,"r") + + classob = tofloat(fo->LAND_CLASS) + + nclass = 20 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + +; get data + + base_1D = ndtooned(classob) + data1_1D = ndtooned(pool) + data2_1D = ndtooned(flux) + +; output + + yvalues = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing data1 (nd=0) or data2 (nd=1). + + base = base_1D + + if(nd.eq.0) then + data = data1_1D + else + data = data2_1D + end if + +; Loop through each range, using base. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(base.ge.range(i)) + end if + +; Calculate average + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data(idx)) + count = dimsizes(idx) + else + yvalues(nd,i) = yvalues@_FillValue + count = 0 + end if + +;############################################################# +; set the following 4 classes to _FillValue: +; Water Bodies(0), Urban and Build-Up(13), +; Permenant Snow and Ice(15), Unclassified(17) + + if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then + yvalues(nd,i) = yvalues@_FillValue + count = 0 + end if +;############################################################# + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + + delete(data) + end do + +;============================ +;compute turnover time +;============================ + + u = yvalues(0,:) + v = yvalues(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + + uu = u(good) + vv = v(good) + + n_biome = dimsizes(uu) + + t_biome = new((/n_biome/),float) + + t_biome = uu/vv + + t_biome_avg = avg(t_biome) + +;print (t_biome) +;print (t_biome_avg) + +;=========================== +; for html table - biome +;=========================== + + output_html = "table_"+component(k)+".html" + +; column (not including header column) + + col_head = (/component(k)+" Flux",component(k)+" Pool",component(k)+" Turnover Time"/) + + ncol = dimsizes(col_head) + +; row (not including header row) +; 4 classes removed: Water Bodies, Urban and Build-Up, +; Unclassified, Permanent Snow and Ice + + row_head = (/"Evergreen Needleleaf Forests" \ + ,"Evergreen Broadleaf Forests" \ + ,"Deciduous Needleleaf Forest" \ + ,"Deciduous Broadleaf Forests" \ + ,"Mixed Forests" \ + ,"Closed Bushlands" \ + ,"Open Bushlands" \ + ,"Woody Savannas (S. Hem.)" \ + ,"Savannas (S. Hem.)" \ + ,"Grasslands" \ + ,"Permanent Wetlands" \ + ,"Croplands" \ + ,"Cropland/Natural Vegetation Mosaic" \ + ,"Barren or Sparsely Vegetated" \ + ,"Woody Savannas (N. Hem.)" \ + ,"Savannas (N. Hem.)" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",vv(i)) + text4(i,1) = sprintf("%.1f",uu(i)) + text4(i,2) = sprintf("%.1f",t_biome(i)) + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = sprintf("%.1f",t_biome_avg) + +;************************************************** +; html table +;************************************************** + + header_text = "

"+component(k)+" Turnover Time: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Class"+col_head(0)+""+col_head(1)+""+col_head(2)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) +end do +end + diff -r 000000000000 -r 0c6405ab2ff4 turnover/03.biome_model.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/turnover/03.biome_model.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,404 @@ +;******************************************************** +;using model biome vlass +; +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;components + + component = (/"Leaf","Wood","Fine_Root","Litter","Coarse_Woody_Debris","Soil"/) + n_comp = dimsizes(component) + + field_pool = (/"LEAFC","WOODC","FROOTC","LITTERC","CWDC","SOILC"/) + field_flux = (/"LEAFC_ALLOC","WOODC_ALLOC","FROOTC_ALLOC","LITTERC_LOSS","CWDC_LOSS","SOILC_HR"/) + +;************************************************ +; model name and grid +;************************************************ + + model_grid = "T42" + + model_name = "i01.06cn" +;model_name = "i01.06casa" + +;************************************************ +; read data: ob +;************************************************ +;------------------------------------------------ +; read biome data: observed + +; biome_name_ob = "MODIS LandCover" + +; diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" +; filo = "land_class_"+model_grid+".nc" + +; fo = addfile(diro+filo,"r") + +; classob = tofloat(fo->LAND_CLASS) + +; delete (fo) + +; observed data has 20 land-type classes + +; nclass_ob = 20 + +;--------------------------------------------------- +; read biome data: model + + biome_name_mod = "Model PFT Class" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = "class_pft_"+model_grid+".nc" + + fm = addfile(dirm+film,"r") + + classmod = fm->CLASS_PFT + + delete (fm) + +; model data has 17 land-type classes + + nclass_mod = 17 + +;--------------------------------------------------- +; read data: model, each component + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name + "_1980-2004_ANN_climo.nc" + + fm = addfile (dirm+film,"r") + + do k = 0,n_comp-1 + + pool = fm->$field_pool(k)$ + flux = fm->$field_flux(k)$ + +;Units for these variables are: +;pool: g C/m^2 +;flux: g C/m^2/s + + nsec_per_year = 60*60*24*365 + + flux = flux * nsec_per_year + +; casa only +; all the plant pools (leaf, wood, and fine root) and +; coarse woody debris (cwd) and litter pools for +; CASA need to be divided by 1200. The soil flux +; and turnover time are fine and do not need to be adjusted. + +; if (k .ne. n_comp-1) then +; flux = flux/1200. +; end if + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + +; using observed biome class +; nclass = nclass_ob +; using model biome class + nclass = nclass_mod + + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + +;============================== +; put data into bins +;============================== + +; using observed biome class +; base_1D = ndtooned(classob) +; using model biome class + base_1D = ndtooned(classmod) + + data1_1D = ndtooned(pool) + data2_1D = ndtooned(flux) + +; output + + yvalues = new((/2,nx/),float) + count = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing data1 (nd=0) or data2 (nd=1). + + base = base_1D + + if(nd.eq.0) then + data = data1_1D + else + data = data2_1D + end if + +; Loop through each range, using base. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(base.ge.range(i)) + end if + +; Calculate average + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data(idx)) + count(nd,i) = dimsizes(idx) + else + yvalues(nd,i) = yvalues@_FillValue + count(nd,i) = 0 + end if + +;############################################################# +;using observed biome class: +; set the following 4 classes to _FillValue: +; Water Bodies(0), Urban and Build-Up(13), +; Permenant Snow and Ice(15), Unclassified(17) + +; if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then +; yvalues(nd,i) = yvalues@_FillValue +; count(nd,i) = 0 +; end if +;############################################################# + +;############################################################# +;using model biome class: +; set the following 4 classes to _FillValue: +; (3)Needleleaf Deciduous Boreal Tree, +; (8)Broadleaf Deciduous Boreal Tree, +; (9)Broadleaf Evergreen Shrub, +; (16)Wheat + + if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then + yvalues(nd,i) = yvalues@_FillValue + count(nd,i) = 0 + end if +;############################################################# + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + + delete(data) + end do + +;============================ +;compute turnover time +;============================ + + u = yvalues(0,:) + v = yvalues(1,:) + u_count = count(0,:) + v_count = count(1,:) + +;print (dimsizes(u)) +;print (dimsizes(v)) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + +;print (good) + + uu = u(good) + vv = v(good) + +;print (dimsizes(uu)) +;print (dimsizes(vv)) + + uu_count = u_count(good) + vv_count = v_count(good) + + n_biome = dimsizes(uu) + t_biome = new((/n_biome/),float) + + t_biome = uu/vv + +;t_biome_avg = avg(t_biome) + t_biome_avg = sum(uu*uu_count)/sum(vv*vv_count) + +;print (t_biome) +;print (t_biome_avg) + +;=========================== +; for html table - biome +;=========================== + + output_html = "table_"+component(k)+".html" + +; column (not including header column) + + col_head = (/component(k)+" Flux",component(k)+" Pool",component(k)+" Turnover Time"/) + + ncol = dimsizes(col_head) + +; row (not including header row) + +;---------------------------------------------------- +; using observed biome class: +; row_head = (/"Evergreen Needleleaf Forests" \ +; ,"Evergreen Broadleaf Forests" \ +; ,"Deciduous Needleleaf Forest" \ +; ,"Deciduous Broadleaf Forests" \ +; ,"Mixed Forests" \ +; ,"Closed Bushlands" \ +; ,"Open Bushlands" \ +; ,"Woody Savannas (S. Hem.)" \ +; ,"Savannas (S. Hem.)" \ +; ,"Grasslands" \ +; ,"Permanent Wetlands" \ +; ,"Croplands" \ +; ,"Cropland/Natural Vegetation Mosaic" \ +; ,"Barren or Sparsely Vegetated" \ +; ,"Woody Savannas (N. Hem.)" \ +; ,"Savannas (N. Hem.)" \ +; ,"All Biome" \ +; /) + +;---------------------------------------------------- +; using model biome class: + row_head = (/"Not Vegetated" \ + ,"Needleleaf Evergreen Temperate Tree" \ + ,"Needleleaf Evergreen Boreal Tree" \ +; ,"Needleleaf Deciduous Boreal Tree" \ + ,"Broadleaf Evergreen Tropical Tree" \ + ,"Broadleaf Evergreen Temperate Tree" \ + ,"Broadleaf Deciduous Tropical Tree" \ + ,"Broadleaf Deciduous Temperate Tree" \ +; ,"Broadleaf Deciduous Boreal Tree" \ +; ,"Broadleaf Evergreen Shrub" \ + ,"Broadleaf Deciduous Temperate Shrub" \ + ,"Broadleaf Deciduous Boreal Shrub" \ + ,"C3 Arctic Grass" \ + ,"C3 Non-Arctic Grass" \ + ,"C4 Grass" \ + ,"Corn" \ +; ,"Wheat" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",vv(i)) + text4(i,1) = sprintf("%.1f",uu(i)) + text4(i,2) = sprintf("%.2f",t_biome(i)) + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = sprintf("%.2f",t_biome_avg) + +;************************************************** +; html table +;************************************************** + + header_text = "

"+component(k)+" Turnover Time: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Class"+col_head(0)+""+col_head(1)+""+col_head(2)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) +end do +end + diff -r 000000000000 -r 0c6405ab2ff4 turnover/03.biome_ob.ncl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/turnover/03.biome_ob.ncl Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,317 @@ +;******************************************************** +; required command line input parameters: +; ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl +; +; histogram normalized by rain and compute correleration +;************************************************************** +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" +;************************************************************** +procedure set_line(lines:string,nline:integer,newlines:string) +begin +; add line to ascci/html file + + nnewlines = dimsizes(newlines) + if(nline+nnewlines-1.ge.dimsizes(lines)) + print("set_line: bad index, not setting anything.") + return + end if + lines(nline:nline+nnewlines-1) = newlines +; print ("lines = " + lines(nline:nline+nnewlines-1)) + nline = nline + nnewlines + return +end +;************************************************************** +; Main code. +begin + + plot_type = "ps" + plot_type_new = "png" + +;components + + component = (/"Leaf","Wood","Fine_Root","Litter","Coarse_Woody_Debris","Soil"/) + n_comp = dimsizes(component) + + field_pool = (/"LEAFC","WOODC","FROOTC","LITTERC","CWDC","SOILC"/) + field_flux = (/"LEAFC_ALLOC","WOODC_ALLOC","FROOTC_ALLOC","LITTERC_LOSS","CWDC_LOSS","SOILC_HR"/) + +;************************************************ +; read data: model +;************************************************ + + model_grid = "T42" + +;model_name = "i01.06cn" + model_name = "i01.06casa" + + dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/" + film = model_name + "_1980-2004_ANN_climo.nc" + + fm = addfile (dirm+film,"r") + + do k = 0,n_comp-1 + + pool = fm->$field_pool(k)$ + flux = fm->$field_flux(k)$ + +;Units for these variables are: +;pool: g C/m^2 +;flux: g C/m^2/s + + nsec_per_year = 60*60*24*365 + + flux = flux * nsec_per_year + +; casa only +; all the plant pools (leaf, wood, and fine root) and +; coarse woody debris (cwd) and litter pools for +; CASA need to be divided by 1200. The soil flux +; and turnover time are fine and do not need to be adjusted. + + if (k .ne. n_comp-1) then + flux = flux/1200. + end if +;************************************************ +; read data: observed-biome +;************************************************ + + ob_name = "MODIS MOD 15A2 2000-2005" + + diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/" + filo = "land_class_"+model_grid+".nc" + + fo = addfile(diro+filo,"r") + + classob = tofloat(fo->LAND_CLASS) + + nclass = 20 + +;******************************************************************* +; Calculate "nice" bins for binning the data in equally spaced ranges +;******************************************************************** + + nclassn = nclass + 1 + range = fspan(0,nclassn-1,nclassn) +; print (range) + +; Use this range information to grab all the values in a +; particular range, and then take an average. + + nr = dimsizes(range) + nx = nr-1 + xvalues = new((/2,nx/),float) + xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2. + dx = xvalues(0,1) - xvalues(0,0) ; range width + dx4 = dx/4 ; 1/4 of the range + xvalues(1,:) = xvalues(0,:) - dx/5. + +; get data + + base_1D = ndtooned(classob) + data1_1D = ndtooned(pool) + data2_1D = ndtooned(flux) + +; output + + yvalues = new((/2,nx/),float) + count = new((/2,nx/),float) + + do nd=0,1 + +; See if we are doing data1 (nd=0) or data2 (nd=1). + + base = base_1D + + if(nd.eq.0) then + data = data1_1D + else + data = data2_1D + end if + +; Loop through each range, using base. + + do i=0,nr-2 + if (i.ne.(nr-2)) then +; print("") +; print("In range ["+range(i)+","+range(i+1)+")") + idx = ind((base.ge.range(i)).and.(base.lt.range(i+1))) + else +; print("") +; print("In range ["+range(i)+",)") + idx = ind(base.ge.range(i)) + end if + +; Calculate average + + if(.not.any(ismissing(idx))) then + yvalues(nd,i) = avg(data(idx)) + count(nd,i) = dimsizes(idx) + else + yvalues(nd,i) = yvalues@_FillValue + count(nd,i) = 0 + end if + +;############################################################# +; set the following 4 classes to _FillValue: +; Water Bodies(0), Urban and Build-Up(13), +; Permenant Snow and Ice(15), Unclassified(17) + + if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then + yvalues(nd,i) = yvalues@_FillValue + count(nd,i) = 0 + end if +;############################################################# + +; print(nd + ": " + count + " points, avg = " + yvalues(nd,i)) + +; Clean up for next time in loop. + + delete(idx) + end do + + delete(data) + end do + +;============================ +;compute turnover time +;============================ + + u = yvalues(0,:) + v = yvalues(1,:) + u_count = count(0,:) + v_count = count(1,:) + + good = ind(.not.ismissing(u) .and. .not.ismissing(v)) + + uu = u(good) + vv = v(good) + uu_count = u_count(good) + vv_count = v_count(good) + + n_biome = dimsizes(uu) + t_biome = new((/n_biome/),float) + + t_biome = uu/vv + +;t_biome_avg = avg(t_biome) + t_biome_avg = sum(uu*uu_count)/sum(vv*vv_count) + +;print (t_biome) +;print (t_biome_avg) + +;=========================== +; for html table - biome +;=========================== + + output_html = "table_"+component(k)+".html" + +; column (not including header column) + + col_head = (/component(k)+" Flux",component(k)+" Pool",component(k)+" Turnover Time"/) + + ncol = dimsizes(col_head) + +; row (not including header row) +; 4 classes removed: Water Bodies, Urban and Build-Up, +; Unclassified, Permanent Snow and Ice + + row_head = (/"Evergreen Needleleaf Forests" \ + ,"Evergreen Broadleaf Forests" \ + ,"Deciduous Needleleaf Forest" \ + ,"Deciduous Broadleaf Forests" \ + ,"Mixed Forests" \ + ,"Closed Bushlands" \ + ,"Open Bushlands" \ + ,"Woody Savannas (S. Hem.)" \ + ,"Savannas (S. Hem.)" \ + ,"Grasslands" \ + ,"Permanent Wetlands" \ + ,"Croplands" \ + ,"Cropland/Natural Vegetation Mosaic" \ + ,"Barren or Sparsely Vegetated" \ + ,"Woody Savannas (N. Hem.)" \ + ,"Savannas (N. Hem.)" \ + ,"All Biome" \ + /) + nrow = dimsizes(row_head) + +; arrays to be passed to table. + text4 = new ((/nrow, ncol/),string ) + + do i=0,nrow-2 + text4(i,0) = sprintf("%.1f",vv(i)) + text4(i,1) = sprintf("%.1f",uu(i)) + text4(i,2) = sprintf("%.2f",t_biome(i)) + end do + text4(nrow-1,0) = "-" + text4(nrow-1,1) = "-" + text4(nrow-1,2) = sprintf("%.2f",t_biome_avg) + +;************************************************** +; html table +;************************************************** + + header_text = "

"+component(k)+" Turnover Time: Model "+model_name+"

" + + header = (/"" \ + ,"" \ + ,"CLAMP metrics" \ + ,"" \ + ,header_text \ + /) + footer = "" + + table_header = (/ \ + "" \ + ,"" \ + ," " \ + ," " \ + ," " \ + ," " \ + ,"" \ + /) + table_footer = "
Biome Class"+col_head(0)+""+col_head(1)+""+col_head(2)+"
" + row_header = "" + row_footer = "" + + lines = new(50000,string) + nline = 0 + + set_line(lines,nline,header) + set_line(lines,nline,table_header) +;----------------------------------------------- +;row of table + + do n = 0,nrow-1 + set_line(lines,nline,row_header) + + txt1 = row_head(n) + txt2 = text4(n,0) + txt3 = text4(n,1) + txt4 = text4(n,2) + + set_line(lines,nline,""+txt1+"") + set_line(lines,nline,""+txt2+"") + set_line(lines,nline,""+txt3+"") + set_line(lines,nline,""+txt4+"") + + set_line(lines,nline,row_footer) + end do +;----------------------------------------------- + set_line(lines,nline,table_footer) + set_line(lines,nline,footer) + +; Now write to an HTML file. + idx = ind(.not.ismissing(lines)) + if(.not.any(ismissing(idx))) then + asciiwrite(output_html,lines(idx)) + else + print ("error?") + end if + + delete (idx) +end do +end + diff -r 000000000000 -r 0c6405ab2ff4 turnover/note.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/turnover/note.1 Mon Jan 26 22:08:20 2009 -0500 @@ -0,0 +1,9 @@ +Just wanted to follow up on your turnover time +analysis for CLAMP. Forrest and I discussed the +problem with the CASA fluxes. It looks like all +the plant pools (leaf, wood, and fine root) and +coarse woody debris (cwd) and litter pools for +CASA need to be divided by 1200. The soil flux +and turnover time are fine and do not need to be adjusted. + +Jim Randerson \ No newline at end of file