Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ This document explains the changes made to Iris for this release
deprecation warnings invite users to contact the Iris Developers if this
isn't the case. (:pull:`4515`)

#. `@wjbenfold`_ removed the :func:`iris.util.as_compatible_shape` function,
which was deprecated in ``v3.0``. Instead use
:class:`iris.common.resolve.Resolve`. For example, rather than calling
``as_compatible_shape(src_cube, target_cube)`` replace with
``Resolve(src_cube, target_cube)(target_cube.core_data())``. (:pull:`4513`)


🔗 Dependencies
===============
Expand Down
144 changes: 0 additions & 144 deletions lib/iris/tests/results/util/as_compatible_shape_collapsed.cml

This file was deleted.

98 changes: 0 additions & 98 deletions lib/iris/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,103 +276,5 @@ def test_output_file(self):
self.assertFilesEqual(filename, "incompatible_cubes.str.txt")


@tests.skip_data
class TestAsCompatibleShape(tests.IrisTest):
def test_slice(self):
cube = tests.stock.realistic_4d()
sliced = cube[1, :, 2, :-2]
expected = cube[1:2, :, 2:3, :-2]
res = iris.util.as_compatible_shape(sliced, cube)
self.assertEqual(res, expected)

def test_transpose(self):
cube = tests.stock.realistic_4d()
transposed = cube.copy()
transposed.transpose()
expected = cube
res = iris.util.as_compatible_shape(transposed, cube)
self.assertEqual(res, expected)

def test_slice_and_transpose(self):
cube = tests.stock.realistic_4d()
sliced_and_transposed = cube[1, :, 2, :-2]
sliced_and_transposed.transpose()
expected = cube[1:2, :, 2:3, :-2]
res = iris.util.as_compatible_shape(sliced_and_transposed, cube)
self.assertEqual(res, expected)

def test_collapsed(self):
cube = tests.stock.realistic_4d()
collapsed = cube.collapsed("model_level_number", iris.analysis.MEAN)
expected_shape = list(cube.shape)
expected_shape[1] = 1
expected_data = collapsed.data.reshape(expected_shape)
res = iris.util.as_compatible_shape(collapsed, cube)
self.assertCML(
res, ("util", "as_compatible_shape_collapsed.cml"), checksum=False
)
self.assertMaskedArrayEqual(expected_data, res.data)

def test_reduce_dimensionality(self):
# Test that as_compatible_shape() can demote
# length one dimensions to scalars.
cube = tests.stock.realistic_4d()
src = cube[:, 2:3]
expected = reduced = cube[:, 2]
res = iris.util.as_compatible_shape(src, reduced)
self.assertEqual(res, expected)

def test_anonymous_dims(self):
cube = tests.stock.realistic_4d()
# Move all coords from dim_coords to aux_coords.
for coord in cube.dim_coords:
dim = cube.coord_dims(coord)
cube.remove_coord(coord)
cube.add_aux_coord(coord, dim)

sliced = cube[1, :, 2, :-2]
expected = cube[1:2, :, 2:3, :-2]
res = iris.util.as_compatible_shape(sliced, cube)
self.assertEqual(res, expected)

def test_scalar_auxcoord(self):
def dim_to_aux(cube, coord_name):
"""Convert coordinate on cube from DimCoord to AuxCoord."""
coord = cube.coord(coord_name)
coord = iris.coords.AuxCoord.from_coord(coord)
cube.replace_coord(coord)

cube = tests.stock.realistic_4d()
src = cube[:, :, 3]
dim_to_aux(src, "grid_latitude")
expected = cube[:, :, 3:4]
dim_to_aux(expected, "grid_latitude")
res = iris.util.as_compatible_shape(src, cube)
self.assertEqual(res, expected)

def test_2d_auxcoord_transpose(self):
dim_coord1 = iris.coords.DimCoord(range(3), long_name="first_dim")
dim_coord2 = iris.coords.DimCoord(range(4), long_name="second_dim")
aux_coord_2d = iris.coords.AuxCoord(
np.arange(12).reshape(3, 4), long_name="spanning"
)
aux_coord_2d_T = iris.coords.AuxCoord(
np.arange(12).reshape(3, 4).T, long_name="spanning"
)
src = iris.cube.Cube(
np.ones((3, 4)),
dim_coords_and_dims=[(dim_coord1, 0), (dim_coord2, 1)],
aux_coords_and_dims=[(aux_coord_2d, (0, 1))],
)
target = iris.cube.Cube(
np.ones((4, 3)),
dim_coords_and_dims=[(dim_coord1, 1), (dim_coord2, 0)],
aux_coords_and_dims=[(aux_coord_2d_T, (0, 1))],
)

res = iris.util.as_compatible_shape(src, target)
self.assertEqual(res[0], target[0])


if __name__ == "__main__":
tests.main()
Loading