| 1 |
package gov.fnal.eag.healpix.test; |
| 2 |
|
| 3 |
import javax.vecmath.Vector3d; |
| 4 |
|
| 5 |
import gov.fnal.eag.healpix.PixTools; |
| 6 |
import junit.framework.TestCase; |
| 7 |
|
| 8 |
|
| 9 |
public class PixToolTest1 extends TestCase { |
| 10 |
|
| 11 |
static PixTools tools = new PixTools(); |
| 12 |
|
| 13 |
long NSIDE1 = 64; |
| 14 |
|
| 15 |
long NSIDE2 = 512; |
| 16 |
|
| 17 |
public void testCircle1(){ |
| 18 |
Vector3d vect = tools.Ang2Vec(0.5178634297507729, 0.06421357206295804); |
| 19 |
System.out.println("vx="+vect.x+" vy="+vect.y+" vz="+vect.z); |
| 20 |
tools.query_disc(NSIDE1, tools.Ang2Vec(0.5178634297507729, 0.06421357206295804), 5.817764173314432E-4, 1, 1); |
| 21 |
} |
| 22 |
|
| 23 |
public void testCircle2(){ |
| 24 |
tools.query_disc(NSIDE1, tools.Ang2Vec(0.3127581538205727, 0.1050979097909252), 0.01454441043328608, 1, 1); |
| 25 |
} |
| 26 |
|
| 27 |
public void testCircle3(){ |
| 28 |
Vector3d vect = tools.Ang2Vec(0.011620983936195673, 0.44456444930382233); |
| 29 |
System.out.println("vx="+vect.x+" vy="+vect.y+" vz="+vect.z); |
| 30 |
tools.query_disc(NSIDE1, vect, 5.526875964648709E-4, 1, 1); |
| 31 |
} |
| 32 |
|
| 33 |
public void testCircle4(){ |
| 34 |
tools.query_disc(NSIDE1, tools.Ang2Vec(0.3127581538205727, 0.1050979097909252), 0.01454441043328608, 1, 1); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
/*** with NSIDE 512 **/ |
| 39 |
public void testCircle5(){ |
| 40 |
tools.query_disc(NSIDE2, tools.Ang2Vec(1.0486568403767373, 0.036411931519731704), 6.399540590645875E-4, 1, 1); |
| 41 |
} |
| 42 |
/*** with NSIDE 512 **/ |
| 43 |
public void testVertexes(){ |
| 44 |
double ra = 30.0; |
| 45 |
double dec=30.0; |
| 46 |
double rad2deg = 180.0/Math.PI; |
| 47 |
double[] radec = new double[2]; |
| 48 |
radec[0] = ra; |
| 49 |
radec[1] = dec; |
| 50 |
double[] thetphi = new double[2]; |
| 51 |
thetphi = tools.RaDecToPolar(radec); |
| 52 |
double theta = thetphi[0]; |
| 53 |
double phi = thetphi[1]; |
| 54 |
long ipix = tools.ang2pix_nest(NSIDE2, theta, phi); |
| 55 |
double[][] vertexes = tools.pix2vertex_nest(NSIDE2, ipix); |
| 56 |
long ipixR = tools.ang2pix_ring(NSIDE2, theta, phi); |
| 57 |
double[][] vertexesr = tools.pix2vertex_ring(NSIDE2, ipixR); |
| 58 |
for (int i=0; i< 4; i++) { |
| 59 |
Vector3d vect = new Vector3d(vertexes[0][i],vertexes[1][i],vertexes[2][i]); |
| 60 |
double[] angs =tools.Vect2Ang(vect); |
| 61 |
Vector3d vectR = new Vector3d(vertexesr[0][i],vertexesr[1][i],vertexesr[2][i]); |
| 62 |
double[] angsR =tools.Vect2Ang(vectR); |
| 63 |
assertEquals("theta="+angs[0],angs[0],angsR[0], 1e-10); |
| 64 |
assertEquals("phi="+angs[1],angs[1],angsR[1], 1e-10); |
| 65 |
} |
| 66 |
|
| 67 |
} |
| 68 |
/*** with high res.**/ |
| 69 |
public void testVertexesHR(){ |
| 70 |
long nside = 1 << 20 ; |
| 71 |
double ra = 30.0; |
| 72 |
double dec=30.0; |
| 73 |
|
| 74 |
double[] radec = new double[2]; |
| 75 |
radec[0] = ra; |
| 76 |
radec[1] = dec; |
| 77 |
double[] thetphi = new double[2]; |
| 78 |
thetphi = tools.RaDecToPolar(radec); |
| 79 |
double theta = thetphi[0]; |
| 80 |
double phi = thetphi[1]; |
| 81 |
long ipix = tools.ang2pix_nest(nside, theta, phi); |
| 82 |
double[][] vertexes = tools.pix2vertex_nest(nside, ipix); |
| 83 |
long ipixR = tools.ang2pix_ring(nside, theta, phi); |
| 84 |
double[][] vertexesr = tools.pix2vertex_ring(nside, ipixR); |
| 85 |
for (int i=0; i< 4; i++) { |
| 86 |
Vector3d vect = new Vector3d(vertexes[0][i],vertexes[1][i],vertexes[2][i]); |
| 87 |
double[] angs =tools.Vect2Ang(vect); |
| 88 |
Vector3d vectR = new Vector3d(vertexesr[0][i],vertexesr[1][i],vertexesr[2][i]); |
| 89 |
double[] angsR =tools.Vect2Ang(vectR); |
| 90 |
assertEquals("theta="+angs[0],angs[0],angsR[0], 1e-10); |
| 91 |
assertEquals("phi="+angs[1],angs[1],angsR[1], 1e-10); |
| 92 |
} |
| 93 |
} |
| 94 |
public void testInverse(){ |
| 95 |
for(double ra = 0.0 ; ra < 360.0; ra+=10) { |
| 96 |
for(double de = -85 ; de <= 85; de+=10) |
| 97 |
{ |
| 98 |
|
| 99 |
long area =getHealId(ra,de,NSIDE2); |
| 100 |
RaDePoint p = getRaDe(area,NSIDE2); |
| 101 |
|
| 102 |
//compare with tolerance |
| 103 |
assertTrue(ra+"!="+p.ra,Math.abs(ra- p.ra)<1); |
| 104 |
assertTrue(de+"!="+p.de,Math.abs(de- p.de)<1); |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* get position ID for ra,de |
| 111 |
* @param ra right ascencion in degrees |
| 112 |
* @param de declination in degrees |
| 113 |
* @param nsides - non default number of nsides |
| 114 |
*/ |
| 115 |
|
| 116 |
public long getHealId(double ra, double de, long nsides) { |
| 117 |
double[] radec = new double[2]; |
| 118 |
radec[0] = ra; |
| 119 |
radec[1] = de; |
| 120 |
double[] polar = tools.RaDecToPolar(radec); |
| 121 |
long ip = tools.ang2pix_ring(nsides, polar[0], polar[1]); |
| 122 |
|
| 123 |
|
| 124 |
return ip; |
| 125 |
} |
| 126 |
|
| 127 |
/** inverse method, convert area ID to RaDePoint */ |
| 128 |
public static RaDePoint getRaDe(long area,long nsides) { |
| 129 |
double [] polar = tools.pix2ang_ring(nsides , area); |
| 130 |
double[]radec = tools.PolarToRaDec(polar); |
| 131 |
return new RaDePoint(radec[0],radec[1]); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
/** |
| 136 |
* Simple point on sky. Used as return value of functions |
| 137 |
* <p> |
| 138 |
* @See CoeliObject for data definition |
| 139 |
*/ |
| 140 |
static public class RaDePoint { |
| 141 |
|
| 142 |
/** coordinates in degrees*/ |
| 143 |
public double ra,de; |
| 144 |
|
| 145 |
|
| 146 |
public RaDePoint() {} |
| 147 |
|
| 148 |
public RaDePoint(double ra, double de){ |
| 149 |
this.ra = ra; |
| 150 |
this.de = de; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
} |
| 155 |
} |