class TestSphere(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def test_invalid(self): with self.assertRaises(ValueError): assert Sphere(0, 0, 0, 0) # zero radius with self.assertRaises(ValueError): assert Sphere(0, 0, 0, -1) # negative radius @data( (np.array([[1, 1, 1]]), Sphere(0, 0, 0, 10), np.array( [True])), # one point (np.array([[0, 0, 10], [0, 10, 0], [10, 0, 0]]), Sphere( 0, 0, 0, 10), np.array([True, True, True])), # some edge vectors (np.array([[0, 0, -10], [0, -10, 0], [-10, 0, 0]]), Sphere( 0, 0, 0, 10), np.array( [True, True, True])), # some edge vectors "on the other side" (np.array([[0, 0, -11], [0, -11, 0], [-11, 0, 0]]), Sphere( 0, 0, 0, 10), np.array([False, False, False])), # just outside ) @unpack def test_intersections(self, trajectory, shape, expected): np.testing.assert_array_equal(shape.intersect(trajectory), expected) @data((Sphere(0, 0, 0, 10), [3, 20, 10])) @unpack def test_to_mesh( self, shape, expected ): # TODO, mesh is huge - function will be changed later on - most likely np.testing.assert_array_equal(shape.to_mesh().shape, expected)
def test_sphere_intersections(self, trajectory, shape_data, expected): shape = Sphere(*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))
def test_invalid(self): with self.assertRaises(ValueError): assert Sphere(0, 0, 0, 0) # zero radius with self.assertRaises(ValueError): assert Sphere(0, 0, 0, -1) # negative radius
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))
def test_invalid_ctor_args_sphere_negative_radius(self): with self.assertRaises(ValueError): assert Sphere(*(0, 0, 0, -1) * km)
coordinate_system=coord_sys) 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])