1 | function [BPMx, BPMy] = plotorbitdata(varargin) |
---|
2 | %PLOTORBITDATA - Plots BPM statistics |
---|
3 | % [BPMx, BPMy] = plotorbitdata(FileName) |
---|
4 | % |
---|
5 | % INPUTS |
---|
6 | % 1. FileName = Filename (w/ or w/o directory) where the data was saved |
---|
7 | % If empty then search for a file in the default BPM directory. |
---|
8 | % If '.' then search for a file in the present directory. |
---|
9 | % |
---|
10 | % OUTPUTS |
---|
11 | % For numeric output: |
---|
12 | % 1. BPMx - Horizontal data structure |
---|
13 | % 2. BPMy - Vertical data structure |
---|
14 | |
---|
15 | % |
---|
16 | % Written by Gregory J. Portmann |
---|
17 | % Modified by Laurent S. Nadolski |
---|
18 | |
---|
19 | BPMxFamily = gethbpmfamily; |
---|
20 | BPMyFamily = getvbpmfamily; |
---|
21 | |
---|
22 | FileName = []; |
---|
23 | if nargin >= 1 |
---|
24 | FileName = varargin{1}; |
---|
25 | end |
---|
26 | |
---|
27 | |
---|
28 | if isstruct(FileName) |
---|
29 | BPMx = FileName; |
---|
30 | if nargin >= 2 |
---|
31 | BPMy = varargin{2}; |
---|
32 | else |
---|
33 | BPMy = BPMx; |
---|
34 | end |
---|
35 | % BPM response matrix cludge |
---|
36 | if all(size(BPMx) == [2 2]) |
---|
37 | BPMx = BPMx(1,1); |
---|
38 | end |
---|
39 | else |
---|
40 | DirFlag = 0; |
---|
41 | if isdir(FileName) |
---|
42 | DirFlag = 1; |
---|
43 | else |
---|
44 | if length(FileName)>=1 |
---|
45 | if strcmp(FileName(end),filesep) |
---|
46 | DirFlag = 1; |
---|
47 | end |
---|
48 | end |
---|
49 | end |
---|
50 | if strcmp(FileName,'.') || isempty(FileName) || DirFlag |
---|
51 | % Data root |
---|
52 | if strcmp(FileName,'.') |
---|
53 | [FileName, DirectoryName] = uigetfile('*.mat', 'Select a file to analyze'); |
---|
54 | elseif DirFlag |
---|
55 | [FileName, DirectoryName] = uigetfile('*.mat', 'Select a file to analyze', FileName); |
---|
56 | else |
---|
57 | DirectoryName = getfamilydata('Directory','DataRoot'); |
---|
58 | [FileName, DirectoryName] = uigetfile('*.mat', 'Select a file to analyze', DirectoryName); |
---|
59 | end |
---|
60 | if FileName == 0 |
---|
61 | return |
---|
62 | end |
---|
63 | FileName = [DirectoryName FileName]; |
---|
64 | end |
---|
65 | |
---|
66 | |
---|
67 | % Get data from file |
---|
68 | try |
---|
69 | BPMx = getdata(BPMxFamily, FileName, 'Struct'); |
---|
70 | BPMy = getdata(BPMyFamily, FileName, 'Struct'); |
---|
71 | catch |
---|
72 | try |
---|
73 | % BPM response |
---|
74 | BPMy = getbpmresp('Filename', FileName, 'Struct'); |
---|
75 | BPMx = BPMy(1,1); |
---|
76 | catch |
---|
77 | try |
---|
78 | % Dispersion |
---|
79 | BPMx = getrespmat(BPMxFamily, 'RF', FileName, 'Struct'); |
---|
80 | BPMy = getrespmat(BPMyFamily, 'RF', FileName, 'Struct'); |
---|
81 | catch |
---|
82 | try |
---|
83 | % Chromaticity |
---|
84 | BPMx = load(FileName); |
---|
85 | catch |
---|
86 | disp('Not sure what type of file this is'); |
---|
87 | return |
---|
88 | end |
---|
89 | end |
---|
90 | end |
---|
91 | end |
---|
92 | end |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | if isfield(BPMx, 'CreatedBy') && (strcmpi(BPMx.CreatedBy, 'monbpm') || ... |
---|
97 | strcmpi(BPMx.CreatedBy, 'measbpmsigma')) |
---|
98 | |
---|
99 | if strcmpi(BPMx.CreatedBy, 'monbpm') |
---|
100 | % Definition of standard deviations |
---|
101 | BPMxStd = std(BPMx.Data, 0, 2); |
---|
102 | BPMyStd = std(BPMy.Data, 0, 2); |
---|
103 | |
---|
104 | % Difference orbit sigma |
---|
105 | BPMxSigma = BPMx.Sigma; |
---|
106 | BPMySigma = BPMy.Sigma; |
---|
107 | |
---|
108 | Mx = BPMx.Data; |
---|
109 | My = BPMy.Data; |
---|
110 | |
---|
111 | tout = BPMx.tout; |
---|
112 | elseif strcmpi(BPMx.CreatedBy, 'measbpmsigma') |
---|
113 | % Definition of standard deviations |
---|
114 | BPMxStd = std(BPMx.RawData, 0, 2); |
---|
115 | BPMyStd = std(BPMy.RawData, 0, 2); |
---|
116 | |
---|
117 | % Difference orbit sigma |
---|
118 | BPMxSigma = BPMx.Data; |
---|
119 | BPMySigma = BPMy.Data; |
---|
120 | |
---|
121 | Mx = BPMx.RawData; |
---|
122 | My = BPMy.RawData; |
---|
123 | |
---|
124 | tout = BPMx.DCCT.tout; |
---|
125 | else |
---|
126 | error('Not sure how to analyze this file'); |
---|
127 | end |
---|
128 | |
---|
129 | |
---|
130 | Mx0 = Mx(:,1); |
---|
131 | for i = 1:size(Mx,2) |
---|
132 | Mx(:,i) = Mx(:,i) - Mx0; |
---|
133 | end |
---|
134 | |
---|
135 | %tout = BPMy.tout; |
---|
136 | My0 = My(:,1); |
---|
137 | for i = 1:size(My,2) |
---|
138 | My(:,i) = My(:,i) - My0; |
---|
139 | end |
---|
140 | |
---|
141 | BPMxMax = max(Mx, [], 2); |
---|
142 | BPMyMax = max(My, [], 2); |
---|
143 | |
---|
144 | BPMxMin = min(Mx, [], 2); |
---|
145 | BPMyMin = min(My, [], 2); |
---|
146 | |
---|
147 | [Sector, Nsectors, Ndevices] = sectorticks(BPMx.DeviceList); |
---|
148 | |
---|
149 | h = gcf; |
---|
150 | figure(h); |
---|
151 | clf reset |
---|
152 | subplot(2,2,1); |
---|
153 | plot(tout, Mx); |
---|
154 | grid on; |
---|
155 | xaxis([0 max(tout)]); |
---|
156 | xlabel('Time [Seconds]'); |
---|
157 | ylabel(sprintf('Horizontal Data [%s]', BPMx.UnitsString)); |
---|
158 | |
---|
159 | subplot(2,2,3); |
---|
160 | plot(tout, My); |
---|
161 | grid on; |
---|
162 | xaxis([0 max(tout)]); |
---|
163 | xlabel('Time [Seconds]'); |
---|
164 | ylabel(sprintf('Vertical Data [%s]', BPMx.UnitsString)); |
---|
165 | |
---|
166 | subplot(2,2,2); |
---|
167 | plot(Sector, abs(BPMxMax),'k'); |
---|
168 | hold on |
---|
169 | plot(Sector, abs(BPMxMin),'r'); |
---|
170 | plot(Sector, BPMxStd,'g'); |
---|
171 | plot(Sector, BPMxSigma,'b'); |
---|
172 | hold off |
---|
173 | grid on; |
---|
174 | xaxis([1 Nsectors+1]) |
---|
175 | set(gca,'XTick',1:Nsectors); |
---|
176 | xlabel('Sector Number'); |
---|
177 | ylabel(sprintf('Horizontal [%s]', BPMx.UnitsString)); |
---|
178 | legend('abs(Max)','abs(Min)','std(Data)', 'std(Difference Orbits)',0) |
---|
179 | |
---|
180 | subplot(2,2,4); |
---|
181 | plot(Sector, abs(BPMyMax),'k'); |
---|
182 | hold on |
---|
183 | plot(Sector, abs(BPMyMin),'r'); |
---|
184 | plot(Sector, BPMyStd,'g'); |
---|
185 | plot(Sector, BPMySigma,'b'); |
---|
186 | hold off |
---|
187 | grid on; |
---|
188 | xaxis([1 Nsectors+1]) |
---|
189 | set(gca,'XTick',1:Nsectors); |
---|
190 | xlabel('Sector Number'); |
---|
191 | ylabel(sprintf('Vertical [%s]', BPMx.UnitsString)); |
---|
192 | legend('abs(Max)','abs(Min)','std(Data)', 'std(Difference Orbits)',0) |
---|
193 | |
---|
194 | addlabel(.5,1,sprintf('BPM Data'), 10); |
---|
195 | addlabel(1,0,sprintf('%s', datestr(BPMx.TimeStamp))); |
---|
196 | orient landscape |
---|
197 | |
---|
198 | h = h + 1; |
---|
199 | |
---|
200 | figure(h); |
---|
201 | clf reset |
---|
202 | subplot(2,1,1); |
---|
203 | bar(Sector, BPMxSigma); |
---|
204 | grid on; |
---|
205 | xaxis([1 Nsectors+1]) |
---|
206 | set(gca,'XTick',1:Nsectors); |
---|
207 | xlabel('Sector Number'); |
---|
208 | ylabel(sprintf('Horizontal STD [%s]', BPMx.UnitsString)); |
---|
209 | title(sprintf('BPM Standard Deviation of Difference Orbits / sqrt(2)')); |
---|
210 | |
---|
211 | subplot(2,1,2); |
---|
212 | bar(Sector, BPMySigma); |
---|
213 | grid on; |
---|
214 | grid on; |
---|
215 | xaxis([1 Nsectors+1]) |
---|
216 | set(gca,'XTick',1:Nsectors); |
---|
217 | xlabel('Sector Number'); |
---|
218 | ylabel(sprintf('Vertical STD [%s]', BPMx.UnitsString)); |
---|
219 | addlabel(1,0,sprintf('%s', datestr(BPMx.TimeStamp))); |
---|
220 | orient tall |
---|
221 | |
---|
222 | elseif isfield(BPMx, 'DataDescriptor') && strcmpi(BPMx.DataDescriptor, 'Dispersion') |
---|
223 | plotdisp(BPMx, BPMy); |
---|
224 | |
---|
225 | elseif isfield(BPMx, 'DataDescriptor') && strcmpi(BPMx.DataDescriptor, 'Chromaticity') |
---|
226 | plotchro(BPMx); |
---|
227 | |
---|
228 | elseif isfield(BPMx, 'DataDescriptor') && strcmpi(BPMx.DataDescriptor, 'Response Matrix') % strcmpi(BPMx.CreatedBy, 'measbpmresp') |
---|
229 | %if exist('plotbpmresp','file') |
---|
230 | % plotbpmresp(BPMy); |
---|
231 | %end |
---|
232 | figure; |
---|
233 | clf reset |
---|
234 | surf([BPMy(1,1).Data BPMy(1,2).Data; BPMy(2,1).Data BPMy(2,2).Data]); |
---|
235 | view(-70, 65); |
---|
236 | title('Orbit Response Matrix'); |
---|
237 | xlabel('CM Number'); |
---|
238 | ylabel('BPM Number'); |
---|
239 | addlabel(1,0,sprintf('%s', datestr(BPMy(1,1).TimeStamp))); |
---|
240 | |
---|
241 | elseif isfield(BPMx, 'QMS') |
---|
242 | quadplot(BPMx.QMS); |
---|
243 | |
---|
244 | elseif isfield(BPMx, 'Data') && isfield(BPMx, 'DataDescriptor') && isfield(BPMx, 'TimeStamp') |
---|
245 | h = gcf; |
---|
246 | figure(h); |
---|
247 | clf reset |
---|
248 | subplot(2,1,1); |
---|
249 | if size(BPMx.Data,2) > 1 |
---|
250 | plot(tout, BPMx.Data); |
---|
251 | xlabel('Time [Seconds]'); |
---|
252 | else |
---|
253 | [Sector, Nsectors, Ndevices] = sectorticks(BPMx.DeviceList); |
---|
254 | plot(Sector, BPMx.Data); |
---|
255 | xaxis([1 Nsectors+1]) |
---|
256 | set(gca,'XTick',1:Nsectors); |
---|
257 | xlabel('Sector Number'); |
---|
258 | end |
---|
259 | grid on; |
---|
260 | ylabel(sprintf('Horizontal [%s]', BPMx.UnitsString)); |
---|
261 | title(sprintf('%s', BPMx.DataDescriptor)); |
---|
262 | |
---|
263 | subplot(2,1,2); |
---|
264 | if size(BPMx.Data,2) > 1 |
---|
265 | plot(tout, BPMy.Data); |
---|
266 | xlabel('Time [Seconds]'); |
---|
267 | else |
---|
268 | [Sector, Nsectors, Ndevices] = sectorticks(BPMy.DeviceList); |
---|
269 | plot(Sector, BPMy.Data); |
---|
270 | xaxis([1 Nsectors+1]) |
---|
271 | set(gca,'XTick',1:Nsectors); |
---|
272 | xlabel('Sector Number'); |
---|
273 | end |
---|
274 | grid on; |
---|
275 | ylabel(sprintf('Vertical [%s]', BPMx.UnitsString)); |
---|
276 | title(sprintf('%s', BPMy.DataDescriptor)); |
---|
277 | addlabel(1,0,sprintf('%s', datestr(BPMx.TimeStamp))); |
---|
278 | orient tall |
---|
279 | |
---|
280 | else |
---|
281 | fprintf(' Not sure how to plot data file %s.\n', FileName); |
---|
282 | end |
---|
283 | |
---|