npp/ob/npp_0.05deg_to_T42.ncl
author Forrest Hoffman <forrest@climatemodeling.org>
Thu, 26 Mar 2009 14:31:28 -0400
changeset 2 e7ba9bcc3020
permissions -rw-r--r--
New model subsets and MODIS NPP for final C-LAMP paper in GCB.
     1 ; ***********************************************
     2 ; interpolate into model grids (T31)
     3 ; ***********************************************
     4 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
     5 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
     6 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
     7 ;************************************************
     8 begin
     9 ;************************************************
    10 ; output data
    11 ;************************************************
    12   diro  = ""
    13   filo  = "npp_T42_mean_2000-2004.nc"
    14   c = addfile(diro+filo,"c")
    15 
    16 ;************************************************
    17 ; read in observed data
    18 ;************************************************
    19   diri  = ""
    20   fili  = "npp_0.05deg_mean_2000-2004.nc"
    21   g     = addfile (diri+fili,"r")
    22   bi    = g->NPP   
    23   xi    = g->lon 
    24   yi    = g->lat
    25 
    26 ;************************************************
    27 ; change into 0-360E, 90S-90N
    28 ; Observed NPP*scale_factor
    29 ;************************************************
    30 
    31  ;scale_factor = 0.1
    32  ; FMH : Now the scaling occurs in the previous routine the writes out the mean
    33  ;       netCDF file, so don't scale again here.
    34  scale_factor = 1.
    35  
    36  yi    = (/ yi(::-1) /)
    37  bi    =  (/ bi(::-1,:) /)
    38  b2    = bi
    39  x2    = xi   
    40  
    41  nx = dimsizes(xi)
    42  do i= 0,nx-1
    43     if (i .lt. 3600) then
    44        p = i + 3600
    45        xi(p) = x2(i) + 360.      
    46     else
    47        p = i - 3600
    48        xi(p) = x2(i)
    49     end if
    50     bi(:,p)= b2(:,i) * scale_factor
    51  end do
    52 
    53  bi&lat =  yi
    54  bi&lon =  xi
    55 
    56 ;print (xi)
    57 ;print (yi)
    58 ;exit
    59 
    60 ;************************************************
    61 ; read in model data
    62 ;************************************************
    63 ;fili2  = "i01.04casa_1605-1629_ANN_climo.nc"
    64  diri   = "../../model/"
    65  fili2  = "i01.10cn_2000-2004_ANN_climo.nc"
    66  f     = addfile (diri+fili2,"r")
    67 
    68  lon    = f->lon     
    69  lat    = f->lat
    70  nlon   = dimsizes(lon)
    71  nlat   = dimsizes(lat)      
    72 
    73 ; print (xi)
    74 ; print (yi)
    75 ; print (xo)
    76 ; print (yo)
    77 
    78 ;(A)
    79 ;bo = linint2_Wrap(xi,yi,bi,True,xo,yo,0)
    80 
    81 ;(B)
    82 
    83   rad   = 4.*atan(1.)/180.
    84   clat  = lat
    85   clat  = cos(lat*rad)
    86   clat@long_name = "cos(latitude)"
    87   delete(clat@units)
    88   printVarSummary(clat)
    89 
    90  bo = new((/nlat,nlon/),float)
    91     do j=0,nlat-1
    92        if (j.eq.0 .or. j.eq.nlat-1) then
    93           if (j.eq.0) then
    94              LATS = -90.          
    95              LATN = lat(j)+0.5*(lat(j+1)-lat(j))
    96           end if
    97           if (j.eq.nlat-1) then
    98              LATS = lat(j)-0.5*(lat(j)-lat(j-1))
    99              LATN = 90.                  
   100           end if
   101        else
   102           LATS = lat(j)-0.5*(lat(j)-lat(j-1))
   103           LATN = lat(j)+0.5*(lat(j+1)-lat(j))
   104        end if
   105  
   106 ;      CLAT = clat({LATS:LATN})      ; do once for *slight* efficiency
   107 ;      TEMP = bi({LATS:LATN},:)      ; 2D [lat,lon]
   108  
   109       do i=0,nlon-1
   110        if (i.eq.0 .or. i.eq.nlon-1) then
   111           if (i.eq.0) then
   112              LONL = 0.          
   113              LONR = lon(i)+0.5*(lon(i+1)-lon(i))
   114           end if
   115           if (i.eq.nlon-1) then
   116              LONL = lon(i)-0.5*(lon(i)-lon(i-1))
   117              LONR = 360.                 
   118           end if
   119        else
   120           LONL = lon(i)-0.5*(lon(i)-lon(i-1))
   121           LONR = lon(i)+0.5*(lon(i+1)-lon(i))
   122        end if
   123 
   124 ;print (LATS)
   125 ;print (LATN)
   126 ;print (LONL)
   127 ;print (LONR)
   128          bo(j,i) = avg(bi({LATS:LATN},{LONL:LONR}))  
   129 ;        bo(j,i) = wgt_areaave(TEMP(:,{LONL:LONR}), CLAT, 1.0, 0)
   130       end do
   131  
   132 ;     delete(CLAT)
   133 ;     delete(TEMP) 
   134     end do
   135 
   136   bo!0   = "lat"
   137   bo!1   = "lon"
   138   bo&lat =  lat
   139   bo&lon =  lon
   140   bo@units      = bi@units
   141   bo@long_name  = bi@long_name
   142 ; bo@_FillValue = bi@_FillValue
   143   bo@_FillValue = 1.e+36
   144 
   145   c->NPP  = bo
   146 end