def test_dir_from_equa(self): random.seed(0) t1 = dataclasses.I3Time() t1.set_utc_cal_date(2000, 1, 1, 0, 0, 0, 0.0) mjd1 = t1.mod_julian_day_double t1.set_utc_cal_date(2030, 1, 1, 0, 0, 0, 0.0) mjd2 = t1.mod_julian_day_double for n in range(1000): t1.set_mod_julian_time_double(random.uniform(mjd1, mjd2)) eq = astro.I3Equatorial(random.uniform(0, 2 * math.pi), random.uniform(-math.pi / 2, math.pi / 2)) d = astro.I3GetDirectionFromEquatorial(eq, t1) eqprime = astro.I3GetEquatorialFromDirection(d, t1) self.assert_almost_equal(eq.ra * math.cos(eq.dec), eqprime.ra * math.cos(eqprime.dec), 4e-6) self.assert_almost_equal(eq.dec, eqprime.dec, 4e-6) self.assert_less( astro.angular_distance(eq.ra, eq.dec, eqprime.ra, eqprime.dec), 5e-6)
def Process(self): try: c = next(self.lines) except StopIteration: self.RequestSuspension() return eq = astro.I3Equatorial(c[0] * I3Units.degree, c[1] * I3Units.degree) time = dataclasses.I3Time(2015, 0) direction = astro.I3GetDirectionFromEquatorial(eq, time) eqq = astro.I3GetEquatorialFromDirection(direction, time) particle = dataclasses.I3Particle() particle.dir = direction header = dataclasses.I3EventHeader() header.start_time = time frame = icetray.I3Frame("P") if self.evthdr: frame["I3EventHeader"] = header frame["Particle"] = particle self.PushFrame(frame)
def test_equa_to_sg(self): for line in self.tevcat: ra, dec = line[1] sgl, sgb = line[2] eq = astro.I3Equatorial(ra * I3Units.degree, dec * I3Units.degree) sg = astro.I3GetSuperGalacticFromEquatorial(eq) self.assertAlmostEqual(sg.l / I3Units.degree, sgl, 2) self.assertAlmostEqual(sg.b / I3Units.degree, sgb, 2)
def test_nan(self): eq = astro.I3Equatorial() assert (np.isnan(eq.ra)) assert (np.isnan(eq.dec)) gal = astro.I3Galactic() assert (np.isnan(gal.l)) assert (np.isnan(gal.b))
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_sg_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), ) sg = astro.I3GetSuperGalacticFromEquatorial(eq) eqprime = astro.I3GetEquatorialFromSuperGalactic(sg) 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_radec(self): src_dec = 22.01450 for src_ra in np.linspace(0, 360, 1): i3src = astro.I3Equatorial(src_ra * I3Units.degree, src_dec * I3Units.degree) i3t0 = dataclasses.I3Time() i3t0.set_utc_cal_date(2000, 1, 1, 0, 0, 0, 0) for day in np.linspace(0, 10000, 100): i3time = i3t0 + day * 86400 * I3Units.s i3dir = astro.I3GetDirectionFromEquatorial(i3src, i3time) i3az = i3dir.azimuth / I3Units.degree i3zen = i3dir.zenith / I3Units.degree #this equation from inspecting the output of ephempy paz = (189.9640733918 - src_ra + day * 360.985606808) % 360 pzen = 90 + src_dec assert (azimuth_distance(i3az, paz) < 0.2) assert (abs(i3zen - pzen) < 0.2)
print #calculate the position of the sun sun_direction = astro.I3GetSunDirection(time) print( "At {} the Sun will be at zenith={:8.4f} deg, azimuth={:7.4f} deg".format( str(time), sun_direction.zenith / I3Units.degree, sun_direction.azimuth / I3Units.degree, )) 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, ))
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)