def test_2d_coordinate_name_ij_indexing_with_kwds(self): grid = Rectilinear( [1.0, 2.0, 4.0, 8.0], [1.0, 2.0, 3.0], indexing="ij", coordinate_names=["latitude", "longitude"], ) self.assertEqual(grid.get_coordinate_name(0), "latitude") self.assertEqual(grid.get_coordinate_name(1), "longitude")
def test_2d_coordinates_ij_default(self): grid = Rectilinear([1.0, 2.0, 4.0, 8.0], [1.0, 2.0, 3.0], indexing="ij") self.assertArrayEqual( grid.get_point_coordinates(axis=0), np.array([1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0, 8.0, 8.0, 8.0]), ) self.assertArrayEqual( grid.get_point_coordinates(axis=1), np.array([1.0, 2.0, 3.0] * 4) )
def test_2d_units_xy_indexing_by_coordinate(self): grid = Rectilinear( [1.0, 2.0, 4.0, 8.0], [1.0, 2.0, 3.0], indexing="ij", units=["y_units", "x_units"], ) self.assertEqual(grid.get_coordinate_units(0), "x_units") self.assertEqual(grid.get_coordinate_units(1), "y_units")
def test_2d_units_xy_indexing_by_name(self): grid = Rectilinear( [1.0, 2.0, 4.0, 8.0], [1.0, 2.0, 3.0], indexing="xy", units=["x_units", "y_units"], ) self.assertEqual(grid.get_x_units(), "x_units") self.assertEqual(grid.get_y_units(), "y_units")
def test_2d_coordinates_xy_default(self): grid = Rectilinear([1.0, 2.0, 4.0, 8.0], [1.0, 2.0, 3.0], indexing="xy") self.assertTrue( np.allclose( grid.get_point_coordinates(axis=0), np.array([1.0, 2.0, 4.0, 8.0] * 3) ) ) self.assertTrue( np.allclose( grid.get_point_coordinates(axis=1), np.tile([1.0, 2.0, 3.0], (4, 1)).T.flat, ) )
def test_1d_grid(self): grid = Rectilinear([1, 3, 4, 5, 6], set_connectivity=True) self.assert_point_count(grid, 5) self.assert_cell_count(grid, 4) self.assert_shape(grid, (5,)) self.assert_x(grid, [1.0, 3.0, 4.0, 5.0, 6.0]) # self.assert_y (grid, [0., 0., 0., 0., 0.]) self.assert_connectivity(grid, [0, 1, 1, 2, 2, 3, 3, 4]) self.assert_offset(grid, [2, 4, 6, 8])
def test_xy_indexing(self): grid = Rectilinear([1.0, 2.0, 4.0, 8.0], [1.0, 2.0, 3.0]) self.assert_point_count(grid, 12) self.assert_cell_count(grid, 6) self.assert_shape(grid, (3, 4)) self.assert_x( grid, [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.assert_y( grid, [1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0] )
def test_2d_coordinates_ij_indexing_with_kwds(self): grid = Rectilinear([1.0, 2.0, 4.0, 8.0], [1.0, 2.0, 3.0], indexing="ij") # self.assertTrue (np.allclose (grid.get_point_coordinates (axis=0, indexing='xy'), # np.array ([1., 2., 3.] * 4))) # self.assertTrue (np.allclose (grid.get_point_coordinates (axis=1, indexing='xy'), # np.tile ([1., 2., 4., 8.], (3, 1)).T.flat)) self.assertTrue( np.allclose( grid.get_point_coordinates(axis=0, indexing="ij"), np.tile([1.0, 2.0, 4.0, 8.0], (3, 1)).T.flat, ) ) self.assertTrue( np.allclose( grid.get_point_coordinates(axis=1, indexing="ij"), np.array([1.0, 2.0, 3.0] * 4), ) )
def test_ij_indexing(self): grid = Rectilinear([1.0, 2.0, 4.0, 8.0], [1.0, 2.0, 3.0], indexing="ij") self.assert_point_count(grid, 12) self.assert_cell_count(grid, 6) self.assert_shape(grid, (4, 3)) self.assert_x( grid, [1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0] ) self.assert_y( grid, [1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0, 8.0, 8.0, 8.0] ) self.assert_connectivity( grid, [0, 1, 4, 3, 1, 2, 5, 4, 3, 4, 7, 6, 4, 5, 8, 7, 6, 7, 10, 9, 7, 8, 11, 10], )
def test_is_rectilinear(self): grid = Rectilinear([1.0, 2.0, 4.0, 8.0], [1.0, 2.0, 3.0]) self.assertTrue(is_rectilinear(grid))
def test_is_not_uniform_rectilinear(self): grid = Rectilinear([1.0, 2.0, 4.0, 8.0], [1.0, 2.0, 3.0]) self.assertFalse(is_uniform_rectilinear(grid))
def test_3d_xy_indexing(self): grid = Rectilinear( [0, 1, 2, 3], [4, 5, 6], [7, 8], set_connectivity=True, indexing="xy" ) self.assert_point_count(grid, 24) self.assert_cell_count(grid, 6) self.assert_shape(grid, (2, 3, 4)) self.assert_x( grid, [ 0.0, 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 3.0, ], ) self.assert_y( grid, [ 4.0, 4.0, 4.0, 4.0, 5.0, 5.0, 5.0, 5.0, 6.0, 6.0, 6.0, 6.0, 4.0, 4.0, 4.0, 4.0, 5.0, 5.0, 5.0, 5.0, 6.0, 6.0, 6.0, 6.0, ], ) self.assert_z( grid, [ 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, ], ) self.assert_offset(grid, 8.0 * np.arange(1, grid.get_cell_count() + 1))
def test_2d_coordinate_name_xy_default(self): grid = Rectilinear([1.0, 2.0, 4.0, 8.0], [1.0, 2.0, 3.0], indexing="xy") self.assertEqual(grid.get_coordinate_name(0), "x") self.assertEqual(grid.get_coordinate_name(1), "y")
def test_is_rectilinear (self): grid = Rectilinear ([1., 2., 4., 8.], [1., 2., 3.]) self.assertTrue (is_rectilinear (grid))
def test_is_not_uniform_rectilinear (self): grid = Rectilinear ([1., 2., 4., 8.], [1., 2., 3.]) self.assertFalse (is_uniform_rectilinear (grid))