-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroseEqualArea.m
178 lines (159 loc) · 6.52 KB
/
roseEqualArea.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
function roseEqualArea(roseAngles, delta, azimuth, roseLengths, sColour)
% equal area rose diagram of trace segment angles
%
% arguments:
% roseAngles - vector of orientations in degrees
% delta - (scalar) bin size for rose plot in degrees
% azimuth - (scalar) rotation angle for final rose plot e.g. northCorrection,
% in degrees
%
% Dave Healy
% February 2017
% d.healy@abdn.ac.uk
%% Copyright
% Permission is hereby granted, free of charge, to any person obtaining a
% copy of this software and associated documentation files (the
% "Software"), to deal in the Software without restriction, including
% without limitation the rights to use, copy, modify, merge, publish,
% distribute, sublicense, and/or sell copies of the Software, and to permit
% persons to whom the Software is furnished to do so, subject to the
% following conditions:
%
% The above copyright notice and this permission notice shall be included
% in all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
% OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
% NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
% DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
% OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
% USE OR OTHER DEALINGS IN THE SOFTWARE.
% if fRosemean
% % calculate circular statistics: mean and std dev
% [ roseMean, roseStddev, roseResultant ] = circStat(roseAngles) ;
%
% disp('Circular statistics:') ;
% disp(['Circular mean (degrees from North): ', num2str(roseMean)]) ;
% disp(['Circular standard deviation (degrees): ', num2str(roseStddev)]) ;
% disp(['Resultant: ', num2str(roseResultant)]) ;
% end ;
% initialise
rinc = 0.0005 ;
r1Percent = 50 ;
r5Percent = r1Percent * sqrt(5) ;
r10Percent = r1Percent * sqrt(10) ;
r20Percent = r1Percent * sqrt(20) ;
r30Percent = r1Percent * sqrt(30) ;
r50Percent = r1Percent * sqrt(50) ;
x1Percent = -r1Percent:rinc:r1Percent ;
y1Percent = sqrt(r1Percent^2 - x1Percent.^2) ;
x5Percent = -r5Percent:rinc:r5Percent ;
y5Percent = sqrt(r5Percent^2 - x5Percent.^2) ;
x10Percent = -r10Percent:rinc:r10Percent ;
y10Percent = sqrt(r10Percent^2 - x10Percent.^2) ;
x20Percent = -r20Percent:rinc:r20Percent ;
y20Percent = sqrt(r20Percent^2 - x20Percent.^2) ;
x30Percent = -r30Percent:rinc:r30Percent ;
y30Percent = sqrt(r30Percent^2 - x30Percent.^2) ;
x50Percent = -r50Percent:rinc:r50Percent ;
y50Percent = sqrt(r50Percent^2 - x50Percent.^2) ;
%
binAngles = 0:delta:360 ;
binAngles2 = zeros(1, max(size(binAngles))*2) ;
numAngles2 = zeros(1, max(size(binAngles))*2) ;
sumLengths2 = zeros(1, max(size(binAngles))*2) ;
j = 1 ;
[ numAngles, ~, indBins ] = histcounts(roseAngles, binAngles) ;
%numAngles = histc(roseAngles, binAngles) ;
% fix 'bug' in histcounts() that rounds into 'wrong' bins at 0, 180 and
% 360
i1 = 1 ;
inhalf = (360/delta) / 2 ;
inhalfnext = inhalf + 1 ;
in = 360/delta ;
n1 = (numAngles(i1) + numAngles(inhalfnext)) / 2 ;
n2 = (numAngles(inhalf) + numAngles(in)) / 2 ;
numAngles(i1) = n1 ;
numAngles(inhalf) = n2 ;
numAngles(inhalfnext) = n1 ;
numAngles(in) = n2 ;
% go through the bins...
for i = 1:max(size(binAngles))-1
binAngles2(j) = binAngles(i) ;
if (i+1) > max(size(binAngles))
binAngles2(j+1) = binAngles(1) ;
else
binAngles2(j+1) = binAngles(i+1) ;
end ;
numAngles2(j:j+1) = numAngles(i) ;
if sum(roseLengths)
sumLengths2(j:j+1) = sum(roseLengths(indBins==i)) ;
end ;
j = j + 2 ;
end ;
if sum(roseLengths) == 0
numAnglesPercent = ( numAngles2 ./ length(roseAngles) ) * 100 ;
else
% length weighted - sum lengths in each bin, and divide by total length
% of all segments
numAnglesPercent = ( sumLengths2 ./ sum(roseLengths) ) * 100 ;
end ;
% this is the equal area bit...
rAnglesPercent = r1Percent .* sqrt(numAnglesPercent) ;
[ xRoseArea, yRoseArea ] = pol2cart((pi/2 - binAngles2*pi/180), rAnglesPercent) ;
limX = max(xRoseArea) ;
limY = max(yRoseArea) ;
lim = max(limX, limY) ;
roseContours = [ max(x1Percent), max(x5Percent), max(x10Percent), ...
max(x20Percent), max(x30Percent), max(x50Percent) ] ;
lim = roseContours(find(roseContours > lim, 1)) ;
hold on ;
for i = 0:delta:binAngles
% clumsy workaround to ?bug in fill() which won't allow FaceColor from a string
h = fill(xRoseArea, yRoseArea, 'r', 'EdgeColor', sColour,'FaceAlpha', .3) ;
set(h, 'FaceColor', sColour) ;
end ;
if max(x1Percent) <= lim
plot(x1Percent, y1Percent, '-k', x1Percent, -y1Percent, '-k', 'LineWidth', 0.25) ;
end ;
if max(x5Percent) <= lim
plot(x5Percent, y5Percent, '-k', x5Percent, -y5Percent, '-k', 'LineWidth', 0.25) ;
end ;
if max(x10Percent) <= lim
plot(x10Percent, y10Percent, '-k', x10Percent, -y10Percent, '-k', 'LineWidth', 0.25) ;
end ;
if max(x20Percent) <= lim
plot(x20Percent, y20Percent, '-k', x20Percent, -y20Percent, '-k', 'LineWidth', 0.25) ;
end ;
if max(x30Percent) <= lim
plot(x30Percent, y30Percent, '-k', x30Percent, -y30Percent, '-k', 'LineWidth', 0.25) ;
end ;
if max(x50Percent) <= lim
plot(x50Percent, y50Percent, '-k', x50Percent, -y50Percent, '-k', 'LineWidth', 0.25) ;
end ;
plot([-r50Percent*1.1, r50Percent*1.1], [0, 0], '-k', 'LineWidth', 0.25) ;
plot([0, 0], [-r50Percent*1.1, r50Percent*1.1], '-k', 'LineWidth', 0.25) ;
% if fRosemean
% plot([lim*sind(roseMean), -lim*sind(roseMean)], ...
% [lim*cosd(roseMean), -lim*cosd(roseMean)], '-r', 'LineWidth', 1) ;
% end ;
hold off ;
axis equal off ;
view(azimuth, 90) ;
text(-(r1Percent), 0, '1%', 'Clipping', 'on', ...
'BackgroundColor', 'w', 'FontSize', 8, 'HorizontalAlignment', 'right') ;
text(-(r5Percent), 0, '5%', 'Clipping', 'on', ...
'BackgroundColor', 'w', 'FontSize', 8, 'HorizontalAlignment', 'right') ;
text(-(r10Percent), 0, '10%', 'Clipping', 'on', ...
'BackgroundColor', 'w', 'FontSize', 8, 'HorizontalAlignment', 'right') ;
text(-(r20Percent), 0, '20%', 'Clipping', 'on', ...
'BackgroundColor', 'w', 'FontSize', 8, 'HorizontalAlignment', 'right') ;
text(-(r30Percent), 0, '30%', 'Clipping', 'on', ...
'BackgroundColor', 'w', 'FontSize', 8, 'HorizontalAlignment', 'right') ;
text(-(r50Percent), 0, '50%', 'Clipping', 'on', ...
'BackgroundColor', 'w', 'FontSize', 8, 'HorizontalAlignment', 'right') ;
xlim([ -lim lim ]) ;
ylim([ -lim lim ]) ;
box off ;
end