SciTools/iris — pull request #722 by esc24 (2013-08-28 12:11:05+00:00)
Title: Some add_missing_dims options.

This PR contains a workaround to an issue affecting a number of users. When collapsing/aggregating/slicing a cube the dimensionality of the resultant cube is often reduced when one or more dimensions are reduced to length one and the associated coordinates become scalar coordinates. This is not always desirable. In the case of slicing one can use slice notation to obtain the desired behaviour. For example:
```python
>>> import iris
>>> cube = iris.load_cube(iris.sample_data_path('air_temp.pp'))
>>> print cube.shape
(73, 96)
>>> print cube[0].shape
(96,)
>>> print cube[0:1].shape
(1, 96)
```
However when collapsing a cube using ```cube.collapsed()```, there is no way to preserve the dimensionality of the cube.

This PR adds a helper function called ```iris.util.add_missing_dims()``` and (as an alternative) a method on the cube called ```cube.add_missing_dims()```. I'm not sure which I prefer, but I'm leaning towards the former as we may ultimately fix the root cause removing the need for this functionality. Perhaps we should modify ```cube.collapsed()``` now rather than add this workaround. However, this function is here now and is a little more generic so might have wider applicability.

These functions do essentially the same thing (although the method version is in-place), figuring out which dimensions have been collapsed through an examination of the coordinates on the two cubes. It then reshapes the cube data and the point/bounds of any coordinates adding in length one dimensions where necessary.

Thoughts?