Skip to content

Commit bac42f5

Browse files
committed
Work with @dkillick to improve the Merge & Concatenate introduction.
1 parent 675332e commit bac42f5

File tree

1 file changed

+54
-31
lines changed

1 file changed

+54
-31
lines changed

docs/iris/src/userguide/merge_and_concat.rst

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,85 @@
44
Merge and Concatenate
55
=====================
66

7-
Sometimes you need to combine multiple Iris cubes to form a single larger Iris cube. You can achieve this with :meth:`merge <iris.cube.CubeList.merge>` and :meth:`concatenate <iris.cube.CubeList.concatenate>`.
7+
We saw in the :doc:`loading_iris_cubes` section that Iris tries to load as few cubes as
8+
possible. This is done by collecting together multiple fields with a shared standard
9+
name (and other key metadata) into a single multidimensional cube. The processes that
10+
perform this behaviour in Iris are known as ``merge`` and ``concatenate``.
811

9-
This chapter of the user guide describes :meth:`merge <iris.cube.CubeList.merge>` and :meth:`concatenate <iris.cube.CubeList.concatenate>`.
10-
It outlines use cases for :meth:`merge <iris.cube.CubeList.merge>` and :meth:`concatenate <iris.cube.CubeList.concatenate>` and describes the differences between them.
11-
It also explains why some common issues occur and how to avoid these issues occurring.
12+
This section describes the ``merge`` and ``concatenate`` processes; it explains
13+
why common issues occur when using them and gives advice on how prevent these
14+
issues from occurring.
1215

13-
The uses of :meth:`merge <iris.cube.CubeList.merge>` and :meth:`concatenate <iris.cube.CubeList.concatenate>` are as follows:
16+
Both ``merge`` and ``concatenate`` take multiple cubes as input and
17+
result in fewer cubes as output. The following diagram illustrates the two processes:
1418

15-
* **Merge:** stacks the instances of a common scalar coordinate on each of a series of input cubes. This makes a resultant cube with a new dimension coordinate created by merging these scalar coordinates.
16-
* **Concatenate:** joins the instances of a common dimension coordinate from each of a series of input cubes. This makes a resultant cube with this dimension coordinate extended.
19+
||| -> MERGE -> |__|
20+
21+
|_| |_| |_| -> CONCATENATE -> |___|
1722

23+
There is one major difference between the ``merge`` and ``concatenate`` processes.
24+
The ``merge`` process combines multiple input cubes into a
25+
single resultant cube with new dimensions created from the
26+
*scalar coordinate values* of the input cubes.
27+
The ``concatenate`` process process combines multiple input cubes into a
28+
single resultant cube with the same *number of dimensions* as the input cubes,
29+
but with the length of one or more dimensions extended by *joining together
30+
sequential dimension coordinates*.
1831

19-
Merge
20-
-----
2132

22-
:meth:`Merge <iris.cube.CubeList.merge>` stacks the instances of a common scalar coordinate on each of a series of input cubes.
23-
This makes a resultant cube with a new dimension coordinate created by merging these scalar coordinates.
24-
This has the following effects:
33+
Let's imagine 28 individual cubes representing the
34+
temperature at a location ``(y, x)``, one cube for each day of February. We can use
35+
:meth:`merge <iris.cube.CubeList.merge>` to combine the 28 ``(y, x)`` cubes into
36+
a single ``(t, y, x)`` cube, where the length of the ``t`` dimension is 28.
2537

26-
* A new dimension coordinate is formed from the series of scalar coordinates from the input cubes. Its data is composed of the scalar coordinates' data values.
27-
* A single resultant cube is formed from the series of input cubes. It will have one more dimension (the new dimension coordinate described above) than the input cubes.
38+
Now imagine 12 individual cubes representing daily temperature at a time and
39+
location ``(t, y, x)``, one cube for each month in the year. We can use
40+
:meth:`concatenate <iris.cube.CubeList.concatenate>` to combine the 12
41+
``(t, y, x)`` cubes into a single ``(t, y, x)`` cube, where the length
42+
of the ``t`` dimension is now 365.
2843

29-
.. note::
3044

31-
The data values in the series of scalar coordinates must describe a single monotonic series.
45+
Merge
46+
-----
3247

33-
.. note::
48+
We've seen that the ``merge`` combines multiple input cubes into a
49+
single resultant cube with new dimensions created from the
50+
*scalar coordinate values* of the input cubes.
51+
52+
In order to construct new coordinates for the new dimensions, the ``merge`` process requires input cubes
53+
with scalar coordinates that can be combined together into monotonic sequences.
54+
The order of the input cubes does not affect the ``merge`` process.
55+
56+
The ``merge`` process can produce a cube that has more than one new dimension,
57+
if the scalar coordinate sequences form an orthogonal basis.
3458

35-
The order of the data values in the series of scalar coordinates does not affect the :meth:`merge <iris.cube.CubeList.merge>` process.
36-
The data values in the series of scalar coordinates will be re-ordered into a montonically increasing series as part of the :meth:`merge <iris.cube.CubeList.merge>` process.
3759

3860
.. warning::
3961

40-
The shape, metadata, attributes, coordinates, coordinates metadata, fill value and other aspects of your input cubes must be consistent across all the input cubes.
41-
The :meth:`merge <iris.cube.CubeList.merge>` process will fail if they are not consistent. Such failures are covered in the common issues section towards the end of this chapter.
62+
The shape, metadata, attributes, coordinates, coordinates metadata, fill value and
63+
other aspects of the a cube must be consistent across all of the input cubes.
4264

43-
Let's have a look at :meth:`merge <iris.cube.CubeList.merge>` in operation. In this example we have three lateral (*x*, *y*) cubes in an :class:`cubelist <iris.cube.CubeList>`, each with a scalar *z* coordinate of differing value.
44-
We can merge these cubes by stacking the scalar *z* coordinates to make a new *z* dimension coordinate::
65+
The :meth:`merge <iris.cube.CubeList.merge>` process will fail if they are not
66+
consistent. Such failures are covered in the common issues section towards the end of this chapter.
4567

46-
>>> print cubelist
68+
Let's have a look at :meth:`merge <iris.cube.CubeList.merge>` in operation. In this example we have
69+
three lateral (*x*, *y*) cubes in an :class:`cubelist <iris.cube.CubeList>`, each with a scalar *z*
70+
coordinate of differing value. We can merge these cubes by stacking the scalar *z* coordinates to
71+
make a new *z* dimension coordinate::
72+
73+
>>> print cubes
4774
0: air_temperature / (kelvin) (x: 10; y: 10)
4875
1: air_temperature / (kelvin) (x: 10; y: 10)
4976
2: air_temperature / (kelvin) (x: 10; y: 10)
50-
>>> print cubelist[0]
77+
>>> print cubes.
5178
air_temperature / (kelvin) (x: 10; y: 10)
5279
Dimension coordinates:
5380
x x -
5481
y - x
5582
Scalar coordinates:
5683
z: 1
57-
print cubelist.merge()[0] # Merge returns a cubelist.
58-
air_temperature / (kelvin) (z: 3; x: 10; y: 10)
59-
Dimension coordinates:
60-
z x - -
61-
x - x -
62-
y - - x
84+
print cubes.merge()
85+
0: air_temperature / (kelvin) (z: 3; x: 10; y: 10)
6386

6487
The following diagram illustrates how :meth:`merge <iris.cube.CubeList.merge>` works:
6588

0 commit comments

Comments
 (0)