Exemple #1
0
    def test_cuboid_intersections(self, trajectory, shape_data, expected):
        shape = Cuboid(*shape_data * km)
        td = np.array(trajectory) * km

        np.testing.assert_array_equal(
            shape.intersect(
                Trajectory(td[:, 0],
                           td[:, 1],
                           td[:, 2],
                           np.arange(0, len(trajectory)),
                           'gse')),
            np.array(expected))
Exemple #2
0
 def test_empty_trajectory(self):
     np.testing.assert_array_equal(
         broni.intervals(
             broni.Trajectory([] * km, [] * km, [] * km,
                              [],
                              'gse'),
             Cuboid(*(0, 0, 0, 2, 2, 2) * km)),
         [])
Exemple #3
0
class TestCuboid(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_invalid(self):
        with self.assertRaises(ValueError):
            assert Cuboid(0, 0, 0, 0, 0, 0)

    @data(
        (np.array([[1, 1, 1]]), Cuboid(0, 0, 0, 10, 10, 10), np.array(
            [True])),  # one point
        (np.array([[0, 0, 0]]), Cuboid(0, 0, 0, 10, 10, 10), np.array(
            [True])),  # edge point
        (np.array([[-1, 0, 0]]), Cuboid(0, 0, 0, 10, 10, 10), np.array(
            [False])),  # outside
        (np.array([[-1, 0, 0], [0, 0, 0], [1, 1, 1], [11, 11, 11]
                   ]), Cuboid(0, 0, 0, 10, 10, 10),
         np.array([False, True, True, False], dtype=bool)),  # multiple points
        (np.array([[-1, 0, 0]]), Cuboid(-10, -10, -10, 0, 0, 0),
         np.array([True])),  # a cuboid in another quadrant
        (np.array([]), Cuboid(0, 0, 0, 1, 1, 1), np.array(
            [])),  # empty trajectory
        (np.array([[0, 0, 0], [3, 3, 3], [2.9, 2.9, 2.9], [10, 10, 10],
                   [10.1, 10.1, 10.1]]), Cuboid(10, 10, 10, 3, 3, 3),
         np.array([False, True, False, True, False],
                  dtype=bool)),  # Cuboid points "inverted"
    )
    @unpack
    def test_intersections(self, trajectory, shape, expected):
        np.testing.assert_array_equal(shape.intersect(trajectory), expected)

    @data((
        Cuboid(0, 0, 0, 10, 10, 10),
        np.array([[[0., 10., 10., 0., 0.], [0., 10., 10., 0., 0.],
                   [0., 10., 10., 0., 0.], [0., 10., 10., 0., 0.]],
                  [[0., 0., 10., 10., 0.], [0., 0., 10., 10., 0.],
                   [0., 0., 0., 0., 0.], [10., 10., 10., 10., 10.]],
                  [[0., 0., 0., 0., 0.], [10., 10., 10., 10., 10.],
                   [0., 0., 10., 10., 0.], [0., 0., 10., 10., 0.]]]),
    ))
    @unpack
    def test_to_mesh(self, shape, expected):
        np.testing.assert_array_equal(shape.to_mesh(), expected)
Exemple #4
0
 def test_invalid_ctor_args_cuboid_without_volume(self):
     with self.assertRaises(ValueError):
         assert Cuboid(0 * km, 0 * km, 0 * km, 0 * km, 0 * km, 0 * km)
Exemple #5
0
class TestTrajectory(unittest.TestCase):
    def test_invalid_ctor_args_with_different_x_y_length(self):
        with self.assertRaises(ValueError):
            assert broni.Trajectory(
                [1], [2, 2], [1],
                [],
                coordinate_system="gse")

    def test_invalid_ctor_args_with_different_x_z_length(self):
        with self.assertRaises(ValueError):
            assert broni.Trajectory(
                [1], [2], [1, 2],
                [],
                coordinate_system="gse")

    def test_invalid_ctor_args_with_different_y_z_length(self):
        with self.assertRaises(ValueError):
            assert broni.Trajectory(
                [1], [2], [1, 2],
                [],
                coordinate_system="gse")

    def test_invalid_ctor_args_time_series_has_to_match_trajectory_length(self):
        with self.assertRaises(ValueError):
            assert broni.Trajectory(
                [0, 0] * km, [0, 0] * km, [0, 0] * km,
                [1, 2, 3],
                coordinate_system="gse")

    def test_empty_trajectory(self):
        np.testing.assert_array_equal(
            broni.intervals(
                broni.Trajectory([] * km, [] * km, [] * km,
                                 [],
                                 'gse'),
                Cuboid(*(0, 0, 0, 2, 2, 2) * km)),
            [])

    @data(
        # simple, one dot trajectory, object-list
        ([[1, 1, 1]], [Cuboid(*(0, 0, 0, 2, 2, 2) * km)], [[0, 0]]),

        # same single object (listified)
        ([[1, 1, 1]], Cuboid(*(0, 0, 0, 2, 2, 2) * km), [[0, 0]]),

        # all points are outside
        ([[2, 2, 2]], Cuboid(*(0, 0, 0, 1, 1, 1) * km), []),

        # no selection objects -> gives empty interval-list
        ([[2, 2, 2]], [], []),

        # single point interval with multi-point trajectory
        ([[-1, -1, -1], [1, 1, 1]], Cuboid(*(0, 0, 0, 2, 2, 2) * km), [[1, 1]]),

        # multi-point interval with multi-point trajectory
        ([[-1, -1, -1], [0, 0, 0], [1, 1, 1]], Cuboid(*(0, 0, 0, 2, 2, 2) * km), [[1, 2]]),

        # trajectory leaving et re-entering the cuboid -> two intervals
        ([[-1, -1, -1], [0, 0, 0], [1, 1, 1], [3, 3, 3], [1, 1, 1], [0, 0, 0]],
         [Cuboid(*(0, 0, 0, 2, 2, 2) * km)], [[1, 2], [4, 5]]),

        # overlapping sphere and cuboid, logical_and between them
        ([[-1, -1, -1], [0, 0, 0], [1, 1, 1], [-1, -1, -1], [0, 0, 0], [1, 1, 1]],
         [Cuboid(*(0, 0, 0, 2, 2, 2) * km), Sphere(*(1.5, 1.5, 1.5, 1) * km)], [[2, 2], [5, 5]]),
    )
    @unpack
    def test_trajectory_intervals_with_primitive_objects_no_time_index(self, trajectory, objects, expected):
        td = np.array(trajectory) * km

        np.testing.assert_array_equal(
            broni.intervals(
                broni.Trajectory(td[:, 0], td[:, 1], td[:, 2],
                                 np.arange(0, len(trajectory)),
                                 'gse'),
                objects),
            np.array(expected))

    @data(
        # multi-point interval with multi-point trajectory
        ([[-1, -1, -1], [0, 0, 0], [1, 1, 1]],
         [1000, 1001, 1002],
         Cuboid(*(0, 0, 0, 2, 2, 2) * km),
         [[1001, 1002]])
    )
    @unpack
    def test_trajectory_intervals_with_dedicated_time_index(self, trajectory, time, objects, expected):
        td = np.array(trajectory) * km

        np.testing.assert_array_equal(
            broni.intervals(
                broni.Trajectory(td[:, 0], td[:, 1], td[:, 2], time, 'gse'),
                objects),
            np.array(expected))
Exemple #6
0
 def test_invalid(self):
     with self.assertRaises(ValueError):
         assert Cuboid(0, 0, 0, 0, 0, 0)
Exemple #7
0
    orbit = broni.Trajectory(sv.data[::2, 0] * km,
                             sv.data[::2, 1] * km,
                             sv.data[::2, 2] * km,
                             sv.time[::2],
                             coordinate_system=coord_sys)

    # sphere = Sphere(30000, 30000, 30000, 15000)
    # intervals = broni.intervals(orbit, sphere)

    # cuboid = Cuboid(10000, 10000, 10000,
    #                25000, 25000, 25000)
    # intervals += broni.intervals(orbit, cuboid)

    sphere = Sphere(30000 * km, 30000 * km, 30000 * km, 20000 * km)
    cuboid = Cuboid(10000 * km, 10000 * km, 10000 * km, 25000 * km, 25000 * km,
                    25000 * km)
    intervals = broni.intervals(orbit, [sphere, cuboid])

    print('found', len(intervals), 'intervals')
    for i in sorted(intervals):
        print('  ', i,
              datetime.datetime.fromtimestamp(i[0]).strftime('%c'), '-',
              datetime.datetime.fromtimestamp(i[1]).strftime('%c'), ';', i[0],
              '-', i[1])

    # intersection points
    slice1 = variable.merge(
        [sv[interval[0]:interval[1]] for interval in intervals])

    fig = plt.figure()
    ax = fig.gca(projection='3d')