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