co2/24.lines.ncl
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
; add another model to plot
forrest@0
     3
; add panel plot to 22.lines.ncl
forrest@0
     4
; add zone plot to 21.lines.ncl
forrest@0
     5
; ***********************************************
forrest@0
     6
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
forrest@0
     7
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
forrest@0
     8
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
forrest@0
     9
;************************************************
forrest@0
    10
begin
forrest@0
    11
;************************************************
forrest@0
    12
; read in data: observed
forrest@0
    13
;************************************************
forrest@0
    14
 diri  = "/fis/cgd/cseg/people/jeff/clamp_data/co2/"
forrest@0
    15
 fili  = "co2_globalView_98.nc"
forrest@0
    16
 g     = addfile (diri+fili,"r")
forrest@0
    17
 val   = g->CO2_SEAS  
forrest@0
    18
 lon   = g->LON 
forrest@0
    19
 lat   = g->LAT
forrest@0
    20
 sta   = chartostring(g->STATION) 
forrest@0
    21
 delete (g)
forrest@0
    22
 
forrest@0
    23
;print (sta(0))
forrest@0
    24
forrest@0
    25
 ncase = dimsizes(lat)
forrest@0
    26
;print (ncase)
forrest@0
    27
forrest@0
    28
;**************************************************************
forrest@0
    29
; get only the lowest level at each station 
forrest@0
    30
;**************************************************************
forrest@0
    31
 lat_tmp = lat
forrest@0
    32
 lat_tmp@_FillValue = 1.e+36
forrest@0
    33
 
forrest@0
    34
 do n = 0,ncase-1
forrest@0
    35
    if (.not. ismissing(lat_tmp(n))) then 
forrest@0
    36
       indexes = ind(lat(n) .eq. lat .and. lon(n) .eq. lon)
forrest@0
    37
       if (dimsizes(indexes) .gt. 1) then
forrest@0
    38
          lat_tmp(indexes(1:)) = lat_tmp@_FillValue
forrest@0
    39
       end if
forrest@0
    40
       delete (indexes)
forrest@0
    41
    end if
forrest@0
    42
 end do
forrest@0
    43
forrest@0
    44
 indexes = ind(.not. ismissing(lat_tmp))
forrest@0
    45
;print (dimsizes(indexes))
forrest@0
    46
;print (indexes)
forrest@0
    47
 
forrest@0
    48
 lat_ob = lat(indexes)
forrest@0
    49
 lon_ob = lon(indexes)
forrest@0
    50
 val_ob = val(indexes,:)
forrest@0
    51
;printVarSummary (val_ob)
forrest@0
    52
;print (lat_ob +"/"+lon_ob)
forrest@0
    53
forrest@0
    54
;************************************************
forrest@0
    55
; read in model data
forrest@0
    56
;************************************************
forrest@0
    57
  diri2 = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
    58
  fili2 = "b30.061n_1995-2004_MONS_climo_atm.nc"
forrest@0
    59
  fili3 = "b30.061m_401_425_MONS_climo_atm.nc"
forrest@0
    60
;--------------------------------------------
forrest@0
    61
  g    = addfile(diri2+fili2,"r")
forrest@0
    62
  x1   = g->CO2
forrest@0
    63
  xi   = g->lon
forrest@0
    64
  yi   = g->lat
forrest@0
    65
  delete (g)
forrest@0
    66
forrest@0
    67
  xdim  = dimsizes(x1)
forrest@0
    68
  nlev  = xdim(1)
forrest@0
    69
  y1     = x1(:,0,:,:)
forrest@0
    70
; printVarSummary (y1)
forrest@0
    71
  
forrest@0
    72
; get the co2 at the lowest level
forrest@0
    73
  y1     = x1(:,nlev-1,:,:)
forrest@0
    74
  delete (x1)
forrest@0
    75
;---------------------------------------------
forrest@0
    76
  g     = addfile(diri2+fili3,"r")
forrest@0
    77
  x2    = g->CO2
forrest@0
    78
  delete (g)
forrest@0
    79
  y2     = x2(:,0,:,:)
forrest@0
    80
  y2     = x2(:,nlev-1,:,:)
forrest@0
    81
  delete (x2)
forrest@0
    82
;---------------------------------------------
forrest@0
    83
; change to unit of observed (u mol/mol)
forrest@0
    84
; Model_units [=] kgCO2 / kgDryAir
forrest@0
    85
; 28.966 = molecular weight of dry air
forrest@0
    86
; 44.       = molecular weight of CO2
forrest@0
    87
; u mol = 1e-6 mol
forrest@0
    88
forrest@0
    89
  factor = (28.966/44.) * 1e6
forrest@0
    90
;---------------------------------------------
forrest@0
    91
  y1 = y1 * factor
forrest@0
    92
  y1@_FillValue = 1.e36
forrest@0
    93
  y1@units      = "u mol/mol"
forrest@0
    94
; y1 = where(y0 .lt. 287.,1y@_FillValue,y1)
forrest@0
    95
; printVarSummary (y1)
forrest@0
    96
; print (min(y1)+"/"+max(y1))
forrest@0
    97
;---------------------------------------------
forrest@0
    98
  y2 = y2 * factor
forrest@0
    99
  y2@_FillValue = 1.e36
forrest@0
   100
  y2@units      = "u mol/mol"
forrest@0
   101
;---------------------------------------------
forrest@0
   102
; interpolate into observed station
forrest@0
   103
; note: model is 0-360E,   90S-90N
forrest@0
   104
;       ob    is -180-180, 90S-90N
forrest@0
   105
forrest@0
   106
; to be able to handle observation at (-89.98,-24.80)
forrest@0
   107
  print (yi(0))
forrest@0
   108
  yi(0) = -90.
forrest@0
   109
forrest@0
   110
  i = ind(lon_ob .lt. 0.)
forrest@0
   111
  lon_ob(i) = lon_ob(i) + 360.  
forrest@0
   112
;----------------------------------------------------------------
forrest@0
   113
  yo = linint2_points_Wrap(xi,yi,y1,True,lon_ob,lat_ob,0)
forrest@0
   114
forrest@0
   115
  val_model1 = yo(pts|:,time|:)
forrest@0
   116
  val_model1_0 = val_model1
forrest@0
   117
; printVarSummary (val_model1)
forrest@0
   118
; print (min(val_model1)+"/"+max(val_model1))
forrest@0
   119
forrest@0
   120
; remove annual mean
forrest@0
   121
  val_model1 = val_model1 - conform(val_model1,dim_avg(val_model1),0)
forrest@0
   122
; print (min(val_model1)+"/"+max(val_model1))
forrest@0
   123
  delete (yo)
forrest@0
   124
;-----------------------------------------------------------------
forrest@0
   125
  yo = linint2_points_Wrap(xi,yi,y2,True,lon_ob,lat_ob,0)
forrest@0
   126
forrest@0
   127
  val_model2 = yo(pts|:,time|:)
forrest@0
   128
  val_model2_0 = val_model2
forrest@0
   129
; printVarSummary (val_model2)
forrest@0
   130
; print (min(val_model2)+"/"+max(val_model2))
forrest@0
   131
forrest@0
   132
; remove annual mean
forrest@0
   133
  val_model2 = val_model2 - conform(val_model2,dim_avg(val_model2),0)
forrest@0
   134
; print (min(val_model2)+"/"+max(val_model2))
forrest@0
   135
  delete (yo)
forrest@0
   136
;-----------------------------------------------------------------
forrest@0
   137
; for x-axis in xyplot
forrest@0
   138
  mon = ispan(1,12,1)
forrest@0
   139
  mon@long_name = "month"
forrest@0
   140
;-----------------------------------------------------------------
forrest@0
   141
  plot_type = "ps"
forrest@0
   142
  plot_type_new = "png"
forrest@0
   143
forrest@0
   144
  res                   = True                      ; plot mods desired
forrest@0
   145
  res@xyLineThicknesses = (/2.0,2.0,2.0/)           ; make 2nd lines thicker
forrest@0
   146
  res@xyLineColors      = (/"red","blue","black"/)  ; change line color
forrest@0
   147
;------------------------------------------------------------------
forrest@0
   148
; Add a boxed legend using the more simple method
forrest@0
   149
forrest@0
   150
  res@pmLegendDisplayMode    = "Always"
forrest@0
   151
; res@pmLegendWidthF         = 0.1
forrest@0
   152
  res@pmLegendWidthF         = 0.08
forrest@0
   153
  res@pmLegendHeightF        = 0.06
forrest@0
   154
; res@pmLegendOrthogonalPosF = -1.17
forrest@0
   155
; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
forrest@0
   156
  res@pmLegendOrthogonalPosF = -0.30  ;(downward)
forrest@0
   157
forrest@0
   158
; res@pmLegendParallelPosF   =  0.18
forrest@0
   159
  res@pmLegendParallelPosF   =  0.23  ;(rightward)
forrest@0
   160
forrest@0
   161
; res@lgPerimOn             = False
forrest@0
   162
  res@lgLabelFontHeightF     = 0.015
forrest@0
   163
  res@xyExplicitLegendLabels = (/"b30.061n","b30.061m","observed"/)
forrest@0
   164
;-------------------------------------------------------------------
forrest@0
   165
forrest@0
   166
  nzone = 4
forrest@0
   167
  do z = 0,nzone-1
forrest@0
   168
forrest@0
   169
  if (z .eq. 0) then 
forrest@0
   170
;    maximum score for the zone, 60N-90N 
forrest@0
   171
     score_max = 5.0
forrest@0
   172
     zone = "60N-90N"
forrest@0
   173
;    index of stations in this zone
forrest@0
   174
     ind_z = ind(lat_ob .ge. 60.)
forrest@0
   175
;    print (ind_z)
forrest@0
   176
;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
forrest@0
   177
;    print (val_ob(ind_z,:))
forrest@0
   178
;    print (val_model(ind_z,:))
forrest@0
   179
  end if
forrest@0
   180
forrest@0
   181
  if (z .eq. 1) then 
forrest@0
   182
;    maximum score for the zone, 30N-60N 
forrest@0
   183
     score_max = 5.0
forrest@0
   184
     zone = "30N-60N"
forrest@0
   185
;    index of stations in this zone
forrest@0
   186
     ind_z = ind(lat_ob .ge. 30. .and. lat_ob .lt. 60.)
forrest@0
   187
;    print (ind_z)
forrest@0
   188
;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
forrest@0
   189
;    print (val_ob(ind_z,:))
forrest@0
   190
;    print (val_model(ind_z,:))
forrest@0
   191
  end if
forrest@0
   192
forrest@0
   193
  if (z .eq. 2) then 
forrest@0
   194
;    maximum score for the zone, EQ-30N 
forrest@0
   195
     score_max = 5.0
forrest@0
   196
     zone = "EQ-30N"
forrest@0
   197
;    index of stations in this zone
forrest@0
   198
     ind_z = ind(lat_ob .ge. 0. .and. lat_ob .lt. 30.)
forrest@0
   199
;    print (ind_z)
forrest@0
   200
;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
forrest@0
   201
;    print (val_ob(ind_z,:))
forrest@0
   202
;    print (val_model(ind_z,:))
forrest@0
   203
  end if
forrest@0
   204
forrest@0
   205
  if (z .eq. 3) then 
forrest@0
   206
;    maximum score for the zone, 90S-EQ 
forrest@0
   207
     score_max = 5.0
forrest@0
   208
     zone = "90S-EQ"     
forrest@0
   209
;    index of stations in this zone
forrest@0
   210
     ind_z = ind(lat_ob .lt. 0. )
forrest@0
   211
;    print (ind_z)
forrest@0
   212
;    print (lat_ob(ind_z)+"/"+lon_ob(ind_z))
forrest@0
   213
;    print (val_ob(ind_z,:))
forrest@0
   214
;    print (val_model(ind_z,:))
forrest@0
   215
  end if
forrest@0
   216
forrest@0
   217
  npts = dimsizes(ind_z)
forrest@0
   218
  print (npts)
forrest@0
   219
forrest@0
   220
  npts_str = ""
forrest@0
   221
  npts_str = npts
forrest@0
   222
; print (npts_str)
forrest@0
   223
forrest@0
   224
  plot_data   = new((/3,12,npts/),float)
forrest@0
   225
  plot_data_0 = new((/2,12,npts/),float)
forrest@0
   226
forrest@0
   227
  plot_data!0 = "case"
forrest@0
   228
  plot_data!1 = "month"
forrest@0
   229
  plot_data!2 = "pts"
forrest@0
   230
  plot_data@long_name   = "CO2 Seasonal"
forrest@0
   231
forrest@0
   232
  plot_data_0!0 = "month"
forrest@0
   233
  plot_data_0!1 = "pts"
forrest@0
   234
  plot_data_0@long_name = "CO2"
forrest@0
   235
forrest@0
   236
  do n=0,npts-1
forrest@0
   237
forrest@0
   238
    plot_data(0,:,n) = (/val_model1(ind_z(n),:)/)
forrest@0
   239
    plot_data(1,:,n) = (/val_model2(ind_z(n),:)/)
forrest@0
   240
    plot_data(2,:,n) = (/val_ob(ind_z(n),:)/)
forrest@0
   241
forrest@0
   242
    plot_data_0(0,:,n) = (/val_model1_0(ind_z(n),:)/)
forrest@0
   243
    plot_data_0(1,:,n) = (/val_model2_0(ind_z(n),:)/)
forrest@0
   244
forrest@0
   245
;*****************************************************
forrest@0
   246
; create plot with 3 lines for each observed station
forrest@0
   247
;*****************************************************   
forrest@0
   248
    plot_name = sta(ind_z(n))    
forrest@0
   249
    title = plot_name+"("+lat(ind_z(n))+","+lon(ind_z(n))+")"
forrest@0
   250
;   print (title)
forrest@0
   251
;   print (plot_name)
forrest@0
   252
forrest@0
   253
    wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
forrest@0
   254
;---------------------------------------------------------------------------
forrest@0
   255
;   for panel plot
forrest@0
   256
   
forrest@0
   257
    plot=new(2,graphic)                        ; create graphic array
forrest@0
   258
    res@gsnFrame     = False                   ; Do not draw plot 
forrest@0
   259
    res@gsnDraw      = False                   ; Do not advance frame
forrest@0
   260
forrest@0
   261
    pres                            = True     ; panel plot mods desired
forrest@0
   262
    pres@gsnPanelYWhiteSpacePercent = 5        ; increase white space around
forrest@0
   263
                                               ; indiv. plots in panel
forrest@0
   264
    pres@gsnMaximize                = True     ; fill the page
forrest@0
   265
;---------------------------------------------------------------------------
forrest@0
   266
    res@tiMainString = title                           ; add title
forrest@0
   267
forrest@0
   268
    plot(0)=gsn_csm_xy(wks,mon,plot_data(:,:,n),res)   ; create plot 1
forrest@0
   269
forrest@0
   270
;   plot(1)=gsn_csm_xy(wks,mon,plot_data_0(:,:,n),res) ; create plot 2
forrest@0
   271
    plot(1)=gsn_csm_xy(wks,mon,plot_data_0(0,:,n),res) ; create plot 2
forrest@0
   272
forrest@0
   273
    gsn_panel(wks,plot,(/2,1/),pres)                 ; create panel plot
forrest@0
   274
forrest@0
   275
    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   276
    system("rm "+plot_name+"."+plot_type)
forrest@0
   277
    clear (wks)
forrest@0
   278
 end do
forrest@0
   279
;*****************************************************************************    
forrest@0
   280
; plot zone average
forrest@0
   281
;*****************************************************************************  
forrest@0
   282
    plot_name = "All_"+npts_str
forrest@0
   283
    title = plot_name + " in "+ zone
forrest@0
   284
;   print (title)
forrest@0
   285
;   print (plot_name)
forrest@0
   286
forrest@0
   287
    wks = gsn_open_wks (plot_type,plot_name)        ; open workstation
forrest@0
   288
;---------------------------------------------------------------------------
forrest@0
   289
;   for panel plot
forrest@0
   290
   
forrest@0
   291
    plot=new(2,graphic)                        ; create graphic array
forrest@0
   292
    res@gsnFrame     = False                   ; Do not draw plot 
forrest@0
   293
    res@gsnDraw      = False                   ; Do not advance frame
forrest@0
   294
forrest@0
   295
    pres                            = True     ; panel plot mods desired
forrest@0
   296
    pres@gsnPanelYWhiteSpacePercent = 5        ; increase white space around
forrest@0
   297
                                               ; indiv. plots in panel
forrest@0
   298
    pres@gsnMaximize                = True     ; fill the page
forrest@0
   299
;---------------------------------------------------------------------------
forrest@0
   300
    res@tiMainString = title                                     ; add title
forrest@0
   301
forrest@0
   302
    plot(0) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data),res)   ; create plot 1
forrest@0
   303
    
forrest@0
   304
;   plot(1) = gsn_csm_xy (wks,mon,dim_avg_Wrap(plot_data_0),res) ; create plot 2
forrest@0
   305
forrest@0
   306
    xx = dim_avg_Wrap(plot_data_0)
forrest@0
   307
    plot(1) = gsn_csm_xy (wks,mon,xx(0,:),res) ; create plot 2
forrest@0
   308
forrest@0
   309
    gsn_panel(wks,plot,(/2,1/),pres)                 ; create panel plot
forrest@0
   310
forrest@0
   311
    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new)
forrest@0
   312
    system("rm "+plot_name+"."+plot_type)
forrest@0
   313
forrest@0
   314
    clear (wks)
forrest@0
   315
    delete (ind_z)
forrest@0
   316
    delete (plot_data)
forrest@0
   317
    delete (plot_data_0)    
forrest@0
   318
 end do
forrest@0
   319
end