Debian Codegraph @

gov/fnal/eag/healpix/test/PixToolsTest.java

raw
1 /*
2 * Created on Mar 10, 2005
3 * Modified on December 2007
4 *
5 */
6 package gov.fnal.eag.healpix.test;
7
8 import java.io.File;
9 import java.io.FileNotFoundException;
10 import java.io.OutputStream;
11 import java.io.PrintStream;
12 import java.util.ArrayList;
13 import gov.fnal.eag.healpix.BitManipulation;
14 import gov.fnal.eag.healpix.PixTools;
15
16 import javax.vecmath.Vector3d;
17
18 import junit.framework.TestCase;
19
20 /**
21 * test suit for PixTools
22 *
23 * @author N. Kuropatkin
24 *
25 */
26
27 public class PixToolsTest extends TestCase {
28
29 /**
30 * test MODULO function
31 */
32 public void testMODULO() {
33 double A = 8.;
34 double B = 5.;
35 double res = BitManipulation.MODULO(A, B);
36 assertEquals("modulo = " + res, 3., res, 1e-10);
37 A = -8.;
38 B = 5.;
39 res = BitManipulation.MODULO(A, B);
40 assertEquals("modulo = " + res, 2., res, 1e-10);
41 A = 8.;
42 B = -5.;
43 res = BitManipulation.MODULO(A, B);
44 assertEquals("modulo = " + res, -2., res, 1e-10);
45 A = -8.;
46 B = -5.;
47 res = BitManipulation.MODULO(A, B);
48 assertEquals("modulo = " + res, -3., res, 1e-10);
49 System.out.println(" test MODULO is done");
50 }
51
52 /**
53 * tests angular distance calculation
54 * @throws Exception
55 */
56 public void testAngDist() throws Exception {
57 Vector3d v1 = new Vector3d(1.5, 1.6, 2.0);
58 Vector3d v2 = new Vector3d(1.2, 1.0, 1.5);
59 PixTools pt = new PixTools();
60 double res1 = pt.AngDist(v1, v2);
61 double res2 = v1.angle(v2);
62 System.out.println("res1 = " + res1 + " res2=" + res2);
63 assertEquals("angular Distance=" + res2, 1.0, res1 / res2, 1e-10);
64
65
66 Vector3d v3 = new Vector3d(1.5, 1.6, 0.);
67 Vector3d v4 = new Vector3d(1.5, 1.601, 0.);
68 double res3 = pt.AngDist(v3, v4);
69 double res4 = v3.angle(v4);
70 //
71 System.out.println("res3 = " + res3 + " res4=" + res4);
72 assertEquals("angular Distance=" + res4, 1., res3/res4, 1e-3);
73 Vector3d v5 = new Vector3d(1.5, 1.6, 0.);
74 Vector3d v6 = new Vector3d(-1.5, -1.75, 0.);
75 double res5 = pt.AngDist(v5, v6);
76 double res6 = v5.angle(v6);
77 System.out.println("res5 = " + res5 + " res6=" + res6);
78 assertEquals("angular Distance=" + res6, 1.0, res5 / res6, 1e-10);
79 System.out.println(" test of AngDist is done");
80 }
81
82 /**
83 * @throws Exception
84 */
85 public void testSurfaceTriangle() throws Exception {
86 Vector3d v1 = new Vector3d(1.0, 0.0, 0.0);
87 Vector3d v2 = new Vector3d(0.0, 1.0, 0.0);
88 Vector3d v3 = new Vector3d(0.0, 0.0, 1.0);
89 PixTools pt = new PixTools();
90 double res = pt.SurfaceTriangle(v1, v2, v3);
91 System.out.println("Triangle surface is=" + res / Math.PI
92 + " steredians");
93 assertEquals("Triangle surface=" + res, 0.5, res / Math.PI, 1e-10);
94 System.out.println(" test of SurfaceTriangle is done");
95 }
96
97 /**
98 * tests calculation of npixels from nside
99 */
100 public void testNside2Npix() {
101 int nside = 1;
102 int npix = 0;
103 PixTools pt = new PixTools();
104 npix = (int) pt.Nside2Npix(nside);
105 assertEquals("Npix=" + npix, 12, npix, 1e-10);
106 nside = 2;
107 npix = (int) pt.Nside2Npix(nside);
108 assertEquals("Npix=" + npix, 48, npix, 1e-10);
109 }
110
111 /**
112 * tests calculation of nsides from npixels
113 */
114 public void testNpix2Nside() {
115 int npix = 12;
116 int nside = 0;
117 PixTools pt = new PixTools();
118 nside = (int) pt.Npix2Nside(npix);
119
120 double pixSize1 = pt.PixRes(65536);
121 long nside1 = pt.GetNSide(pixSize1);
122 assertEquals("Nside=" + nside1, 65536, nside1, 1e-10);
123
124 assertEquals("Nside=" + nside, 1, nside, 1e-10);
125
126 }
127
128 /**
129 * test of directional angles calculation
130 */
131 public void testVec2Ang() {
132 double PI = Math.PI;
133 Vector3d v = new Vector3d(0.0, 1.0, 0.0);
134 PixTools pt = new PixTools();
135 double[] ang_tup = { 0., 0. };
136 ang_tup = pt.Vect2Ang(v);
137 System.out.println(" Theta=" + ang_tup[0] / PI + " Phi=" + ang_tup[1]
138 / PI);
139 assertEquals("Theta=" + ang_tup[0], 0.5, ang_tup[0] / PI, 1e-10);
140 assertEquals("Phi=" + ang_tup[1], 0.5, ang_tup[1] / PI, 1e-10);
141 v = new Vector3d(1.0, 0.0, 0.0);
142 ang_tup = pt.Vect2Ang(v);
143 assertEquals("phi=" + ang_tup[1], 0., ang_tup[1] / PI, 1e-10);
144 System.out.println(" test Vect2Ang is done");
145 }
146
147 /**
148 * tests calculation of pixel from polar angles
149 * in ring schema of pixalization
150 * @throws Exception
151 */
152 public void testAng2Pix() throws Exception {
153 System.out.println(" Test ang2pix_ring ___________________");
154 double PI = Math.PI;
155 long pix = -1;
156 double theta = PI / 2. - 0.2;
157 double phi = PI / 2. ;
158 long nside = 4;
159 PixTools pt = new PixTools();
160 try {
161 pix = pt.ang2pix_ring(nside,theta, phi);
162 } catch (Exception e) {
163 e.printStackTrace();
164 }
165 Vector3d v = pt.Ang2Vec(theta,phi);
166 long pix1 = pt.vect2pix_ring(nside,v);
167 assertEquals("pix=" + pix, pix1, pix, 1e-10);
168 assertEquals("pix=" + pix, 76, pix, 1e-10);
169
170 long pix2 = pt.ang2pix_nest(nside,theta,phi);
171 long pix3 = pt.vect2pix_nest(nside,v);
172 assertEquals("pix2=" + pix2, pix3, pix2, 1e-10);
173 assertEquals("pix2=" + pix2, 92, pix2, 1e-10);
174
175
176 double[] radec = pt.pix2ang_ring(nside,76);
177 assertEquals("theta=" + theta, theta, radec[0], 4e-2);
178 assertEquals("phi=" + phi, radec[1], phi, 1e-2);
179 double[] radec1 = pt.pix2ang_nest(nside,92);
180 System.out.println("theta="+radec1[0]+" phi="+radec1[1]);
181 assertEquals("theta=" + theta, theta, radec1[0], 4e-2);
182 assertEquals("phi=" + phi, radec1[1], phi, 1e-2);
183 System.out.println(" test Ang2Pix is done");
184 }
185
186 /**
187 * tests calculation of unit vector from polar angles
188 * @throws Exception
189 */
190 public void testAng2Vect() throws Exception {
191 System.out.println(" Start test Ang2Vect----------------");
192 double PI = Math.PI;
193 double theta = PI / 2.;
194 double phi = PI / 2;
195 PixTools pt = new PixTools();
196 Vector3d v = pt.Ang2Vec(theta, phi);
197 System.out.println("Vector x=" + v.x + " y=" + v.y + " z=" + v.z);
198 assertEquals("x=" + v.x, 0., v.x, 1e-10);
199 assertEquals("y=" + v.y, 1., v.y, 1e-10);
200 assertEquals("z=" + v.z, 0., v.z, 1e-10);
201 System.out.println(" test Ang2Vect is done");
202 }
203
204 /**
205 * tests calculation of ring number from z coordinate
206 * @throws Exception
207 */
208 public void testRingNum() throws Exception {
209 double z = 0.25;
210 int nside = 1;
211 System.out.println("Start test RingNum !!!!!!!!!!!!!!!!!!!!");
212 PixTools pt = new PixTools();
213 int nring = (int) pt.RingNum(nside, z);
214 System.out.println("z=" + z + " ring number =" + nring);
215 assertEquals("z=" + z, 2, nring, 1e-10);
216 z = -0.25;
217 nring = (int) pt.RingNum(nside, z);
218 assertEquals("z=" + z, 2, nring, 1e-10);
219 z = 0.8;
220 nring = (int) pt.RingNum(nside, z);
221 assertEquals("z=" + z, 1, nring, 1e-10);
222 z = -0.8;
223 nring = (int) pt.RingNum(nside, z);
224 assertEquals("z=" + z, 3, nring, 1e-10);
225 System.out.println(" test RingNum is done");
226 nside = 4;
227 int pix = 3;
228 Vector3d v = pt.pix2vect_ring(nside, pix);
229 z = v.z;
230 nring = (int) pt.RingNum(nside, z);
231 assertEquals("z=" + z, 1, nring, 1e-10);
232 pix = 11;
233 v = pt.pix2vect_ring(nside, pix);
234 z = v.z;
235 nring = (int) pt.RingNum(nside, z);
236 assertEquals("z=" + z, 2, nring, 1e-10);
237 pix = 23;
238 v = pt.pix2vect_ring(nside, pix);
239 z = v.z;
240 nring = (int) pt.RingNum(nside, z);
241 assertEquals("z=" + z, 3, nring, 1e-10);
242 pix = 39;
243 v = pt.pix2vect_ring(nside, pix);
244 z = v.z;
245 nring = (int) pt.RingNum(nside, z);
246 assertEquals("z=" + z, 4, nring, 1e-10);
247 pix = 55;
248 v = pt.pix2vect_ring(nside, pix);
249 z = v.z;
250 nring = (int) pt.RingNum(nside, z);
251 assertEquals("z=" + z, 5, nring, 1e-10);
252 pix = 71;
253 v = pt.pix2vect_ring(nside, pix);
254 z = v.z;
255 nring = (int) pt.RingNum(nside, z);
256 assertEquals("z=" + z, 6, nring, 1e-10);
257 pix = 87;
258 v = pt.pix2vect_ring(nside, pix);
259 z = v.z;
260 nring = (int) pt.RingNum(nside, z);
261 assertEquals("z=" + z, 7, nring, 1e-10);
262 pix = 103;
263 v = pt.pix2vect_ring(nside, pix);
264 z = v.z;
265 nring = (int) pt.RingNum(nside, z);
266 assertEquals("z=" + z, 8, nring, 1e-10);
267 pix = 119;
268 v = pt.pix2vect_ring(nside, pix);
269 z = v.z;
270 nring = (int) pt.RingNum(nside, z);
271 assertEquals("z=" + z, 9, nring, 1e-10);
272 pix = 135;
273 v = pt.pix2vect_ring(nside, pix);
274 z = v.z;
275 nring = (int) pt.RingNum(nside, z);
276 assertEquals("z=" + z, 10, nring, 1e-10);
277 pix = 151;
278 v = pt.pix2vect_ring(nside, pix);
279 z = v.z;
280 nring = (int) pt.RingNum(nside, z);
281 assertEquals("z=" + z, 11, nring, 1e-10);
282 pix = 167;
283 v = pt.pix2vect_ring(nside, pix);
284 z = v.z;
285 nring = (int) pt.RingNum(nside, z);
286 assertEquals("z=" + z, 12, nring, 1e-10);
287 pix = 169;
288 v = pt.pix2vect_ring(nside, pix);
289 z = v.z;
290 nring = (int) pt.RingNum(nside, z);
291 assertEquals("z=" + z, 13, nring, 1e-10);
292 pix = 180;
293 v = pt.pix2vect_ring(nside, pix);
294 z = v.z;
295 nring = (int) pt.RingNum(nside, z);
296 assertEquals("z=" + z, 14, nring, 1e-10);
297 System.out.println("End test RingNum");
298 }
299
300 /**
301 * tests conversion from nest schema pixel to ring schema pixel
302 * @throws Exception
303 */
304 public void testNest2Ring() throws Exception {
305 PixTools pt = new PixTools();
306 int ipnest = 3;
307 int nside = 2;
308 int ipring = (int) pt.nest2ring(nside, ipnest);
309 assertEquals("ipring=" + ipring, 0, ipring, 1e-10);
310 ipnest = 0;
311 nside = 2;
312 ipring = (int) pt.nest2ring(nside, ipnest);
313 assertEquals("ipring=" + ipring, 13, ipring, 1e-10);
314 ipnest = 18;
315 nside = 2;
316 ipring = (int) pt.nest2ring(nside, ipnest);
317 assertEquals("ipring=" + ipring, 27, ipring, 1e-10);
318 ipnest = 23;
319 nside = 2;
320 ipring = (int) pt.nest2ring(nside, ipnest);
321 assertEquals("ipring=" + ipring, 14, ipring, 1e-10);
322 ipnest = 5;
323 nside = 4;
324 ipring = (int) pt.nest2ring(nside, ipnest);
325 assertEquals("ipring = " + ipring, 27, ipring, 1e-10);
326 System.out.println(" test Nest2Ring is done");
327 }
328
329 /**
330 * tests conversion from ring schema pixel to nest schema pixel
331 * @throws Exception
332 */
333 public void testRing2Nest() throws Exception {
334 PixTools pt = new PixTools();
335 System.out.println(" start test Ring2Nest !!!!!!!!!!!!!!!!!!!!!!");
336 int ipring = 0;
337 int nside = 2;
338
339 int ipnest = (int) pt.ring2nest(nside, ipring);
340 assertEquals("ipnest=" + ipnest, 3, ipnest, 1e-10);
341 ipring = 13;
342 nside = 2;
343 ipnest = (int) pt.ring2nest(nside, ipring);
344 assertEquals("ipnest=" + ipnest, 0, ipnest, 1e-10);
345 ipring = 27;
346 nside = 2;
347 ipnest = (int) pt.ring2nest(nside, ipring);
348 assertEquals("ipnest=" + ipnest, 18, ipnest, 1e-10);
349 ipring = 14;
350 nside = 2;
351 ipnest = (int) pt.ring2nest(nside, ipring);
352 assertEquals("ipnest=" + ipnest, 23, ipnest, 1e-10);
353 ipring = 27;
354 nside = 4;
355 ipnest = (int) pt.ring2nest(nside, ipring);
356 assertEquals("ipnest = " + ipnest, 5, ipnest, 1e-10);
357 ipring = 83;
358 nside = 4;
359 ipnest = (int) pt.ring2nest(nside, ipring);
360 assertEquals("ipnest = " + ipnest, 123, ipnest, 1e-10);
361 System.out.println(" test Ring2Nest is done");
362 }
363
364 /**
365 * tests Next_In_Line method for the nest schema
366 * @throws Exception
367 */
368 public void testNext_In_Line_Nest() throws Exception {
369 PixTools pt = new PixTools();
370 int ipix = 0;
371 int nside = 2;
372 int ipnext = (int) pt.next_in_line_nest(nside, ipix);
373 assertEquals("ipnext=" + ipnext, 23, ipnext, 1e-10);
374 ipix = 1;
375 nside = 2;
376 ipnext = (int) pt.next_in_line_nest(nside, ipix);
377 assertEquals("ipnext=" + ipnext, 6, ipnext, 1e-10);
378 ipix = 4;
379 nside = 2;
380 ipnext = (int) pt.next_in_line_nest(nside, ipix);
381 assertEquals("ipnext=" + ipnext, 27, ipnext, 1e-10);
382 ipix = 27;
383 nside = 2;
384 ipnext = (int) pt.next_in_line_nest(nside, ipix);
385 assertEquals("ipnext=" + ipnext, 8, ipnext, 1e-10);
386 ipix = 12;
387 nside = 2;
388 ipnext = (int) pt.next_in_line_nest(nside, ipix);
389 assertEquals("ipnext=" + ipnext, 19, ipnext, 1e-10);
390 ipix = 118;
391 nside = 4;
392 ipnext = (int) pt.next_in_line_nest(nside, ipix);
393 assertEquals("ipnext = " + ipnext, 117, ipnext, 1e-10);
394 System.out.println(" test next_in_line_nest is done");
395 }
396
397 /**
398 * tests InRing method
399 * @throws Exception
400 */
401 public void testInRing() throws Exception {
402 System.out.println(" Start test InRing !!!!!!!!!!!!!!!!!!!!!!!!!");
403 PixTools pt = new PixTools();
404 int[] nestComp = { 19, 0, 23, 4, 27, 8, 31, 12 };
405 long[] ringHi = {17, 18, 19, 12, 13 };
406 long[] nestHi = { 8, 31, 12, 19, 0 };
407 long[] ringLow = {19, 12, 13, 14, 15 };
408 long[] nestLow = { 12, 19, 0, 23, 4 };
409 double PI = Math.PI;
410 int nside = 2;
411 boolean nest = false;
412 int iz = 3;
413 double phi = PI;
414 double dphi = PI;
415 ArrayList ring = pt.InRing(nside, iz, phi, dphi, nest);
416 for (int i = 0; i < ring.size(); i++) {
417 assertEquals("ipnext = " + ((Long) ring.get(i)).longValue(),
418 i + 12, ((Long) ring.get(i)).longValue(), 1e-10);
419 }
420 Vector3d v = new Vector3d(1., 0., 0.);
421 double[] ang_tup = { 0., 0. };
422 ang_tup = pt.Vect2Ang(v);
423 phi = ang_tup[1]/PI;
424 ring = pt.InRing(nside, iz, phi, dphi, nest);
425 for (int i = 0; i < ring.size(); i++) {
426 assertEquals("ipnext = " + ((Long) ring.get(i)).longValue(),
427 i + 12, ((Long) ring.get(i)).longValue(), 1e-10);
428 }
429 Vector3d v1 = new Vector3d(-1., 0., 0.);
430
431 ang_tup = pt.Vect2Ang(v1);
432 phi = ang_tup[1]/PI;
433 ring = pt.InRing(nside, iz, phi, dphi, nest);
434 for (int i = 0; i < ring.size(); i++) {
435 assertEquals("ipnext = " + ((Long) ring.get(i)).longValue(),
436 i + 12, ((Long) ring.get(i)).longValue(), 1e-10);
437 }
438 phi = 1.75*PI;
439 dphi = 0.5*PI;
440 ring = pt.InRing(nside, iz, phi, dphi, nest);
441 for (int i = 0; i < ring.size(); i++) {
442 assertEquals("ipnext = " + ((Long) ring.get(i)).longValue(),
443 ringHi[i], ((Long) ring.get(i)).longValue(), 1e-10);
444
445 }
446
447 phi = 1.75*PI;
448 dphi = 0.5*PI;
449 nest = true;
450 ring = pt.InRing(nside, iz, phi, dphi, nest);
451 for (int i = 0; i < ring.size(); i++) {
452 assertEquals("ipnext = " + ((Long) ring.get(i)).longValue(),
453 nestHi[i], ((Long) ring.get(i)).longValue(), 1e-10);
454
455 }
456 phi = 0.25*PI;
457 dphi = 0.5*PI;
458 nest = false;
459 ring = pt.InRing(nside, iz, phi, dphi, nest);
460 for (int i = 0; i < ring.size(); i++) {
461 assertEquals("ipnext = " + ((Long) ring.get(i)).longValue(),
462 ringLow[i], ((Long) ring.get(i)).longValue(), 1e-10);
463
464 }
465 phi = 0.25*PI;
466 dphi = 0.5*PI;
467 nest = true;
468 ring = pt.InRing(nside, iz, phi, dphi, nest);
469 for (int i = 0; i < ring.size(); i++) {
470 assertEquals("ipnext = " + ((Long) ring.get(i)).longValue(),
471 nestLow[i], ((Long) ring.get(i)).longValue(), 1e-10);
472
473 }
474
475 nest = true;
476 dphi = PI;
477 ring = pt.InRing(nside, iz, phi, dphi, nest);
478 for (int i = 0; i < ring.size(); i++) {
479 assertEquals("ipnext = " + ((Long) ring.get(i)).longValue(),
480 nestComp[i], ((Long) ring.get(i)).longValue(), 1e-10);
481 }
482 nest = false;
483 nside = 4;
484 phi = 2.1598449493429825;
485 iz = 8;
486 dphi = 0.5890486225480867;
487 // System.out.println(" iz="+iz+" phi="+phi+" dphi="+dphi);
488 ring = pt.InRing(nside, iz, phi, dphi, nest);
489 // for (int i = 0; i<ring.size(); i++) {
490 // System.out.println("ipnext = "+ ((Integer)ring.get(i)).intValue());
491 // }
492 nest = false;
493 nside = 4;
494 dphi = 0. * PI;
495 iz = 8;
496 phi = 2.1598449493429825;
497 // System.out.println(" iz="+iz+" phi="+phi+" dphi="+dphi);
498 ring = pt.InRing(nside, iz, phi, dphi, nest);
499 // for (int i = 0; i<ring.size(); i++) {
500 // System.out.println("ipnext = "+ ((Integer)ring.get(i)).intValue());
501 // }
502 System.out.println(" test InRing is done");
503 }
504
505 /**
506 * tests Neighbour's method for nest schema of the pixelization
507 * @throws Exception
508 */
509 public void testNeighbours_Nest() throws Exception {
510 System.out.println(" Start test Neighbours_Nest !!!!!!!!!!!!!!!!!");
511 PixTools pt = new PixTools();
512 long nside = 2;
513 long ipix = 25;
514 long[] test17 = { 34, 16, 18, 19, 2, 0, 22, 35 };
515 long[] test32 = { 40, 44, 45, 34, 35, 33, 38, 36 };
516 long[] test3 = { 0, 2, 13, 15, 11, 7, 6, 1 };
517 long[] test25 = { 42, 24, 26, 27, 10, 8, 30, 43 };
518 //
519 ArrayList npixList = new ArrayList();
520 npixList = pt.neighbours_nest(nside, ipix);
521 for (int i = 0; i < npixList.size(); i++) {
522 assertEquals("ip = " + ((Long) npixList.get( i)).longValue(),
523 test25[ i], ((Long) npixList.get( i)).longValue(), 1e-10);
524 }
525 ipix = 17;
526
527 npixList = pt.neighbours_nest(nside, ipix);
528 for (int i = 0; i < npixList.size(); i++) {
529 assertEquals("ip = " + ((Long) npixList.get(i)).longValue(),
530 test17[i], ((Long) npixList.get(i)).longValue(), 1e-10);
531 }
532 ipix = 32;
533
534 npixList = pt.neighbours_nest(nside, ipix);
535 for (int i = 0; i < npixList.size(); i++) {
536 assertEquals("ip = " + ((Long) npixList.get(i)).longValue(),
537 test32[i], ((Long) npixList.get(i)).longValue(), 1e-10);
538 }
539 ipix = 3;
540
541 npixList = pt.neighbours_nest(nside, ipix);
542 for (int i = 0; i < npixList.size(); i++) {
543 assertEquals("ip = " + ((Long) npixList.get(i)).longValue(),
544 test3[i], ((Long) npixList.get(i)).longValue(), 1e-10);
545 }
546 System.out.println(" test NeighboursNest is done");
547 }
548
549 /**
550 * tests intrs_intrv method
551 * @throws Exception
552 */
553 public void testIntrs_Intrv() throws Exception {
554 System.out.println(" test intrs_intrv !!!!!!!!!!!!!!!!!!!!!!!!!!!");
555 PixTools pt = new PixTools();
556 double[] d1 = { 1.0, 9.0 };
557 double[] d2 = { 3.0, 16.0 };
558 double[] di;
559 // System.out.println("Case "+d1[0]+" "+d1[1]+" | "+d2[0]+" "+d2[1]);
560 di = pt.intrs_intrv(d1, d2);
561 // System.out.println("Result "+di[0]+" - "+di[1]);
562 int n12 = di.length / 2;
563 assertEquals("n12 = " + n12, 1, n12, 1e-6);
564 assertEquals("di[0] = " + di[0], 3.0, di[0], 1e-6);
565 assertEquals("di[1] = " + di[1], 9.0, di[1], 1e-6);
566 d1 = new double[] { 0.537, 4.356 };
567 d2 = new double[] { 3.356, 0.8 };
568 // System.out.println("Case "+d1[0]+" "+d1[1]+" | "+d2[0]+" "+d2[1]);
569 di = pt.intrs_intrv(d1, d2);
570 n12 = di.length / 2;
571 assertEquals("n12 = " + n12, 2, n12, 1e-6);
572 assertEquals("di[0] = " + di[0], 0.537, di[0], 1e-6);
573 assertEquals("di[1] = " + di[1], 0.8, di[1], 1e-6);
574 assertEquals("di[2] = " + di[2], 3.356, di[2], 1e-6);
575 assertEquals("di[1] = " + di[3], 4.356, di[3], 1e-6);
576
577 d1 = new double[] { 2.356194490092345, 2.356194490292345 };
578 d2 = new double[] { 1.251567, 4.17 };
579 // System.out.println("Case "+d1[0]+" "+d1[1]+" | "+d2[0]+" "+d2[1]);
580 di = pt.intrs_intrv(d1, d2);
581 n12 = di.length / 2;
582 assertEquals("n12 = " + n12, 1, n12, 1e-6);
583 assertEquals("di[0] = " + di[0], 2.35619449009, di[0], 1e-6);
584 assertEquals("di[1] = " + di[1], 2.35619449029, di[1], 1e-6);
585
586 System.out.println(" test intrs_intrv is done");
587 }
588
589 /**
590 * tests conversion from pixel number to vector
591 * @throws Exception
592 */
593 public void testPix2Vect_ring() throws Exception {
594 System.out.println("Start test Pix2Vect_ring !!!!!!!!!!!!!!!!!!!");
595 double TWOPI = 2.0 * Math.PI;
596 int nside = 2;
597 int ipix = 0;
598 PixTools pt = new PixTools();
599 Vector3d v1 = new Vector3d(0., 0., 0.);
600 v1 = pt.pix2vect_ring(nside, ipix);
601 assertEquals("v1.z = " + v1.z, 1.0, v1.z, 1e-1);
602
603 ipix = 20;
604 Vector3d v2 = new Vector3d(0., 0., 0.);
605 v2 = pt.pix2vect_ring(nside, ipix);
606 assertEquals("v2.x = " + v2.x, 1.0, v2.x, 1e-1);
607 assertEquals("v2.z = " + v2.z, 0.0, v2.z, 1e-1);
608 ipix = 22;
609 Vector3d v3 = new Vector3d();
610 v3 = pt.pix2vect_ring(nside, ipix);
611 assertEquals("v3.y = " + v3.y, 1.0, v3.y, 1e-1);
612 assertEquals("v3.z = " + v3.z, 0.0, v3.z, 1e-1);
613 // System.out.println("Vector3 x="+v3.x+" y="+v3.y+" z="+v3.z);
614 ipix = 95;
615 nside = 4;
616 v1 = pt.pix2vect_ring(nside, ipix);
617 v1.normalize();
618 double phi1 = Math.atan2(v1.y, v1.x);
619 double[] tetphi = new double[2];
620 tetphi = pt.pix2ang_ring(nside, ipix);
621 assertEquals("phi = " + phi1, 0.0, Math.abs(phi1 - tetphi[1]), 1e-10);
622 ipix = 26;
623 nside = 4;
624 v1 = pt.pix2vect_ring(nside, ipix);
625 v1.normalize();
626 phi1 = Math.atan2(v1.y, v1.x);
627 if (phi1 < 0.)
628 phi1 += TWOPI;
629 tetphi = new double[2];
630 tetphi = pt.pix2ang_ring(nside, ipix);
631 assertEquals("phi = " + phi1, 0.0, Math.abs(phi1 - tetphi[1]), 1e-10);
632 System.out.println("------------------------------------------");
633 System.out.println(" test pix2vect_ring is done");
634 }
635
636 /**
637 * tests conversion from pixel number to vector
638 * @throws Exception
639 */
640 public void testPix2Vect_nest() throws Exception {
641 double TWOPI = 2.0 * Math.PI;
642 int nside = 2;
643 int ipix = 3;
644 System.out.println(" Start test Pix2Vect_nest !!!!!!!!!!!!!!");
645 PixTools pt = new PixTools();
646 Vector3d v1 = new Vector3d(0., 0., 0.);
647 v1 = pt.pix2vect_nest(nside, ipix);
648 assertEquals("v1.z = " + v1.z, 1.0, v1.z, 1e-1);
649 ipix = 17;
650 Vector3d v2 = new Vector3d(0., 0., 0.);
651 v2 = pt.pix2vect_nest(nside, ipix);
652 assertEquals("v2.x = " + v2.x, 1.0, v2.x, 1e-1);
653 assertEquals("v2.z = " + v2.z, 0.0, v2.z, 1e-1);
654
655 ipix = 21;
656 Vector3d v3 = new Vector3d();
657 v3 = pt.pix2vect_nest(nside, ipix);
658 assertEquals("v3.y = " + v3.y, 1.0, v3.y, 1e-1);
659 assertEquals("v3.z = " + v3.z, 0.0, v3.z, 1e-1);
660 nside = 4;
661 ipix = 105;
662 v1 = pt.pix2vect_nest(nside, ipix);
663 v1.normalize();
664 double phi1 = Math.atan2(v1.y, v1.x);
665 if (phi1 < 0.)
666 phi1 += TWOPI;
667 double[] tetphi = new double[2];
668 tetphi = pt.pix2ang_nest(nside, ipix);
669 assertEquals("phi = " + phi1, 0.0, Math.abs(phi1 - tetphi[1]), 1e-10);
670 nside = 4;
671 ipix = 74;
672 v1 = pt.pix2vect_nest(nside, ipix);
673 v1.normalize();
674 phi1 = Math.atan2(v1.y, v1.x);
675 if (phi1 < 0.)
676 phi1 += TWOPI;
677 tetphi = new double[2];
678 tetphi = pt.pix2ang_nest(nside, ipix);
679 assertEquals("phi = " + phi1, 0.0, Math.abs(phi1 - tetphi[1]), 1e-10);
680
681 System.out.println(" test pix2vect_nest is done");
682 System.out.println("-------------------------------------------");
683 }
684
685 /**
686 * tests conversion from vector to pixel number
687 * @throws Exception
688 */
689 public void testVect2Pix_ring() throws Exception {
690 System.out.println("Start test Vect2Pix_ring !!!!!!!!!!!!!!!!!!!");
691
692 long nside = 4;
693 long ipix = 83;
694 long respix = 0;
695 PixTools pt = new PixTools();
696 Vector3d v1 = new Vector3d(0., 0., 0.);
697 v1 = pt.pix2vect_ring(nside, ipix);
698 respix = (int) pt.vect2pix_ring(nside, v1);
699 assertEquals("respix = " + respix, 83, respix, 1e-10);
700 // Hi resolution test
701 long nside1 = 1 << 20;
702 long maxpix= pt.Nside2Npix(nside1);
703 System.out.println("nside="+nside1+" maxpix="+maxpix);
704 Vector3d v2 = new Vector3d( -0.704, 0.580, 0.408);
705 respix = pt.vect2pix_ring(nside1, v2); // ring pixel
706 long respixN = pt.ring2nest(nside1, respix); // convert to nest
707 long respixNC = pt.vect2pix_nest(nside1,v2); // nest pixel from the same vector
708 long respixR = pt.nest2ring(nside1, respixN); // convert pixel
709 System.out.println(" orig="+respix+" doubleT="+respixR+" nest="+respixN+" correct nest="+respixNC);
710 assertEquals("ringpix = " + respix, respix, respixR);
711 assertEquals("nestpix = " + respixNC, respixNC, respixN);
712 System.out.println("------------------------------------------");
713 System.out.println(" test vect2pix_ring is done");
714 }
715
716 /**
717 * tests conversion from vector to pixel number
718 * @throws Exception
719 */
720 public void testVect2Pix_nest() throws Exception {
721 System.out.println("Start test Vect2Pix_nest !!!!!!!!!!!!!!!!!!!");
722 long nside = 4;
723 long ipix = 83;
724 long respix = 0;
725 PixTools pt = new PixTools();
726 Vector3d v1 = new Vector3d(0., 0., 0.);
727 v1 = pt.pix2vect_ring(nside, ipix);
728 respix = (int) pt.vect2pix_nest(nside, v1);
729 assertEquals("respix = " + respix, 123, respix, 1e-10);
730 //
731 long nside1 = 1 << 20;
732 long maxpix= pt.Nside2Npix(nside1);
733 System.out.println("nside="+nside1+" maxpix="+maxpix);
734 Vector3d v2 = new Vector3d( -0.704, 0.580, 0.408);
735 respix = pt.vect2pix_nest(nside1, v2);
736 long respixRC = pt.vect2pix_ring(nside1, v2);
737 long respixR = pt.nest2ring(nside1, respix);
738 long respixN = pt.ring2nest(nside1, respixRC);
739 System.out.println(" orig="+respix+" doubleT="+respixN+" ring="+respixR+" correct ring="+respixRC);
740 assertEquals("ringpix = " + respixRC, respixRC, respixR);
741 assertEquals("nestpix = " + respix, respix, respixN);
742 System.out.println("------------------------------------------");
743 System.out.println(" test vect2pix_nest is done");
744 }
745
746 /**
747 * tests Query_Strip method
748 * @throws Exception
749 */
750 public void testQuery_Strip() throws Exception {
751 System.out.println(" Start test query Strip !!!!!!!!!!!!!!!!");
752 PixTools pt = new PixTools();
753 int[] pixel1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
754 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
755 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
756 48, 49, 50, 51, 52, 53, 54, 55 };
757 int nside = 4;
758 int nest = 0;
759 double theta1 = 0.0;
760 double theta2 = Math.PI / 4.0 + 0.2;
761 ArrayList pixlist;
762 pixlist = pt.query_strip(nside, theta1, theta2, nest);
763 int nlist = pixlist.size();
764 for (int i = 0; i < nlist; i++) {
765 long ipix = ((Long) pixlist.get(i)).longValue();
766 assertEquals("pixel = " + ipix, pixel1[i], ipix, 1e-10);
767 }
768
769 System.out.println(" test query_strip is done");
770
771 }
772
773 /**
774 * tests Query_Disc method
775 * @throws Exception
776 */
777 public void testQuery_Disc() throws Exception {
778 System.out.println(" Start test query_disc !!!!!!!!!!!!!!!!!!!!!");
779 PixTools pt = new PixTools();
780 long nside = 4;
781 int nest = 0;
782 long ipix = 0;
783
784
785 int[] pixel1 = { 45, 46, 60, 61, 62, 77, 78, 92, 93, 94,
786 109, 110, 124, 125, 126, 141, 142
787 };
788
789
790
791 int[] pixel2 = { 24, 19, 93, 18, 17, 87, 16,86, 85,
792 106, 84, 159, 81, 158, 157, 155, 156
793 };
794
795
796 int[] pixel3 = {52, 79, 49, 78, 77, 75, 76, 74, 73, 70,
797 72, 67, 189, 66, 65, 183, 64
798 };
799 int inclusive = 1;
800 double radius = Math.PI / 8.0;
801 Vector3d v = pt.pix2vect_ring(nside, 93);
802 ArrayList pixlist;
803 pixlist = pt.query_disc(nside, v, radius, nest, inclusive);
804
805 int nlist = pixlist.size();
806
807 for (int i = 0; i < nlist; i++) {
808 ipix = ((Long) pixlist.get(i)).longValue();
809 // System.out.println("i="+i+"pixel="+ipix+" pixel1="+pixel1[i]);
810 assertEquals("pixel = " + ipix, pixel1[i], ipix, 1e-10);
811 }
812 radius = Math.PI/2.0;
813 nest = 0;
814 v = new Vector3d(1.0,0.0,0.0);
815 ArrayList pixlistT = pt.query_disc(2, v, radius, nest, inclusive);
816
817 radius = Math.PI / 8.0;
818 v = pt.pix2vect_ring(nside, 93);
819 nest = 1;
820 ArrayList pixlist2 = pt.query_disc(nside, v, radius, nest, inclusive);
821
822 int nlist2 = pixlist2.size();
823 assertEquals("npix="+nlist, nlist, nlist2, 1e-10);
824 for (int i = 0; i < nlist2; i++) {
825 ipix = ((Long) pixlist2.get(i)).longValue();
826
827 assertEquals("pixel = " + ipix, pixel2[i], ipix, 1e-10);
828
829 }
830
831 v = pt.pix2vect_ring(nside, 103);
832 nest = 1;
833 inclusive = 1;
834 ArrayList pixlist3 = pt.query_disc(nside, v, radius, nest, inclusive);
835 nlist = pixlist3.size();
836 assertEquals("npix="+nlist, nlist, pixel3.length, 1e-10);
837
838 for (int i = 0; i < pixlist3.size(); i++) {
839 ipix = ((Long) pixlist3.get(i)).longValue();
840
841 assertEquals("pixel = " + ipix, pixel3[i], ipix, 1e-10);
842 }
843
844
845 for (int i=0; i<pixel1.length; i++) {
846 long ipixR = pixel1[i];
847 long ipixT = pt.ring2nest(nside, ipixR);
848 assertEquals("pixel="+ipixT, ipixT, pixel2[i], 1e-10);
849 long ipixN = pt.nest2ring(nside, ipixT);
850 assertEquals("pixel="+ipixN, ipixN, pixel1[i], 1e-10);
851 }
852 System.out.println(" End query_disk test ______________________________");
853 }
854
855 /**
856 * tests Query_Triangle method
857 * @throws Exception
858 */
859 public void testQuery_Triangle() throws Exception {
860 PixTools pt = new PixTools();
861 long nside = 4;
862 int nest = 0;
863 long ipix = 0;
864 int[] pixel1 = { 57, 58, 59, 60, 61, 62, 74, 75, 76, 77, 78, 90, 91,
865 92, 93, 107, 108, 109, 123, 124, 140 };
866 int[] pixel2 = { 88, 89, 90, 91, 105, 106, 107, 108, 121, 122, 123,
867 138, 139, 154 };
868 int[] pixel3 = { 49, 64, 80, 81, 95, 96, 112, 113,
869 127, 128, 142, 143, 144, 145 };
870 int[] pixel4 = { 36, 52, 53, 67, 68, 69, 83, 84, 85, 86, 98, 99, 100,
871 101, 102, 114, 115, 116, 117, 118, 119, 129, 130, 131, 132,
872 133, 134, 135 };
873 int[] pixel5 = { 58, 127, 56, 126, 125, 50, 123, 124, 119, 48, 122,
874 121, 118, 117, 74, 175, 120, 115, 116, 191, 72, 174, 173, 114,
875 113, 190, 189, 66 };
876 int[] pixel6 = { 110, 123, 124, 125, 140, 141, 156 };
877 int[] pixel7 = { 53, 68, 69 };
878 long pix1 = 62;
879 long pix2 = 57;
880 long pix3 = 140;
881 System.out.println("Start test Query Triangle !!!!!!!!!!!!!!!!!!!!");
882 Vector3d v11 = pt.pix2vect_ring(nside, pix1);
883
884 Vector3d v22 = pt.pix2vect_ring(nside, pix2);
885
886 Vector3d v33 = pt.pix2vect_ring(nside, pix3);
887
888 // System.out.println("nside="+nside+" triangle pixels "+pix1+" "+pix2+"
889 // "+pix3);
890 int inclusive = 0;
891
892 ArrayList pixlist;
893 pixlist = pt.query_triangle(nside, v11, v22, v33, nest, inclusive);
894
895 int nlist = pixlist.size();
896
897 for (int i = 0; i < nlist; i++) {
898 ipix = ((Long) pixlist.get(i)).longValue();
899
900 assertEquals("pixel = " + ipix, pixel1[i], ipix, 1e-10);
901 }
902 pix1 = 92;
903 pix2 = 88;
904 pix3 = 154;
905 v11 = pt.pix2vect_ring(nside, pix1);
906 v22 = pt.pix2vect_ring(nside, pix2);
907 v33 = pt.pix2vect_ring(nside, pix3);
908
909 inclusive = 0;
910 ArrayList pixlist1;
911 pixlist1 = pt.query_triangle(nside, v11, v22, v33, nest, inclusive);
912
913 nlist = pixlist1.size();
914
915 for (int i = 0; i < nlist; i++) {
916 ipix = ((Long) pixlist1.get(i)).longValue();
917 // System.out.println(ipix);
918 assertEquals("pixel = " + ipix, pixel2[i], ipix, 1e-10);
919 }
920 pix1 = 49;
921 pix2 = 142;
922 pix3 = 145;
923 v11 = pt.pix2vect_ring(nside, pix1);
924 v22 = pt.pix2vect_ring(nside, pix2);
925 v33 = pt.pix2vect_ring(nside, pix3);
926
927 inclusive = 0;
928 ArrayList pixlist2;
929 pixlist2 = pt.query_triangle(nside, v11, v22, v33, nest, inclusive);
930
931 nlist = pixlist2.size();
932
933 for (int i = 0; i < nlist; i++) {
934 ipix = ((Long) pixlist2.get(i)).longValue();
935 // System.out.println(ipix);
936 assertEquals("pixel = " + ipix, pixel3[i], ipix, 1e-10);
937 }
938 pix1 = 36;
939 pix2 = 129;
940 pix3 = 135;
941 v11 = pt.pix2vect_ring(nside, pix1);
942 v22 = pt.pix2vect_ring(nside, pix2);
943 v33 = pt.pix2vect_ring(nside, pix3);
944
945 inclusive = 0;
946
947 pixlist2 = pt.query_triangle(nside, v11, v22, v33, nest, inclusive);
948
949 nlist = pixlist2.size();
950
951 for (int i = 0; i < nlist; i++) {
952 ipix = ((Long) pixlist2.get(i)).longValue();
953 assertEquals("pixel = " + ipix, pixel4[i], ipix, 1e-10);
954 }
955 pix1 = 36;
956 pix2 = 129;
957 pix3 = 135;
958 nest = 1;
959 v11 = pt.pix2vect_ring(nside, pix1);
960 v22 = pt.pix2vect_ring(nside, pix2);
961 v33 = pt.pix2vect_ring(nside, pix3);
962 inclusive = 0;
963
964 pixlist2 = pt.query_triangle(nside, v11, v22, v33, nest, inclusive);
965
966 nlist = pixlist2.size();
967
968 for (int i = 0; i < nlist; i++) {
969 ipix = ((Long) pixlist2.get(i)).longValue();
970 // System.out.println("ipix="+ipix);
971 assertEquals("pixel = " + ipix, pixel5[i], ipix, 1e-10);
972 }
973 pix1 = 123;
974 pix2 = 156;
975 pix3 = 110;
976 nest = 0;
977 v11 = pt.pix2vect_ring(nside, pix1);
978 v22 = pt.pix2vect_ring(nside, pix2);
979 v33 = pt.pix2vect_ring(nside, pix3);
980 inclusive = 0;
981
982 pixlist2 = pt.query_triangle(nside, v11, v22, v33, nest, inclusive);
983
984 nlist = pixlist2.size();
985
986 for (int i = 0; i < nlist; i++) {
987 ipix = ((Long) pixlist2.get(i)).longValue();
988 assertEquals("pixel = " + ipix, pixel6[i], ipix, 1e-10);
989 // System.out.println("i="+i+" pixel#="+ipix);
990 }
991 pix1 = 69;
992 pix2 = 53;
993 pix3 = 68;
994 nest = 0;
995 v11 = pt.pix2vect_ring(nside, pix1);
996 v22 = pt.pix2vect_ring(nside, pix2);
997 v33 = pt.pix2vect_ring(nside, pix3);
998 inclusive = 0;
999
1000 pixlist2 = pt.query_triangle(nside, v11, v22, v33, nest, inclusive);
1001
1002 nlist = pixlist2.size();
1003
1004 for (int i = 0; i < nlist; i++) {
1005 ipix = ((Long) pixlist2.get(i)).longValue();
1006 assertEquals("pixel = " + ipix, pixel7[i], ipix, 1e-10);
1007 // System.out.println("i="+i+" pixel#="+ipix);
1008 }
1009 System.out.println(" test query_triangle is done");
1010
1011 }
1012
1013 /**
1014 * tests Query_Poligon method
1015 * @throws Exception
1016 */
1017 public void testQuery_Polygon() throws Exception {
1018 PixTools pt = new PixTools();
1019 long nside = 4;
1020 int nest = 0;
1021 long ipix = 0;
1022 int inclusive = 0;
1023 int[] result = { 51, 52, 53, 66, 67, 68, 69, 82, 83, 84, 85, 86, 98,
1024 99, 100, 101, 115, 116, 117 };
1025 int[] result1 = { 55, 70, 71, 87 };
1026 int[] result2 = { 137, 152, 153, 168 };
1027 int[] result3 = { 27, 43, 44, 58, 59, 60, 74, 75, 76, 77, 89, 90, 91,
1028 92, 93, 105, 106, 107, 108, 109, 110, 121, 122, 123, 124, 125,
1029 138, 139, 140, 141, 154, 156 };
1030
1031
1032 System.out.println("Start test query_polygon !!!!!!!!!!!!!!!!!!!!!!");
1033 ArrayList vlist = new ArrayList();
1034 Vector3d v = pt.pix2vect_ring(nside, 53);
1035 vlist.add( v);
1036 v = pt.pix2vect_ring(nside, 51);
1037 vlist.add( v);
1038 v = pt.pix2vect_ring(nside, 82);
1039 vlist.add( v);
1040 v = pt.pix2vect_ring(nside, 115);
1041 vlist.add( v);
1042 v = pt.pix2vect_ring(nside, 117);
1043 vlist.add( v);
1044 v = pt.pix2vect_ring(nside, 86);
1045 vlist.add( v);
1046
1047 ArrayList pixlist;
1048 pixlist = pt.query_polygon(nside, vlist, nest, inclusive);
1049 // System.out.println(" List size="+pixlist.size());
1050 int nlist = pixlist.size();
1051 // System.out.println(" Pixel list:");
1052 for (int i = 0; i < nlist; i++) {
1053 ipix = ((Long) pixlist.get(i)).longValue();
1054 assertEquals("pixel = " + ipix, result[i], ipix, 1e-10);
1055 // System.out.println("i="+i+" pixel # "+ipix);
1056 }
1057
1058 /* Yet another test */
1059
1060 ArrayList vlist1 = new ArrayList();
1061 v = pt.pix2vect_ring(nside, 71);
1062 vlist1.add( v);
1063 v = pt.pix2vect_ring(nside, 55);
1064 vlist1.add( v);
1065 v = pt.pix2vect_ring(nside, 70);
1066 vlist1.add( v);
1067 v = pt.pix2vect_ring(nside, 87);
1068 vlist1.add( v);
1069 pixlist = pt.query_polygon(nside, vlist1, nest, inclusive);
1070
1071 nlist = pixlist.size();
1072
1073 for (int i = 0; i < nlist; i++) {
1074 ipix = ((Long) pixlist.get(i)).longValue();
1075 // System.out.println("i="+i+" pixel # "+ipix);
1076 assertEquals("pixel = " + ipix, result1[i], ipix, 1e-10);
1077 }
1078
1079 /* Yet another test */
1080 ArrayList vlist2 = new ArrayList();
1081 v = pt.pix2vect_ring(nside, 153);
1082 vlist2.add( v);
1083 v = pt.pix2vect_ring(nside, 137);
1084 vlist2.add( v);
1085 v = pt.pix2vect_ring(nside, 152);
1086 vlist2.add( v);
1087 v = pt.pix2vect_ring(nside, 168);
1088 vlist2.add( v);
1089 pixlist = pt.query_polygon(nside, vlist2, nest, inclusive);
1090
1091 nlist = pixlist.size();
1092
1093 for (int i = 0; i < nlist; i++) {
1094 ipix = ((Long) pixlist.get(i)).longValue();
1095 assertEquals("pixel = " + ipix, result2[i], ipix, 1e-10);
1096 // System.out.println("i="+i+" pixel # "+ipix);
1097 }
1098 /* Yet another test */
1099
1100 ArrayList vlist3 = new ArrayList();
1101 v = pt.pix2vect_ring(nside, 110);
1102 vlist3.add( v);
1103 v = pt.pix2vect_ring(nside, 27);
1104 vlist3.add( v);
1105 v = pt.pix2vect_ring(nside, 105);
1106 vlist3.add( v);
1107 v = pt.pix2vect_ring(nside, 154);
1108 vlist3.add( v);
1109 v = pt.pix2vect_ring(nside, 123);
1110 vlist3.add( v);
1111 v = pt.pix2vect_ring(nside, 156);
1112 vlist3.add( v);
1113 pixlist = pt.query_polygon(nside, vlist3, nest, inclusive);
1114
1115 nlist = pixlist.size();
1116
1117 for (int i = 0; i < nlist; i++) {
1118 ipix = ((Long) pixlist.get(i)).longValue();
1119 assertEquals("pixel = " + ipix, result3[i], ipix, 1e-10);
1120 // System.out.println("i="+i+" pixel # "+ipix);
1121 }
1122 System.out.println(" test query_polygon is done");
1123
1124 }
1125 /**
1126 * tests MaxResolution method
1127 */
1128 public void testMaxResolution() {
1129 System.out.println(" Start test MaxRes !!!!!!!!!!!!!!!!!!!!!");
1130
1131 long nside = 1048576;
1132 PixTools pt = new PixTools();
1133 double res = pt.PixRes(nside);
1134 System.out.println("Minimum size of the pixel side is "+res+" arcsec.");
1135 assertEquals("res = " + res, 0.2, res, 1e-1);
1136 long nsideR = pt.GetNSide(res);
1137 assertEquals("nside = " + nside, nside, nsideR, 1e-1);
1138 System.out.println(" End of MaxRes test _______________________");
1139 }
1140 /**
1141 * tests QueryDiscResolution method
1142 * @throws Exception
1143 */
1144 public void testQueryDiscRes() throws Exception {
1145 System.out.println(" Start test DiscRes !!!!!!!!!!!!!!!!!!!!!");
1146 PixTools pt = new PixTools();
1147
1148 int nest = 0;
1149 long ipix = 0;
1150
1151 int inclusive = 0;
1152 double theta= Math.PI;
1153 double phi = Math.PI;
1154 double radius = Math.toRadians(0.2/3600.); // One arcse
1155 long nside = pt.GetNSide(radius);
1156 System.out.println(" calculated nside="+nside);
1157 long cpix = pt.ang2pix_ring(nside,theta,phi);
1158 Vector3d vc = pt.pix2vect_ring(nside, cpix);
1159 ArrayList pixlist;
1160 pixlist = pt.query_disc(nside, vc, radius, nest, inclusive);
1161
1162 int nlist = pixlist.size();
1163 for (int i = 0; i < nlist; i++) {
1164 ipix = ((Long) pixlist.get(i)).longValue();
1165 Vector3d v = pt.pix2vect_ring(nside,ipix);
1166 double dist = pt.AngDist(v,vc);
1167 assertTrue(dist<=2.*radius);
1168 }
1169 cpix = pt.ang2pix_nest(nside,theta,phi);
1170 Vector3d vc1 = pt.pix2vect_nest(nside, cpix);
1171 ArrayList pixlist1;
1172 nest = 1;
1173 radius *=4;
1174 pixlist1 = pt.query_disc(nside, vc1, radius, nest, inclusive);
1175 int nlist1 = pixlist1.size();
1176 for (int i = 0; i < nlist1; i++) {
1177 ipix = ((Long) pixlist1.get(i)).longValue();
1178 Vector3d v = pt.pix2vect_nest(nside,ipix);
1179 double dist = pt.AngDist(v,vc1);
1180 assertTrue(dist<=2.*radius);
1181 }
1182 System.out.println(" test query disk is done -------------------");
1183 }
1184 /**
1185 * test Query_disk check for consistency in the query for RING/NESTED
1186 */
1187 public void testQuery_disk2() {
1188 System.out.println(" Start test query_disk HiRes!!!!!!!!!!!!!!!!!!!!!!!!");
1189 PixTools pt = new PixTools();
1190 long nside = 1 << 20 ;
1191 double res = pt.PixRes(nside);
1192 System.out.println("nside="+nside+" sresolution="+res);
1193 double radius = Math.toRadians(res/3600.)/2.;
1194 System.out.println("radius="+radius);
1195 Vector3d v1 = new Vector3d(-0.704, 0.580, 0.408);
1196 System.out.println("!!!!!!!!!!!!! NESTED !!!!!!!!!!!");
1197 ArrayList diskQ = pt.query_disc(nside,
1198 v1,
1199 radius, 1,1); // inclusive query at vector point
1200 assertEquals("npixels = " + diskQ.size(), 8, diskQ.size() , 1e-1);
1201 long pix1 = pt.vect2pix_nest(nside, v1);
1202 Vector3d v2 = pt.pix2vect_nest(nside, pix1); // vector to pix center
1203 //
1204 ArrayList diskQ2 = pt.query_disc(nside,
1205 v2,
1206 radius, 1,1); // inclusive with point at pixel center
1207 assertEquals("npixels = " + diskQ2.size(), 9, diskQ2.size() , 1e-1);
1208
1209 //
1210 ArrayList diskQ3 = pt.query_disc(nside,
1211 v2,
1212 radius, 1,0); // exclusive with point at pixel center
1213 assertEquals("npixels = " + diskQ3.size(), 1, diskQ3.size() , 1e-1);
1214
1215 // RING schema
1216 System.out.println("!!!!!!!!!!!!! RING !!!!!!!!!!!");
1217 ArrayList diskQ4 = pt.query_disc(nside,
1218 v1,
1219 radius, 0,1); // inclusiv at vector point
1220 assertEquals("npixels = " + diskQ4.size(), 8, diskQ4.size() , 1e-1);
1221 //
1222
1223 ArrayList diskQ5 = pt.query_disc(nside,
1224 v2,
1225 radius, 0, 1); // inclusive at pixel center
1226 assertEquals("npixels = " + diskQ5.size(), 9, diskQ5.size() , 1e-1);
1227
1228 // System.out.println("n pixels in disk5 ="+diskQ5.size());
1229 ArrayList diskQ6 = pt.query_disc(nside,
1230 v2,
1231 radius, 0,0); // exclusive at pixel center
1232 assertEquals("npixels = " + diskQ6.size(), 1, diskQ6.size() , 1e-1);
1233 //
1234 // test HiRes conversions
1235 //
1236 Vector3d pos = new Vector3d( -0.704, 0.580, 0.408 );
1237
1238 nside = 1 << 20;
1239 System.out.println("HiRes transformation tests: nside="+nside);
1240 ArrayList nestPixels = pt.query_disc(nside, pos, radius, 1, 1);
1241 ArrayList ringPixels = pt.query_disc(nside, pos, radius, 0, 1);
1242 assertEquals(nestPixels.size(), ringPixels.size());
1243 for(int i=0; i< ringPixels.size(); i++) {
1244 long iring = ((Number)ringPixels.get(i)).longValue();
1245 Vector3d cv = pt.pix2vect_ring(nside, iring);
1246 long inest = pt.ring2nest(nside, iring);
1247 long inestC = ((Number)nestPixels.get(i)).longValue();
1248 Vector3d cvN = pt.pix2vect_nest(nside, inestC);
1249 long iringT = pt.nest2ring(nside, inestC);
1250 assertEquals(iring,iringT);
1251 assertEquals(inest,inestC);
1252 assertEquals(" Xv="+cv.x,cv.x,cvN.x,1.e-10);
1253 assertEquals(" Yv="+cv.y,cv.y,cvN.y,1.e-10);
1254 assertEquals(" Zv="+cv.z,cv.z,cvN.z,1.e-10);
1255 // System.out.println(" inest orig="+inestC+" transformed="+inest+" iring orig="+iring+" transf="+iringT);
1256 // System.out.println("Vector cv vs cvN x="+cv.x+" cvN.x="+cvN.x);
1257 // System.out.println("Vector cv vs cvN y="+cv.y+" cvN.y="+cvN.y);
1258 // System.out.println("Vector cv vs cvN z="+cv.z+" cvN.z="+cvN.z);
1259 double[] tetphiR = pt.pix2ang_ring(nside, iring);
1260 double[] tetphiN= pt.pix2ang_nest(nside, inestC);
1261 assertEquals(" theta="+tetphiR[0],tetphiR[0],tetphiN[0],1.e-10);
1262 assertEquals(" phi="+tetphiR[1],tetphiR[1],tetphiN[1],1.e-10);
1263 // System.out.println("theta R vs N "+tetphiR[0]+" "+tetphiN[0]);
1264 // System.out.println("phi R vs N "+tetphiR[1]+" "+tetphiN[1]);
1265 }
1266
1267 System.out.println(" End test of query_disc2____________________________");
1268
1269 }
1270 /**
1271 * tests GetNside method
1272 */
1273 public void testGetNside() {
1274 System.out.println(" Start test GetNside !!!!!!!!!!!!!!!!!!!!!");
1275
1276 double pixsize = 0.3;
1277 PixTools pt = new PixTools();
1278 long nside = pt.GetNSide(pixsize);
1279 System.out.println("Requared nside is "+nside);
1280 assertEquals("nside = " + nside, 1048576, nside, 1e-1);
1281 System.out.println(" End of GetNSide test _______________________");
1282 }
1283
1284
1285 /**
1286 * test conversion of Ra Dec to polar coordinates
1287 */
1288 public void testRaDecToPolar() {
1289 System.out.println(" Start test RaDecToPolar !!!!!!!!!!!!!!!!!!!!!");
1290 PixTools pt = new PixTools();
1291 double [] radec = new double[2];
1292 radec[0] = 312.115456;
1293 radec[1] = -1.153759;
1294 double[] polar = pt.RaDecToPolar(radec);
1295 assertEquals("theta = " + polar[0], 1.5909332201194137, polar[0], 1e-10);
1296 assertEquals("phi = " + polar[1], 5.447442353563491, polar[1], 1e-10);
1297 System.out.println("End test RaDecToPolar__________________________");
1298
1299 }
1300 }
1301