Re: Height/Pressure versus time plot - interpolation

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Wed, 25 Feb 2009 16:52:22 -0700

Hi Helen,
It's totally up to you on how you want to do it. Different people
post-process data in different ways. If you are going to use the
(interpolated to) pressure data in other scripts, then yes, you should
write out the data to .nc files.

The order I use depends on the size of the output files. I have no idea
what resolution you ran CAM in, or how many timesteps you have, as these
would affect things. You typically do not want to create .nc files >
2GB, or have files where individual variables > 2GB.

Keeping all of that in mind, here's a general way to post-process data:

1) Use the netCDF operator ncrcat to concatenate one variable from the
original monthly .nc files into a single file. For example, let's say
you want to concatenate the U variable from monthly netCDF files that
span from Jan 1950 - Dec 1959:
ncrcat -v U,PS,date,datesec gen.cam2.h0.195?-??.nc
U.gen.cam2.h0.195001-195912.nc

PS is used in the vinth2p interpolation scheme; it's good practice to
keep date/datesec.

2) Pass U.gen.cam2.h0.195001-195912.nc into a NCL script that
interpolates to your desired pressure levels, similar to the script that
you attached. Write out the new data to another .nc file. You will need
to read in P0, hyam, and hybm once from one of your original files
(files used to create file in 1) ), as they do not change with time.

3) Delete the file you created in 1.

4) If neccesary, use ncrcat to concatenate all the files created in 2)
(for one variable) to a single file. For instance, following what I did
in 1) and 2), do it for the 1960's, 1970's, etc. Then at this step
concatenate all the decadal files together.

The end result is a file that contains one variable, all timesteps (or
some, depending on size). Repeat the process for each variable you are
interested in. You can incorporate all of the above steps into one NCL
program, with a large do loop that loops over each of the variables that
you are interested in.

Once complete, you will not need to use the original monthly .nc files
that CAM created. You could simply refer to your newly created pressure
level files that contain one variable per file all timesteps.

Hopefully, this gets you on the right track..
Good luck,
Adam

Helen Parish wrote:
> 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

-- 
--------------------------------------------------------------
Adam Phillips			             asphilli_at_ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
ESSL/CGD/CAS                               fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000	  http://www.cgd.ucar.edu/cas/asphilli
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Feb 25 2009 - 16:52:22 MST

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