Re: average on 2 dimensions?

From: Dennis Shea (shea AT XXXXXX)
Date: Wed Apr 14 2004 - 13:38:02 MDT

  • Next message: Dennis Shea: "Re: help!"

    >
    >One more question:
    >
    >I got this data set ts(365,4,73,144). Is there any way to average data
    >on first two dimensions? I found this function dim_avg only for
    >right-most dimension.
    >

    Liz,

    You have to do some dimension reordering. The "trick" is
    to get the rightmost dimension to contain the temporal
    points of interest.Your array is

        ts(date,time,latitude,longitude)

    Specifically,

       [date | 365] x [time | 4] x [latitude | 73] x [longitude| 144]
       
       dim_ts = dimsizes(ts)
       dim_ts(0) = ndate ; 365
       dim_ts(1) = ntime ; 4 [00, 06, 12, 18]
       dim_ts(2) = nlat ; 73
       dim_ts(3) = nlon ; 144
       
    I will assume you have loaded contributed.ncl

       
    load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

    None of the following has beens ted .. perhaps typos are present.

       TS00 = ts(latitude|:,longitude|:,date|:,time|0) ;(73,144,365) 00z data
       TS06 = ts(latitude|:,longitude|:,date|:,time|1)
       TS12 = ts(latitude|:,longitude|:,date|:,time|2)
       TS18 = ts(latitude|:,longitude|:,date|:,time|3)
       
       TS00_AVE = dim_avg_Wrap(TS00) ;(73,144)
                :
       TS18_AVE = dim_avg_Wrap(TS18)

    To get the overall average you could

       TS_AVE = TS00 ; create array with meta data
       TS_AVE = TS00 + TS06 + TS12 + TS18
       
    Another approach uses reordering, ndtooned and onedtond

       TS_1D = ndtooned( ts(latitude|:,longitude|:,date|:,time|:) )
       TS_3D = onedtond( TS_1D, (/nlat,nlon, ndate*ntime/) ) ;(73,144,1460)
       delete (TS_1D)
       
       TS_AVE = dim_avg(TS_3D) ; (73,144)
       TS_AVE!0 = "latitude"
       TS_AVE!1 = "longtitude"
       TS_AVE&latitude = ts&latitude
       TS_AVE&longitude= ts&longitude
       delete(TS_3D)
       

    ---
    Use "printVarSummary" to examine these arrays
       
       
    good luck
    D  
    

    _______________________________________________ ncl-talk mailing list ncl-talk@ucar.edu http://mailman.ucar.edu/mailman/listinfo/ncl-talk



    This archive was generated by hypermail 2b29 : Wed Apr 14 2004 - 14:09:57 MDT