Mercurial > hg > ltpda
comparison m-toolbox/test/test_ao_removeVal.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % Test ao/removeVal for: | |
2 % - functionality | |
3 % | |
4 % M Hueller 10-03-10 | |
5 % | |
6 % $Id: test_ao_removeVal.m,v 1.1 2010/03/13 06:36:20 mauro Exp $ | |
7 % | |
8 | |
9 %% Start with an AO with no "bad" data in it | |
10 a_orig = ao(plist(... | |
11 'waveform', 'sinewave', ... | |
12 'Nsecs', 100, ... | |
13 'fs', 1, ... | |
14 'f', 0.02, ... | |
15 'yunits', 'V', ... | |
16 't0', '2010-03-10 20:00:00.000' ... | |
17 )) + 2; | |
18 a_orig.setName('original'); | |
19 | |
20 %% 1) Test the case where we remove only Inf, removing data | |
21 value = Inf; | |
22 % Prepare a list of index where we add the "bad" points | |
23 N = randi(10, 1); | |
24 bad_index = randi(numel(a_orig.x), N, 1); | |
25 | |
26 % Mix the AO with the "bad" values | |
27 y_orig = a_orig.y(); | |
28 y_bad = y_orig; | |
29 y_bad(bad_index) = value; | |
30 a_bad = a_orig.setY(y_bad); | |
31 a_bad.setName('corrupted'); | |
32 | |
33 % Run the ao/removeVal method | |
34 a_clean = a_bad.removeVal(plist('value', value)); | |
35 a_clean.setName('cleaned'); | |
36 | |
37 % Compare against the original: | |
38 % units | |
39 if ~eq(a_clean.yunits, a_bad.yunits) | |
40 disp('Warning: wrong yunits!'); | |
41 end | |
42 if ~eq(a_clean.xunits, a_bad.xunits) | |
43 disp('Warning: wrong xunits!'); | |
44 end | |
45 | |
46 % t0 | |
47 if ~eq(a_clean.t0, a_bad.t0) | |
48 disp('Warning: wrong t0!'); | |
49 end | |
50 | |
51 index = true(size(a_bad.x)); | |
52 index(bad_index) = false; | |
53 | |
54 % "good" values: x | |
55 x_clean = a_clean.x; | |
56 x_bad = a_bad.x; | |
57 if ~eq(x_bad(index), x_clean) | |
58 disp('Warning: wrong x values!'); | |
59 end | |
60 | |
61 % "good" values: y | |
62 y_clean = a_clean.y; | |
63 y_bad = a_bad.y; | |
64 if ~eq(y_bad(index), y_clean) | |
65 disp('Warning: wrong y values!'); | |
66 end | |
67 | |
68 %% 2) Test the case where we remove only NaN, removing data | |
69 value = NaN; | |
70 % Prepare a list of index where we add the "bad" points | |
71 N = randi(10, 1); | |
72 bad_index = randi(numel(a_orig.x), N, 1); | |
73 | |
74 % Mix the AO with the "bad" values | |
75 y_orig = a_orig.y(); | |
76 y_bad = y_orig; | |
77 y_bad(bad_index) = value; | |
78 a_bad = a_orig.setY(y_bad); | |
79 a_bad.setName('corrupted'); | |
80 | |
81 % Run the ao/removeVal method | |
82 a_clean = a_bad.removeVal(plist('value', value)); | |
83 a_clean.setName('cleaned'); | |
84 | |
85 % Compare against the original: | |
86 % units | |
87 if ~eq(a_clean.yunits, a_bad.yunits) | |
88 disp('Warning: wrong yunits!'); | |
89 end | |
90 if ~eq(a_clean.xunits, a_bad.xunits) | |
91 disp('Warning: wrong xunits!'); | |
92 end | |
93 | |
94 % t0 | |
95 if ~eq(a_clean.t0, a_bad.t0) | |
96 disp('Warning: wrong t0!'); | |
97 end | |
98 | |
99 index = true(size(a_bad.x)); | |
100 index(bad_index) = false; | |
101 | |
102 % "good" values: x | |
103 x_clean = a_clean.x; | |
104 x_bad = a_bad.x; | |
105 if ~eq(x_bad(index), x_clean) | |
106 disp('Warning: wrong x values!'); | |
107 end | |
108 | |
109 % "good" values: y | |
110 y_clean = a_clean.y; | |
111 y_bad = a_bad.y; | |
112 if ~eq(y_bad(index), y_clean) | |
113 disp('Warning: wrong y values!'); | |
114 end | |
115 | |
116 | |
117 %% 3) Test the case where we remove only 0s, removing data | |
118 value = 0; | |
119 % Prepare a list of index where we add the "bad" points | |
120 N = randi(10, 1); | |
121 bad_index = randi(numel(a_orig.x), N, 1); | |
122 | |
123 % Mix the AO with the "bad" values | |
124 y_orig = a_orig.y(); | |
125 y_bad = y_orig; | |
126 y_bad(bad_index) = value; | |
127 a_bad = a_orig.setY(y_bad); | |
128 a_bad.setName('corrupted'); | |
129 | |
130 % Run the ao/removeVal method | |
131 a_clean = a_bad.removeVal(plist('value', value)); | |
132 a_clean.setName('cleaned'); | |
133 | |
134 % Compare against the original: | |
135 % units | |
136 if ~eq(a_clean.yunits, a_bad.yunits) | |
137 disp('Warning: wrong yunits!'); | |
138 end | |
139 if ~eq(a_clean.xunits, a_bad.xunits) | |
140 disp('Warning: wrong xunits!'); | |
141 end | |
142 | |
143 % t0 | |
144 if ~eq(a_clean.t0, a_bad.t0) | |
145 disp('Warning: wrong t0!'); | |
146 end | |
147 | |
148 index = true(size(a_bad.x)); | |
149 index(bad_index) = false; | |
150 | |
151 % "good" values: x | |
152 x_clean = a_clean.x; | |
153 x_bad = a_bad.x; | |
154 if ~eq(x_bad(index), x_clean) | |
155 disp('Warning: wrong x values!'); | |
156 end | |
157 | |
158 % "good" values: y | |
159 y_clean = a_clean.y; | |
160 y_bad = a_bad.y; | |
161 if ~eq(y_bad(index), y_clean) | |
162 disp('Warning: wrong y values!'); | |
163 end | |
164 | |
165 | |
166 %% 4) Test the case where we remove Inf AND NaN AND 0s, removing data | |
167 % Prepare a list of index where we add the "bad" points | |
168 N_nan = randi(10, 1); | |
169 N_inf = randi(10, 1); | |
170 N_zeros = randi(10, 1); | |
171 nan_index = randi(numel(a_orig.x), N_nan, 1); | |
172 inf_index = randi(numel(a_orig.x), N_inf, 1); | |
173 zeros_index = randi(numel(a_orig.x), N_zeros, 1); | |
174 | |
175 % Mix the AO with NaN, Inf, and 0s inside | |
176 y_orig = a_orig.y(); | |
177 y_bad = y_orig; | |
178 y_bad(nan_index) = NaN; | |
179 y_bad(inf_index) = Inf; | |
180 y_bad(zeros_index) = 0; | |
181 a_bad = a_orig.setY(y_bad); | |
182 a_bad.setName('corrupted'); | |
183 | |
184 % Run the ao/removeVal method | |
185 value = [Inf NaN 0]; | |
186 a_clean = a_bad.removeVal(plist('value', value)); | |
187 a_clean.setName('cleaned'); | |
188 | |
189 % Compare against the original | |
190 % units | |
191 if ~eq(a_clean.yunits, a_bad.yunits) | |
192 disp('Warning: wrong yunits!'); | |
193 end | |
194 if ~eq(a_clean.xunits, a_bad.xunits) | |
195 disp('Warning: wrong xunits!'); | |
196 end | |
197 | |
198 % t0 | |
199 if ~eq(a_clean.t0, a_bad.t0) | |
200 disp('Warning: wrong t0!'); | |
201 end | |
202 | |
203 index = true(size(a_bad.x)); | |
204 index(nan_index) = false; | |
205 index(inf_index) = false; | |
206 index(zeros_index) = false; | |
207 | |
208 % "good" values: x | |
209 x_clean = a_clean.x; | |
210 x_bad = a_bad.x; | |
211 if ~eq(x_bad(index), x_clean) | |
212 disp('Warning: wrong x values!'); | |
213 end | |
214 | |
215 % "good" values: y | |
216 y_clean = a_clean.y; | |
217 y_bad = a_bad.y; | |
218 if ~eq(y_bad(index), y_clean) | |
219 disp('Warning: wrong y values!'); | |
220 end | |
221 | |
222 % plots the original, "bad", and "clean" data | |
223 iplot(a_orig, a_bad, a_clean, plist('LineStyles', {'-', '-', 'None'}, 'Markers', {'.', '.', 'o'})); | |
224 | |
225 %% 5) Test the case where we remove Inf AND NaN AND 0s, interpolating data | |
226 % Prepare a list of index where we add the "bad" points | |
227 N_nan = randi(10, 1); | |
228 N_inf = randi(10, 1); | |
229 N_zeros = randi(10, 1); | |
230 nan_index = randi(numel(a_orig.x), N_nan, 1); | |
231 inf_index = randi(numel(a_orig.x), N_inf, 1); | |
232 zeros_index = randi(numel(a_orig.x), N_zeros, 1); | |
233 | |
234 % Mix the AO with NaN, Inf, and 0s inside | |
235 y_orig = a_orig.y(); | |
236 y_bad = y_orig; | |
237 y_bad(nan_index) = NaN; | |
238 y_bad(inf_index) = Inf; | |
239 y_bad(zeros_index) = 0; | |
240 a_bad = a_orig.setY(y_bad); | |
241 a_bad.setName('corrupted'); | |
242 | |
243 % Run the ao/removeVal method | |
244 value = [Inf NaN 0]; | |
245 a_clean = a_bad.removeVal(plist('value', value, 'method', 'interp')); | |
246 a_clean.setName('cleaned'); | |
247 | |
248 % Compare against the original | |
249 % units | |
250 if ~eq(a_clean.yunits, a_bad.yunits) | |
251 disp('Warning: wrong yunits!'); | |
252 end | |
253 if ~eq(a_clean.xunits, a_bad.xunits) | |
254 disp('Warning: wrong xunits!'); | |
255 end | |
256 | |
257 % t0 | |
258 if ~eq(a_clean.t0, a_bad.t0) | |
259 disp('Warning: wrong t0!'); | |
260 end | |
261 | |
262 % plots the original, "bad", and "clean" data | |
263 iplot(a_orig, a_bad, a_clean, plist('LineStyles', {'-', '-', 'None'}, 'Markers', {'.', '.', 'o'})); | |
264 |