class BasicTest(unittest.TestCase): """Basic integration test to demonstrate use of service tester. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_config.json').get_config() self.service = Service(config) self.assertTrue(self.service.setup()) self.assertIsNotNone(self.service.new_working_project()) def tearDown(self): self.service.teardown() def test_basic(self): print("Hello world")
class BatchPropagationTest(unittest.TestCase): 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() def new_batch_propagation(self): now = datetime.datetime.utcnow() later = now + datetime.timedelta(10 * 365) propagation_params = PropagationParams({ 'start_time': now.isoformat() + 'Z', 'end_time': later.isoformat() + 'Z', 'step_size': 60 * 60, # 1 hour. 'description': 'Created by test at ' + str(now) + 'Z' }) state_vec = [ 130347560.13690618, -74407287.6018632, -35247598.541470632, 23.935241263310683, 27.146279819258538, 10.346605942591514 ] opm_params = OpmParams({ 'epoch': now.isoformat() + 'Z', 'state_vector': state_vec, # Comment out state_vector and uncomment this to try with keplerian elements instead. # '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 # }, 'mass': 500.5, 'solar_rad_area': 25.2, 'solar_rad_coeff': 1.2, 'drag_area': 33.3, 'drag_coeff': 2.5, 'originator': 'Test', 'object_name': 'TestObj', 'object_id': 'TestObjId', # Uncomment this to try a hypercube propagation. # Lower triangular covariance matrix (21 elements in a list) # 'covariance': [ # 3.331349476038534e-04, # 4.618927349220216e-04, 6.782421679971363e-04, # -3.070007847730449e-04, -4.221234189514228e-04, 3.231931992380369e-04, # -3.349365033922630e-07, -4.686084221046758e-07, 2.484949578400095e-07, 4.296022805587290e-10, # NOQA (we want to keep the visual triangle) # -2.211832501084875e-07, -2.864186892102733e-07, 1.798098699846038e-07, 2.608899201686016e-10, 1.767514756338532e-10, # NOQA # -3.041346050686871e-07, -4.989496988610662e-07, 3.540310904497689e-07, 1.869263192954590e-10, 1.008862586240695e-10, 6.224444338635500e-10], # NOQA # 'perturbation': 3, # 'hypercube': 'FACES', }) return BatchPropagation(propagation_params, opm_params) def test_batch_propagation(self): batch_propagation = self.new_batch_propagation() props = BatchPropagations(self.service.rest) props.insert(batch_propagation, self.working_project.get_uuid()) uuid = batch_propagation.get_uuid() self.assertIsNotNone(uuid) print(uuid) runnable_state = props.get_runnable_state(uuid) self.assertIsNotNone(runnable_state) while (runnable_state.get_calc_state() != 'COMPLETED'): print(runnable_state.get_calc_state()) runnable_state = props.get_runnable_state(uuid) self.assertIsNotNone(runnable_state) self.assertEqual('COMPLETED', runnable_state.get_calc_state()) self.assertIsNone(runnable_state.get_error()) runnable_state_list = props.get_runnable_states( self.working_project.get_uuid()) self.assertEqual(1, len(runnable_state_list)) props.update_with_results(batch_propagation) self.assertIsNotNone(batch_propagation) fresh_batch = props.get(uuid) self.assertIsNotNone(fresh_batch) children = props.get_children(uuid) self.assertEqual(len(batch_propagation.get_final_state_vectors()), len(children)) for i in range(len(batch_propagation.get_final_state_vectors())): self.assertEqual(batch_propagation.get_final_state_vectors()[i], children[i].get_final_state_vector()) props.delete(uuid) self.assertIsNone(props.get(uuid)) self.assertEqual(0, len(props.get_children(uuid)))
class BackwardsPropagationTest(unittest.TestCase): """Integration test of backwards propagation. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_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_batch(self, state_vec, start_time, end_time): start_time_str = start_time.isoformat() + 'Z' end_time_str = end_time.isoformat() + 'Z' propagation_params = PropagationParams({ 'start_time': start_time_str, 'end_time': end_time_str, 'step_size': 0, 'project_uuid': self.working_project.get_uuid(), 'description': 'Created by test at ' + start_time_str }) opm_params = OpmParams({ 'epoch': start_time_str, 'state_vector': state_vec, 'mass': 500.5, 'solar_rad_area': 25.2, 'solar_rad_coeff': 1.2, 'drag_area': 33.3, 'drag_coeff': 2.5, 'originator': 'Test', 'object_name': 'TestObj', 'object_id': 'TestObjId', }) return Batch(propagation_params, opm_params) def test_backwards_and_forwards(self): now = datetime.datetime.now() later = now + datetime.timedelta(10 * 365) # 10 years state_vec = [ 130347560.13690618, -74407287.6018632, -35247598.541470632, 23.935241263310683, 27.146279819258538, 10.346605942591514 ] print("Starting at %s" % (state_vec)) print("Propagating forward from %s to %s" % (now, later)) batch = self.make_batch(state_vec, now, later) runner = BatchRunManager(self.service.get_batches_module(), [batch]) runner.run() forward_end_state = batch.get_results().get_end_state_vector() print("Final state at %s" % forward_end_state) print("Propagating backward from %s to %s" % (later, now)) batch = self.make_batch(forward_end_state, later, now) runner = BatchRunManager(self.service.get_batches_module(), [batch]) runner.run() backwards_end_state = batch.get_results().get_end_state_vector() print("Final state at %s" % backwards_end_state) difference = np.subtract(state_vec, backwards_end_state) print("Difference is %s" % difference) npt.assert_allclose(difference[0:3], [0, 0, 0], rtol=0, atol=1e-3) npt.assert_allclose(difference[3:6], [0, 0, 0], rtol=0, atol=1e-10)
class HypercubeTest(unittest.TestCase): """Tests hypercube propagation. """ 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 new_hypercube_batch(self, hypercube): now = datetime.datetime.utcnow() later = now + datetime.timedelta(365 * 10) # 10 years propagation_params = PropagationParams({ 'start_time': now.isoformat() + 'Z', 'end_time': later.isoformat() + 'Z', 'step_size': 0, 'project_uuid': self.working_project.get_uuid(), 'description': 'Created by test at ' + str(now) + 'Z' }) state_vec = [130347560.13690618, -74407287.6018632, -35247598.541470632, 23.935241263310683, 27.146279819258538, 10.346605942591514] opm_params = OpmParams({ 'epoch': now.isoformat() + 'Z', 'state_vector': state_vec, 'mass': 500.5, 'solar_rad_area': 25.2, 'solar_rad_coeff': 1.2, 'drag_area': 33.3, 'drag_coeff': 2.5, 'originator': 'Test', 'object_name': 'TestObj', 'object_id': 'TestObjId', # Lower triangular covariance matrix (21 elements in a list) 'covariance': [ 3.331349476038534e-04, 4.618927349220216e-04, 6.782421679971363e-04, -3.070007847730449e-04, -4.221234189514228e-04, 3.231931992380369e-04, -3.349365033922630e-07, -4.686084221046758e-07, 2.484949578400095e-07, 4.296022805587290e-10, # NOQA (we want to keep the visual triangle) -2.211832501084875e-07, -2.864186892102733e-07, 1.798098699846038e-07, 2.608899201686016e-10, 1.767514756338532e-10, # NOQA -3.041346050686871e-07, -4.989496988610662e-07, 3.540310904497689e-07, 1.869263192954590e-10, 1.008862586240695e-10, 6.224444338635500e-10], # NOQA 'perturbation': 3, 'hypercube': hypercube, }) return Batch(propagation_params, opm_params) def test_faces(self): batch = self.new_hypercube_batch('FACES') runner = BatchRunManager(self.service.get_batches_module(), [batch]) runner.run() self.assertEqual('COMPLETED', batch.get_calc_state()) parts = batch.get_results().get_parts() self.assertEqual(13, len(parts)) def test_corners(self): batch = self.new_hypercube_batch('CORNERS') runner = BatchRunManager(self.service.get_batches_module(), [batch]) runner.run() self.assertEqual('COMPLETED', batch.get_calc_state()) parts = batch.get_results().get_parts() self.assertEqual(65, len(parts))
class BatchRunnerTest(unittest.TestCase): """Integration test of batch running. """ 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 new_dummy_batch(self, days_to_propagate): if (days_to_propagate > 36500): print("Server has trouble handling propagation durations longer than 100 years. " + "Try something smaller.") return now = datetime.datetime.utcnow() later = now + datetime.timedelta(days_to_propagate) propagation_params = PropagationParams({ 'start_time': now.isoformat() + 'Z', 'end_time': later.isoformat() + 'Z', 'step_size': 60 * 60, # 1 hour. 'project_uuid': self.working_project.get_uuid(), 'description': 'Created by test at ' + str(now) + 'Z' }) state_vec = [130347560.13690618, -74407287.6018632, -35247598.541470632, 23.935241263310683, 27.146279819258538, 10.346605942591514] opm_params = OpmParams({ 'epoch': now.isoformat() + 'Z', 'state_vector': state_vec, 'mass': 500.5, 'solar_rad_area': 25.2, 'solar_rad_coeff': 1.2, 'drag_area': 33.3, 'drag_coeff': 2.5, 'originator': 'Test', 'object_name': 'TestObj', 'object_id': 'TestObjId', }) return Batch(propagation_params, opm_params) def test_small_batch(self): num_batches = 3 duration = 365 # 1 year batches = [self.new_dummy_batch(duration) for i in range(num_batches)] runner = BatchRunManager(self.service.get_batches_module(), batches) runner.run() statuses = runner.get_latest_statuses() self.assertEqual(0, len(statuses['PENDING'])) self.assertEqual(0, len(statuses['RUNNING'])) self.assertEqual(num_batches, len(statuses['COMPLETED'])) self.assertEqual(0, len(statuses['FAILED'])) end_state_vec = [-37535741.96415495, 492953227.1713997, 204483503.94517875, -11.337510170756701, 7.185009462698965, 3.3597614338244766] for batch in batches: npt.assert_allclose(end_state_vec, batch.get_results().get_end_state_vector(), rtol=1e-3, atol=0)
class StmPropagationModuleTest(unittest.TestCase): """Basic integration test to demonstrate use of service tester. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_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) self.stm_module = StmPropagationModule( self.service.get_batches_module()) def tearDown(self): self.service.teardown() def test_basic_stm(self): state_vec = [ 130347560.13690618, -74407287.6018632, -35247598.541470632, 23.935241263310683, 27.146279819258538, 10.346605942591514 ] start_time = datetime.datetime(2017, 10, 4, 0, 0, 0, 123456) end_time = datetime.datetime(2018, 10, 4, 0, 0, 0, 123456) propagation_params = PropagationParams({ 'start_time': start_time.isoformat() + 'Z', 'end_time': end_time.isoformat() + 'Z', 'project_uuid': self.working_project.get_uuid(), 'description': 'Created by test at ' + start_time.isoformat() + 'Z' }) opm_params = OpmParams({ 'epoch': start_time.isoformat() + 'Z', 'state_vector': state_vec, }) end_state, stm = self.stm_module.run_stm_propagation( propagation_params, opm_params) # Taken from printed output of ../state_stm_propagation.py expected_end_state = np.array([ -37523497.931654416, 492950622.8491298, 204482176.63445434, -11.336957217854795, 7.18499733419028, 3.3597496059480085 ]) expected_stm = np.matrix( [[ 9.70874844e+00, -1.21563565e+00, -9.26967637e-01, 5.34214567e+07, 1.64329953e+07, 5.30094892e+06 ], [ 7.11171945e+00, -3.24202476e+00, -5.93038128e-01, 3.90278376e+07, 3.82420496e+07, 9.62761631e+06 ], [ 2.50503331e+00, -3.00334152e-01, -2.62144498e+00, 1.46131045e+07, 1.04218322e+07, 1.53347450e+07 ], [ 2.14264136e-07, -2.82295666e-08, -2.23357566e-08, 1.33259336e+00, 6.98930318e-01, 2.41824966e-01 ], [ 4.69172199e-07, -2.03571494e-07, -6.32223023e-08, 2.52995851e+00, 2.04570983e+00, 7.47014439e-01 ], [ 1.82661672e-07, -4.57388872e-08, -1.15455121e-07, 9.96459361e-01, 8.11376173e-01, 3.16765622e-01 ]]) npt.assert_allclose(expected_end_state, np.array(end_state), rtol=1e-8, atol=0) npt.assert_allclose(expected_stm.getA(), stm.getA(), rtol=1e-8, atol=0)
class TargetedPropagationTest(unittest.TestCase): 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() def new_targeted_propagation(self, initial_maneuver): start = '2013-05-25T00:00:02.000000Z' end = '2018-04-25T03:06:14.200000Z' propagation_params = PropagationParams({ 'start_time': start, 'end_time': end, 'project_uuid': self.working_project.get_uuid(), 'description': 'Created by test at ' + start }) state_vec = [ -1.4914794358536252e+8, 1.0582106861692128e+8, 6.0492834101479955e+7, -11.2528789273597756, -22.3258231726462242, -9.7271222877710155 ] opm_params = OpmParams({ 'epoch': start, 'state_vector': state_vec, 'initial_maneuver': initial_maneuver, }) return TargetedPropagation( propagation_params, opm_params, TargetingParams({ 'target_distance_from_earth': 1.0e4, 'tolerance': 1.0 })) def test_targeted_propagation(self): targeted_propagation = self.new_targeted_propagation([0, 0, 0]) props = TargetedPropagations(self.service.rest) props.insert(targeted_propagation, self.working_project.get_uuid()) uuid = targeted_propagation.get_uuid() self.assertIsNotNone(uuid) runnable_state = props.get_runnable_state(uuid) self.assertIsNotNone(runnable_state) while (runnable_state.get_calc_state() != 'COMPLETED' and runnable_state.get_calc_state() != 'FAILED'): runnable_state = props.get_runnable_state(uuid) self.assertIsNotNone(runnable_state) self.assertEqual('COMPLETED', runnable_state.get_calc_state()) self.assertIsNone(runnable_state.get_error()) runnable_state_list = props.get_runnable_states( self.working_project.get_uuid()) self.assertEqual(1, len(runnable_state_list)) props.update_with_results(targeted_propagation) self.assertIsNotNone(targeted_propagation.get_ephemeris()) maneuver = targeted_propagation.get_maneuver() fresh_targeted_prop = props.get(uuid) self.assertIsNotNone(fresh_targeted_prop) self.assertEqual(uuid, fresh_targeted_prop.get_uuid()) props.delete(uuid) self.assertIsNone(props.get(uuid)) # Create a new propagation with the given maneuver as the initial maneuver. # It should report no additional maneuver needed. targeted_propagation2 = self.new_targeted_propagation(maneuver) RunnableManager(props, [targeted_propagation2], self.working_project.get_uuid()).run() self.assertEqual(maneuver[0], targeted_propagation2.get_maneuver()[0]) self.assertEqual(maneuver[1], targeted_propagation2.get_maneuver()[1]) self.assertEqual(maneuver[2], targeted_propagation2.get_maneuver()[2])
class KeplerianTest(unittest.TestCase): """Integration test of using keplerian elements instead of cartesian. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_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 RunnableManagerTest(unittest.TestCase): 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() def new_batch_propagation(self): now = datetime.datetime.utcnow() later = now + datetime.timedelta(10 * 365) propagation_params = PropagationParams({ 'start_time': now.isoformat() + 'Z', 'end_time': later.isoformat() + 'Z', 'step_size': 60 * 60, # 1 hour. 'description': 'Created by test at ' + str(now) + 'Z' }) state_vec = [ 130347560.13690618, -74407287.6018632, -35247598.541470632, 23.935241263310683, 27.146279819258538, 10.346605942591514 ] opm_params = OpmParams({ 'epoch': now.isoformat() + 'Z', 'state_vector': state_vec, 'mass': 500.5, 'solar_rad_area': 25.2, 'solar_rad_coeff': 1.2, 'drag_area': 33.3, 'drag_coeff': 2.5, 'originator': 'Test', 'object_name': 'TestObj', 'object_id': 'TestObjId', }) return BatchPropagation(propagation_params, opm_params) def test_runnable_manager(self): batch_propagations = [self.new_batch_propagation() for i in range(3)] batch_propagations_module = BatchPropagations(self.service.rest) manager = RunnableManager(batch_propagations_module, batch_propagations, self.working_project.get_uuid()) manager.run() for prop in batch_propagations: self.assertEqual('COMPLETED', prop.get_runnable_state().get_calc_state()) self.assertEqual(len(prop.get_final_state_vectors()), len(prop.get_children())) for i in range(len(prop.get_final_state_vectors())): self.assertEqual( prop.get_final_state_vectors()[i], prop.get_children()[i].get_final_state_vector())
class PropagatorConfigTest(unittest.TestCase): """Test of propagator config manipulation. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_config.json').get_config() self.service = Service(config) self.assertTrue(self.service.setup()) def tearDown(self): self.service.teardown() def test_get_public_configs(self): # Config management isn't very common, doesn't merit direct addition to service. configs = PropagatorConfigs(self.service.rest) public_config_1 = configs.get_config( PropagatorConfigs.PUBLIC_CONFIG_ALL_PLANETS_AND_MOON) self.assertEqual("00000000-0000-0000-0000-000000000001", public_config_1.get_uuid()) public_config_2 = configs.get_config( PropagatorConfigs.PUBLIC_CONFIG_SUN_ONLY) self.assertEqual("00000000-0000-0000-0000-000000000002", public_config_2.get_uuid()) public_config_3 = configs.get_config( PropagatorConfigs.PUBLIC_CONFIG_ALL_PLANETS_AND_MOON_AND_ASTEROIDS) self.assertEqual("00000000-0000-0000-0000-000000000003", public_config_3.get_uuid()) def test_config_management(self): # Config management isn't very common, doesn't merit direct addition to service. configs = PropagatorConfigs(self.service.rest) project = self.service.new_working_project() self.assertIsNotNone(project) config = configs.new_config({ 'project': project.get_uuid(), 'description': 'test config' }) self.assertEqual(project.get_uuid(), config.get_project()) my_configs = configs.get_configs() self.assertIn(config.get_uuid(), [c.get_uuid() for c in my_configs]) config_again = configs.get_config(config.get_uuid()) self.assertEqual(config.get_config_json(), config_again.get_config_json()) configs.delete_config(config.get_uuid()) my_configs = configs.get_configs() self.assertNotIn(config.get_uuid(), [c.get_uuid() for c in my_configs]) def test_config_in_use_pins_project(self): # Config management isn't very common, doesn't merit direct addition to service. configs = PropagatorConfigs(self.service.rest) projects = self.service.get_projects_module() project = self.service.new_working_project() project1 = projects.new_project(project.get_uuid(), "", "") self.assertIsNotNone(project1) project2 = projects.new_project(project.get_uuid(), "", "") self.assertIsNotNone(project2) print("Added child projects to working project: " + "[" + project1.get_uuid() + ", " + project2.get_uuid() + "]") config = configs.new_config({ 'project': project1.get_uuid(), 'description': 'test config' }) self.assertEqual(project1.get_uuid(), config.get_project()) batch = Batch( PropagationParams({ 'start_time': '2017-10-04T00:00:00Z', 'end_time': '2017-10-05T00:00:00Z', 'project_uuid': project2.get_uuid(), 'propagator_uuid': config.get_uuid() }), OpmParams({ 'epoch': '2017-10-04T00:00:00Z', 'state_vector': [ 130347560.13690618, -74407287.6018632, -35247598.541470632, 23.935241263310683, 27.146279819258538, 10.346605942591514 ] })) BatchRunManager(self.service.get_batches_module(), [batch]).run() # Attempt to delete the project with the config in it. It should refuse because the # config is still in use by the batch. with self.assertRaises(RuntimeError): projects.delete_project(project1.get_uuid()) # Then delete the batch. After that, the project with the config in it should # delete no problem. self.service.batches.delete_batch(batch.get_uuid()) projects.delete_project(project1.get_uuid()) # Clean up the batch holder project. projects.delete_project(project2.get_uuid())
class ReferenceFrameTest(unittest.TestCase): """Integration test of using different reference frames. """ def setUp(self): config = ConfigManager(os.getcwd() + '/test_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)
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())