Skip to content

Commit

Permalink
Merge pull request #790 from MetOffice/merge_cubes_after_load
Browse files Browse the repository at this point in the history
Merge and concatinate cubes on load
  • Loading branch information
ukmo-huw-lewis committed Aug 15, 2024
2 parents 0ab5315 + 22751b3 commit cd485e2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/CSET/operators/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def read_cubes(
"""Read cubes from files.
Read operator that takes a path string (can include wildcards), and uses
iris to load_cube all the cubes matching the constraint and return a
CubeList object.
iris to load the minimal set of cubes matching the constraint.
If the loaded data is split across multiple files, a filename_pattern can be
specified to select the read files using Unix shell-style wildcards. In this
Expand Down Expand Up @@ -124,7 +123,7 @@ def read_cubes(
Returns
-------
cubes: iris.cube.CubeList
Cubes loaded
Cubes loaded after being merged and concatenated.
Raises
------
Expand All @@ -141,8 +140,9 @@ def read_cubes(
callback = _create_callback(is_ensemble=True)
cubes = iris.load(input_files, constraint, callback=callback)

# Merge cubes now metadata has been fixed.
cubes.merge()
# Merge and concatenate cubes now metadata has been fixed.
cubes = cubes.merge()
cubes = cubes.concatenate()

logging.debug("Loaded cubes: %s", cubes)
if len(cubes) == 0:
Expand Down
6 changes: 6 additions & 0 deletions tests/operators/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ def test_read_cube_unconstrained():
read.read_cube("tests/test_data/air_temp.nc")


def test_read_cube_merge_concatenate():
"""Cubes are combined after callbacks have been applied."""
cube = read.read_cube("tests/test_data/concat_after_fix_[12].nc")
assert isinstance(cube, iris.cube.Cube)


def test_check_input_files_direct_path(tmp_path):
"""Get a iterable of a single file from a direct path."""
file_path = tmp_path / "file"
Expand Down
Binary file added tests/test_data/concat_after_fix_1.nc
Binary file not shown.
Binary file added tests/test_data/concat_after_fix_2.nc
Binary file not shown.

0 comments on commit cd485e2

Please sign in to comment.