Debian Codegraph @

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

raw
1 package gov.fnal.eag.healpix.test;
2
3 import java.util.ArrayList;
4 import javax.vecmath.Vector3d;
5 import gov.fnal.eag.healpix.PixTools;
6 import gov.fnal.eag.healpix.Region;
7 import gov.fnal.eag.healpix.BitManipulation;
8 import junit.framework.TestCase;
9
10 /**
11 * @author kuropat
12 * Junit methods to test Region class
13 */
14 public class RegionTest extends TestCase {
15 private final static double TWOPI = 2.0 * Math.PI;
16 private final static double epsilon = 1.0e-10;
17 private BitManipulation bm = new BitManipulation();
18 /**
19 * test default constructor
20 */
21 public void testRegion() {
22 double xMin = 0.;
23 double xMax = 30.;
24 double yMin = 0.;
25 double yMax = 10.;
26 PixTools pt = new PixTools();
27 Region rg = new Region(xMin,xMax,yMin,yMax);
28 assertNotNull(rg);
29 double x = -10.;
30 double y = 15.;
31 assertFalse(rg.inReg(x,y));
32 x = 10.;
33 y = 5.;
34 assertTrue(rg.inReg(x,y));
35 xMax = -10.;
36 ArrayList vert = rg.getVertices();
37 double[][] vertPol = rg.getPolReg();
38 for ( int ind=0; ind<vert.size(); ind++) {
39 Vector3d vv = (Vector3d) vert.get(ind);
40 double [] vvAng = pt.Vect2Ang(vv);
41 if (vertPol[ind][1] < 0) vertPol[ind][1] += TWOPI;
42 double comp = bm.MODULO(vvAng[1], TWOPI) - epsilon;
43 assertEquals("theta ",vertPol[ind][0],vvAng[0], 1.0e-5);
44 assertEquals("phi ="+vertPol[ind][1],vertPol[ind][1],vvAng[1], 1.0e-5);
45 }
46 xMin = 20.;
47 xMax = 95.;
48 Region rg1 = new Region(xMin,xMax,yMin,yMax);
49 assertNotNull(rg1);
50 x = 45.;
51 y = 5.;
52 assertTrue(rg1.inReg(x,y));
53 }
54 /**
55 * test pixelization
56 *
57 */
58 public void testPixelize() {
59 System.out.println("test pixelize");
60 ArrayList pixels = new ArrayList();
61 double xMin = 10.;
62 double xMax = 60.;
63 double yMin = -20.0;
64 double yMax = 0.;
65 PixTools pt = new PixTools();
66 Region rg = new Region(xMin,xMax,yMin,yMax);
67 double[][] regCoord = rg.getPolReg();
68 for (int i = 0; i<regCoord.length; i++ ) {
69 System.out.println("thet="+regCoord[i][0]+" phi="+regCoord[i][1]);
70 }
71 double resolution = 10.*60.*60.; // resolution in arcsec (= 10 degrees)
72
73 try {
74 pixels = rg.pixelize(resolution);
75 long nside = pt.GetNSide(resolution);
76 int npix = pixels.size();
77 assertFalse(npix == 0);
78 System.out.println("npix="+npix);
79 for (int i=0; i<npix; i++) {
80 long pix = ((Long) pixels.get(i)).longValue();
81 System.out.println("pixel="+pix);
82 double[] pixpos = pt.pix2ang_ring(nside,pix);
83 System.out.println("theta="+pixpos[0]+" phi="+pixpos[1]);
84 double[] radec = pt.PolarToRaDec(pixpos);
85 double[][] pixvert = pt.pix2vertex_ring(nside,pix);
86 System.out.println("corners");
87 for (int j=0; j<pixvert[0].length; j++) {
88 double x = pixvert[0][j];
89 double y = pixvert[1][j];
90 double z = pixvert[2][j];
91 double[] pol = pt.xyzToPolar(x,y,z);
92 double[] radec1 = pt.PolarToRaDec(pol);
93 System.out.println("ra= "+radec1[0]+" dec="+radec1[1]);
94 }
95 System.out.println();
96
97 }
98
99 } catch (Exception e) {
100 System.err.println("Exception in pixelize");
101 e.printStackTrace();
102 }
103
104 }
105 }