コード例 #1
0
ファイル: batch_test.py プロジェクト: vvittaldev/adam
    def test_get_final_state_vector(self):
        pr = PropagationResults([None])
        self.assertIsNone(pr.get_end_state_vector())

        pr = PropagationResults([{'part_index': 'a', 'calc_state': 'RUNNING'}])
        self.assertIsNone(pr.get_end_state_vector())

        pr = PropagationResults([
            None, {
                'part_index': 'a',
                'calc_state': 'RUNNING',
                'stk_ephemeris': 'c'
            }, {
                'part_index':
                'b',
                'calc_state':
                'COMPLETED',
                'stk_ephemeris':
                """
some junk here
1 2 3 4 5 6 7
7 6 5 4 3 2 1
            """
            }
        ])
        self.assertEqual([0.006, 0.005, 0.004, 0.003, 0.002, 0.001],
                         pr.get_end_state_vector())
コード例 #2
0
ファイル: batch_test.py プロジェクト: vvittaldev/adam
    def test_get_methods(self):
        # All keys.
        pr = PropagationResults([{
            'part_index': 'a',
            'calc_state': 'b',
            'stk_ephemeris': 'c',
            'error': 'd'
        }])
        self.assertEqual(1, len(pr.get_parts()))
        p = pr.get_parts()[0]
        self.assertEqual('a', p.get_part_index())
        self.assertEqual('b', p.get_calc_state())
        self.assertEqual('c', p.get_ephemeris())
        self.assertEqual('d', p.get_error())

        # Only required keys.
        pr = PropagationResults([{
            'part_index': 'a',
            'calc_state': 'b',
        }])
        self.assertEqual(1, len(pr.get_parts()))
        p = pr.get_parts()[0]
        self.assertEqual('a', p.get_part_index())
        self.assertEqual('b', p.get_calc_state())
        self.assertIsNone(p.get_ephemeris())
        self.assertIsNone(p.get_error())
コード例 #3
0
ファイル: batch_test.py プロジェクト: vvittaldev/adam
 def test_empty_parts(self):
     parts = [None, {'part_index': 'a', 'calc_state': 'b'}, None]
     results = PropagationResults(parts)
     self.assertEqual(3, len(results.get_parts()))
     self.assertIsNone(results.get_parts()[0])
     self.assertIsNotNone(results.get_parts()[1])
     self.assertIsNone(results.get_parts()[2])
コード例 #4
0
    def get_propagation_results(self, state_summary):
        """ Returns a PropagationResults object with as many PropagationPart objects as
            the state summary  claims to have parts, or raises an error. Note that if
            state of given summary is not 'COMPLETED' or 'FAILED', not all parts are
            guaranteed to exist or to have an ephemeris.
        """
        if state_summary.get_parts_count() is None or state_summary.get_parts_count() < 1:
            print("Unable to retrieve results for batch with no parts")
            return None

        parts = [self._get_part(state_summary, i)
                 for i in range(state_summary.get_parts_count())]
        return PropagationResults(parts)
コード例 #5
0
    def test_flow(self):
        batches = MockBatches()

        b1 = get_dummy_batch("p1")
        pending_state = StateSummary({'uuid': 'b1', 'calc_state': 'PENDING'})
        running_state = StateSummary({'uuid': 'b1', 'calc_state': 'RUNNING'})
        completed_state = StateSummary({
            'uuid': 'b1',
            'calc_state': 'COMPLETED'
        })
        failed_state = StateSummary({'uuid': 'b1', 'calc_state': 'FAILED'})
        results = PropagationResults([None])

        batches.expect_new_batch(b1, pending_state)
        batches.expect_get_summaries("p1", {"b1": completed_state})
        batches.expect_get_results(completed_state, results)

        batch_runner = BatchRunManager(batches, [b1], "p1")
        batch_runner.run()
        self.assertEqual(b1.get_state_summary(), completed_state)
        self.assertEqual(b1.get_results(), results)

        batches.clear_expectations()

        batches.expect_new_batch(b1, pending_state)
        batches.expect_get_summaries("p1", {"b1": pending_state})
        batches.expect_get_summaries("p1", {"b1": running_state})
        batches.expect_get_summaries("p1", {"b1": running_state})
        batches.expect_get_summaries("p1", {"b1": completed_state})
        batches.expect_get_results(completed_state, results)

        batch_runner = BatchRunManager(batches, [b1])
        batch_runner.run()
        self.assertEqual(b1.get_state_summary(), completed_state)
        self.assertEqual(b1.get_results(), results)

        batches.clear_expectations()

        batches.expect_new_batch(b1, pending_state)
        batches.expect_get_summaries("p1", {"b1": pending_state})
        batches.expect_get_summaries("p1", {"b1": failed_state})
        batches.expect_get_results(failed_state, results)

        batch_runner = BatchRunManager(batches, [b1])
        batch_runner.run()
        self.assertEqual(b1.get_state_summary(), failed_state)
        self.assertEqual(b1.get_results(), results)

        batches.clear_expectations()
コード例 #6
0
ファイル: batch_test.py プロジェクト: vvittaldev/adam
 def test_no_parts(self):
     with self.assertRaises(RuntimeError):
         PropagationResults([])
コード例 #7
0
ファイル: batch_test.py プロジェクト: vvittaldev/adam
    def test_required_keys(self):
        with self.assertRaises(KeyError):
            PropagationResults([{'part_index': 'a'}])

        with self.assertRaises(KeyError):
            PropagationResults([{'calc_state': 'b'}])
コード例 #8
0
    def test_get_state_at_time(self):
        pr = PropagationResults([None])
        self.assertIsNone(pr.get_state_vector_at_time(datetime.now()))

        pr = PropagationResults([{'part_index': 'a', 'calc_state': 'RUNNING'}])
        self.assertIsNone(pr.get_state_vector_at_time(datetime.now()))

        pr = PropagationResults([
            None, {
                'part_index':
                'a',
                'calc_state':
                'COMPLETED',
                'stk_ephemeris':
                """
some junk here not a file epoch
1 2 3 4 5 6 7
7 6 5 4 3 2 1
            """
            }
        ])
        self.assertIsNone(pr.get_state_vector_at_time(datetime.now()))

        pr = PropagationResults([
            None,
            {
                'part_index':
                'b',
                'calc_state':
                'COMPLETED',
                'stk_ephemeris':
                """
stk.v.9.0

# WrittenBy    STK_Components_2017 r4(17.4.392.0)

BEGIN Ephemeris

NumberOfEphemerisPoints	18252
ScenarioEpoch	21 Jul 2009 13:42:34.615999999999985
InterpolationMethod	Hermite
InterpolationSamplesM1	2
CentralBody	Sun
CoordinateSystem	ICRF

EphemerisTimePosVel

0 73136102939.90326 -133490160572.72543 8406324.905534467 28220.13126652218 22868.590558009368 -0.19231683186022774
-86400 70687762770.92772 -135447234231.29443 8421107.139721738 28452.654845207973 22433.79996994943 -0.1499638154415067
-172800 68219786459.42084 -137366684784.5862 8432255.918466914 28674.683201744967 21997.744385379105 -0.10821028857188271
-259200 65733077574.2293 -139248418103.58472 8439823.350024007 28886.293259423644 21560.77327825493 -0.06706343692839449
-345600 63228532421.91671 -141092369828.8071 8443862.153904703 29087.576060079045 21123.22618751113 -0.026530247821391004
-432000 60707038864.30396 -142898504487.95035 8444425.64979409 29278.635896145453 20685.43217483686 0.013382350455396062
-518400 58169475211.58147 -144666814569.93005 8441567.758123463 29459.589430332002 20247.709357212265 0.052667360276471335
-604800 55616709191.788055 -146397319561.69974 8435343.01074691 29630.564809218675 19810.364512470725 0.09131761180289957
-691200 53049596996.92381 -148090064954.06686 8425806.568807617 29791.700776677662 19373.692755679345 0.12932570231264304
-777600 50468982405.472176 -149745121222.51495 8413014.243413422 29943.145792593295 18937.977283700522 0.16668399446203316
            """

                # NOQA
            }
        ])
        # Wrong time, no match.
        self.assertEqual(
            None,
            pr.get_state_vector_at_time(
                datetime.strptime("21 Jul 2009 13:42:35.616",
                                  "%d %b %Y %H:%M:%S.%f")))

        # Middle point.
        npt.assert_almost_equal([
            70687762.77092772, -135447234.23129443, 8421.107139721738,
            28.452654845207973, 22.43379996994943, -0.0001499638154415067
        ],
                                pr.get_state_vector_at_time(
                                    datetime.strptime(
                                        "20 Jul 2009 13:42:34.616",
                                        "%d %b %Y %H:%M:%S.%f")))

        # Check last point.
        npt.assert_almost_equal([
            50468982.405472176, -149745121.22251495, 8413.014243413422,
            29.943145792593295, 18.937977283700522, 0.00016668399446203316
        ],
                                pr.get_state_vector_at_time(
                                    datetime.strptime(
                                        "12 Jul 2009 13:42:34.616",
                                        "%d %b %Y %H:%M:%S.%f")))