def test_server_fails(self): """Test a failing server This function tests a failed submit on the server side (i.e. code returned is not 200). """ # Use REST proxy for testing rest = _RestProxyForTest() # Set expected 'POST' request with 404 error rest.expect_post(self._base + '/batch', lambda x: True, 404, {}) # Initiate Batch class batch = Batch() # Set start time, end time, and state vector with epoch batch.set_start_time("AAA") batch.set_end_time("BBB") batch.set_state_vector('CCC', [1, 2, 3, 4, 5, 6]) # Override network access with proxy batch.set_rest_accessor(rest) # Assert that the error code raises a RuntimeError with batch submission with self.assertRaises(RuntimeError): batch.submit()
def _verify_params(self, field): """(Private) Verify parameters (fields) raise KeyErrors if not found This function tests that a given field set to None will raise a KeyError. Args: field (str) - attribute to set to None """ # Use REST proxy for testing rest = _RestProxyForTest() # Initiate Batch class batch = Batch() # Set start time, end time, and state vector with epoch batch.set_start_time("AAA") batch.set_end_time("BBB") batch.set_state_vector('CCC', [1, 2, 3, 4, 5, 6]) # Override network access with proxy batch.set_rest_accessor(rest) # Set batch attribute (field) to None setattr(batch, field, None) # Assert that a missing field will return a KeyError with batch submission with self.assertRaises(KeyError): batch.submit()
def propagate_states(state_vectors, epoch_time, end_time): """Propagate states from one time to another Assume state epoch is the same as integration start time Args: sate_vectors (list of lists) - list of lists with 6 elements [rx, ry, rz, vx, vy, vz] [km, km/s] epoch_time (datetime.datetime) - epoch of state (UTC datetime) end_time (datetime.datetime) - time at which to end the simulation (UTC datetime) Returns: end_state_vectors (list of lists) - states at end of integration [rx, ry, rz, vx, vy, vz] [km, km/s] """ # Convert times to strings epoch_time_str = batch_time_string_from_datetime(epoch_time) start_time_str = epoch_time_str end_time_str = batch_time_string_from_datetime(end_time) print("Propagating %i states to propagate from %s to %s" % (len(state_vectors), start_time_str, end_time_str)) # Create batches from statevectors batches = [] url = "https://pro-equinox-162418.appspot.com/_ah/api/adam/v1" rest = RestRequests(url) for state_vector in state_vectors: batch = Batch(rest) batch.set_state_vector(epoch_time_str, state_vector) batch.set_start_time(start_time_str) batch.set_end_time(end_time_str) batch.set_project('ffffffff-ffff-ffff-ffff-ffffffffffff') batches.append(batch) # submit batches and wait till they finish running submit_batches(batches) # Get final states end_state_vectors = [] for batch in batches: end_state_vectors.append(batch.get_end_state_vector()) return end_state_vectors
def test_bad_step_size_unit(self): """Tests an invalid step size unit This function tests that an invalid defined step size unit will raise a KeyError. """ # Use REST proxy for testing rest = _RestProxyForTest() # Initiate Batch class batch = Batch() # Set start time, end time, and state vector with epoch batch.set_start_time("AAA") batch.set_end_time("BBB") batch.set_state_vector('CCC', [1, 2, 3, 4, 5, 6]) with self.assertRaises(KeyError): batch.set_step_size(3600, 'blah')
def test_good_submit(self): """Test a good/passing batch submit This function tests a good batch submit run. """ # Use REST proxy for testing rest = _RestProxyForTest() def check_input(data_dict): """Check input data Checks input data by asserting the following: - start time = 'AAA' - end time = 'BBB' - step size = 86400 (default) - opm string in data dictionary is not None - originator = 'ADAM_User' - object name = 'dummy' - object ID = '001' - epoch and state vector are 'CCC' and [1, 2, 3, 4, 5, 6], respectively - object mass = 1000 (default) - object solar radiation area = 20 (default) - object solar radiation coefficient = 1 (default) - object drag area = 20 (default) - object drag coefficient = 2.2 (default) - propagator ID is default (none specified) Args: data_dict (dict) - input data for POST Returns: True """ self.assertEqual(data_dict['start_time'], 'AAA') self.assertEqual(data_dict['end_time'], 'BBB') self.assertEqual(data_dict['step_duration_sec'], 86400) opm = data_dict['opm_string'] self.assertIsNotNone(opm) self.assertIn('ORIGINATOR = ADAM_User', opm) self.assertIn('OBJECT_NAME = dummy', opm) self.assertIn('OBJECT_ID = 001', opm) self.assertIn('EPOCH = CCC', opm) self.assertIn('X = 1', opm) self.assertIn('Y = 2', opm) self.assertIn('Z = 3', opm) self.assertIn('X_DOT = 4', opm) self.assertIn('Y_DOT = 5', opm) self.assertIn('Z_DOT = 6', opm) self.assertIn('MASS = 1000', opm) self.assertIn('SOLAR_RAD_AREA = 20', opm) self.assertIn('SOLAR_RAD_COEFF = 1', opm) self.assertIn('DRAG_AREA = 20', opm) self.assertIn('DRAG_COEFF = 2.2', opm) self.assertEqual(data_dict['propagator_uuid'], "00000000-0000-0000-0000-000000000001") return True # Set expected 'POST' request (good) rest.expect_post(self._base + "/batch", check_input, 200, { 'calc_state': 'PENDING', 'uuid': 'BLAH' }) # Initiate Batch class batch = Batch() # Set start time, end time, and state vector with epoch batch.set_start_time("AAA") batch.set_end_time("BBB") batch.set_state_vector('CCC', [1, 2, 3, 4, 5, 6]) # Override network access with proxy batch.set_rest_accessor(rest) # Submit job batch.submit() # Assert that the calc state is 'PENDING' and the UUID is 'BLAH' self.assertEqual(batch.get_calc_state(), 'PENDING') self.assertEqual(batch.get_uuid(), 'BLAH')
def test_custom_inputs(self): """Test setting custom inputs This function tests that setting an optional input will yield that value (instead of the default value). """ # Use REST proxy for testing rest = _RestProxyForTest() def check_custom_inputs(data_dict): """Check custom inputs Checks input data for custom inputs by asserting the following: - propagator uuid = 00000000-0000-0000-0000-000000000002 - step size = 216000 - object mass = 500.5 - object solar radiation area = 25.2 - object solar radiation coefficient = 1.2 - object drag area = 33.3 - object drag coefficient = 2.5 Args: data_dict (dict) - input data for POST Returns: True """ self.assertEqual(data_dict['propagator_uuid'], "00000000-0000-0000-0000-000000000002") self.assertEqual(data_dict['step_duration_sec'], 216000) self.assertIsNotNone(data_dict['description']) self.assertEqual(data_dict['description'], 'some description') opm = data_dict['opm_string'] self.assertIn('ORIGINATOR = Robot', opm) self.assertIn('OBJECT_NAME = TestObj', opm) self.assertIn('OBJECT_ID = test1234', opm) self.assertIn('MASS = 500.5', opm) self.assertIn('SOLAR_RAD_AREA = 25.2', opm) self.assertIn('SOLAR_RAD_COEFF = 1.2', opm) self.assertIn('DRAG_AREA = 33.3', opm) self.assertIn('DRAG_COEFF = 2.5', opm) return True # Set expected 'POST' request (good) rest.expect_post(self._base + "/batch", check_custom_inputs, 200, { 'calc_state': 'PENDING', 'uuid': 'BLAH' }) # Initiate Batch class batch = Batch() # Set start time, end time, and state vector with epoch batch.set_start_time("AAA") batch.set_end_time("BBB") batch.set_state_vector('CCC', [1, 2, 3, 4, 5, 6]) # Set custom inputs batch.set_propagator_uuid("00000000-0000-0000-0000-000000000002") batch.set_step_size(3600, 'min') batch.set_mass(500.5) batch.set_solar_rad_area(25.2) batch.set_solar_rad_coeff(1.2) batch.set_drag_area(33.3) batch.set_drag_coeff(2.5) batch.set_originator('Robot') batch.set_object_name('TestObj') batch.set_object_id('test1234') batch.set_description('some description') # Override network access with proxy batch.set_rest_accessor(rest) # Submit job batch.submit() # Assert that the calc state is 'PENDING' and the UUID is 'BLAH' self.assertEqual(batch.get_calc_state(), 'PENDING') self.assertEqual(batch.get_uuid(), 'BLAH')
def test_custom_inputs(self): """Test setting custom inputs This function tests that setting an optional input will yield that value (instead of the default value). """ # Use REST proxy for testing rest = _RestProxyForTest() def check_custom_inputs(data_dict): """Check custom inputs Checks input data for custom inputs by asserting the following: - propagator uuid = 00000000-0000-0000-0000-000000000002 - step size = 216000 - covariance = [0, 1, 2, ... , 20] - perturbation = 3 - hypercube = FACES - object mass = 500.5 - object solar radiation area = 25.2 - object solar radiation coefficient = 1.2 - object drag area = 33.3 - object drag coefficient = 2.5 Args: data_dict (dict) - input data for POST Returns: True """ self.assertEqual(data_dict['propagator_uuid'], "00000000-0000-0000-0000-000000000002") self.assertEqual(data_dict['step_duration_sec'], 216000) self.assertIsNotNone(data_dict['description']) self.assertEqual(data_dict['description'], 'some description') opm = data_dict['opm_string'] self.assertIn('ORIGINATOR = Robot', opm) self.assertIn('OBJECT_NAME = TestObj', opm) self.assertIn('OBJECT_ID = test1234', opm) self.assertIn('MASS = 500.5', opm) self.assertIn('SOLAR_RAD_AREA = 25.2', opm) self.assertIn('SOLAR_RAD_COEFF = 1.2', opm) self.assertIn('DRAG_AREA = 33.3', opm) self.assertIn('DRAG_COEFF = 2.5', opm) self.assertIn('CX_X = 0', opm) self.assertIn('CY_X = 1', opm) self.assertIn('CY_Y = 2', opm) self.assertIn('CZ_X = 3', opm) self.assertIn('CZ_Y = 4', opm) self.assertIn('CZ_Z = 5', opm) self.assertIn('CX_DOT_X = 6', opm) self.assertIn('CX_DOT_Y = 7', opm) self.assertIn('CX_DOT_Z = 8', opm) self.assertIn('CX_DOT_X_DOT = 9', opm) self.assertIn('CY_DOT_X = 10', opm) self.assertIn('CY_DOT_Y = 11', opm) self.assertIn('CY_DOT_Z = 12', opm) self.assertIn('CY_DOT_X_DOT = 13', opm) self.assertIn('CY_DOT_Y_DOT = 14', opm) self.assertIn('CZ_DOT_X = 15', opm) self.assertIn('CZ_DOT_Y = 16', opm) self.assertIn('CZ_DOT_Z = 17', opm) self.assertIn('CZ_DOT_X_DOT = 18', opm) self.assertIn('CZ_DOT_Y_DOT = 19', opm) self.assertIn('CZ_DOT_Z_DOT = 20', opm) self.assertIn('USER_DEFINED_ADAM_INITIAL_PERTURBATION = 3 [sigma]', opm) self.assertIn('USER_DEFINED_ADAM_HYPERCUBE = FACES', opm) return True # Set expected 'POST' request (good) rest.expect_post("/batch", check_custom_inputs, 200, { 'calc_state': 'PENDING', 'uuid': 'BLAH' }) # Initiate Batch class batch = Batch(rest) # Set start time, end time, and state vector with epoch batch.set_start_time("AAA") batch.set_end_time("BBB") batch.set_state_vector('CCC', [1, 2, 3, 4, 5, 6]) # Set custom inputs batch.set_propagator_uuid("00000000-0000-0000-0000-000000000002") batch.set_step_size(3600, 'min') batch.set_covariance([x for x in range(0, 21)], 'FACES', 3) batch.set_mass(500.5) batch.set_solar_rad_area(25.2) batch.set_solar_rad_coeff(1.2) batch.set_drag_area(33.3) batch.set_drag_coeff(2.5) batch.set_originator('Robot') batch.set_object_name('TestObj') batch.set_object_id('test1234') batch.set_description('some description') # Submit job batch.submit() # Assert that the calc state is 'PENDING' and the UUID is 'BLAH' self.assertEqual(batch.get_calc_state(), 'PENDING') self.assertEqual(batch.get_uuid(), 'BLAH')
from adam import Batch import time state_vec = [ 130347560.13690618, -74407287.6018632, -35247598.541470632, 23.935241263310683, 27.146279819258538, 10.346605942591514 ] batch_run = Batch() batch_run.set_start_time('2017-10-04T00:00:00Z') batch_run.set_end_time('2017-10-11T00:00:00Z') batch_run.set_state_vector('2017-10-04T00:00:00.000Z', state_vec) # Optional parameters (uncomment to use) # batch_run.set_propagator_uuid("00000000-0000-0000-0000-000000000002") # Only Sun as point mass, nothing else # batch_run.set_step_size(3600, 'min') # batch_run.set_mass(500.5) # batch_run.set_solar_rad_area(25.2) # batch_run.set_solar_rad_coeff(1.2) # batch_run.set_drag_area(33.3) # batch_run.set_drag_coeff(2.5) # batch_run.set_originator('Robot') # batch_run.set_object_name('TestObj') # batch_run.set_object_id('test1234') # batch_run.set_description('some description') print("Initial state %s" % batch_run) print print(batch_run.generate_opm()) batch_run.submit() print
23.935241263310683, 27.146279819258538, 10.346605942591514 ] # 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, + \ -2.211832501084875e-07, -2.864186892102733e-07, 1.798098699846038e-07, 2.608899201686016e-10, 1.767514756338532e-10, + \ -3.041346050686871e-07, -4.989496988610662e-07, 3.540310904497689e-07, 1.869263192954590e-10, 1.008862586240695e-10, 6.224444338635500e-10] # Create batch class batch_run = Batch(rest) # initialize batch_run.set_start_time( '2017-10-04T00:00:00Z') # set propagation start time in ISO format batch_run.set_end_time( '2017-10-11T00:00:00Z') # set propagation end time in ISO format batch_run.set_state_vector( '2017-10-04T00:00:00.000Z', state_vec) # set epoch (in ISO format) and state vector # Use the catch-all project for now. batch_run.set_project('ffffffff-ffff-ffff-ffff-ffffffffffff') # Optional parameters (uncomment to use) # batch_run.set_propagator_uuid("00000000-0000-0000-0000-000000000002") # set force model from config # batch_run.set_step_size(3600, 'min') # set step size and units # batch_run.set_covariance(covariance, 'FACES', 3) # set covariance, type, and sigma # batch_run.set_mass(500.5) # set object mass # batch_run.set_solar_rad_area(25.2) # set object solar radiation area (m^2) # batch_run.set_solar_rad_coeff(1.2) # set object solar radiation coefficient # batch_run.set_drag_area(33.3) # set object drag area (m^2)