예제 #1
0
    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(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 batch attribute (field) to None
        getattr(batch, 'set' + field)(None)

        # Assert that a missing field will return a KeyError with batch submission
        with self.assertRaises(KeyError):
            batch.submit()
예제 #2
0
    def test_part_not_in_range(self):
        """Test a part not in the part range

        This function tests that a part not within its range will raise an error.

        """
        # Dummy UUID and part number for testing
        uuid = 'BLAH'
        part = 15
        num_parts = 10

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Initiate Batch class
        batch = Batch(rest)

        # Set UUID, parts count, and overall calc state (as 'RUNNING')
        batch.set_uuid_for_testing(uuid)
        batch.set_parts_count_for_testing(10)
        batch.set_calc_state_for_testing('COMPLETED')

        # Assert that a part outside its range will return an IndexError
        with self.assertRaises(IndexError):
            batch.get_part_state(part)
예제 #3
0
    def test_server_failed_part(self):
        """Test a failing server for a specific part

        This function tests a failed submit on the server side (i.e. code returned is not 200) for a specified part.

        """

        # Dummy UUID and part number for testing
        uuid = 'BLAH'
        part = 3
        num_parts = 10

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Set expected 'GET' requests with 404 error
        for i in range(1, num_parts + 1):
            rest.expect_get('/batch/' + uuid + '/' + str(i), 404, {})

        # Initiate Batch class
        batch = Batch(rest)

        # Set UUID, parts count, and overall calc state (as 'RUNNING')
        batch.set_uuid_for_testing(uuid)
        batch.set_parts_count_for_testing(10)
        batch.set_calc_state_for_testing('COMPLETED')

        # Assert that a 404 error code will raise a RuntimeError
        with self.assertRaises(RuntimeError):
            batch.get_part_state(part)
예제 #4
0
    def test_server_failed_part(self):
        """Test a failing server for a specific part

        This function tests a failed submit on the server side (i.e. code returned is not 200) for a specified part.

        """

        # Dummy UUID and part number for testing
        uuid = 'BLAH'
        part = 3

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Set expected 'GET' request with 404 error
        rest.expect_get(self._base + '/batch/' + uuid + '/' + str(part), 404,
                        {})

        # Initiate Batch class
        batch = Batch()

        # Set UUID, parts count, and overall calc state (as 'RUNNING')
        batch._uuid = uuid
        batch._parts_count = 10
        batch._calc_state = 'COMPLETED'

        # Override network access with proxy
        batch.set_rest_accessor(rest)

        # Assert that a 404 error code will raise a RuntimeError
        with self.assertRaises(RuntimeError):
            batch.get_part_state(part)
예제 #5
0
    def test_part_not_in_range(self):
        """Test a part not in the part range

        This function tests that a part not within its range will raise an error.

        """
        # Dummy UUID and part number for testing
        uuid = 'BLAH'
        part = 15

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Initiate Batch class
        batch = Batch()

        # Set UUID, parts count, and overall calc state (as 'RUNNING')
        batch._uuid = uuid
        batch._parts_count = 10
        batch._calc_state = 'COMPLETED'

        # Override network access with proxy
        batch.set_rest_accessor(rest)

        # Assert that a part outside its range will return an IndexError
        with self.assertRaises(IndexError):
            batch.get_part_state(part)
예제 #6
0
    def test_is_not_ready_part(self):
        """Test when an individual part is not ready

        This function tests that a job will correctly indicate when a part is not ready.

        """

        # Dummy UUID and part number for testing
        uuid = 'BLAH'
        part = 3
        num_parts = 10

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Set expected 'GET' requests with calc_states as 'RUNNING'
        for i in range(1, num_parts + 1):
            rest.expect_get('/batch/' + uuid + '/' + str(i), 200, {
                'calc_state': 'RUNNING',
                'part_index': i
            })

        # Initiate Batch class
        batch = Batch(rest)

        # Set UUID, parts count, and overall calc state (as 'RUNNING')
        batch.set_uuid_for_testing(uuid)
        batch.set_parts_count_for_testing(num_parts)
        batch.set_calc_state_for_testing('RUNNING')

        # Assert that checking if the part is ready will return False
        self.assertFalse(batch.is_ready_part(part))
예제 #7
0
    def test_sun_ememe(self, service, working_project):
        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':
            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(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()
        assert "ICRF" in ephem
        assert "EMEME" not in ephem
예제 #8
0
    def test_is_not_ready_part(self):
        """Test when an individual part is not ready

        This function tests that a job will correctly indicate when a part is not ready.

        """

        # Dummy UUID and part number for testing
        uuid = 'BLAH'
        part = 3

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Set expected 'GET' request with calc_state as 'RUNNING'
        rest.expect_get(self._base + '/batch/' + uuid + '/' + str(part), 200, {
            'calc_state': 'RUNNING',
            'part_index': part
        })

        # Initiate Batch class
        batch = Batch()

        # Set UUID, parts count, and overall calc state (as 'RUNNING')
        batch._uuid = uuid
        batch._parts_count = 10
        batch._calc_state = 'RUNNING'

        # Override network access with proxy
        batch.set_rest_accessor(rest)

        # Assert that checking if the part is ready will return False
        self.assertFalse(batch.is_ready_part(part))
예제 #9
0
    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_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())
예제 #11
0
    def test_is_ready_fails_no_uuid(self):
        """Test that no specified UUID will raise a KeyError when retrieved

        This function tests that checking if a job is ready without specifying the UUID will result in a KeyError.

        """

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Initiate Batch class
        batch = Batch(rest)

        # Assert that a KeyError is raised when checking if it is ready
        with self.assertRaises(KeyError):
            batch.is_ready()
    def _propagate_states(self, state_vectors, propagation_params, opm_params_templ):
        """Propagate states using many initial state vectors.

        Args:
            state_vectors (list of lists):
                list of lists with 6 elements [rx, ry, rz, vx, vy, vz]  [km, km/s]
            propagation_params (PropagationParams):
                propagation-related parameters to be used for all propagations
            opm_params_templ (OpmParams):
                opm-related parameters to be used for all propagations, once with each
                of the given state vectors.

        Returns:
            end_state_vectors (list of lists):
                states at end of integration [rx, ry, rz, vx, vy, vz]  [km, km/s]
        """

        # Create batches from state vectors
        batches = []
        for state_vector in state_vectors:
            opm_params = deepcopy(opm_params_templ)
            opm_params.set_state_vector(state_vector)
            batches.append(Batch(propagation_params, opm_params))

        # submit batches and wait till they finish running
        runner = BatchRunManager(self.batches_module, batches)
        runner.run()

        # Get final states
        end_state_vectors = []
        for batch in batches:
            end_state_vectors.append(batch.get_results().get_end_state_vector())

        return end_state_vectors
    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)
예제 #14
0
    def test_is_not_ready(self):
        """Test when a job is not ready

        This function tests that a job will correctly indicate when it is not ready and returns the expected number of
        ephemeris parts count.

        """

        # Dummy UUID for testing
        uuid = 'BLAH'

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Set expected 'GET' request with calc_state as 'RUNNING'
        rest.expect_get(self._base + '/batch/' + uuid, 200, {
            'calc_state': 'RUNNING',
            'parts_count': 5
        })

        # Initiate Batch class
        batch = Batch()

        # Set UUID
        batch._uuid = uuid

        # Override network access with proxy
        batch.set_rest_accessor(rest)

        # Assert that checking if the batch is ready will return False
        self.assertFalse(batch.is_ready())

        # Assert that the number of expected parts is returned
        self.assertEqual(batch.get_parts_count(), 5)
예제 #15
0
    def test_is_ready_fails_error_code(self):
        """Test that a failed job returns a RuntimeError when retrieved

        This function tests that a failed error code will return a RuntimeError when attempting to check if it is ready.

        """

        # Dummy UUID for testing
        uuid = 'BLAH'

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Set expected 'GET' request with 500 error (fail)
        rest.expect_get(self._base + '/batch/' + uuid, 500, {})

        # Initiate Batch class
        batch = Batch()

        # Set UUID
        batch._uuid = uuid

        # Override network access with proxy
        batch.set_rest_accessor(rest)

        # Assert that a RuntimeError is raised when checking if it is ready
        with self.assertRaises(RuntimeError):
            batch.is_ready()
예제 #16
0
    def test_icrf(self, service, working_project):
        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':
            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(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()
        assert "ICRF" in ephem
예제 #17
0
    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')
예제 #18
0
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))

    url = "https://pro-equinox-162418.appspot.com/_ah/api/adam/v1"
    rest = RestRequests(url)
    batches_module = Batches(rest)

    # Create batches from statevectors
    batches = []
    propagation_params = PropagationParams({
        'start_time':
        start_time_str,
        'end_time':
        end_time_str,
        'project_uuid':
        'ffffffff-ffff-ffff-ffff-ffffffffffff'
    })
    for state_vector in state_vectors:
        opm_params = OpmParams({
            'epoch': start_time_str,
            'state_vector': state_vector
        })
        batches.append(Batch(propagation_params, opm_params))

    # submit batches and wait till they finish running
    BatchRunManager(batches_module, batches).run()

    # Get final states
    end_state_vectors = []
    for batch in batches:
        end_state_vectors.append(batch.get_results().get_end_state_vector())

    return end_state_vectors
예제 #19
0
    def test_is_ready_failed_part(self):
        """Test when an individual part has failed

        This function tests that a job will correctly indicate when a part has failed, that it returns the expected
        error, and that it returns None for ephemeris.

        """

        # Dummy UUID and part number for testing
        uuid = 'BLAH'
        part = 3

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Set expected 'GET' request with calc_state as 'FAILED'
        rest.expect_get(self._base + '/batch/' + uuid + '/' + str(part), 200, {
            'calc_state': 'FAILED',
            'error': 'Some error',
            'part_index': part
        })

        # Initiate Batch class
        batch = Batch()

        # Set UUID, parts count, and overall calc state (as 'FAILED')
        batch._uuid = uuid
        batch._parts_count = 10
        batch._calc_state = 'FAILED'

        # Override network access with proxy
        batch.set_rest_accessor(rest)

        # Assert that the calc state for the specific part's run is as expected
        self.assertEqual(batch.get_part_state(part), 'FAILED')

        # Assert that the error returned is as expected
        self.assertEqual(batch.get_part_error(part), 'Some error')

        # Assert that attempting to retrieve a part's ephemeris will return None
        self.assertEqual(batch.get_part_ephemeris(part), None)
예제 #20
0
    def test_is_ready_not_found(self):
        """Test that a job is not ready if not found

        This function tests that if a job is not found from a UUID, it will not return as 'ready'.

        """

        # Dummy UUID for testing
        uuid = 'BLAH'

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Set expected 'GET' request with 404 error
        rest.expect_get(self._base + '/batch/' + uuid, 404, {})

        # Initiate Batch class
        batch = Batch()

        # Set UUID
        batch._uuid = uuid

        # Override network access with proxy
        batch.set_rest_accessor(rest)

        # Assert that the job does not show as ready
        self.assertFalse(batch.is_ready())
예제 #21
0
    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('/batch', lambda x: True, 404, {})

        # 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])

        # Assert that the error code raises a RuntimeError with batch submission
        with self.assertRaises(RuntimeError):
            batch.submit()
예제 #22
0
    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)
예제 #23
0
    def test_is_ready_failed(self):
        """Test that job is ready when failed

        This function tests that a job will indicate that it is ready if it has failed.

        """

        # Dummy UUID for testing
        uuid = 'BLAH'

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Set expected 'GET' request with calc_state as 'FAILED'
        rest.expect_get(
            self._base + '/batch/' + uuid, 200, {
                'calc_state': 'FAILED',
                'parts_count': 42,
                'summary': "ZQZ",
                'error': 'No error!'
            })

        # Initiate Batch class
        batch = Batch()

        # Set UUID
        batch._uuid = uuid

        # Override network access with proxy
        batch.set_rest_accessor(rest)

        # Assert that checking if the batch is ready will return True
        self.assertTrue(batch.is_ready())

        # Assert that the calc state is as expected
        self.assertEqual(batch.get_calc_state(), 'FAILED')

        # Assert that the number of expected parts is returned
        self.assertEqual(batch.get_parts_count(), 42)
예제 #24
0
    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)
예제 #25
0
    def test_is_ready_completed(self):
        """Test that job is ready when completed

        This function tests that a job will indicate that it is ready if it has completed.

        """

        # Dummy UUID for testing
        uuid = 'BLAH'

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Set expected 'GET' request with calc_state as 'COMPLETED'
        rest.expect_get(
            '/batch/' + uuid, 200, {
                'uuid': uuid,
                'calc_state': 'COMPLETED',
                'parts_count': 42,
                'summary': "ZQZ",
                'error': 'No error!'
            })

        # Initiate Batch class
        batch = Batch(rest)

        # Set UUID
        batch.set_uuid_for_testing(uuid)

        # Assert that checking if the batch is ready will return True
        self.assertTrue(batch.is_ready())

        # Assert that the calc state is as expected
        self.assertEqual(batch.get_calc_state(), 'COMPLETED')

        # Assert that the number of expected parts is returned
        self.assertEqual(batch.get_parts_count(), 42)
예제 #26
0
            
#     'mass': 500.5,              # object mass
#     'solar_rad_area': 25.2,     # object solar radiation area (m^2)
#     'solar_rad_coeff': 1.2,     # object solar radiation coefficient
#     'drag_area': 33.3,          # object drag area (m^2)
#     'drag_coeff': 2.5,          # object drag coefficient
    
#     'covariance': covariance,   # object covariance
#     'perturbation': 3,          # sigma perturbation on state vector
#     'hypercube': 'FACES',       # hypercube propagation type
    
#     'originator': 'Robot',      # originator of run
#     'object_name': 'TestObj',   # object name
#     'object_id': 'test1234',    # object ID
})
batch = Batch(propagation_params, opm_params)
print("Submitting OPM:")
print(batch.get_opm_params().generate_opm())

# Submit and wait until batch run is ready
batches_module = Batches(auth_rest)
BatchRunManager(batches_module, [batch]).run()

# Get final parts count
parts_count = batch.get_state_summary().get_parts_count()
print("Final state: %s, part count %s\n" % (batch.get_calc_state(), parts_count))

# Get ephemeris of specified part
part_to_get = 0
eph = batch.get_results().get_parts()[part_to_get].get_ephemeris()
print("Ephemeris:")
예제 #27
0
    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')
예제 #28
0
    def test_get_ephemeris(self):
        """Test that an ephemeris is returned if the job has completed successfully

        This function tests that a job that is completed successfully will return the expected ephemeris.

        """

        # Dummy UUID and part number for testing
        uuid = 'BLAH'
        part = 3

        # Use REST proxy for testing
        rest = _RestProxyForTest()

        # Set expected 'GET' request with calc_state as 'COMPLETED' for specific part
        rest.expect_get(
            self._base + '/batch/' + uuid + '/' + str(part), 200, {
                'calc_state': 'COMPLETED',
                'error': 'No error!',
                'stk_ephemeris': 'something',
                'part_index': part
            })

        # Initiate Batch class
        batch = Batch()

        # Set UUID, parts count, and overall calc state (as 'COMPLETED')
        batch._uuid = uuid
        batch._parts_count = 10
        batch._calc_state = 'COMPLETED'

        # Override network access with proxy
        batch.set_rest_accessor(rest)

        # Assert that an overall calc state as 'COMPLETED' will return the expected ephemeris
        self.assertEqual(batch.get_part_ephemeris(part), 'something')

        # Assert that the error is as expected
        self.assertEqual(batch.get_part_error(part), 'No error!')

        # Assert that the calc state for the specific part's run is as expected
        self.assertEqual(batch.get_part_state(part), 'COMPLETED')

        # Assert that checking if the part is ready will return True
        self.assertTrue(batch.is_ready_part(part))
예제 #29
0
    def test_get_methods(self):
        propagation_params = {'a': 1}
        opm_params = {'b': 2}
        batch = Batch(propagation_params, opm_params)
        self.assertEqual(propagation_params, batch.get_propagation_params())
        self.assertEqual(opm_params, batch.get_opm_params())
        self.assertIsNone(batch.get_uuid())
        self.assertIsNone(batch.get_calc_state())
        self.assertIsNone(batch.get_state_summary())
        self.assertIsNone(batch.get_results())

        state_summary = StateSummary({'uuid': 'aaa', 'calc_state': 'RUNNING'})
        batch.set_state_summary(state_summary)
        self.assertEqual(state_summary, batch.get_state_summary())
        self.assertEqual('aaa', batch.get_uuid())
        self.assertEqual('RUNNING', batch.get_calc_state())

        results = {'c': 3}
        batch.set_results(results)
        self.assertEqual(results, batch.get_results())
예제 #30
0
    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')