def test_without_singletons(self): grid = UniformRectilinear((4, 5), (1., 1.), (0., 0.)) self.assertArrayEqual(utils.non_singleton_axes(grid), np.array((0, 1))) grid = UniformRectilinear((5, ), (1., ), (0., )) self.assertArrayEqual(utils.non_singleton_axes(grid), np.array((0, ))) grid = UniformRectilinear((4, 5, 6), (1., 1., 1.), (0., 0., 0.)) self.assertArrayEqual(utils.non_singleton_axes(grid), np.array((0, 1, 2)))
def test_without_singletons(self): grid = UniformRectilinear((4, 5), (1.0, 1.0), (0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_shape(grid), np.array( (4, 5))) grid = UniformRectilinear((5, ), (1.0, ), (0.0, )) self.assertArrayEqual(utils.non_singleton_shape(grid), np.array((5, ))) grid = UniformRectilinear((4, 5, 6), (1.0, 1.0, 1.0), (0.0, 0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_shape(grid), np.array((4, 5, 6)))
def test_without_singletons(self): grid = UniformRectilinear((4, 5), (1., 1.), (0., 0.)) self.assertArrayEqual(utils.non_singleton_coordinate_names(grid), ('y', 'x')) grid = UniformRectilinear((5, ), (1., ), (0., )) self.assertArrayEqual(utils.non_singleton_coordinate_names(grid), ('x', )) grid = UniformRectilinear((4, 5, 6), (1., 1., 1.), (0., 0., 0.)) self.assertArrayEqual(utils.non_singleton_coordinate_names(grid), ('z', 'y', 'x'))
def test_without_singletons(self): grid = UniformRectilinear((4, 5), (1.0, 1.0), (0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_coordinate_names(grid), ("y", "x")) grid = UniformRectilinear((5, ), (1.0, ), (0.0, )) self.assertArrayEqual(utils.non_singleton_coordinate_names(grid), ("x", )) grid = UniformRectilinear((4, 5, 6), (1.0, 1.0, 1.0), (0.0, 0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_coordinate_names(grid), ("z", "y", "x"))
def test_without_singletons(self): grid = UniformRectilinear((4, 5), (1., 1.), (0., 0.)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), np.array([['y'], ['x']])) grid = UniformRectilinear((5, ), (1., ), (0., )) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), np.array([['x']])) grid = UniformRectilinear((4, 5, 6), (1., 1., 1.), (0., 0., 0.)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), np.array([['z'], ['y'], ['x']]))
def test_without_singletons(self): grid = UniformRectilinear((4, 5), (1.0, 1.0), (0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_dimension_names(grid), np.array(["y", "x"])) grid = UniformRectilinear((5, ), (1.0, ), (0.0, )) self.assertArrayEqual(utils.non_singleton_dimension_names(grid), np.array(["x"])) grid = UniformRectilinear((4, 5, 6), (1.0, 1.0, 1.0), (0.0, 0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_dimension_names(grid), ("z", "y", "x"))
def test_with_singletons(self): grid = UniformRectilinear((4, 1), (1.0, 1.0), (0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_axes(grid), np.array((0, ))) grid = UniformRectilinear((1, 4), (1.0, 1.0), (0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_axes(grid), np.array((1, ))) grid = UniformRectilinear((4, 1, 1), (1.0, 1.0, 1.0), (0.0, 0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_axes(grid), np.array((0, ))) grid = UniformRectilinear((1, 4, 1), (1.0, 1.0, 1.0), (0.0, 0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_axes(grid), np.array((1, ))) grid = UniformRectilinear((1, 4, 5), (1.0, 1.0, 1.0), (0.0, 0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_axes(grid), np.array((1, 2)))
def test_with_singletons(self): grid = UniformRectilinear((4, 1), (1., 1.), (0., 0.)) self.assertArrayEqual(utils.non_singleton_shape(grid), np.array((4, ))) grid = UniformRectilinear((1, 4), (1., 1.), (0., 0.)) self.assertArrayEqual(utils.non_singleton_shape(grid), np.array((4, ))) grid = UniformRectilinear((4, 1, 1), (1., 1., 1.), (0., 0., 0.)) self.assertArrayEqual(utils.non_singleton_shape(grid), np.array((4, ))) grid = UniformRectilinear((1, 4, 1), (1., 1., 1.), (0., 0., 0.)) self.assertArrayEqual(utils.non_singleton_shape(grid), np.array((4, ))) grid = UniformRectilinear((1, 4, 5), (1., 1., 1.), (0., 0., 0.)) self.assertArrayEqual(utils.non_singleton_shape(grid), np.array( (4, 5)))
def test_xy_indexing(self): grid = UniformRectilinear((2, 3), (1, 2), (.5, 0)) self.assert_point_count(grid, 6) self.assert_cell_count(grid, 2) self.assert_shape(grid, (3, 2)) self.assert_spacing(grid, (2., 1.)) self.assert_origin(grid, (0., .5)) self.assert_x(grid, [0.5, 1.5, 0.5, 1.5, 0.5, 1.5]) self.assert_y(grid, [0., 0., 2., 2., 4., 4.])
def test_with_singletons(self): grid = UniformRectilinear((4, 1), (1.0, 1.0), (0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), (("y", ), )) grid = UniformRectilinear((1, 4), (1.0, 1.0), (0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), (("x", ), )) grid = UniformRectilinear((4, 1, 1), (1.0, 1.0, 1.0), (0.0, 0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), (("z", ), )) grid = UniformRectilinear((1, 4, 1), (1.0, 1.0, 1.0), (0.0, 0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), (("y", ), )) grid = UniformRectilinear((1, 4, 5), (1.0, 1.0, 1.0), (0.0, 0.0, 0.0)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), (("y", ), ("x", )))
def test_ij_indexing(self): grid = UniformRectilinear((2, 3), (1, 2), (.5, 0), indexing='ij', units=('m', 'km')) self.assert_point_count(grid, 6) self.assert_cell_count(grid, 2) self.assert_shape(grid, (2, 3)) self.assert_spacing(grid, (1., 2.)) self.assert_origin(grid, (0.5, .0)) self.assert_x(grid, [0., 2., 4., 0., 2., 4.]) self.assert_y(grid, [0.5, 0.5, 0.5, 1.5, 1.5, 1.5])
def test_ij_indexing(self): grid = UniformRectilinear((2, 3), (1, 2), (0.5, 0), indexing="ij", units=("m", "km")) self.assert_point_count(grid, 6) self.assert_cell_count(grid, 2) self.assert_shape(grid, (2, 3)) self.assert_spacing(grid, (1.0, 2.0)) self.assert_origin(grid, (0.5, 0.0)) self.assert_x(grid, [0.0, 2.0, 4.0, 0.0, 2.0, 4.0]) self.assert_y(grid, [0.5, 0.5, 0.5, 1.5, 1.5, 1.5])
def test_with_singletons(self): grid = UniformRectilinear((4, 1), (1., 1.), (0., 0.)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), (('y', ), )) grid = UniformRectilinear((1, 4), (1., 1.), (0., 0.)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), (('x', ), )) grid = UniformRectilinear((4, 1, 1), (1., 1., 1.), (0., 0., 0.)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), (('z', ), )) grid = UniformRectilinear((1, 4, 1), (1., 1., 1.), (0., 0., 0.)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), (('y', ), )) grid = UniformRectilinear((1, 4, 5), (1., 1., 1.), (0., 0., 0.)) self.assertArrayEqual(utils.non_singleton_dimension_shape(grid), (('y', ), ('x', )))
def test_3d_grid_xy_indexing(self): grid = UniformRectilinear((4, 3, 2), (1, 2, 3), (-1, 0, 1), indexing='xy') self.assert_point_count(grid, 24) self.assert_cell_count(grid, 6) self.assert_shape(grid, (2, 3, 4)) self.assert_spacing(grid, (3., 2., 1.)) self.assert_origin(grid, (1., 0., -1.)) self.assert_x(grid, [ -1., 0., 1., 2., -1., 0., 1., 2., -1., 0., 1., 2., -1., 0., 1., 2., -1., 0., 1., 2., -1., 0., 1., 2. ]) self.assert_y(grid, [ 0., 0., 0., 0., 2., 2., 2., 2., 4., 4., 4., 4., 0., 0., 0., 0., 2., 2., 2., 2., 4., 4., 4., 4. ]) self.assert_z(grid, [ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4. ]) self.assert_offset(grid, 8. * np.arange(1, grid.get_cell_count() + 1))
def test_3d_grid_xy_indexing(self): grid = UniformRectilinear((4, 3, 2), (1, 2, 3), (-1, 0, 1), indexing="xy") self.assert_point_count(grid, 24) self.assert_cell_count(grid, 6) self.assert_shape(grid, (2, 3, 4)) self.assert_spacing(grid, (3.0, 2.0, 1.0)) self.assert_origin(grid, (1.0, 0.0, -1.0)) self.assert_x( grid, [ -1.0, 0.0, 1.0, 2.0, -1.0, 0.0, 1.0, 2.0, -1.0, 0.0, 1.0, 2.0, -1.0, 0.0, 1.0, 2.0, -1.0, 0.0, 1.0, 2.0, -1.0, 0.0, 1.0, 2.0, ], ) self.assert_y( grid, [ 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0, 4.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0, 4.0, ], ) self.assert_z( grid, [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, ], ) self.assert_offset(grid, 8.0 * np.arange(1, grid.get_cell_count() + 1))
def test_3d_grid_ij_indexing(self): grid = UniformRectilinear((4, 3, 2), (1, 2, 3), (-1, 0, 1), indexing="ij") self.assert_point_count(grid, 24) self.assert_cell_count(grid, 6) self.assert_shape(grid, (4, 3, 2)) self.assert_spacing(grid, (1.0, 2.0, 3.0)) self.assert_origin(grid, (-1.0, 0.0, 1.0)) self.assert_x( grid, [ 1.0, 4.0, 1.0, 4.0, 1.0, 4.0, 1.0, 4.0, 1.0, 4.0, 1.0, 4.0, 1.0, 4.0, 1.0, 4.0, 1.0, 4.0, 1.0, 4.0, 1.0, 4.0, 1.0, 4.0, ], ) self.assert_y( grid, [ 0.0, 0.0, 2.0, 2.0, 4.0, 4.0, 0.0, 0.0, 2.0, 2.0, 4.0, 4.0, 0.0, 0.0, 2.0, 2.0, 4.0, 4.0, 0.0, 0.0, 2.0, 2.0, 4.0, 4.0, ], ) self.assert_z( grid, [ -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, ], ) self.assert_offset(grid, 8.0 * np.arange(1, grid.get_cell_count() + 1))
def test_is_uniform_rectilinear(self): grid = UniformRectilinear((5, 4), (1, 1), (0, 0)) self.assertTrue(is_uniform_rectilinear(grid))
def test_is_strictly_unstructured(self): grid = UniformRectilinear((5, 4), (1, 1), (0, 0)) self.assertFalse(is_unstructured(grid))
def test_is_not_strictly_unstructured(self): grid = UniformRectilinear((5, 4), (1, 1), (0, 0)) self.assertTrue(is_unstructured(grid, strict=False))