def compare_file(self, hor_file, obj): hor = read_horizons(hor_file) for i, date in enumerate(hor['date']): t = dataclasses.make_I3Time(date) if obj == 'sun': d = astro.I3GetSunDirection(t) elif obj == 'moon': d = astro.I3GetMoonDirection(t) el = 90 - math.degrees(d.zenith) az = (90 - math.degrees(d.azimuth + astro.ICECUBE_LONGITUDE)) % 360. eq = astro.I3GetEquatorialFromDirection(d, t) ra = math.degrees(eq.ra) dec = math.degrees(eq.dec) gal = astro.I3GetGalacticFromEquatorial(eq) l = math.degrees(gal.l) b = math.degrees(gal.b) #print el - hor['el'][i], az - hor['az'][i], ra - hor['ra'][i], dec - hor['dec'][i],l - hor['l'][i],b -hor['b'][i] assert (abs(el - hor['el'][i]) < 0.003) assert (azimuth_distance(az, hor['az'][i]) < 1.0) assert (abs(ra - hor['ra'][i]) < 0.005) assert (abs(dec - hor['dec'][i]) < 0.004) assert (abs(l - hor['l'][i]) < 0.02) assert (abs(b - hor['b'][i]) < 0.01)
def test_equa_to_gal(self): for line in self.tevcat: ra, dec = line[1] l, b = line[3] eq = astro.I3Equatorial(ra * I3Units.degree, dec * I3Units.degree) gal = astro.I3GetGalacticFromEquatorial(eq) self.assertAlmostEqual(gal.l / I3Units.degree, l, 3) self.assertAlmostEqual(gal.b / I3Units.degree, b, 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)
)) print #This is where the crab lives on the sky crab_position = astro.I3Equatorial(83.63308 * I3Units.degree, 22.01450 * I3Units.degree) print( "The Crab Nebula is located at RA = {:8.4f} deg, Dec ={:+7.4f} deg (J2000)" .format( crab_position.ra / I3Units.degree, crab_position.dec / I3Units.degree, )) #calculate the location of the crab in galactic coordinates crab_galactic = astro.I3GetGalacticFromEquatorial(crab_position) print( "Which Means its galactic coordinates are l={:+8.4f} deg, b={:+7.4f} deg". format( crab_galactic.l / I3Units.degree, crab_galactic.b / I3Units.degree, )) #calculat the position of the crab nebula in local coordinates crab_direction = astro.I3GetDirectionFromEquatorial(crab_position, time) print( "At {} the Crab will be at zenith={:8.4f} deg, azimuth={:7.4f} deg".format( str(time), crab_direction.zenith / I3Units.degree, crab_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)