Removes the least squares linear trend and estimates of the linear trend at all grid points.

Note: This function is only available in version 4.1.1 of NCL. If your site is licensed for version 4.1, then you can get version 4.1.1 for free. To get version 4.1.1 of NCAR Graphics software, please contact your site representative. If you don't know who your site representative is, then send email to ncarginf@ucar.edu or call (303) 497-1201.


    function dtrend(
        x            : float,
        return_slope : logical


Input float array, series to be detrended. The dimension to be detrended (usually "time") should be the fastest varying dimension (i.e. the rightmost dimension). The mean of x is also removed.

Set this to True or False, depending on whether you want the slope(s) returned as an attribute of the value returned by the function. The attribute will be called slope. If return_slope is True, then the slope(s) will be a returned as a float one-dimensional array or a scalar, with the same dimensions as x only with the last dimension omitted. If x is a one-dimensional array, then slope will be a scalar.


Using least squares, dtrend removes the linear trend at all grid points and returns a float array of the detrended series. It will also return the linear trend per unit time interval (slope) as an attribute called slope if the second argument is set to True. The input data cannot contain any missing values.

Example 1

Let x(lat,lon,time) and sizes nlat=64, mlon=128 and ktime = 120 (months). Then

    xnew = dtrend (x,False)
will return an array xnew(lat,lon,time). xnew will contain the detrended data. The mean is also removed.

Example 1a

    xnew = dtrend (x,True)
will return an array xnew(lat,lon,time). xnew will contain the detrended data and the slopes as an attribute called slope containing nlat*mlon elements. Thus, if x contained temperatures [degrees K] and time was in months then the units of xnew@slope would be [K/month]. Since attributes can not be returned as two-dimensional arrays, the user should use the NCL function "onedtond" to create a two-dimensional array if it is desired for something like plotting purposes:

   slope2D = onedtond(xnew@slope, (/nlat,mlon/) )
   delete (xnew@slope)
   slope2D = slope2D*120        ; would give [K/decade]

Example 2

Let x(time,lat,lon) with named dimensions "time", "lat", "lon", then one must use NCL's named dimensions to reorder:
    xnew = dtrend (x(lat|:,lon|:,time|:), False)
xnew will have dimension order (lat,lon,time).

Reference Manual Control Panel

NG4.1 Home, Index, Examples, Glossary, Feedback, Ref Contents, Ref WhereAmI?

$Revision: 1.7 $ $Date: 1999/03/22 21:07:44 $