energy/99.all.ncl.1
changeset 1 4be95183fbcd
equal deleted inserted replaced
-1:000000000000 0:deb9a13063ee
       
     1 ; ***********************************************
       
     2 ; using gsn_table for all
       
     3 ; output: line plot for each site (4 fields)
       
     4 ;         table for M_score
       
     5 ; ***********************************************
       
     6 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test"
       
     7 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test"
       
     8 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
       
     9 ;load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl"
       
    10 ;************************************************
       
    11 begin
       
    12 
       
    13   plot_type     = "ps"
       
    14   plot_type_new = "png"
       
    15 
       
    16 ;************************************************
       
    17 ; read model data
       
    18 ;************************************************
       
    19   model_name = "10cn"
       
    20   film = "i01.10cn_1948-2004_MONS_climo.nc"
       
    21 
       
    22 ; model_name = "10casa"
       
    23 ; film = "i01.10casa_1948-2004_MONS_climo.nc"
       
    24 
       
    25  system("sed s#model_name#"+model_name+"# table.html > table.html.new")
       
    26  system("mv -f table.html.new table.html")
       
    27 ;--------------------------------------------
       
    28   dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
       
    29   fm    = addfile(dirm+film,"r")
       
    30 
       
    31   xm    = fm->lon
       
    32   ym    = fm->lat
       
    33   nlat = dimsizes(ym)
       
    34   nlon = dimsizes(xm)
       
    35 
       
    36   nmon      = 12
       
    37   nfield    = 4
       
    38 
       
    39   data_mod0 = new ((/nfield,nmon,nlat,nlon/),float)
       
    40 
       
    41 ; change to unit of observed (u mol/m2/s)
       
    42 ; Model_units [=] gC/m2/s
       
    43 ; 12. = molecular weight of C
       
    44 ; u mol = 1e-6 mol 
       
    45   data = fm->NEE
       
    46 
       
    47   factor = 1e6 /12.
       
    48 
       
    49   data_mod0(0,:,:,:) = data(:,:,:) * factor
       
    50   delete (data)
       
    51 
       
    52   data = fm->NETRAD
       
    53   data_mod0(1,:,:,:) = data(:,:,:) 
       
    54   delete (data)
       
    55 
       
    56   data = fm->LATENT
       
    57   data_mod0(2,:,:,:) = data(:,:,:) 
       
    58   delete (data)
       
    59 
       
    60   data = fm->SENSIBLE
       
    61   data_mod0(3,:,:,:) = data(:,:,:) 
       
    62   delete (data)
       
    63 
       
    64 ; printVarSummary (data_mod0)
       
    65 ;************************************************
       
    66 ; read in data: observed
       
    67 ;************************************************
       
    68  station = (/"BOREAS_NSA_OBS" \
       
    69             ,"CastelPorziano" \
       
    70             ,"Hyytiala" \
       
    71             ,"Kaamanen" \
       
    72             ,"LBA_Tapajos_KM67" \
       
    73             ,"Lethbridge" \
       
    74             ,"Tharandt" \
       
    75             ,"Vielsalm" \
       
    76             /)
       
    77 
       
    78  year_ob = (/"1994-2004" \
       
    79             ,"1997-2003" \
       
    80             ,"1996-2003" \
       
    81             ,"2000-2003" \
       
    82             ,"2002-2005" \
       
    83             ,"1999-2004" \
       
    84             ,"1996-2003" \
       
    85             ,"1998-2003" \
       
    86             /)
       
    87 
       
    88  field   = (/"CO2 Flux" \
       
    89             ,"Net Radiation" \
       
    90             ,"Latent Heat" \
       
    91             ,"Sensible Heat" \
       
    92             /)
       
    93 
       
    94  nstation  = dimsizes(station)
       
    95  nmon      = 12
       
    96  nfield    = dimsizes(field)
       
    97 
       
    98  data_ob   = new ((/nstation, nfield, nmon/),float)
       
    99  lat_ob    = new ((/nstation/),float)
       
   100  lon_ob    = new ((/nstation/),float)
       
   101 
       
   102  diri_root  = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/"
       
   103 
       
   104  do n = 0,nstation-1
       
   105     diri = diri_root + station(n)+"/"
       
   106     fili = station(n)+"_"+year_ob(n)+"_monthly.nc"
       
   107     g     = addfile (diri+fili,"r")
       
   108  
       
   109     lon_ob(n) = g->lon 
       
   110     lat_ob(n) = g->lat
       
   111 
       
   112     data      = g->CO2_FLUX
       
   113     data_ob(n,0,:) = dim_avg(data(month|:,year|:))
       
   114     delete (data)
       
   115 
       
   116     data      = g->RAD_FLUX
       
   117     data_ob(n,1,:) = dim_avg(data(month|:,year|:))
       
   118     delete (data)
       
   119 
       
   120     data      = g->LH_FLUX
       
   121     data_ob(n,2,:) = dim_avg(data(month|:,year|:))
       
   122     delete (data)
       
   123 
       
   124     data      = g->SH_FLUX
       
   125     data_ob(n,3,:) = dim_avg(data(month|:,year|:))
       
   126     delete (data)
       
   127 
       
   128     delete (g)
       
   129  end do
       
   130  
       
   131 ;print (lat_ob)
       
   132 ;print (lon_ob)
       
   133 ;printVarSummary (data_ob)
       
   134 
       
   135 ;************************************************************
       
   136 ; interpolate model data into observed station
       
   137 ; note: model is 0-360E, 90S-90N
       
   138 ;************************************************************
       
   139 
       
   140 ; to be able to handle observation at (-89.98,-24.80)
       
   141 ; print (ym(0))
       
   142   ym(0) = -90.  
       
   143 
       
   144   yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0)
       
   145 
       
   146   delete (data_mod0)
       
   147   yy!0 = "field"
       
   148   data_mod = yy(pts|:,field|:,time|:)
       
   149 ; printVarSummary (data_mod)
       
   150 
       
   151 ;************************************************************
       
   152 ; compute correlation coef and M score
       
   153 ;************************************************************
       
   154 
       
   155  score_max = 5.
       
   156 
       
   157  ccr     = new ((/nstation, nfield/),float)
       
   158  M_score = new ((/nstation, nfield/),float) 
       
   159 
       
   160  do n=0,nstation-1
       
   161  do m=0,nfield-1   
       
   162     ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
       
   163     bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
       
   164     M_score(n,m) = (1. -(bias/nmon)) * score_max
       
   165  end do
       
   166  end do
       
   167 
       
   168 ;*******************************************************************
       
   169 ; for station line plot
       
   170 ;*******************************************************************
       
   171 
       
   172 ; for x-axis in xyplot
       
   173   mon = ispan(1,12,1)
       
   174   mon@long_name = "month"
       
   175 
       
   176   res                   = True               ; plot mods desired
       
   177   res@xyLineThicknesses = (/2.0,2.0/)        ; make 2nd lines thicker
       
   178   res@xyLineColors      = (/"blue","red"/)   ; line color (ob,model)
       
   179 ;-------------------------------------------------------------------------
       
   180 ; Add a boxed legend using the more simple method
       
   181 
       
   182   res@pmLegendDisplayMode    = "Always"
       
   183 ; res@pmLegendWidthF         = 0.1
       
   184   res@pmLegendWidthF         = 0.08
       
   185   res@pmLegendHeightF        = 0.06
       
   186 ; res@pmLegendOrthogonalPosF = -1.17
       
   187 ; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
       
   188   res@pmLegendOrthogonalPosF = -0.30  ;(downward)
       
   189 
       
   190 ; res@pmLegendParallelPosF   =  0.18
       
   191   res@pmLegendParallelPosF   =  0.23  ;(rightward)
       
   192 
       
   193 ; res@lgPerimOn             = False
       
   194   res@lgLabelFontHeightF     = 0.015
       
   195   res@xyExplicitLegendLabels = (/"observed",model_name/)
       
   196 ;-------------------------------------------------------------------
       
   197 ; for panel plot
       
   198   res@gsnFrame     = False                   ; Do not draw plot 
       
   199   res@gsnDraw      = False                   ; Do not advance frame
       
   200 
       
   201   pres                            = True     ; panel plot mods desired
       
   202   pres@gsnPanelYWhiteSpacePercent = 5        ; increase white space around
       
   203                                              ; indiv. plots in panel
       
   204   pres@gsnMaximize                = True     ; fill the page
       
   205 ;-------------------------------------------------------------------
       
   206 
       
   207   plot_data   = new((/2,12/),float)
       
   208   plot_data!0 = "case"
       
   209   plot_data!1 = "month"
       
   210 
       
   211   do n = 0,nstation-1
       
   212 ;----------------------------
       
   213 ; for observed
       
   214 
       
   215     plot_name = station(n)+"_ob"    
       
   216     title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
       
   217     res@tiMainString = title
       
   218 
       
   219     wks = gsn_open_wks (plot_type,plot_name)
       
   220     plot=new(4,graphic)                        ; create graphic array   
       
   221                            
       
   222     plot_data(0,:) = (/data_ob (n,0,:)/)
       
   223     plot_data@long_name = field(0)   
       
   224     plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 1
       
   225 
       
   226     plot_data(0,:) = (/data_ob (n,1,:)/)
       
   227     plot_data@long_name = field(1)
       
   228     plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 2
       
   229 
       
   230     plot_data(0,:) = (/data_ob (n,2,:)/)
       
   231     plot_data@long_name = field(2)   
       
   232     plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 3
       
   233 
       
   234     plot_data(0,:) = (/data_ob (n,3,:)/)
       
   235     plot_data@long_name = field(3)
       
   236     plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 4
       
   237 
       
   238     gsn_panel(wks,plot,(/2,2/),pres)                 ; create panel plot
       
   239 
       
   240     system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
       
   241     system("rm "+plot_name+"."+plot_type)
       
   242     clear (wks)  
       
   243     delete (plot)
       
   244 ;----------------------------
       
   245 ; for model_vs_ob
       
   246 
       
   247     plot_name = station(n)+"_model_vs_ob"
       
   248     title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"    
       
   249     res@tiMainString = title
       
   250 
       
   251     wks = gsn_open_wks (plot_type,plot_name)
       
   252     plot=new(4,graphic)                        ; create graphic array   
       
   253                            
       
   254     plot_data(0,:) = (/data_ob (n,0,:)/)
       
   255     plot_data(1,:) = (/data_mod(n,0,:)/)
       
   256     plot_data@long_name = field(0)   
       
   257     plot(0)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 1
       
   258 
       
   259     plot_data(0,:) = (/data_ob (n,1,:)/)
       
   260     plot_data(1,:) = (/data_mod(n,1,:)/)
       
   261     plot_data@long_name = field(1)
       
   262     plot(1)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 2
       
   263 
       
   264     plot_data(0,:) = (/data_ob (n,2,:)/)
       
   265     plot_data(1,:) = (/data_mod(n,2,:)/)
       
   266     plot_data@long_name = field(2)   
       
   267     plot(2)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 3
       
   268 
       
   269     plot_data(0,:) = (/data_ob (n,3,:)/)
       
   270     plot_data(1,:) = (/data_mod(n,3,:)/)
       
   271     plot_data@long_name = field(3)
       
   272     plot(3)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 4
       
   273 
       
   274     gsn_panel(wks,plot,(/2,2/),pres)                 ; create panel plot
       
   275 
       
   276     system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
       
   277     system("rm "+plot_name+"."+plot_type)
       
   278     clear (wks)  
       
   279     delete (plot)
       
   280  end do
       
   281 
       
   282 ;*******************************************************************
       
   283 ; for table of site score
       
   284 ;*******************************************************************
       
   285 
       
   286   table_length = 0.8 
       
   287 
       
   288 ; table header name
       
   289   table_header_name = "Site" 
       
   290 
       
   291 ; column (not including header column)
       
   292   col_header = (/"Latitude","Longitude","observed" \
       
   293                 ,"CO2 Flux","Net Radiation","Latent Heat" \
       
   294                 ,"Sensible Heat","Average" \
       
   295                 /)
       
   296   ncol = dimsizes(col_header) 
       
   297 
       
   298 ; row (not including header row) 
       
   299   nrow       = nstation + 1
       
   300   row_header = new ((/nrow/),string )
       
   301   row_header(0:nstation-1) = station(:)
       
   302   row_header(nrow-1)       = "All Sites" 
       
   303 
       
   304 ; Table header
       
   305   ncr1  = (/1,1/)               ; 1 row, 1 column
       
   306   x1    = (/0.005,0.15/)        ; Start and end X
       
   307   y1    = (/0.800,0.895/)       ; Start and end Y
       
   308   text1 = table_header_name
       
   309   res1               = True
       
   310   res1@txFontHeightF = 0.03
       
   311   res1@gsFillColor   = "CornFlowerBlue"
       
   312 
       
   313 ; Column header (equally space in x2)
       
   314   ncr2  = (/1,ncol/)            ; 1 rows, ncol columns
       
   315   x2    = (/x1(1),0.995/)       ; start from end of x1
       
   316   y2    = y1                    ; same as y1
       
   317   text2 = col_header
       
   318   res2               = True
       
   319   res2@txFontHeightF = 0.010
       
   320   res2@gsFillColor   = "Gray"
       
   321 
       
   322 ; Row header (equally space in y2)
       
   323   ncr3  = (/nrow,1/)                 ; nrow rows, 1 columns
       
   324   x3    = x1                         ; same as x1
       
   325   y3    = (/1.0-table_length,y1(0)/) ; end at start of y1
       
   326   text3 = row_header
       
   327   res3               = True
       
   328   res3@txFontHeightF = 0.010
       
   329   res3@gsFillColor   = "Gray"
       
   330 
       
   331 ; Main table body
       
   332   ncr4  = (/nrow,ncol/)           ; nrow rows, ncol columns
       
   333   x4    = x2                      ; Start and end x
       
   334   y4    = y3                      ; Start and end Y
       
   335   text4 = new((/nrow,ncol/),string)
       
   336 
       
   337   color_fill4           = new((/nrow,ncol/),string)
       
   338   color_fill4           = "white"
       
   339   color_fill4(:,ncol-1) = "grey"
       
   340   color_fill4(nrow-1,:) = "green"
       
   341 
       
   342   res4               = True       ; Set up resource list
       
   343 ; res4@gsnDebug      = True       ; Useful to print NDC row,col values used.
       
   344   res4@txFontHeightF = 0.015
       
   345   res4@gsFillColor   = color_fill4
       
   346 
       
   347   delete (color_fill4)
       
   348 ;-------------------------------------------------------------------
       
   349 ; for table value
       
   350 
       
   351   do n = 0,nrow-2
       
   352      text4(n,0) = sprintf("%5.2f", lat_ob(n))  
       
   353      text4(n,1) = sprintf("%5.2f", lon_ob(n))  
       
   354      text4(n,2) = year_ob(n)  
       
   355      text4(n,3) = sprintf("%5.2f", M_score(n,0))      ; CO2 Flux
       
   356      text4(n,4) = sprintf("%5.2f", M_score(n,1))      ; Net Radiation
       
   357      text4(n,5) = sprintf("%5.2f", M_score(n,2))      ; Latent Heat
       
   358      text4(n,6) = sprintf("%5.2f", M_score(n,3))      ; Sensible Heat
       
   359      text4(n,7) = sprintf("%5.2f", avg(M_score(n,:))) ; avg all fields    
       
   360   end do
       
   361 
       
   362 ;    for the last row
       
   363 
       
   364      M_co2 = avg(M_score(:,0))
       
   365      M_rad = avg(M_score(:,1))
       
   366      M_lh  = avg(M_score(:,2))
       
   367      M_sh  = avg(M_score(:,3))
       
   368      M_all = M_co2+ M_rad +M_lh + M_sh
       
   369      
       
   370      text4(nrow-1,0) = "-"
       
   371      text4(nrow-1,1) = "-"
       
   372      text4(nrow-1,2) = "-"
       
   373      text4(nrow-1,3) = sprintf("%5.2f", M_co2) ; avg all sites
       
   374      text4(nrow-1,4) = sprintf("%5.2f", M_rad) ; avg all sites
       
   375      text4(nrow-1,5) = sprintf("%5.2f", M_lh ) ; avg all sites
       
   376      text4(nrow-1,6) = sprintf("%5.2f", M_sh ) ; avg all sites
       
   377      text4(nrow-1,7) = sprintf("%5.2f", M_all) ; avg all sites
       
   378 
       
   379      print (M_co2)
       
   380      print (M_rad)
       
   381      print (M_lh )
       
   382      print (M_sh)
       
   383      print (M_all)
       
   384 
       
   385   M_energy_co2 = sprintf("%.2f", M_co2)
       
   386   system("sed s#M_energy_co2#"+M_energy_co2+"# table.html > table.html.new")
       
   387   system("mv -f table.html.new table.html")
       
   388   print (M_energy_co2)
       
   389  
       
   390   M_energy_rad = sprintf("%.2f", M_rad)
       
   391   system("sed s#M_energy_rad#"+M_energy_rad+"# table.html > table.html.new")
       
   392   system("mv -f table.html.new table.html")
       
   393   print (M_energy_rad)
       
   394  
       
   395   M_energy_lh = sprintf("%.2f", M_lh)
       
   396   system("sed s#M_energy_lh#"+M_energy_lh+"# table.html > table.html.new")
       
   397   system("mv -f table.html.new table.html")
       
   398   print (M_energy_lh)
       
   399  
       
   400   M_energy_sh = sprintf("%.2f", M_sh)
       
   401   system("sed s#M_energy_sh#"+M_energy_sh+"# table.html > table.html.new")
       
   402   system("mv -f table.html.new table.html")
       
   403   print (M_energy_sh) 
       
   404 ;---------------------------------------------------------------------------
       
   405  
       
   406   plot_name = "table_site_score"
       
   407  
       
   408   wks = gsn_open_wks (plot_type,plot_name)
       
   409 ;------------------------------------------
       
   410 ; for table title
       
   411 
       
   412   gRes               = True
       
   413   gRes@txFontHeightF = 0.02
       
   414 ; gRes@txAngleF      = 90
       
   415 
       
   416   title_text = "Model  " + model_name +  "  M_Score"
       
   417 
       
   418   gsn_text_ndc(wks,title_text,0.50,0.95,gRes)
       
   419 ;------------------------------------------   
       
   420 
       
   421   gsn_table(wks,ncr1,x1,y1,text1,res1)
       
   422   gsn_table(wks,ncr2,x2,y2,text2,res2)
       
   423   gsn_table(wks,ncr3,x3,y3,text3,res3)
       
   424   gsn_table(wks,ncr4,x4,y4,text4,res4) 
       
   425 
       
   426   frame(wks)
       
   427 
       
   428   system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
       
   429   system("rm "+plot_name+"."+plot_type)
       
   430 ;-------------------------------------------------------------------
       
   431   temp_name = "energy." + model_name
       
   432   system("mkdir -p " + temp_name)
       
   433   system("cp table.html " + temp_name)
       
   434   system("mv *.png " + temp_name)
       
   435   system("tar cf "+ temp_name +".tar " + temp_name)
       
   436 ;------------------------------------------------------------------- 
       
   437 
       
   438 end