def test_3d(self): x = [0, 1, 0, 1, 0, 1, 0, 1] y = [0, 0, 1, 1, 0, 0, 1, 1] z = [0, 0, 0, 0, 1, 1, 1, 1] grid = Structured(z, y, x, (2, 2, 2)) self.assertArrayEqual( grid.get_x(), np.array([0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]) ) self.assertArrayEqual( grid.get_y(), np.array([0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0]) ) self.assertArrayEqual( grid.get_z(), np.array([0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0]) ) self.assertArrayEqual(grid.get_offset(), np.array([8])) self.assertArrayEqual( grid.get_connectivity(), np.array([0, 1, 3, 2, 4, 5, 7, 6]) ) grid = Structured(x, y, z, (2, 2, 2), ordering="ccw") self.assertArrayEqual( grid.get_connectivity(), np.array([1, 0, 2, 3, 5, 4, 6, 7]) )
def test_get_axis_coordinates(self): grid = Structured((1, 1, 4, 4, 5, 5), (2, 3, 2, 3, 2, 3), (3, 2), units=('m', 'km')) self.assertArrayEqual(grid.get_axis_coordinates(0), np.array([1., 1., 4., 4., 5., 5.])) self.assertArrayEqual(grid.get_axis_coordinates(1), np.array([2., 3., 2., 3., 2., 3.]))
def test_1d(self): grid = Structured([-1, 2, 3, 6], (4,)) self.assertEqual(grid.get_point_count(), 4) self.assertEqual(grid.get_cell_count(), 3) self.assertArrayEqual(grid.get_x(), np.array([-1.0, 2.0, 3.0, 6.0])) with self.assertRaises(IndexError): grid.get_y() self.assertArrayEqual(grid.get_shape(), (4,)) self.assertArrayEqual(grid.get_offset(), np.array([2, 4, 6])) self.assertArrayEqual(grid.get_connectivity(), np.array([0, 1, 1, 2, 2, 3]))
def test_get_axis_coordinates(self): grid = Structured( (1, 1, 4, 4, 5, 5), (2, 3, 2, 3, 2, 3), (3, 2), units=("m", "km") ) self.assertArrayEqual( grid.get_axis_coordinates(0), np.array([1.0, 1.0, 4.0, 4.0, 5.0, 5.0]) ) self.assertArrayEqual( grid.get_axis_coordinates(1), np.array([2.0, 3.0, 2.0, 3.0, 2.0, 3.0]) )
def test_structured_without_singletons(self): grid = Structured([0, 0, 0, 1, 1, 1], [1, 2, 3, 1, 2, 3], (2, 3)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), np.array([['y', 'x'], ['y', 'x']])) grid = Structured([0, 1, 2, 3, 4], (5, )) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), np.array([['x']])) grid = Structured([0.] * 6 + [1.] * 6, [0, 0, 0, 1, 1, 1] * 2, [1, 2, 3, 1, 2, 3] * 2, (2, 3, 2)) self.assertArrayEqual( utils.non_singleton_dimension_shape(grid), np.array([['z', 'y', 'x'], ['z', 'y', 'x'], ['z', 'y', 'x']]))
def test_structured_with_singletons(self): grid = Structured([0, 1, 2, 3], [0] * 4, (4, 1)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), np.array([['y']])) grid = Structured([0] * 4, [0, 1, 2, 3], (1, 4)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), np.array([['x']])) grid = Structured([0, 1, 2, 3], [0] * 4, [0] * 4, (4, 1, 1)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), np.array([['z']])) grid = Structured([0] * 4, [0, 1, 2, 3], [0] * 4, (1, 4, 1)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), np.array([['y']])) grid = Structured([0] * 6, [0, 0, 1, 1, 2, 2], [0, 1] * 3, (1, 3, 2)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), np.array([['y', 'x'], ['y', 'x']]))
def test_2d(self): (x, y) = np.meshgrid([1.0, 2.0, 4.0, 8.0], [1.0, 2.0, 3.0]) grid = Structured(y.flatten(), x.flatten(), [3, 4]) self.assertEqual(grid.get_point_count(), 12) self.assertEqual(grid.get_cell_count(), 6) self.assertArrayEqual( grid.get_x(), np.array([1.0, 2.0, 4.0, 8.0, 1.0, 2.0, 4.0, 8.0, 1.0, 2.0, 4.0, 8.0]), ) self.assertArrayEqual( grid.get_y(), np.array([1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0]), ) self.assertArrayEqual(grid.get_shape(), [3, 4]) self.assertArrayEqual(grid.get_offset(), np.array([4, 8, 12, 16, 20, 24])) self.assertArrayEqual( grid.get_connectivity(), np.array( [ 0, 1, 5, 4, 1, 2, 6, 5, 2, 3, 7, 6, 4, 5, 9, 8, 5, 6, 10, 9, 6, 7, 11, 10, ] ), )
def test_structured_without_singletons(self): grid = Structured([0, 0, 0, 1, 1, 1], [1, 2, 3, 1, 2, 3], (2, 3)) self.assertArrayEqual( utils.non_singleton_dimension_shape(grid), np.array([["y", "x"], ["y", "x"]]), ) grid = Structured([0, 1, 2, 3, 4], (5, )) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), np.array([["x"]])) grid = Structured( [0.0] * 6 + [1.0] * 6, [0, 0, 0, 1, 1, 1] * 2, [1, 2, 3, 1, 2, 3] * 2, (2, 3, 2), ) self.assertArrayEqual( utils.non_singleton_dimension_shape(grid), np.array([["z", "y", "x"], ["z", "y", "x"], ["z", "y", "x"]]), )
def test_is_structured(self): grid = Structured([0, 1, 2, 0, 1, 2], [0, 0, 0, 1, 1, 1], (3, 2)) self.assertTrue(is_structured(grid))
def test_is_not_rectilinear(self): grid = Structured([0, 1, 2, 0, 1, 2], [0, 0, 0, 1, 1, 1], (3, 2)) self.assertFalse(is_rectilinear(grid))