Representing Directional Data

10.1 Representing Directional Data

Directional data is analysed by means of unit length vectors, i.e., by representing the angular observations as points on the unit radius circle or sphere.

For circular data, the angle, φ, is usually specified in [−180º, 180º] or in [0º, 360º]. Spherical data is represented in polar form by specifying the azimuth (or

declination) and the latitude (or inclination). The azimuth, φ, is given in [−180º, 180º]. The latitude (also called elevation angle), θ, is specified in [−90º, 90º]. Instead of an azimuth and latitude, a longitude angle in [0º, 360º] and a co-latitude angle in [0º, 180º] are often used.

When dealing with directional data, one often needs, e.g. for representational purposes, to obtain the Cartesian co-ordinates of vectors with specified length and angular directions or, vice-versa, to convert Cartesian co-ordinates to angular, polar or spherical form. The conversion formulas for azimuths and latitudes are given in Table 10.1 with the angles expressed in radians through multiplication of

the values in degrees by π /180.

The MATLAB and R functions for performing these conversions, with the angles expressed in radians, are given in Commands 10.1.

10 Directional Data

Example 10.1

Q: Consider the Joints’ dataset, containing measurements of azimuth and pitch in degrees for several joint surfaces of a granite structure. What are the Cartesian co-ordinates of the unit length vector representing the first measurement?

A: Since the pitch is a descent angle, we use the following MATLAB instructions (see Commands 10.1 for R instructions), where joints is the original data matrix (azimuth in the first column, pitch in the second column):

» j = joints*pi/180; % convert to radians » [x,y,z]=sph2cart(j(1,1),-j(1,2),1) x=

0.1162 y= -0.1290

z= -0.9848

Table 10.1. Conversion formulas from Cartesian to polar or spherical co-ordinates (azimuths and latitudes) and vice-versa.

Polar to Cartesian Cartesian to Polar Circle

( φ, ρ) → (x, y) (x, y) → (φ, ρ) x= ρ cosφ ; y =ρ sin φ

φ = atan2(y,x) ; a ρ = (x 2 + y 2 ) ½

Sphere ( φ, θ, ρ) → (x, y, z) (x, y, z) → (φ, θ, ρ)

x= ρ cosθ cosφ ; y = ρ cosθ sinφ ; θ = arctan(z / (x + y ) ) ; z= ρ sinθ

φ = atan2(y,x) ; ρ = (x 2 + y 2 + z 2 ) ½

a atan2(y,x) denotes the arc tangent of y/x with correction of the angle for x < 0 (see formula 10.4).

Commands 10.1. MATLAB and R functions converting from Cartesian to polar or spherical co-ordinates and vice-versa.

[x,y]=pol2cart(phi,rho) [phi,rho]=cart2pol(x,y)

MATLAB

[x,y,z]=sph2cart(phi,theta,rho) [phi,theta,rho]=cart2sph(x,y,z)

pol2cart(phi,rho) R cart2pol(x,y) sph2cart(phi,theta,rho) cart2sph(x,y,z)

10.1 Representing Directional Data 377

The R functions work in the same way as their MATLAB counterparts. They all return a matrix whose columns have the same information as the returned MATLAB vectors. For instance, the conversion to spherical co-ordinates in Example 10.1 can be obtained with:

> m <- sph2cart(phi*pi/180,-pitch*pi/180,1)

where phi and pitch are the columns of the attached joints data frame. The columns of matrix m are the vectors x, y and z.

In the following sections we assume, unless stated otherwise, that circular data is specified in [0º, 360º] and spherical data is specified by the pair (longitude, co- latitude). We will call these specifications the standard format for directional data. The MATLAB and R-implemented functions convazi and convlat (see Commands 10.3) perform the azimuth and latitude conversions to standard format.

Also in all MATLAB and R functions described in the following sections, the directional data is represented by a matrix (often denoted as a), whose first column contains the circular or longitude data, and the second column, when it exists, the co-latitudes and both in degrees.

Circular data is usually plotted in circular plots with a marker for each direction plotted over the corresponding point in the unit circle. Spherical data is conveniently represented in spherical plots, showing a projection of the unit sphere with markers over the points corresponding to the directions.

For circular data, a popular histogram plot is the rose diagram, which shows circular slices whose height is proportional to the frequency of occurrence in a specified angular bin.

Commands 10.2 lists the MATLAB and R functions used for obtaining these plots.

Figure 10.1. Circular plot (obtained in MATLAB) of the wind direction WDB sample included in the Weather dataset.

10 Directional Data

Example 10.2

Q: Plot the March, 1999 wind direction WDB sample, included in the Weather dataset (datasheet Data 3).

A: Figure 10.1 shows the circular plot of this data obtained with polar2d. Visual inspection of the plot suggests a multimodal distribution with dispersed data and a mean direction somewhere near 135º.

Example 10.3

Q: Plot the Joints’ dataset consisting of azimuth and pitch of granite joints of a city street in Porto, Portugal. Assume that the data is stored in the joints matrix whose first column is the azimuth and the second column is the pitch (descent 1 angle) .

A: Figure 10.2 shows the spherical plot obtained in MATLAB with:

» j=convlat([joints(:,1),-joints(:,2)]); » polar3d(j);

Figure 10.2 suggests a unimodal distribution with the directions strongly concentrated around a modal co-latitude near 180º. We then expect the anti-mode (distribution minimum) to be situated near 0º.

Figure 10.2. Spherical plot of the Joints’ dataset. Solid circles are visible points; open circles are occluded points.

Note that strictly speaking the joints’ data is an example of axial data , since there is no difference

between the symmetrical directions ( φ , θ ) and ( φ + π ,- θ ). We will treat it, however, as spherical data.

10.1 Representing Directional Data 379

Example 10.4

Q: Represent the rose diagram of the angular measurements H of the VCG dataset.

A: Let vcg denote the data matrix whose first column contains the H measurements. Figure 10.3 shows the rose diagram using the MATLAB rose command:

» rose(vcg(:,1) *pi/180,12) % twelve bins

Using [t,r]=rose(vcg(:,1)*pi/180,12), one can confirm that 70/120 = 58% of the measurements are in the [ −60º, 60º] interval. The same results are obtained with R rose function.

Figure 10.3. Rose diagram (obtained with MATLAB) of the angular H measurements of the VCG dataset.

Commands 10.2. MATLAB and R functions for representing and graphically assessing directional data.

[phi, r] = rose(a,n) MATLAB polar2d(a, mark) ; polar3d(a) unifplot(a) h=colatplot(a,kl) ; h=longplot(a)

R rose(a) polar2d(a)

10 Directional Data

The MATLAB function rose(a,n) plots the rose diagram of the circular data vector a (radians) with n bins; [phi, r]=rose(a,n)returns the vectors phi and r such that polar(phi, r) is the histogram (no plot is drawn in this case).

The polar2d and polar3d functions are used to obtain circular and spherical plots, respectively. The argument a is, as previously mentioned, either a column vector for circular data or a matrix whose first column contains the longitudes, and the second column the co-latitudes (in degrees).

The unifplot command draws a uniform probability plot of the circular data vector a (see section 10.4). The colatplot and longplot commands are used to assess the von Misesness of a spherical distribution (see section 10.4). The returned value h is 1 if the von Mises hypothesis is rejected at 1% significance level, and 0 otherwise. The parameter kl of colatplot must be 1 for assessing von Misesness with large concentration distributions and 0 for assessing uniformity with low concentration.

The R functions behave much in the same way as their equivalent MATLAB functions. The only differences are: the rose function always uses 12 histogram bins; the polar2d function always uses open circles as marks.