Re: how to calculate seasonal means

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Mon Aug 30 2010 - 06:09:35 MDT

Hi,

If you use printVarSummary to look at the variable u, which you
extracted from the file variable with the line:

  u = short2flt(fu[:]->uwnd(1,0,:,:))

you will see that it has 2 dimensions. That is because you used scalar
subscripts for the first 2 dimensions.
The error message is diagnosing your problem exactly.
You could retain single-element dimensions if you rewrite the
statement above as:
  u = short2flt(fu[:]->uwnd(1:1,0:0,:,:))
This is one way to eliminate this particular error.
But with this code there is no point in reordering the dimensions
because the time dimension has been eliminated.
(Even if you retain it as a single-element dimension, reordering will
have no effect.)
  -dave

On Aug 30, 2010, at 4:34 AM, Vishali P. wrote:

> Hi
>
> I tried to addapt your suggestion:
>
> ;************************************************
>
> ; wind.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"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
> ;************************************************
> begin
> ;************************************************
> ; read in netCDF file
> ;************************************************
> diru ="/home/Vishali/Documents/dadosVentos/"
> filu = systemfunc("cd "+diru+" ; ls uwnd*nc")
> print(filu)
> fu = addfiles(diru+filu, "r")
>
>
> dirv ="/home/Vishali/Documents/dadosVentos/"
> filv = systemfunc("cd "+dirv+" ; ls vwnd*nc")
> print(filv)
> fv = addfiles(dirv+filv, "r")
>
> ;************************************************
> ; read in zonal [u] and meridional [v] winds (July)
> ;************************************************
>
> u = short2flt(fu[:]->uwnd(1,0,:,:))
> v = short2flt(fv[:]->vwnd(1,0,:,:)) ; Get u, v, time (1),level
> (1000hpa),latitude(-90:90) and longitude(0:360) data.
>
> printVarSummary(u)
> printVarSummary(v)
>
>
> speed = sqrt(u^2+v^2) ; wind speed magnitude
>
> ;************************************************
> ; create plot
> ;************************************************
> wks = gsn_open_wks("ps","vector_v") ; open a ps file
> gsn_define_colormap(wks,"BlAqGrYeOrRevi200") ; choose color map
>
>
> vcres = True ; plot mods desired
> vcres@gsnFrame = False ; so we can draw
> time stamp
>
> vcres@vcRefAnnoOrthogonalPosF = -1.0 ; move ref vector
> up
> vcres@vcRefMagnitudeF = 10.0 ; define vector
> ref mag
> vcres@vcRefLengthF = 0.045 ; define length
> of vec ref
> vcres@vcGlyphStyle = "CurlyVector" ; turn on curly
> vectors
> vcres@vcMinDistanceF = 0.017
>
>
> vcres@gsnSpreadColors = True ; use full colormap
> vcres@gsnSpreadColorEnd = -2 ; don't use added gray
> i = NhlNewColor(wks,0.8,0.8,0.8) ; add gray to colors
>
> vcres@vcMonoLineArrowColor = False ; create color
> vectors
> vcres@pmTickMarkDisplayMode = "Always" ; turn on tickmarks
>
> ;vcres@lbOrientation = "vertical" ; vertical label bar
> ;vcres@pmLabelBarDisplayMode = "Always" ; Turn on a label
> bar.
> ;vcres@pmLabelBarWidthF = 1
>
> ;************************************************
> ; Averages
>
> ;************************************************
>
> yr = fspan(1998,2004,7)
> dims_u = dimsizes( u(lev|:,lat|:,lon|:,time|:) )
> u_jas = new( (/dims_u(0),dims_u(1),dims_u(2),dimsizes(yr)/), float )
>
> do i=0,dimsizes(yr)-1
> beg_date=10000*yr+0701.00
> end_date=10000*yr+0930.99
> u_jas(:,:,:,i) = dim_avg_Wrap(u(lev|:,lat|:,lon|:,{time|
> beg_date:end_date}) )
> end do
>
>
> ;************************************************
> ; Choose a subregion
> ;************************************************
> vcres@mpFillOn = False ; turn off gray
> fill
> vcres@mpOutlineBoundarySets = "National" ; turn on country
> boundaries
> vcres@mpGeophysicalLineColor = "Navy" ; color of cont.
> outlines
> vcres@mpGeophysicalLineThicknessF = 1.5 ; thickness of
> outlines
>
> vcres@mpMaxLatF = 0 ;maximum latitude
> vcres@mpMinLatF = -45 ;minimum latitude
> vcres@mpMaxLonF = 55 ;maximum longitude
> vcres@mpMinLonF = 5 ;minimum longitude
>
> vector = gsn_csm_vector_map_ce(wks,u,v,vcres)
> ;************************************************
> ; add time stamp to plot
> ;************************************************
> infoTimeStamp(wks,0.025,"wnd.1998.nc") ; arguments are
> workstation
> ; size of text desired, and
> ; right string.
> frame (wks)
> end
>
>
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> but the script gave me the following error
>
> fatal:Number of subscripts do not match number of dimensions of
> variable,(4) Subscripts used, (2) Subscripts expected
> fatal:Execute: Error occurred at or near line 70 in file wind.ncl
>
> line 70 ------>>>>> dims_u =
> dimsizes( u(lev|:,lat|:,lon|:,time|:) )
>
>
> Please help
>
> Vp
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Aug 30 06:10:13 2010

This archive was generated by hypermail 2.1.8 : Thu Sep 09 2010 - 05:56:39 MDT