mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
zernike_test.cpp
Go to the documentation of this file.
1/** \file zernike_test.cpp
2 */
3#include "../../catch2/catch.hpp"
4
5#include <Eigen/Dense>
6
7#define MX_NO_ERROR_REPORTS
8
9#include "../../../include/sigproc/zernike.hpp"
10
11/** Scenario: testing noll_nm
12 *
13 * Verify calculation of Noll nm values from j.
14 * Goes through each of the cases in Table 1 of \cite noll_1976
15 *
16 * \anchor tests_sigproc_zernike_noll_nm
17 */
18SCENARIO( "testing noll_nm", "[sigproc::zernike]" )
19{
20
21 GIVEN( "a j value" )
22 {
23 WHEN( "j==0" )
24 {
25 int m, n;
26 int rv = mx::sigproc::noll_nm( n, m, 0 );
27 REQUIRE( rv == -1 );
28 }
29
30 WHEN( "j==1" )
31 {
32 int m, n;
33 int rv = mx::sigproc::noll_nm( n, m, 1 );
34 REQUIRE( rv == 0 );
35 REQUIRE( n == 0 );
36 REQUIRE( m == 0 );
37 }
38
39 WHEN( "j==2" )
40 {
41 int m, n;
42 int rv = mx::sigproc::noll_nm( n, m, 2 );
43 REQUIRE( rv == 0 );
44 REQUIRE( n == 1 );
45 REQUIRE( m == 1 );
46 }
47
48 WHEN( "j==3" )
49 {
50 int m, n;
51 int rv = mx::sigproc::noll_nm( n, m, 3 );
52 REQUIRE( rv == 0 );
53 REQUIRE( n == 1 );
54 REQUIRE( m == -1 );
55 }
56
57 WHEN( "j==4" )
58 {
59 int m, n;
60 int rv = mx::sigproc::noll_nm( n, m, 4 );
61 REQUIRE( rv == 0 );
62 REQUIRE( n == 2 );
63 REQUIRE( m == 0 );
64 }
65
66 WHEN( "j==5" )
67 {
68 int m, n;
69 int rv = mx::sigproc::noll_nm( n, m, 5 );
70 REQUIRE( rv == 0 );
71 REQUIRE( n == 2 );
72 REQUIRE( m == -2 );
73 }
74
75 WHEN( "j==6" )
76 {
77 int m, n;
78 int rv = mx::sigproc::noll_nm( n, m, 6 );
79 REQUIRE( rv == 0 );
80 REQUIRE( n == 2 );
81 REQUIRE( m == 2 );
82 }
83
84 WHEN( "j==7" )
85 {
86 int m, n;
87 int rv = mx::sigproc::noll_nm( n, m, 7 );
88 REQUIRE( rv == 0 );
89 REQUIRE( n == 3 );
90 REQUIRE( m == -1 );
91 }
92
93 WHEN( "j==8" )
94 {
95 int m, n;
96 int rv = mx::sigproc::noll_nm( n, m, 8 );
97 REQUIRE( rv == 0 );
98 REQUIRE( n == 3 );
99 REQUIRE( m == 1 );
100 }
101
102 WHEN( "j==9" )
103 {
104 int m, n;
105 int rv = mx::sigproc::noll_nm( n, m, 9 );
106 REQUIRE( rv == 0 );
107 REQUIRE( n == 3 );
108 REQUIRE( m == -3 );
109 }
110
111 WHEN( "j==10" )
112 {
113 int m, n;
114 int rv = mx::sigproc::noll_nm( n, m, 10 );
115 REQUIRE( rv == 0 );
116 REQUIRE( n == 3 );
117 REQUIRE( m == 3 );
118 }
119
120 WHEN( "j==11" )
121 {
122 int m, n;
123 int rv = mx::sigproc::noll_nm( n, m, 11 );
124 REQUIRE( rv == 0 );
125 REQUIRE( n == 4 );
126 REQUIRE( m == 0 );
127 }
128
129 WHEN( "j==12" )
130 {
131 int m, n;
132 int rv = mx::sigproc::noll_nm( n, m, 12 );
133 REQUIRE( rv == 0 );
134 REQUIRE( n == 4 );
135 REQUIRE( m == 2 );
136 }
137
138 WHEN( "j==13" )
139 {
140 int m, n;
141 int rv = mx::sigproc::noll_nm( n, m, 13 );
142 REQUIRE( rv == 0 );
143 REQUIRE( n == 4 );
144 REQUIRE( m == -2 );
145 }
146
147 WHEN( "j==14" )
148 {
149 int m, n;
150 int rv = mx::sigproc::noll_nm( n, m, 14 );
151 REQUIRE( rv == 0 );
152 REQUIRE( n == 4 );
153 REQUIRE( m == 4 );
154 }
155
156 WHEN( "j==15" )
157 {
158 int m, n;
159 int rv = mx::sigproc::noll_nm( n, m, 15 );
160 REQUIRE( rv == 0 );
161 REQUIRE( n == 4 );
162 REQUIRE( m == -4 );
163 }
164
165 WHEN( "j==16" )
166 {
167 int m, n;
168 int rv = mx::sigproc::noll_nm( n, m, 16 );
169 REQUIRE( rv == 0 );
170 REQUIRE( n == 5 );
171 REQUIRE( m == 1 );
172 }
173
174 WHEN( "j==17" )
175 {
176 int m, n;
177 int rv = mx::sigproc::noll_nm( n, m, 17 );
178 REQUIRE( rv == 0 );
179 REQUIRE( n == 5 );
180 REQUIRE( m == -1 );
181 }
182
183 WHEN( "j==18" )
184 {
185 int m, n;
186 int rv = mx::sigproc::noll_nm( n, m, 18 );
187 REQUIRE( rv == 0 );
188 REQUIRE( n == 5 );
189 REQUIRE( m == 3 );
190 }
191
192 WHEN( "j==19" )
193 {
194 int m, n;
195 int rv = mx::sigproc::noll_nm( n, m, 19 );
196 REQUIRE( rv == 0 );
197 REQUIRE( n == 5 );
198 REQUIRE( m == -3 );
199 }
200
201 WHEN( "j==20" )
202 {
203 int m, n;
204 int rv = mx::sigproc::noll_nm( n, m, 20 );
205 REQUIRE( rv == 0 );
206 REQUIRE( n == 5 );
207 REQUIRE( m == 5 );
208 }
209
210 WHEN( "j==21" )
211 {
212 int m, n;
213 int rv = mx::sigproc::noll_nm( n, m, 21 );
214 REQUIRE( rv == 0 );
215 REQUIRE( n == 5 );
216 REQUIRE( m == -5 );
217 }
218
219 WHEN( "j==22" )
220 {
221 int m, n;
222 int rv = mx::sigproc::noll_nm( n, m, 22 );
223 REQUIRE( rv == 0 );
224 REQUIRE( n == 6 );
225 REQUIRE( m == 0 );
226 }
227
228 WHEN( "j==23" )
229 {
230 int m, n;
231 int rv = mx::sigproc::noll_nm( n, m, 23 );
232 REQUIRE( rv == 0 );
233 REQUIRE( n == 6 );
234 REQUIRE( m == -2 );
235 }
236
237 WHEN( "j==24" )
238 {
239 int m, n;
240 int rv = mx::sigproc::noll_nm( n, m, 24 );
241 REQUIRE( rv == 0 );
242 REQUIRE( n == 6 );
243 REQUIRE( m == 2 );
244 }
245
246 WHEN( "j==25" )
247 {
248 int m, n;
249 int rv = mx::sigproc::noll_nm( n, m, 25 );
250 REQUIRE( rv == 0 );
251 REQUIRE( n == 6 );
252 REQUIRE( m == -4 );
253 }
254
255 WHEN( "j==26" )
256 {
257 int m, n;
258 int rv = mx::sigproc::noll_nm( n, m, 26 );
259 REQUIRE( rv == 0 );
260 REQUIRE( n == 6 );
261 REQUIRE( m == 4 );
262 }
263 }
264}
265
266/** Scenario: testing zernikeQNorm
267 * Verify compilation and execution of zernikeQNorm.
268 * This does not validate the output.
269 * \anchor tests_sigproc_zernike_zernikeQNorm
270 */
271SCENARIO( "testing zernikeQNorm", "[sigproc::zernike]" )
272{
273 GIVEN( "an array" )
274 {
275 WHEN( "j==1" )
276 {
277 Eigen::Array<double, -1, -1> arr, k, phi;
278 arr.resize( 32, 32 );
279 k.resize( 32, 32 );
280 phi.resize( 32, 32 );
281
282 for( int i = 0; i < 32; ++i )
283 {
284 for( int j = 0; j < 32; ++j )
285 {
286 double kx = i - 5;
287 double ky = j - 15;
288 k( i, j ) = sqrt( kx * kx + ky * ky );
289 phi( i, j ) = atan( ky / kx );
290 }
291 }
292 int rv = mx::sigproc::zernikeQNorm( arr, k, phi, 1 );
293 REQUIRE( rv == 0 );
294 }
295 }
296}
int noll_nm(int &n, int &m, int j)
Get the Zernike coefficients n,m corrresponding the Noll index j.
Definition zernike.cpp:35
realT zernikeQNorm(realT k, realT phi, int n, int m)
Calculate the square-normed Fourier transform of a Zernike polynomial at position (k,...
Definition zernike.hpp:595
SCENARIO("testing noll_nm", "[sigproc::zernike]")