Skip to content

Commit

Permalink
Refactor CubeCombiner (#1383)
Browse files Browse the repository at this point in the history
* Factored multiplication case out of CubeCombiner.  All CLI tests pass.  Need to sort unit tests and then make code nicer.

* Split existing unit tests between plugins and they pass.

* Reduced "broadcast_to_coords" to "broadcast_to_threshold" boolean, consistent with use case and CLI interface.

* Simplified setting up of coords for broadcast to use threshold only.

* Factored out broadcasting into CubeMultiplier.  Coord checking needs tidying up but all tests pass.

* Removed unused method.

* Pythonified coordinate checking.

* Removed "self.operation" and summarised use more clearly.

* Addressed comments from first review.

* Response to second review.
  • Loading branch information
cgsandford authored Dec 16, 2020
1 parent 8da46d9 commit a7a9a38
Show file tree
Hide file tree
Showing 4 changed files with 302 additions and 238 deletions.
19 changes: 11 additions & 8 deletions improver/cli/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,22 @@ def process(
result (iris.cube.Cube):
Returns a cube with the combined data.
"""
from improver.cube_combiner import CubeCombiner
from improver.cube_combiner import CubeCombiner, CubeMultiplier
from iris.cube import CubeList

if not cubes:
raise TypeError("A cube is needed to be combined.")
if new_name is None:
new_name = cubes[0].name()
broadcast_to_coords = ["threshold"] if broadcast_to_threshold else None
result = CubeCombiner(operation, warnings_on=check_metadata)(
CubeList(cubes),
new_name,
broadcast_to_coords=broadcast_to_coords,
use_midpoint=use_midpoint,
)

if operation == "*" or operation == "multiply":
result = CubeMultiplier()(
CubeList(cubes), new_name, broadcast_to_threshold=broadcast_to_threshold,
)

else:
result = CubeCombiner(operation)(
CubeList(cubes), new_name, use_midpoint=use_midpoint,
)

return result
Loading

0 comments on commit a7a9a38

Please sign in to comment.