Re: Height/Pressure versus time plot - interpolation

From: Helen Parish <hparish_at_nyahnyahspammersnyahnyah>
Date: Wed, 25 Feb 2009 02:42:20 -0800

Dear Adam,

Using gsn_csm_contour provided a quick and dirty solution to getting
something plotted. However, the way it is plotted makes the results
very hard to interpret. I really need to interpolate onto sensible
pressure/height levels to be able to understand what is going on.

The major problem is I cant work out how to do an interpolation of
multiple files simultaneously. The functions "addfiles" and
"addfiles_GetVar" in my script seem to nicely open all the files at
once, and select the same variables out of each file for further
processing. However, I also need to interpolate the results in all
the files onto the pressure height grid before the further processing.

I am not sure how to do this. I assume that a variable such as U will
interpolate differently onto the grid for each file. I am not sure if
the addfiles routine can be used in any way to do this ?. Or do I
need to interpolate each file one by one using a do loop ?. If I use
a do loop, how do I tell the script which file I am referring to in
the do loop ?.

Do I need to store the interpolated data in separate arrays for each
interpolated file ?. Do I store the interpolated data in a different
new file for each file I am interpolating, and then read in the new
files ?. (the interpolation routine I have used before for a single
file appears to store some output into a new separate file).

Does anyone know how to do this ?.

I enclose the lines I have used before to do interpolation of a
single file, followed by the script I am currently using.

Thanks,
Helen.

1) Here are the lines I have used before to interpolate a single file :

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
                                        ; input file
   diri = "./"
   fili = "zeusorigspongej.cam2.h0.0038-11-21-00000.nc"
   fi = addfile (diri+fili, "r")
                                        ; output file
   diro = "./"
   filo = "helen.nc"
   system ("/bin/rm -f "+diro+filo) ; remove any pre-exist file
   fo = addfile (diro+filo, "c")
                                        ; add any file attributes
   fo_at_title = fi_at_title + ": Selected Variables at pressure levels"
   fo_at_history = systemfunc ("date")
   fo_at_source = fi_at_source
   fo_at_case = fi_at_case
   fo_at_Conventions = fi_at_Conventions

   Var = (/ "T" , "Q", "U", "V"/) ; select variable to be
interpolated.
   nVar = dimsizes (Var)
                                        ; desired output levels

lev_p = (/ 91500., 90000., 87500., 80000., 67500., 50000., 30000.,
20000., 10000., 5000., 3000., 1500., 750., 390., 200., 100., 50.,25.,
14., 7., 3.5, 1.9, 0.95, 0.4, 0.1, 0.03 /)

   lev_p!0 = "lev_p" ; variable and dimension name
the same
   lev_p&lev_p = lev_p ; create coordinate variable
   lev_p_at_long_name = "pressure" ; attach some attributes
   lev_p_at_units = "hPa"
   lev_p_at_positive = "down"

   hyam = fi->hyam ; read hybrid info
   hybm = fi->hybm
   PS = fi->PS
   P0mb = 0.01*fi->P0

   do n=0,nVar-1 ; loop over the variables
      X = fi->$Var(n)$
      Xp = vinth2p (X, hyam, hybm, lev_p ,PS, 1, P0mb, 2, True)
      copy_VarAtts(X, Xp)
      fo->$Var(n)$ = Xp ; write to netCDF file
      print (Var(n)+": interpolated and written to netCDF")
   end do

end

2) Here is my current script, which processes multiple files :

;***********************
; timely.ncl
;***********************
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
;***********************
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

begin

; Keep all files open when have a lot of files :
   setfileoption("nc","SuppressClose",False)

   diri = "./"
; fili = systemfunc("cd "+diri+" ; ls zeusorigspongej*.cam2.h0*nc")
; fili = systemfunc("cd "+diri+" ; ls
zeusrand09125daily*.cam2.h0*nc")
   fili = systemfunc("cd "+diri+" ; ls rand09125*.cam2.h0*nc")

   f = addfiles (fili,"r")
   U = addfiles_GetVar(f,fili,"U")
   lat = addfiles_GetVar(f,fili,"lat")
   lon = addfiles_GetVar(f,fili,"lon")
   lev = addfiles_GetVar(f,fili,"lev")
   time = addfiles_GetVar(f,fili,"time")
   printVarSummary( U )

   dimu = dimsizes( U )
   ntim = dimu(0)
   klvl = dimu(1)
   nlon = dimu(2)
   mlon = dimu(3)

  uavg = dim_avg_Wrap(U)

  uavg_reverse = uavg(lev | :, time | :, lat | :)

;***********************
; Create Plot
;***********************
  wks = gsn_open_wks ("pdf", "presstimetest" ) ; open
workstation
   gsn_define_colormap(wks,"rainbow") ; choose colormap

   res = True
   res_at_cnFillOn = True
   res_at_lbLabelAutoStride = True
   res_at_gsnMaximize = True ; if [ps, eps, pdf] make large
   res_at_gsnSpreadColors = True ; span color map

   nl = 96

      res_at_gsnCenterString = "zeusorigspongej381121"
;; plot = gsn_csm_pres_hgt(wks, uavg(nt,:,:), res ) ; (lev,lat)
; plot = gsn_csm_pres_hgt(wks, uavg_reverse(:,:,nl), res ) ;
(time,lev,lat)
      plot = gsn_csm_contour(wks, uavg_reverse(:,:,nl), res ) ;
(time,lev,lat)

      res_at_trYReverse = True

end

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Feb 25 2009 - 03:42:20 MST

This archive was generated by hypermail 2.2.0 : Tue Mar 03 2009 - 09:53:57 MST