Re: difference between avg and dim_avg (BIG DIFFERENCE ????????)

From: Sanjiv Kumar <sanjivconscious_at_nyahnyahspammersnyahnyah>
Date: Tue Nov 02 2010 - 12:50:45 MDT

thank you arnidam.

you are right in your answer.

Sanjiv

On Tue, Nov 2, 2010 at 1:49 PM, Arindam Chakraborty <arch@caos.iisc.ernet.in
> wrote:

> hi Sanjiv,
> the results are different probably because you have some undefined
> (missing or fill) values in your data set. Since you've mentioned about mask
> file of river basin I'm guessing so. In this case, the avg() and
> dim_avg(dim_avg()) would give two different results because avg() gives
> equal weights to all the valid values (does the averaging in a single go).
> But in the other method, the first dim_avg() will create a vector averaging
> all valid values along the mentioned dimension (in this case the last one)
> and then the second dim_avg() will average over those averaged values. In
> this way, weight given to every element is not same because after the first
> dim_avg() information about how many valid values were there along the first
> averaged dimension was lost. You can see this in the following simple
> example:
>
> a = (/(/3,4,5/),(/-9,6,7/)/)
> a@_FillValue = -9
> print(dim_avg(dim_avg(a)))
> print(avg(a))
>
> The results are 5.25 and 5, respectively. By simple calculation we get the
> right answer to be 5 (given by avg).
>
> When you need to do average over an area, you can use wgt_areaave(), where
> you can specify weights optionally (that vary with latitude), or can use the
> avg function the way you used.
>
> Hope this helps.
>
> regards,
>
> arindam
> --
> ARINDAM CHAKRABORTY
> <http://caos.iisc.ernet.in/>
>
> *---------- Original Message -----------*
> From: Sanjiv Kumar <sanjivconscious@gmail.com>
> To: ncl-talk USERS <ncl-talk@ucar.edu>
> Sent: Tue, 2 Nov 2010 11:54:42 -0400
> Subject: difference between avg and dim_avg (BIG DIFFERENCE
> ????????)
>
> > Hello,
> >
> > I am using follwing functions to calculate average monthly value for the
> mississipi river basin.
> > I have a mask file for the mississippi river basin that i used to mask
> the data.
> >
> > *PrintVarSummary(pcp)*
> > Variable: pcp
> > Type: float
> > Total Size: 41880240 bytes
> > 10470060 values
> > Number of Dimensions: 3
> > Dimensions and sizes: [month | 12] x [lat | 621] x [lon | 1405]
> > Coordinates:
> > month: [0..11]
> > lat: [49.9375..24.0625]
> > lon: [-125.0208..-66.47912]
> > Number Of Attributes: 5
> > units : mm/month
> > long_name : monthly_prism_pcp
> > _FillValue : -9999
> > time_op_ncl : Climatology: 25 years
> > info : function clmMonLLT: contributed.ncl
> >
> > *option 1: print(dim_avg_Wrap(dim_avg_Wrap(pcp)))*
> > **
> > (0) 58.64856
> > (1) 58.87543
> > (2) 74.17915
> > (3) 79.49629
> > (4) 102.1536
> > (5) 105.3508
> > (6) 89.25518
> > (7) 77.08332
> > (8) 74.19021
> > (9) 71.37045
> > (10) 71.6111
> > (11) 63.43136
> >
> > *Average: 77.14*
> > **
> > **
> > *Option2: *
> > **
> > *do i= 0, 11
> > print(avg(pcp(month|i, lat|:, lon|:)))
> > end do*
> >
> > (0) 40.91084
> > (0) 43.56288
> > (0) 61.70639
> > (0) 72.314
> > (0) 98.81877
> > (0) 95.28362
> > (0) 84.07236
> > (0) 72.15498
> > (0) 67.86727
> > (0) 61.63789
> > (0) 59.42875
> > (0) 48.38778
> >
> > *Average: 67.16*
> > **
> > *My question is whay there is big difference between these
> two???????????????*
> > **
> > *Results obtained from option 2 seem to be more realistic to me.*
> > **
> > *Let me know if you need any further detail.*
> > **
> > *thanks*
> > *sanjiv*
> >
> >
> > --
> > This message has been scanned for viruses and
> > dangerous content by *MailScanner* <http://www.mailscanner.info/>, and
> is
> > believed to be clean.
> *------- End of Original Message -------*
>
> --
> This message has been scanned for viruses and
> dangerous content by *MailScanner* <http://www.mailscanner.info/>, and is
> believed to be clean.
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Nov 2 12:50:56 2010

This archive was generated by hypermail 2.1.8 : Mon Nov 08 2010 - 08:08:50 MST