Skip to content

Conversation

@lbdreyer
Copy link
Member

@lbdreyer lbdreyer commented Oct 1, 2019

Currently cell measures are not handled when you do a transpose of a cube.

>>> c = Cube(np.arange(6).reshape(2,3), 'x_wind')
>>> cm = CellMeasure(np.arange(6).reshape(2,3), measure='area')
>>> c.add_cell_measure(cm, (0,1))
>>> print(c._cell_measures_and_dims)
[[CellMeasure(array([[0, 1, 2],
       [3, 4, 5]]), measure=area, standard_name=None, units=Unit('1')), (0, 1)]]
>>> c.transpose()
>>> print(c._cell_measures_and_dims)
[[CellMeasure(array([[0, 1, 2],
       [3, 4, 5]]), measure=area, standard_name=None, units=Unit('1')), (0, 1)]]

Where I would expect the last line to return:

>>> print(c._cell_measures_and_dims)
[[CellMeasure(array([[0, 1, 2],
       [3, 4, 5]]), measure=area, standard_name=None, units=Unit('1')), (1, 0)]]

i.e. the dims swapped, as it does with auxiliary coords.

This PR includes the handling of the above, plus tests.

@lbdreyer lbdreyer added this to the v2.3.0 milestone Oct 1, 2019
lib/iris/cube.py Outdated
def remap_aux_coord(coord_and_dims):
# Remaps all cube dimensional metadata that may have multiple
# dimensions.
def remap_cube_metadata(coord_and_dims):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lbdreyer Is there an opportunity here to take a step further and combine remap_dim_coord and remap_cube_metadata? e.g., some thing along the lines of:

from collections import Iterable
...
def remap_cube_metadata(coord_and_dims):
    coord, dims = coord_and_dims
    if isinstance(dims, Iterable):
        dims = tuple(dim_mapping[dim] for dim in dims)
    else:
        dims = dim_mapping[dims]
    return coord, dims

Then deriving both self._dim_coords_and_dims, self._aux_coords_and_dims and self._cell_measures_and_dims all call the same helper function?

@bjlittle
Copy link
Member

bjlittle commented Oct 1, 2019

@lbdreyer Minor comment to think about...

Also, travis-ci is failing when it attempts to build the whatsnew. The reason (I think) is that you need to add a .txt to your new whatsnew contribution file.

@lbdreyer lbdreyer force-pushed the cell_measures_transpose branch from fc11cf7 to fa54e06 Compare October 1, 2019 15:48
@bjlittle
Copy link
Member

bjlittle commented Oct 1, 2019

@lbdreyer Awesome, thanks 👍

@bjlittle bjlittle merged commit 40b892f into SciTools:master Oct 1, 2019
@lbdreyer lbdreyer deleted the cell_measures_transpose branch June 23, 2021 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants