Re: Area average

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Wed Mar 03 2010 - 11:02:14 MST

Hi Kim,
Now I understand what you are trying to do. The first thing that you
need to do is to set all those areas that you do not want to go into the
calculation to @_FillValue. Then plot a simple map to verify that you
have correctly masked out the areas. The following code assumes that
your data is spatially complete, in that there isn't any missing data
present.

(If there is missing data, and it varies in time, you will have to make
quite sure that your mask is accurate. You can do that be setting the
entire array z to a single value, say 1 (syntax: z=1). And then apply
your masks, and plot. Modify masks, plot. Then take out the z = 1 line,
and move to the next step.)

    f = addfile("shtfl.sfc.gauss.2000.nc","r")
    z = short2flt(f->shtfl(120:211,:,:))
    printVarSummary(z)

; These are guesses, you will need to add to/modify the following lines to
; perfect your masking
    z(:,{:29},:) = z@_FillValue ; set all areas south of 29N to missing
    z(:,{:31},{67:}) = z@_FillValue
    z(:,{ 32},{70:}) = z@_FillValue
    z(:,{39:},:) = z@_FillValue
    z(:,:,{:60}) = z@_FillValue
    z(:,:,{72:}) = z@_FillValue

   wks = gsn_open_wks("x11","map")
   res = True
   res@mpMinLatF = 25
   res@mpMaxLatF = 43
   res@mpMinLonF = 55
   res@mpMaxLonF = 77

   res@cnFillOn = True
   res@cnLinesOn =False
   res@cnFillMode = "RasterFill" ; done to see individual grid boxes
   res@cnMissingValFillColor = "gray60" ; color all missing areas to
medium-gray
   res@cnMissingValFillPattern = 0
   plot = gsn_csm_contour_map_ce(wks,z(0,:,:),res)
---------------------------------------
You will need to add to and modify the .. = z@_FillValue lines to
perfect your area mask. Once you are happy with your mask, you can
continue on with the rest of your program, as you had it coded.

Good luck.
Adam

On 03/02/2010 08:25 PM, Kim wrote:
> Dear Adam Phillips,
> Thanks alot for your continued support. So for your convenience I’m also
> attaching the code and Fig, may be this will help you to understand the
> problem. In case of time vs lon (shown in Fig2) I only need the output
> indicated in Fig 1 and no need the other parts above and below. Because
> in Fig.2 there is a total output from lat(28:38.5) and lon (60:72) . I
> want to remove (no need area) as I mentioned in Fig.1, so that I can
> calculate the actual output of the parameters in time vs lon plot.
> thanks again for your continued help,
> kim
> --- On *Tue, 3/2/10, Adam Phillips /<asphilli@ucar.edu>/* wrote:
>
>
> From: Adam Phillips <asphilli@ucar.edu>
> Subject: Re: [ncl-talk] Area average
> To: "Kim" <r4rid@yahoo.com>
> Cc: ncl-talk@ucar.edu
> Date: Tuesday, March 2, 2010, 2:11 PM
>
> Hi Kim,
> I'm afraid I'm not clear as to what you are trying to accomplish. The
> code you sent won't work for a few reasons:
> 1) This line: z3 = z0-(z1+z2) will result in an error as you are
> subtracting/adding arrays of different sizes, specifically in the
> longitude dimension.
> 2) As you are creating the z3 array from the equation on the other side
> of the = sign, meta-data (coordinate variables, attributes) will not be
> assigned to the z3 array. Thus, time = z3&time will result in a fatal
> error.
>
> You speak of area-averages (normally calculated via wgt_areaave, as I
> wrote in my original email) but then you are using the dim_avg_Wrap
> function, which will average only the rightmost dimension.
>
> If you could provide a clearer explanation of what you wish to
> accomplish that would prove helpful. This is just a guess: If you need
> to take an area average of a region that isn't a box (defined by a
> latitudinal range and a longitudinal range), then you can set certain
> regions to @_FillValue. For instance, let's say you want to take the
> area average from 10:20N, and 5:35E, but don't want to include the
> region from 12:15N, and 10:20E... Then you can do something like this:
> z0(:,{12:15},{10:20}) = z0@_FillValue
> z0Area = wgt_areaave_Wrap(z0(:,{10:20},{5:35}),1.0,1.0,0)
> Adam
>
> On 03/02/2010 02:03 AM, Kim wrote:
> > Dear Adam Phillips , thanks for your kind help. Particularly, in
> case of
> > time vs long, I 'm feeling difficulty to remove the z1& z2
> average area
> > from the total average area (z0), so that I can calculate the actual
> > area averaged, actually my required fig.is in the form of diagonal.
> > However, I made some assumption but could not succeed, because
> the time
> > is a problem. kindly have a look on the said assumption given below:
> >
> > f = addfile("olr.day.mean.nc","r")
> >
> > z = short2flt(f->olr(120:243,:,:))
> >
> > printVarSummary(z)
> >
> > z0 = dim_avg_Wrap(z(time|:,{lon|60:76},{lat|25:40}))
> >
> > z1 = dim_avg_Wrap(z(time|:,{lon|60:66},{lat|30:36}))
> >
> > z2 = dim_avg_Wrap(z(time|:,{lon|70:76},{lat|25:28}))
> >
> > z3 = z0-(z1+z2)
> >
> > printVarSummary(z3)
> >
> > time = z3&time
> >
> > =================
> >
> > =================
> >
> > plot = gsn_csm_hov(wks, z3(:,:) , res )
> >
> > end
> > thanks again and regards,
> > kim
> > --- On *Mon, 3/1/10, Adam Phillips /<asphilli@ucar.edu
> <http://us.mc371.mail.yahoo.com/mc/compose?to=asphilli@ucar.edu>>/*
> wrote:
> >
> >
> > From: Adam Phillips <asphilli@ucar.edu
> <http://us.mc371.mail.yahoo.com/mc/compose?to=asphilli@ucar.edu>>
> > Subject: Re: [ncl-talk] Area average
> > To: "Kim" <r4rid@yahoo.com
> <http://us.mc371.mail.yahoo.com/mc/compose?to=r4rid@yahoo.com>>
> > Cc: ncl-talk@ucar.edu
> <http://us.mc371.mail.yahoo.com/mc/compose?to=ncl-talk@ucar.edu>
> > Date: Monday, March 1, 2010, 8:45 AM
> >
> > Hi Kim,
> > I think the following code will do what you want:
> > z2 = z(:,{30:40},{60:72}) ; select specific region
> > delete(z)
> > printVarSummary(z2)
> > z2Area = wgt_areaave_Wrap(z2,1.0,1.0,0) ; create area-avg. timeseries
> > printVarSummary(z2Area)
> > z2_za = dim_avg_Wrap(z2) ; create time x lat array
> > z2_ma = dim_avg_Wrap(z2(time|:,lon|:,lat|:) ; create time x lon array
> > printVarSummary(z2_za)
> > printVarSummary(z2_ma)
> >
> > printVarSummary is a wonderful tool that you can use to view the
> details
> > of an array. printVarSummary will show the metadata associated
> with an
> > array, as well as the range of the coordinate variables (if there are
> > any).
> >
> > As you are area-averging, you should account for the difference
> in sizes
> > of the grid boxes as the meridians converge at the poles. You can do
> > this
> > by applying gaussian or cosine weights in the area-averaging
> > process. See
> > example 1 here:
> > http://www.ncl.ucar.edu/Document/Functions/Built-in/wgt_areaave.shtml
> >
> > If you haven't done so already, I suggest you take a look at the NCL
> > Mini-Language Manual available here:
> > http://www.ncl.ucar.edu/Document/Manuals/
> >
> > Good luck,
> > Adam
> >
> >
> > > Dear NCL users,
> > > I want to calculate only the map area averaged and remove the
> > area outside
> > > the map (sample Fig.attached). I don’t know how to calculate the
> > > required map area and remove the outside area?
> > > Furthermore, how does calculate time vs lon and time series plot
> > of only
> > > map area?
> > > Is it correct if I use this function?
> > > zArea = wgt_areaave_Wrap(z(:,{30:40},{60:72}),1.0,1.0,0)
> > > but how I confirm it is only map area averaged(as indicated in
> Fig)?
> > > Kindly, your guidance regarding this will be appreciated.
> > > Thanks in advance,
> > > kim
> > > Â
> > >
> > >
> > > _______________________________________________
> > > ncl-talk mailing list
> > > List instructions, subscriber options, unsubscribe:
> > > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> > >
> >
> >
> >
>
> --
> __________________________________________________
> Adam Phillips
> asphilli@ucar.edu
> <http://us.mc371.mail.yahoo.com/mc/compose?to=asphilli@ucar.edu>
> National Center for Atmospheric Research tel: (303) 497-1726
> Climate and Global Dynamics Division 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

-- 
__________________________________________________
Adam Phillips 
asphilli@ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
Climate and Global Dynamics Division         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 Mar 3 11:02:21 2010

This archive was generated by hypermail 2.1.8 : Thu Mar 04 2010 - 15:07:06 MST