[R] Re: [STATSGRASS] Interpolation of azimuth values

Hamish hamish_nospam at yahoo.com
Tue Oct 21 03:57:54 CEST 2003


> I will make an interpolation of data which represents azimuth
> direction( angle from north in clockwise direction) values.
> But there is a problem.
> Say, for instance, while 1 and 359 indicate somewhat same direction, 
> interpolation puts  values
> in the range from 1 to 359.  What can I do to solve the problem ?


You might try breaking it down to x,y components on a circle of radius
1, or take the real and imaginary parts. Bin/average the results and
then convert back to polar angles.

Note if you are comparing vectors it is important to include magnitude
in the calculation and otherwise think about the reality of the answer.
e.g. A strong east-west dominant wind flow through a valley, which may
be 15 km/hr east half the time and 15 km/hr west the other half may
average to a weak north-south net, which tells you nothing about the
'usual' conditions. Sorry, that example isn't very illustrative of my
point.


R CircStats's circ.mean.R does this:
http://cran.r-project.org/src/contrib/PACKAGES.html#CircStats

circ.mean <- function(x) {
        sinr <- sum(sin(x))
        cosr <- sum(cos(x))
        circmean <- atan(sinr, cosr)
        circmean



or a Matlab example:

TH=wind.dirns;
R=wind.velos;
[X,Y] = pol2cart(TH,R);
[TH1,R1] = cart2pol(mean(X),mean(Y));
wind_mean.dirn = TH1 * (180/pi)
wind_mean.velo = mean(wind.velos);



Hamish




More information about the R-help mailing list