def test_gal_to_equa(self): for line in self.tevcat: ra, dec = line[1] l, b = line[3] gal = astro.I3Galactic(l * I3Units.degree, b * I3Units.degree) eq = astro.I3GetEquatorialFromGalactic(gal) self.assertAlmostEqual(eq.ra / I3Units.degree, ra, 3) self.assertAlmostEqual(eq.dec / I3Units.degree, dec, 3)
def test_gal_from_equa(self): random.seed(0) for n in range(10000): eq = astro.I3Equatorial(random.uniform(0,2* math.pi), random.uniform(-math.pi/2,math.pi/2), ) gal = astro.I3GetGalacticFromEquatorial(eq) eqprime = astro.I3GetEquatorialFromGalactic(gal) self.assert_almost_equal(math.cos(eq.dec)*eq.ra ,math.cos(eqprime.dec)*eqprime.ra,1e-9) self.assert_almost_equal(eq.dec,eqprime.dec,1e-10) self.assert_less(astro.angular_distance(eq.ra,eq.dec,eqprime.ra,eqprime.dec),1e-10)
def test_equa_from_gal(self): random.seed(0) for n in range(10000): gal = astro.I3Galactic(random.uniform(0,2*math.pi), random.uniform(-math.pi/2,math.pi/2), ) eq = astro.I3GetEquatorialFromGalactic(gal) galprime = astro.I3GetGalacticFromEquatorial(eq) self.assert_almost_equal(math.cos(gal.b)*gal.l,math.cos(galprime.b)*galprime.l,1e-9) self.assert_almost_equal(gal.b,galprime.b,1e-10) self.assert_less(astro.angular_distance(gal.l,gal.b,galprime.l,galprime.b),1e-10)
crab_direction.azimuth / I3Units.degree, )) print #the center of the galaxy is easy to remember in galactic coordinates galaxy_center = astro.I3Galactic(0, 0) print( "The Galactic Center's galactic coordinates are l={:+8.4f} deg, b={:+7.4f} deg" .format( galaxy_center.l / I3Units.degree, galaxy_center.b / I3Units.degree, )) #convert to equatorial coordinates gc_equatorial = astro.I3GetEquatorialFromGalactic(galaxy_center) print( "Which means its equatorial coordinates are ra={:8.4f} deg, dec={:+7.4f} deg" .format( gc_equatorial.ra / I3Units.degree, gc_equatorial.dec / I3Units.degree, )) #calculat the position of the galactic in local coordinates gc_direction = astro.I3GetDirectionFromEquatorial(gc_equatorial, time) print( "At {} the Crab will be at zenith={:8.4f} deg, azimuth={:7.4f} deg".format( str(time), gc_direction.zenith / I3Units.degree, gc_direction.azimuth / I3Units.degree, ))
def test_reference_points(self): #Test the reference points that define the galactic coordinate system #take from Wikipedia, the orignal paper was in B1950 #celestial north pole eq = astro.I3Equatorial((12+51.4/60.)*15*I3Units.degree, 27.13 * I3Units.degree) gal = astro.I3GetGalacticFromEquatorial(eq) self.assertAlmostEqual(gal.b/I3Units.degree,+90,1) #south pole eq.ra = (+51.4/60.)*15*I3Units.degree eq.dec = -27.13 * I3Units.degree gal = astro.I3GetGalacticFromEquatorial(eq) self.assertAlmostEqual(gal.b/I3Units.degree,-90,1) #galactic center eq.ra = (17+45.6/60.)*15*I3Units.degree eq.dec = -28.94 * I3Units.degree gal = astro.I3GetGalacticFromEquatorial(eq) self.assertAlmostEqual(gal.b/I3Units.degree,0,1) self.assertAlmostEqual(gal.l/I3Units.degree,360,1) #anti-center eq.ra = (5+45.6/60.)*15*I3Units.degree eq.dec = +28.94 * I3Units.degree gal = astro.I3GetGalacticFromEquatorial(eq) self.assertAlmostEqual(gal.b/I3Units.degree,0,1) self.assertAlmostEqual(gal.l/I3Units.degree,180,1) #now test the reverse transform #galactic north pole gal = astro.I3Galactic( 0 * I3Units.degree, +90 * I3Units.degree) eq = astro.I3GetEquatorialFromGalactic(gal) self.assertAlmostEqual(eq.ra/I3Units.degree, (12+51.4/60.)*15.,1) self.assertAlmostEqual(eq.dec/I3Units.degree, 27.13,1) #south pole gal.l = 0 * I3Units.degree gal.b = -90 * I3Units.degree eq = astro.I3GetEquatorialFromGalactic(gal) self.assertAlmostEqual(eq.ra/I3Units.degree, (0+51.4/60.)*15.,1) self.assertAlmostEqual(eq.dec/I3Units.degree, -27.13,1) #galactic center gal.l = 0 * I3Units.degree gal.b = 0 * I3Units.degree eq = astro.I3GetEquatorialFromGalactic(gal) self.assertAlmostEqual(eq.ra/I3Units.degree, (17+45.6/60.)*15.,1) self.assertAlmostEqual(eq.dec/I3Units.degree, -28.94,1) #anti center gal.l = 0 * I3Units.degree gal.b = 180 * I3Units.degree eq = astro.I3GetEquatorialFromGalactic(gal) self.assertAlmostEqual(eq.ra/I3Units.degree, (5+45.6/60.)*15.,1) self.assertAlmostEqual(eq.dec/I3Units.degree, +28.94,1) #supergalactic north pole sg = astro.I3SuperGalactic() sg.b = 90 *I3Units.degree sg.l = 0 *I3Units.degree gal = astro.I3GetGalacticFromSuperGalactic(sg) self.assertAlmostEqual(gal.l/I3Units.degree, 47.37,6) self.assertAlmostEqual(gal.b/I3Units.degree, 6.32,6) eq = astro.I3GetEquatorialFromSuperGalactic(sg) print(eq.ra/I3Units.degree/15,eq.dec/I3Units.degree) self.assertAlmostEqual(eq.ra/I3Units.degree, 18.92*15,1) self.assertAlmostEqual(eq.dec/I3Units.degree, 15.7,1) #supergalactic origin sg = astro.I3SuperGalactic() sg.b = 0 *I3Units.degree sg.l = 0 *I3Units.degree gal = astro.I3GetGalacticFromSuperGalactic(sg) self.assertAlmostEqual(gal.l/I3Units.degree, 137.37,6) self.assertAlmostEqual(gal.b/I3Units.degree, 0,6) eq = astro.I3GetEquatorialFromSuperGalactic(sg) self.assertAlmostEqual(eq.ra/I3Units.degree, 2.82*15,1) self.assertAlmostEqual(eq.dec/I3Units.degree, 59.5,1)