class ProjectsTest(unittest.TestCase): """Integration test of project management. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_adam_config.json').get_config() self.service = Service(config) self.assertTrue(self.service.setup()) self.working_project = self.service.new_working_project() self.assertIsNotNone(self.working_project) def delete_children(self, project): projects = self.service.get_projects_module().get_projects() # First topographically sort all children of <project> so that we can delete # them in dependency-order. parent_map = {} for p in projects: parent_map[p.get_uuid()] = p.get_parent() children = [project.get_uuid()] change = 1 while change > 0: change = 0 for p in projects: if not p.get_uuid() in children and p.get_parent() in children: children.append(p.get_uuid()) change = change + 1 children = children[1:] if len(children) > 0: print("Cleaning up " + str(len(children)) + " children of " + project.get_uuid()) for p in reversed(children): self.service.get_projects_module().delete_project(p) def tearDown(self): self.delete_children(self.working_project) self.service.teardown() def test_projects(self): parent = self.working_project p = self.service.get_projects_module() projects = p.get_projects() self.assertTrue(parent.get_uuid() in [p.get_uuid() for p in projects]) p1 = p.new_project(parent.get_uuid(), 'p1', 'description') self.assertTrue(p1.get_uuid() is not None) self.assertTrue(p1.get_parent() == parent.get_uuid()) self.assertTrue(p1.get_name() == 'p1') self.assertTrue(p1.get_description() == 'description') projects = p.get_projects() self.assertTrue(parent.get_uuid() in [p.get_uuid() for p in projects]) self.assertTrue(p1.get_uuid() in [p.get_uuid() for p in projects]) p2 = p.new_project(p1.get_uuid(), 'p2', 'another description') self.assertTrue(p2.get_uuid() is not None) self.assertTrue(p2.get_parent() == p1.get_uuid()) projects = p.get_projects() self.assertTrue(parent.get_uuid() in [p.get_uuid() for p in projects]) self.assertTrue(p1.get_uuid() in [p.get_uuid() for p in projects]) self.assertTrue(p2.get_uuid() in [p.get_uuid() for p in projects]) # Can't delete the project before its children are deleted. try: p.delete_project(p1.get_uuid()) self.fail("Expected error deleting project that still has children.") except RuntimeError: pass # This is expected p.delete_project(p2.get_uuid()) p.delete_project(p1.get_uuid())
class KeplerianTest(unittest.TestCase): """Integration test of using keplerian elements instead of cartesian. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_adam_config.json').get_config() self.service = Service(config) self.assertTrue(self.service.setup()) self.working_project = self.service.new_working_project() self.assertIsNotNone(self.working_project) def tearDown(self): self.service.teardown() def make_cartesian_and_keplerian_batches(self, start_time_str, end_time_str): keplerian_elements = { 'semi_major_axis_km': 3.1307289138037175E8, 'eccentricity': 0.5355029800000188, 'inclination_deg': 23.439676743246295, 'ra_of_asc_node_deg': 359.9942693176405, 'arg_of_pericenter_deg': 328.5584374618295, 'true_anomaly_deg': -127.01778914927144, 'gm': 1.327124400419394E11 } cartesian_state_vector = [ -3.0653634150102222e8, -1.1097955684640282e8, -4.8129706422527283e7, # x, y, z 15.7598552764090590, -10.5875673291958420, -4.5896734328869746 # dx, dy, dZ ] propagation_params = PropagationParams({ 'start_time': start_time_str, 'end_time': end_time_str, 'project_uuid': self.working_project.get_uuid(), 'description': 'Created by test at ' + start_time_str }) opm_params_templ = { 'epoch': start_time_str, # state_vector or keplerian_elements will be set later. 'mass': 500.5, 'solar_rad_area': 25.2, 'solar_rad_coeff': 1.2, 'drag_area': 33.3, 'drag_coeff': 2.5 } cartesian_opm_params = opm_params_templ.copy() cartesian_opm_params['state_vector'] = cartesian_state_vector keplerian_opm_params = opm_params_templ.copy() keplerian_opm_params['keplerian_elements'] = keplerian_elements cartesian = Batch(propagation_params, OpmParams(cartesian_opm_params)) keplerian = Batch(propagation_params, OpmParams(keplerian_opm_params)) return cartesian, keplerian def test_keplerian_and_cartesian(self): start = datetime.datetime.now() end = start + datetime.timedelta(10) # 10 days start_time_str = start.isoformat() + 'Z' end_time_str = end.isoformat() + 'Z' cartesian, keplerian = self.make_cartesian_and_keplerian_batches( start_time_str, end_time_str) BatchRunManager(self.service.get_batches_module(), [cartesian, keplerian]).run() cartesian_end_state = cartesian.get_results().get_end_state_vector() keplerian_end_state = keplerian.get_results().get_end_state_vector() difference = np.subtract(cartesian_end_state, keplerian_end_state) npt.assert_allclose(difference[0:3], [0, 0, 0], rtol=0, atol=1e-5) npt.assert_allclose(difference[3:6], [0, 0, 0], rtol=0, atol=1e-10)
class ReferenceFrameTest(unittest.TestCase): """Integration test of using different reference frames. """ def setUp(self): config = ConfigManager( os.getcwd() + '/test_adam_config.json').get_config('dev') self.service = Service(config) self.assertTrue(self.service.setup()) self.working_project = self.service.new_working_project() self.assertIsNotNone(self.working_project) def tearDown(self): self.service.teardown() # This test and the following test are exactly the same propagation, but are done # in two different reference frames. def test_icrf(self): start_time_str = "2000-01-01T11:58:55.816Z" end_time_str = "2009-07-21T21:55:08.813Z" sun_icrf_state_vec = [-306536341.5010222, -110979556.84640282, -48129706.42252728, 15.75985527640906, -10.587567329195842, -4.589673432886975] propagation_params = PropagationParams({ 'start_time': start_time_str, 'end_time': end_time_str, 'step_size': 86400, 'project_uuid': self.working_project.get_uuid(), 'description': 'Created by test at ' + start_time_str }) opm_params = OpmParams({ 'epoch': start_time_str, 'state_vector': sun_icrf_state_vec, 'center_name': 'SUN', 'ref_frame': 'ICRF', }) batch = Batch(propagation_params, opm_params) runner = BatchRunManager(self.service.get_batches_module(), [batch]) runner.run() end_state = batch.get_results().get_end_state_vector() expected_end_state = [73978163.61069362, -121822760.05571477, -52811158.83249758, 31.71000343989318, 29.9657246374751, .6754531613947713] difference = np.subtract(expected_end_state, end_state) print("Difference is %s" % difference) print("End state: %s" % end_state) npt.assert_allclose(difference[0:3], [0, 0, 0], rtol=0, atol=.02) npt.assert_allclose(difference[3:6], [0, 0, 0], rtol=0, atol=.00002) ephem = batch.get_results().get_parts()[-1].get_ephemeris() self.assertTrue("ICRF" in ephem) def test_sun_ememe(self): start_time_str = "2000-01-01T11:58:55.816Z" end_time_str = "2009-07-21T21:55:08.813Z" sun_ememe_state_vec = [-306536346.18024945, -120966638.54521248, -12981.069369263947, 15.759854830195243, -11.539570959741736, 0.0005481049628786039] propagation_params = PropagationParams({ 'start_time': start_time_str, 'end_time': end_time_str, 'step_size': 86400, 'project_uuid': self.working_project.get_uuid(), 'description': 'Created by test at ' + start_time_str }) opm_params = OpmParams({ 'epoch': start_time_str, 'state_vector': sun_ememe_state_vec, 'center_name': 'SUN', 'ref_frame': 'EMEME2000', }) batch = Batch(propagation_params, opm_params) runner = BatchRunManager(self.service.get_batches_module(), [batch]) runner.run() end_state = batch.get_results().get_end_state_vector() # The output state is expected to be in ICRF. expected_end_state = [73978163.61069362, -121822760.05571477, -52811158.83249758, 31.71000343989318, 29.9657246374751, .6754531613947713] # These values are in EMEME. The resulting ephemeris is not expected to match these values. # expected_end_state = [73978158.47632701, -132777272.5255892, 5015.073123970032, # 31.710003506237434, 27.761693311026138, -11.299967713192564] difference = np.subtract(expected_end_state, end_state) print("Difference is %s" % difference) print("End state: %s" % end_state) npt.assert_allclose(difference[0:3], [0, 0, 0], rtol=0, atol=.02) npt.assert_allclose(difference[3:6], [0, 0, 0], rtol=0, atol=.00002) # The returned ephemeris will be in Sun-centered ICRF, not EMEME. My best guess is that # the ephemeris file doesn't support all reference frames, so if it encounters one that # isn't supported, it'll choose a similar one. ephem = batch.get_results().get_parts()[-1].get_ephemeris() self.assertTrue("ICRF" in ephem) self.assertFalse("EMEME" in ephem)