co2/19.metric_plot.ncl
author Forrest Hoffman <forrest@climatemodeling.org>
Mon, 26 Jan 2009 22:08:20 -0500
changeset 0 0c6405ab2ff4
permissions -rw-r--r--
Initial commit of C-LAMP Diagnostics from Jeff Lee
forrest@0
     1
; ***********************************************
forrest@0
     2
; xy_4.ncl
forrest@0
     3
; ***********************************************
forrest@0
     4
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
forrest@0
     5
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
forrest@0
     6
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
forrest@0
     7
load "/fis/cgd/cseg/people/jeff/clamp/co2/metrics_table.ncl"
forrest@0
     8
;************************************************
forrest@0
     9
begin
forrest@0
    10
;************************************************
forrest@0
    11
; read in data: observed
forrest@0
    12
;************************************************
forrest@0
    13
 diri  = "/fis/cgd/cseg/people/jeff/clamp_data/co2/"
forrest@0
    14
 fili  = "co2_globalView_98.nc"
forrest@0
    15
 g     = addfile (diri+fili,"r")
forrest@0
    16
 val   = g->CO2_SEAS  
forrest@0
    17
 lon   = g->LON 
forrest@0
    18
 lat   = g->LAT
forrest@0
    19
 sta   = chartostring(g->STATION) 
forrest@0
    20
 delete (g)
forrest@0
    21
 
forrest@0
    22
;print (sta(0))
forrest@0
    23
forrest@0
    24
 ncase = dimsizes(lat)
forrest@0
    25
;print (ncase)
forrest@0
    26
forrest@0
    27
;**************************************************************
forrest@0
    28
; get only the lowest level at each station 
forrest@0
    29
;**************************************************************
forrest@0
    30
 lat_tmp = lat
forrest@0
    31
 lat_tmp@_FillValue = 1.e+36
forrest@0
    32
 
forrest@0
    33
 do n = 0,ncase-1
forrest@0
    34
    if (.not. ismissing(lat_tmp(n))) then 
forrest@0
    35
       indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon)
forrest@0
    36
       if (dimsizes(indexes) .gt. 1) then
forrest@0
    37
          lat_tmp(indexes(1:)) = lat_tmp@_FillValue
forrest@0
    38
       end if
forrest@0
    39
       delete (indexes)
forrest@0
    40
    end if
forrest@0
    41
 end do
forrest@0
    42
forrest@0
    43
 indexes = ind(.not. ismissing(lat_tmp))
forrest@0
    44
;print (dimsizes(indexes))
forrest@0
    45
;print (indexes)
forrest@0
    46
 
forrest@0
    47
 lat_ob = lat(indexes)
forrest@0
    48
 lon_ob = lon(indexes)
forrest@0
    49
 val_ob = val(indexes,:)
forrest@0
    50
;printVarSummary (val_ob)
forrest@0
    51
;print (lat_ob +"/"+lon_ob)
forrest@0
    52
forrest@0
    53
;************************************************
forrest@0
    54
; read in model data
forrest@0
    55
;************************************************
forrest@0
    56
  diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
    57
; fili2 = "b30.061m_401_425_MONS_climo_atm.nc"
forrest@0
    58
  fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc"
forrest@0
    59
forrest@0
    60
  g     = addfile(diri2+fili2,"r")
forrest@0
    61
  x     = g->CO2
forrest@0
    62
  xi    = g->lon
forrest@0
    63
  yi    = g->lat
forrest@0
    64
  xdim  = dimsizes(x)
forrest@0
    65
  nlev  = xdim(1)
forrest@0
    66
  y     = x(:,0,:,:)
forrest@0
    67
; printVarSummary (y)
forrest@0
    68
  
forrest@0
    69
; get the co2 at the lowest level
forrest@0
    70
  y     = x(:,nlev-1,:,:)
forrest@0
    71
forrest@0
    72
; change to unit of observed (u mol/mol)
forrest@0
    73
; Model_units [=] kgCO2 / kgDryAir
forrest@0
    74
; 28.966 = molecular weight of dry air
forrest@0
    75
; 44.       = molecular weight of CO2
forrest@0
    76
; u mol = 1e-6 mol
forrest@0
    77
forrest@0
    78
  factor = (28.966/44.) * 1e6
forrest@0
    79
  y      = y * factor
forrest@0
    80
forrest@0
    81
  y@_FillValue = 1.e36
forrest@0
    82
  y@units      = "u mol/mol"
forrest@0
    83
; y = where(y0 .lt. 287.,y@_FillValue,y)
forrest@0
    84
; printVarSummary (y)
forrest@0
    85
; print (min(y)+"/"+max(y))
forrest@0
    86
forrest@0
    87
; interpolate into observed station
forrest@0
    88
; note: model is 0-360E, 90S-90N
forrest@0
    89
forrest@0
    90
; to be able to handle observation at (-89.98,-24.80)
forrest@0
    91
  print (yi(0))
forrest@0
    92
  yi(0) = -90.
forrest@0
    93
forrest@0
    94
  i = ind(lon_ob .lt. 0.)
forrest@0
    95
  lon_ob(i) = lon_ob(i) + 360.  
forrest@0
    96
forrest@0
    97
  yo = linint2_points_Wrap(xi,yi,y,True,lon_ob,lat_ob,0)
forrest@0
    98
forrest@0
    99
  val_model = yo(pts|:,time|:)
forrest@0
   100
; printVarSummary (val_model)
forrest@0
   101
; print (min(val_model)+"/"+max(val_model))
forrest@0
   102
forrest@0
   103
; remove annual mean
forrest@0
   104
  val_model = val_model - conform(val_model,dim_avg(val_model),0)
forrest@0
   105
; print (min(val_model)+"/"+max(val_model))
forrest@0
   106
forrest@0
   107
  nzone = 4
forrest@0
   108
forrest@0
   109
; column
forrest@0
   110
  case_zone = (/"Stations","Amplitude Ratio", \
forrest@0
   111
                "Correlation Coef","M score","Combined Score"/)
forrest@0
   112
  nCase_zone = dimsizes(case_zone ) 
forrest@0
   113
forrest@0
   114
; row
forrest@0
   115
  var_zone = (/"60N-90N","30N-60N","EQ-30N","90S-EQ","Total"/)  
forrest@0
   116
  nVar_zone = dimsizes(var_zone)                  
forrest@0
   117
forrest@0
   118
; arrays to be passed to diagram. 
forrest@0
   119
  case_value_zone = new ((/nCase_zone, nVar_zone/),float )  
forrest@0
   120
forrest@0
   121
  do z = 0,nzone-1
forrest@0
   122
forrest@0
   123
  if (z .eq. 0) then 
forrest@0
   124
;    maximum score for the zone, 60N-90N
forrest@0
   125
     zone = "60N-90N" 
forrest@0
   126
     score_max = 5.0
forrest@0
   127
;    index of stations in this zone
forrest@0
   128
     ind_z = ind(lat_ob .ge. 60.)
forrest@0
   129
;    print (ind_z)
forrest@0
   130
;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
forrest@0
   131
;    print (val_ob(ind_z,:))
forrest@0
   132
;    print (val_model(ind_z,:))
forrest@0
   133
  end if
forrest@0
   134
forrest@0
   135
  if (z .eq. 1) then 
forrest@0
   136
;    maximum score for the zone, 30N-60N
forrest@0
   137
     zone = "30N-60N" 
forrest@0
   138
     score_max = 5.0
forrest@0
   139
;    index of stations in this zone
forrest@0
   140
     ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.)
forrest@0
   141
;    print (ind_z)
forrest@0
   142
;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
forrest@0
   143
;    print (val_ob(ind_z,:))
forrest@0
   144
;    print (val_model(ind_z,:))
forrest@0
   145
  end if
forrest@0
   146
forrest@0
   147
  if (z .eq. 2) then 
forrest@0
   148
;    maximum score for the zone, EQ-30N 
forrest@0
   149
     zone = "EQ-30N"
forrest@0
   150
     score_max = 5.0
forrest@0
   151
;    index of stations in this zone
forrest@0
   152
     ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.)
forrest@0
   153
;    print (ind_z)
forrest@0
   154
;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
forrest@0
   155
;    print (val_ob(ind_z,:))
forrest@0
   156
;    print (val_model(ind_z,:))
forrest@0
   157
  end if
forrest@0
   158
forrest@0
   159
  if (z .eq. 3) then 
forrest@0
   160
;    maximum score for the zone, 90S-EQ
forrest@0
   161
     zone = "90S-EQ" 
forrest@0
   162
     score_max = 5.0
forrest@0
   163
;    index of stations in this zone
forrest@0
   164
     ind_z = ind(lat_ob .lt. 0. )
forrest@0
   165
;    print (ind_z)
forrest@0
   166
;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
forrest@0
   167
;    print (val_ob(ind_z,:))
forrest@0
   168
;    print (val_model(ind_z,:))
forrest@0
   169
  end if
forrest@0
   170
forrest@0
   171
 npts = dimsizes(ind_z)
forrest@0
   172
 print (npts)
forrest@0
   173
forrest@0
   174
 amp_ob        = new((/npts/),float)
forrest@0
   175
 amp_model     = new((/npts/),float)
forrest@0
   176
forrest@0
   177
 amp_ratio_sta = new((/npts/),float)
forrest@0
   178
 ccr_sta       = new((/npts/),float)
forrest@0
   179
 M_sta         = new((/npts/),float)
forrest@0
   180
 score_sta     = new((/npts/),float)
forrest@0
   181
forrest@0
   182
 do n=0,npts-1
forrest@0
   183
    amp_ob(n)    = max(val_ob(ind_z(n),:)) - min(val_ob(ind_z(n),:)) 
forrest@0
   184
    amp_model(n) = max(val_model(ind_z(n),:)) - min(val_model(ind_z(n),:))
forrest@0
   185
forrest@0
   186
    amp_ratio_sta(n) = amp_model(n)/amp_ob(n)
forrest@0
   187
    ccr_sta(n) = esccr(val_ob(ind_z(n),:),val_model(ind_z(n),:),0)
forrest@0
   188
    M_sta(n) = 1.-abs(amp_ratio_sta(n)-1.)
forrest@0
   189
    score_sta(n) = (ccr_sta(n)*ccr_sta(n) + M_sta(n))*0.5 * score_max
forrest@0
   190
forrest@0
   191
    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))  
forrest@0
   192
 end do
forrest@0
   193
forrest@0
   194
 amp_ratio_zone = avg(amp_ratio_sta)
forrest@0
   195
 ccr_zone       = avg(ccr_sta)
forrest@0
   196
 M_zone   = 1.- (sum(abs(amp_model-amp_ob)/(amp_model+amp_ob))/npts) 
forrest@0
   197
 score_zone   = (ccr_zone*ccr_zone + M_zone)*0.5 * score_max
forrest@0
   198
forrest@0
   199
 print (npts+"/"+amp_ratio_zone+"/"+ccr_zone+"/"+M_zone+"/"+score_zone)
forrest@0
   200
forrest@0
   201
  case_value_zone(0,z) = npts
forrest@0
   202
  case_value_zone(1,z) = (/amp_ratio_zone/)
forrest@0
   203
  case_value_zone(2,z) = (/ccr_zone/)
forrest@0
   204
  case_value_zone(3,z) = (/M_zone/)
forrest@0
   205
  case_value_zone(4,z) = (/score_zone/)  
forrest@0
   206
;**************************************************
forrest@0
   207
; plot station table
forrest@0
   208
;**************************************************
forrest@0
   209
; column for station table
forrest@0
   210
  case_sta   = (/"Latitude","Longitude","Amplitude Ratio", \
forrest@0
   211
                 "Correlation Coef","M score","Combined Score"/) 
forrest@0
   212
  nCase_sta  = dimsizes(case_sta )                 
forrest@0
   213
forrest@0
   214
; row for station table
forrest@0
   215
  var_sta  = sta(ind_z) 
forrest@0
   216
  nVar_sta = dimsizes(var_sta)                 
forrest@0
   217
forrest@0
   218
; arrays to be passed to diagram. 
forrest@0
   219
  case_value_sta = new ((/nCase_sta, nVar_sta/),float )  
forrest@0
   220
forrest@0
   221
  case_value_sta(0,:) = (/lat(ind_z)/)
forrest@0
   222
  case_value_sta(1,:) = (/lon(ind_z)/)
forrest@0
   223
  case_value_sta(2,:) = (/amp_ratio_sta/)
forrest@0
   224
  case_value_sta(3,:) = (/ccr_sta/)
forrest@0
   225
  case_value_sta(4,:) = (/M_sta/)
forrest@0
   226
  case_value_sta(5,:) = (/score_sta/)
forrest@0
   227
 
forrest@0
   228
;**************************************************
forrest@0
   229
; plot station table
forrest@0
   230
;**************************************************
forrest@0
   231
  tt_opt        = True
forrest@0
   232
  tt_opt@pltType= "png" ; "eps" [default], "pdf", "ps"
forrest@0
   233
                        ; "png", "gif" [if you have ImageMajik 'convert']
forrest@0
   234
forrest@0
   235
  tt_opt@tableTitle = "Zone "+ zone
forrest@0
   236
  plot_name         = "table_sta." + zone
forrest@0
   237
forrest@0
   238
  metrics_table(plot_name, var_sta, case_sta , case_value_sta, tt_opt)
forrest@0
   239
forrest@0
   240
 delete (ind_z)
forrest@0
   241
 delete (amp_model)
forrest@0
   242
 delete (amp_ob)
forrest@0
   243
 delete (amp_ratio_sta)
forrest@0
   244
 delete (ccr_sta)
forrest@0
   245
 delete (M_sta)
forrest@0
   246
 delete (score_sta)
forrest@0
   247
 delete (var_sta)
forrest@0
   248
 delete (case_value_sta)
forrest@0
   249
 end do
forrest@0
   250
;**************************************************
forrest@0
   251
; plot zone table
forrest@0
   252
;**************************************************
forrest@0
   253
  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) 
forrest@0
   254
  case_value_zone(1,4) = 0.
forrest@0
   255
  case_value_zone(2,4) = 0.
forrest@0
   256
  case_value_zone(3,4) = 0.
forrest@0
   257
  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) 
forrest@0
   258
  
forrest@0
   259
  tt_opt        = True
forrest@0
   260
  tt_opt@pltType= "png" ; "eps" [default], "pdf", "ps"
forrest@0
   261
                        ; "png", "gif" [if you have ImageMajik 'convert']
forrest@0
   262
forrest@0
   263
  tt_opt@tableTitle = "Zone"
forrest@0
   264
  plot_name         = "table_zone" 
forrest@0
   265
forrest@0
   266
  metrics_table(plot_name, var_zone, case_zone , case_value_zone, tt_opt)
forrest@0
   267
forrest@0
   268
end