Re: Problems defining an array to be plotted in gsn_csm_xy

From: Carl Schreck <Carl.Schreck_at_nyahnyahspammersnyahnyah>
Date: Mon Feb 21 2011 - 06:20:22 MST

Hi Kelly,

Hope things are going well for you out in Boulder.

A quick idea that you might try... Instead of looping through each level,
try this:

sum_graup_past_ht_array = dim_sum( dim_sum( qgraup_plane_past ) )
x = sum_graup_past_ht_array(0,:)

Assuming qgraup_plane_past was correctly interpolated and it t,z,y,x, then
the innermost dim_sum will sum all x at each t,z,y, and then the outer most
will sum those at each t,z. Then the next line should just grab the first
(and probably only) t.

Hope this helps!

    Carl

On Fri, Feb 18, 2011 at 6:41 PM, Kelly Mahoney <Kelly.Mahoney@noaa.gov>wrote:

> Hi,
> I have what is probably an incredibly basic question, but I'm stuck.
> I am trying to: read in a grid, interpolate it to height coordinates,
> sum values over all gridpoints per each individual pressure level, and
> then write those sum values vs. height on an xy plot.
> The problem is that I can't seem to correctly define the
> sum-values-at-each-height-level array: attempts have resulted in index
> errors, only one value getting written (at the top height level,
> presumably because I'm overwriting it every time through the loop), and
> too many other problems to list.
> Again, I think this is basic array construction, but I can't figure it
> out for this purpose.
> Any help would be incredibly appreciated!
> Thanks in advance,
> Kelly Mahoney
>
>
>
> ************************************************************************************************************************************************
>
> 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"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
>
> begin
> setvalues NhlGetWorkspaceObjectId()
> "wsMaximumSize" : 100000000000
> end setvalues
> setfileoption("nc", "SuppressClose", False)
>
>
> imgdir="./"
> diri="./"
>
> fils = systemfunc("ls ./wrfout_d02_2040*")+".nc"
> nfil = dimsizes(fils)
>
> fils_past = systemfunc("ls ./wrfout_d02_1970*")+".nc"
>
> do nf=0,nfil-1
> f=addfile(fils(nf),"r")
> times = wrf_user_list_times(f) ; get time(s) in the file
> ntimes = dimsizes(times)
>
> f_past=addfile(fils_past(nf),"r")
> times_past = wrf_user_list_times(f_past) ; get time(s) in the file
>
> lat=f->XLAT(0,:,:)
> lon=f->XLONG(0,:,:)
> hgt=f->HGT(0,:,:)
>
>
> ;KM read in 3D graupel:
> ;****** PAST ********
> qgraup_past = wrf_user_getvar(f_past,"QGRAUP",-1)
> p_past = wrf_user_getvar(f_past, "pressure",-1) ; pressure is our
> vertical coordinate
> z_past = wrf_user_getvar(f_past, "z",-1) ; grid point height
>
> ; The specific height levels that we want the data interpolated to.
> ; And interpolate to these levels
> height_levels = (/0.,200.,400.,600.,800.,1000., \ ; height
> levels - in meters
> 1200.,1400.,1600.,1800.,2000.,\
> 2200.,2400.,2600.,2800.,3000.,\
> 3200.,3400.,3600.,3800.,4000.,\
> 4200.,4400.,4600.,4800.,5000.,\
> 5200.,5400.,5600.,5800.,6000.,\
> 6200.,6400.,6600.,6800.,7000.,\
> 7200.,7400.,7600.,7800.,8000.,\
> 9200.,9400.,9600.,9800.,10000.,\
> 10200.,10400.,10600.,10800.,11000.,\
> 11200.,11400.,11600.,11800.,12000.,\
> 12200.,12400.,12600.,12800.,13000.,\
> 13200.,13400.,13600.,13800.,14000.,\
> 14200.,14400.,14600.,14800.,15000./)
>
> nlevels = dimsizes(height_levels) ; number of height levels
>
> ;****** INTERPOLATE TO HEIGHT: PAST ********
> qgraup_plane_past = int2p_n_Wrap(z_past,qgraup_past,height_levels,1,1)
> qgraup_plane_past@_FillValue = -999.
> qgraup_plane_past@lat = lat
> qgraup_plane_past@lon = lon
>
> ;****** SUM/AVG/MEDIAN ETC AMT OF GRAUPEL PER HEIGHT LEVEL ********
>
> do level = 0,nlevels-1 ; LOOP OVER LEVELS
>
> height = height_levels(level)
>
> sum_graup_past = sum(qgraup_plane_past(0,level,:,:))
>
> printVarSummary(sum_graup_past)
>
> ;km sum_graup_past_ht_array = new((/sum_graup_past,height(level)/,float))
> ;km sum_graup_past_ht_array = (/(/sum_graup_past/),(/height/)/)
> ;km this is just a sample of many things I've tried...
> sum_graup_past_ht_array = sum_graup_past(level)
> ;KM ????? How to define an array of sum_graup_past *and* height so that
> it can be plotted on an xy plot ?????
>
> print("At "+height+"m sum_graup_past from all gridpoints =
> "+sum_graup_past)
>
> end do ; file loop
>
> end do ; height loop
>
> print(sum_graup_past_ht_array)
> print(height_levels)
>
> ;***** TRY TO PLOT HEIGHT(YAXIS) VS. SUM_GRAUP_PAST (XAXIS): ************
>
> x = sum_graup_past_ht_array
> y = height_levels
>
> wks = gsn_open_wks("ps","xy_test")
>
> res = True
> res@trYMinF = 0.
> res@trYMaxF = 15000.
>
> res@trXMinF = 0.
> res@trXMaxF = 30.
>
> plot = gsn_csm_xy(wks,x,y,res)
>
>
> end
>
> exit
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

-- 
Carl J. Schreck III, PhD
Postdoctoral Research Associate
Cooperative Institute for Climate and Satellites (CICS-NC)
NOAA's National Climatic Data Center
151 Patton Avenue
Asheville, NC 28801
Tel: 828-257-3140
carl.schreck@noaa.gov
http://www.atmos.albany.edu/student/carl/

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Feb 21 06:21:27 2011

This archive was generated by hypermail 2.1.8 : Wed Feb 23 2011 - 16:47:57 MST