def test_unproject(self): camera = Camera() pixel_pos = (960, 720) sph = camera.unproject(pixel_pos) self.assertEquals(sph[0], np.pi) self.assertEquals(sph[1], np.pi / 2) pixel_pos = (960, 0) sph = camera.unproject(pixel_pos) self.assertEquals(sph[0], 3 * np.pi / 2) self.assertEquals(sph[1], np.pi / 2 - np.deg2rad(5)) pixel_pos = (960, 1440) sph = camera.unproject(pixel_pos) self.assertEquals(sph[0], np.pi / 2) self.assertEquals(sph[1], np.pi / 2 - np.deg2rad(5)) pixel_pos = (1920, 720) sph = camera.unproject(pixel_pos) self.assertEquals(sph[0], np.pi) self.assertEquals(sph[1], np.pi / 2 - np.deg2rad(5)) pixel_pos = (0, 720) sph = camera.unproject(pixel_pos) self.assertEquals(sph[0], 0) self.assertEquals(sph[1], np.pi / 2 - np.deg2rad(5)) pixel_pos = (0, 0) pixel_pos2 = (1920, 1440) sph = camera.unproject(pixel_pos) sph2 = camera.unproject(pixel_pos2) star1 = Star(0, 0, sph=sph) star2 = Star(1, 0, sph=sph2) d = star1.calc_angular_distance(star2) actual = 2 * np.arctan(np.tan(np.deg2rad(5)) * np.sqrt(2)) self.assertEquals(round(d, 5), round(actual, 5))
def setUp(self): star1 = Star(0, 0, sph=(0, np.pi / 2)) self.scene1 = Scene([star1]) star1 = Star(1, 0, sph=(0, 0)) star2 = Star(2, 0, sph=(0, np.deg2rad(5))) star3 = Star(3, 0, sph=(2 * np.pi - np.deg2rad(5), 0)) self.scene2 = Scene([star1, star2, star3])
def test_reorient(self): star = Star(1, 0, sph=(0.1204, 1.283)) #star.spherical_to_cartesian() camera = Camera() camera.point_at(star) orientation = camera.orientation new_star = star.reorient(orientation) self.assertEquals(tuple(map(round, new_star.cartesian)), (0, 0, 1))
def setUp(self): star1 = Star(0,1,sph=(0,0)) star2 = Star(1,1,sph=(np.pi,0)) star3 = Star(2,1,sph=(np.pi/3,0)) star4 = Star(3,1,sph=(np.pi/2,0)) self.d1 = AngularDistance(star1,star2) self.d2 = AngularDistance(star1,star3) self.d3 = AngularDistance(star2,star3) self.d4 = AngularDistance(star1,star4)
def test_find_matching_triplets_none(self): ms1 = Star(3,0,sph=(np.pi,0)) ms2 = Star(4,0,sph=(4*np.pi/3,0)) ms3 = Star(5,0,sph=(np.pi,np.pi/6+0.001)) full_scene = Scene([ms1,ms2,ms3]) distances = full_scene.get_all_angular_distances() pyramid = Pyramid(self.scene,full_scene) with self.assertRaises(Exception, msg='No suitable stars found.'): matches = pyramid.find_matching_triplets(self.scene,distances)
def setUp(self): #Degrees to radians d2r = np.pi/180 self.d2r = d2r self.star1 = Star(1,3.1,sph=(45*d2r,45*d2r)) self.star2 = Star(2,4.5,sph=(90*d2r,-45*d2r)) self.star3 = Star(3,1.3,sph=(180*d2r,60*d2r)) self.star4 = Star(4,2.4,sph=(225*d2r,20*d2r)) self.star5 = Star(5,6.1,sph=(315*d2r,-30*d2r)) stars = [self.star1,self.star2,self.star3,self.star4,self.star5] self.scene = Scene(stars)
def setUp(self): __location__ = os.path.realpath( os.path.join(os.getcwd(), os.path.dirname(__file__))) self.test_csv_path = os.path.join(__location__, 'test_input.csv') self.test_hip_path = os.path.join(__location__, 'test_hip.dat') self.test_csv_row = [1,2,0.1, 3,4,0.2, 5,6,0.3, 7,8,0.4] self.test_csv_row_uncastable = [1,2,0.1, 'not id',5,2] self.test_csv_row_not_groups_of_three = [1,2,0.1, 2,3] self.star1 = Star(0,0.1,pixel_pos=(1,2)) self.star2 = Star(1,0.2,pixel_pos=(3,4)) self.star3 = Star(2,0.3,pixel_pos=(5,6)) self.star4 = Star(3,0.4,pixel_pos=(7,8))
def test_get_all_angular_distances_sorted(self): star1 = Star(1,1,sph=(0,np.pi/4)) star2 = Star(2,1,sph=(0,np.pi/2)) star3 = Star(3,1,sph=(0,np.pi)) distance1 = AngularDistance(star1, star2) distance2 = AngularDistance(star1, star3) distance3 = AngularDistance(star2, star3) scene = Scene([star1,star2,star3]) distances = scene.get_all_angular_distances() self.assertEquals(distance1,distances.distances[0]) self.assertEquals(distance3,distances.distances[1]) self.assertEquals(distance2,distances.distances[2])
def test_parse_hip_data(self): d2r = np.pi/180 star1 = Star(118318,6.99,sph=(359.96374383*d2r,11.67370866*d2r)) star2 = Star(118319,8.23,sph=(359.97391252*d2r,-22.42818030*d2r)) star3 = Star(118321,9.20,sph=(359.97823891*d2r,-64.37257220*d2r)) scene, fail = SceneParser.parse_hip_data(self.test_hip_path) self.assertEquals(len(scene.stars),3) self.assertIn(star1, scene.stars) self.assertIn(star2, scene.stars) self.assertIn(star3, scene.stars) self.assertEquals(len(fail),2) self.assertEquals(fail[0][1].strip(),'118320') self.assertEquals(fail[1][1],'not_an_id')
def setUp(self): distances = Distances() self.star1 = Star(1, 0, sph=(0, 0)) self.star2 = Star(2, 0, sph=(np.pi / 3, 0)) self.star3 = Star(3, 0, sph=(np.pi, 0)) self.star4 = Star(4, 0, sph=(2 * np.pi / 3 + 0.001, 0)) self.distance12 = AngularDistance(self.star1, self.star2) self.distance13 = AngularDistance(self.star1, self.star3) self.distance23 = AngularDistance(self.star2, self.star3) distances.add_distance(self.star1, self.star3) distances.add_distance(self.star1, self.star2) distances.add_distance(self.star2, self.star3) self.distances = distances
def test_parse_csv(self): scenes, fails = SceneParser.parse_csv(self.test_csv_path) star1 = Star(0,4.6258962869844291,pixel_pos=(1092.2860064407901,636.85114847774378)) star2 = Star(1,4.8178697493028348,pixel_pos=(1426.1402525032968,1425.6987141468878)) star3 = Star(0,4.6802248025298114,pixel_pos=(1365.1549861743506,690.55647884712869)) star4 = Star(2,4.7534443440485514,pixel_pos=(393.47343264299639,3.4957577462069356)) self.assertEquals(len(scenes),2) self.assertEquals(len(fails),2) self.assertEquals(len(scenes[0].stars),2) self.assertIn(star1, scenes[0].stars) self.assertIn(star2, scenes[0].stars) self.assertEquals(len(scenes[1].stars),2) self.assertIn(star3, scenes[1].stars) self.assertIn(star4, scenes[1].stars)
def test_cartesian_to_spherical(self): camera = Camera() star = Star(1, 0) star.cartesian = (1 / np.sqrt(2), 1 / np.sqrt(2), 0) star.cartesian_to_spherical() self.assertEquals(star.sph[0], np.pi / 4) self.assertEquals(star.sph[1], 0) star = Star(1, 0) star.cartesian = ( 1 / np.sqrt(2), 0, 1 / np.sqrt(2), ) star.cartesian_to_spherical() self.assertEquals(star.sph[0], 0) self.assertEquals(round(star.sph[1], 10), round(np.pi / 4, 10))
def test_init_spherical(self): idnum = 1 magnitude = 4 sph = (40, 11) try: return Star(idnum, magnitude, sph=sph) except: self.fail('Couldn\'t initialise star class')
def test_init_cartesian(self): idnum = 1 magnitude = 4 pixel_pos = (5, 6) try: return Star(idnum, magnitude, pixel_pos) except: self.fail('Couldn\'t initialise star class')
def test_find_close_several(self): distances = self.distances d_check = AngularDistance(self.star1, Star(5, 0, sph=(np.pi / 3, 0))) epsilon = np.pi / 3 + 0.1 close = distances.find_close(d_check, epsilon) self.assertEquals(len(close.distances), 2) self.assertIn(self.distance12, close.distances) self.assertIn(self.distance23, close.distances)
def test_reorient_no_change(self): star_orig = Star(1, 0, sph=(0, 0)) star_orig.spherical_to_cartesian() star = Star(1, 0, sph=(0, 0)) camera = Camera() camera.point_at(star) orientation = camera.orientation new_star = star.reorient(orientation) self.assertEquals(star, star_orig)
def test_spherical_to_cartesian(self): camera = Camera() star = Star(1, 0, sph=(45 * self.d2r, 45 * self.d2r)) star.spherical_to_cartesian() self.assertEquals(round(star.cartesian[0], 5), 0.5) self.assertEquals(round(star.cartesian[1], 5), 0.5) self.assertEquals(round(star.cartesian[2], 5), round(1 / np.sqrt(2), 5)) star = Star(1, 0, sph=(0, 0)) star.spherical_to_cartesian() self.assertEquals(star.cartesian[0], 1) self.assertEquals(star.cartesian[1], 0) self.assertEquals(star.cartesian[2], 0)
def test_find_matching_triplets_many(self): ms1 = Star(3,0,sph=(np.pi,0)) ms2 = Star(4,0,sph=(4*np.pi/3,0)) ms3 = Star(5,0,sph=(np.pi,np.pi/6)) ms4 = Star(6,0,sph=(2*np.pi/3,0)) full_scene = Scene([ms1,ms2,ms3,ms4]) distances = full_scene.get_all_angular_distances() pyramid = Pyramid(self.scene,full_scene) matches = pyramid.find_matching_triplets(self.scene,distances) self.assertEquals(len(matches), 2) self.assertIn(ms1,matches[0].stars) self.assertIn(ms3,matches[0].stars) self.assertIn(ms1,matches[1].stars) self.assertIn(ms3,matches[1].stars) odd1 = [s for s in matches[0].stars if s not in matches[1].stars] odd2 = [s for s in matches[1].stars if s not in matches[0].stars] self.assertEquals(len(odd1+odd2),2) self.assertIn(ms2,odd1+odd2) self.assertIn(ms4,odd1+odd2)
def test_find_matching_triplets(self): ms1 = Star(3,0,sph=(np.pi,0)) ms2 = Star(4,0,sph=(4*np.pi/3,0)) ms3 = Star(5,0,sph=(np.pi,np.pi/6)) ms4 = Star(6,0,sph=(5*np.pi/6,0)) ms5 = Star(7,0,sph=(np.pi,np.pi/2)) ms6 = Star(8,0,sph=(np.pi/2,np.pi/6)) full_scene = Scene([ms1,ms2,ms3,ms4,ms5,ms6]) distances = full_scene.get_all_angular_distances() pyramid = Pyramid(self.scene,full_scene) matches = pyramid.find_matching_triplets(self.scene,distances) self.assertEquals(len(matches), 1) self.assertIn(ms1,matches[0].stars) self.assertIn(ms2,matches[0].stars) self.assertIn(ms3,matches[0].stars)
def test_calc_angular_distance_1d(self): star1 = Star(1, 0, sph=(40 * self.d2r, 0)) star2 = Star(2, 0, sph=(50 * self.d2r, 0)) angle = round(star1.calc_angular_distance(star2), 5) check = round(10 * self.d2r, 5) self.assertEquals(angle, check)
def test_calc_angular_distance_0(self): star1 = Star(1, 0, sph=(40, 11)) star2 = Star(2, 0, sph=(40, 11)) self.assertEquals(star1.calc_angular_distance(star2), 0)
def test_equal_duplicate(self): s1 = Star(1, 0) s2 = Star(2, 0) e1 = Edge(s1, s2) e2 = Edge(s1, s2) self.assertEquals(e1, e2)
def test_equal_self(self): s1 = Star(1, 0) s2 = Star(2, 0) e = Edge(s1, s2) self.assertEquals(e, e)
def setUp(self): s1 = Star(0,0,sph=(0,0)) s2 = Star(1,0,sph=(np.pi/3,0)) s3 = Star(2,0,sph=(0,np.pi/6)) self.scene = Scene([s1,s2,s3])
def test_calc_angular_distance_180(self): star1 = Star(1, 0, sph=(315 * self.d2r, 45 * self.d2r)) star2 = Star(2, 0, sph=(135 * self.d2r, -45 * self.d2r)) angle = round(star1.calc_angular_distance(star2), 5) check = round(np.pi, 5) self.assertEquals(angle, check)
def test_reduce_to_one_distance_all_gone(self): distances = self.distances d = AngularDistance(self.star4, Star(5, 0, sph=(0, 0))) new_distances = distances.reduce_to_one_distance(d) self.assertEquals(new_distances.distances, [])
def test_reorient_raise(self): star = Star(1, 0) with self.assertRaises(Exception, msg='Star theta,psi coordinates not \ set.'): star.reorient(None)