def default(): """ Default Astra Viso demo. Creates a single image. Parameters ---------- None Returns ------- None """ # Create StarCam and define motion cam = av.StarCam() cam.set_pointing_preset("kinematic", initial_quaternion=[0,0,0,1,], \ initial_angular_rate=[0,0.025,0.1]) # Setup star catalog cam.star_catalog.load_preset("random", 100000) # Create WorldObject and define motion cam.add_worldobject() cam.external_objects[0].set_position_preset("kinematic", \ initial_position=np.array([0, 0, 1000]), initial_velocity=np.array([50, 25, 0])) cam.external_objects[0].set_vismag_preset("constant", vismag=2) # Create image and display av.imageutils.imshow(cam.snap(0, 1), [])
def sequence(count=2): """ Astra Viso sequence demo. Parameters ---------- count : int, optional Number of sequential images to generate. Default is 2. Returns ------- None """ # Create StarCam and define motion cam = av.StarCam() cam.set_pointing_preset("kinematic", initial_quaternion=[0,0,0,1,], \ initial_angular_rate=[0.01, 0, 0]) # Setup star catalog cam.star_catalog.load_preset("random", 100000) # Create WorldObject and define motion cam.add_worldobject() cam.external_objects[0].set_position_preset("kinematic", \ initial_position=np.array([0, 0, 1]), initial_velocity=np.array([0, 0, 0])) cam.external_objects[0].set_vismag_preset("constant", vismag=-1) # Create image and display for idx in range(count): av.imageutils.imshow(cam.snap(idx, 1), [])
def test_random(self): """ Verify multiple randomly-generated orientations. Requirement(s) Verified: #1, #2 """ # Initial setup num_tests = 20 cam = av.StarCam() cam.star_catalog.load_preset("random", 0) cam.set_noise_preset("off") # Speed-up hack for when integration accuracy is not important cam._StarCam__settings["integration_steps"] = 1 # Iterate through test cases for idx in range(num_tests): # Generate random quaternion rand_quat = np.random.rand(4) rand_quat = rand_quat / np.linalg.norm(rand_quat) # Set up camera cam.set_pointing_preset("static", initial_quaternion=rand_quat) # Set up object obj = av.WorldObject() position = 10 * cam.get_pointing(0, mode="dcm")[:, 2] obj.set_position_preset("kinematic", initial_position=position, \ initial_velocity=np.array([0, 0, 0])) # Add object and generate image cam.add_worldobject(obj) image = cam.integrate(0, 1) # Verify requirement #1 self.assertGreater(np.sum(image), 0, "Image must contain test object.") self.assertTrue(np.all(image >= 0), "Images must be strictly positive.") # Verify requirement #2 correct_coord = (cam._StarCam__settings["resolution"] - 1) / 2 test_coord = np.hstack(cam.get_projection(obj.in_frame_of(cam, 1))) self.assertTrue( np.isclose(test_coord[0], correct_coord), "Coordinates must correspond \ to the center of the image frame." ) self.assertTrue( np.isclose(test_coord[1], correct_coord), "Coordinates must correspond \ to the center of the image frame." )
def test_rotation_directions(self): """ Verify worldobject rotation about x, y, and z axes. Requirement(s) Verified: #5, #6 """ # Initial setup cam = av.StarCam() cam.star_catalog.load_preset("random", 0) cam.set_noise_preset("off") quat = np.array([0, 0, 0, 1]) rate = np.array([0, 0, 0]) cam.set_pointing_preset("kinematic", initial_quaternion=quat, initial_angular_rate=rate) # Speed-up hack for when integration accuracy is not important cam._StarCam__settings["integration_steps"] = 1 # Set up object obj = av.WorldObject() position = np.array([0, 0, 1]) velocity = np.array([0, 0, 0]) obj.set_position_preset("kinematic", initial_position=position, initial_velocity=velocity) # Store reference coordinates cam.add_worldobject(obj) ref_coords = cam.get_projection(obj.in_frame_of(cam, 0)) # Set up +x test rate = np.array([0.01, 0, 0]) cam.set_pointing_preset("kinematic", initial_quaternion=quat, initial_angular_rate=rate) # Verify +x result test_coords = cam.get_projection(obj.in_frame_of(cam, 1)) self.assertGreater( test_coords[1], ref_coords[1], "For x-axis rotation, object must move \ in the -y direction." ) # Set up -x test rate = np.array([-0.01, 0, 0]) cam.set_pointing_preset("kinematic", initial_quaternion=quat, initial_angular_rate=rate) # Verify -x result test_coords = cam.get_projection(obj.in_frame_of(cam, 1)) self.assertLess( test_coords[1], ref_coords[1], "For negative x-axis rotation, object \ must move in the +y direction." ) # Set up +y test rate = np.array([0, 0.01, 0]) cam.set_pointing_preset("kinematic", initial_quaternion=quat, initial_angular_rate=rate) # Verify +y result test_coords = cam.get_projection(obj.in_frame_of(cam, 1)) self.assertLess( test_coords[0], ref_coords[0], "For y-axis rotation, object must move \ in the -x direction." ) # Set up -y test rate = np.array([0, -0.01, 0]) cam.set_pointing_preset("kinematic", initial_quaternion=quat, initial_angular_rate=rate) # Verify -y result test_coords = cam.get_projection(obj.in_frame_of(cam, 1)) self.assertGreater( test_coords[0], ref_coords[0], "For negative y-axis rotation, object \ must move in the +x direction." ) # Set up +z test rate = np.array([0, 0, 0.01]) cam.set_pointing_preset("kinematic", initial_quaternion=quat, initial_angular_rate=rate) # Verify +z result test_coords = cam.get_projection(obj.in_frame_of(cam, 1)) self.assertTrue( np.all(test_coords == ref_coords), "For z-axis rotation, object must not \ move." ) # Set up -z test rate = np.array([0, 0, -0.01]) cam.set_pointing_preset("kinematic", initial_quaternion=quat, initial_angular_rate=rate) # Verify -z result test_coords = cam.get_projection(obj.in_frame_of(cam, 1)) self.assertTrue( np.all(test_coords == ref_coords), "For negative z-axis rotation, object \ must note move." )