Skip to content

Commit

Permalink
Addressed comments from first review.
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsandford committed Dec 8, 2020
1 parent 8304a7a commit 20ca58c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions improver/cube_combiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _combine_cube_data(self, cube_list):
iris.cube.Cube
Raises:
ValueError: if the operation results in an escalated datatype
TypeError: if the operation results in an escalated datatype
"""
result = cube_list[0].copy()
for cube in cube_list[1:]:
Expand Down Expand Up @@ -195,7 +195,6 @@ def process(
Raises:
ValueError: If the cube_list contains only one cube.
TypeError: If combining data results in float64 data.
"""
if len(cube_list) < 2:
msg = "Expecting 2 or more cubes in cube_list"
Expand Down Expand Up @@ -236,12 +235,18 @@ def _setup_coords_for_broadcast(self, cube_list):
match the dimensions, in order, of the first cube in the list
Args:
cube_list: (iris.cube.CubeList)
cube_list (iris.cube.CubeList or list of iris.cube.Cube)
Returns:
iris.cube.CubeList
Updated version of cube_list
Raises:
CoordinateNotFoundError: if there is no threshold coordinate on the
first cube in the list
TypeError: if there is a scalar threshold coordinate on any of the
later cubes, which would indicate that the cube is only valid for
a single threshold and should not be broadcast to all thresholds.
"""
target_cube = cube_list[0]
try:
Expand All @@ -265,9 +270,6 @@ def _setup_coords_for_broadcast(self, cube_list):
)
else:
if found_coord not in cube.dim_coords:
# We don't expect the coord to already exist in a scalar form as
# this would indicate that the broadcast-from cube is only valid
# for a single threshold and therefore should be rejected.
msg = "Cannot broadcast to coord threshold as it already exists as an AuxCoord"
raise TypeError(msg)
new_list.append(cube)
Expand Down
9 changes: 9 additions & 0 deletions improver_tests/cube_combiner/test_CubeMultiplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ def test_multiply_preserves_bounds(self):
self.assertArrayAlmostEqual(result.data, np.full((2, 3, 3), 0.3))
self.assertArrayEqual(result.coord("time"), precip_accum.coord("time"))

def test_exception_for_single_entry_cubelist(self):
"""Test that the plugin raises an exception if a cubelist containing
only one cube is passed in."""
plugin = CubeMultiplier()
msg = "Expecting 2 or more cubes in cube_list"
cubelist = iris.cube.CubeList([self.cube1])
with self.assertRaisesRegex(ValueError, msg):
plugin.process(cubelist, "new_cube_name")


if __name__ == "__main__":
unittest.main()

0 comments on commit 20ca58c

Please sign in to comment.