Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* :meth:`iris.cube.Cube.remove_cell_measure` now also allows removal of a cell
measure by its name (previously only accepted a CellMeasure object).
27 changes: 22 additions & 5 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2010 - 2018, Met Office
# (C) British Crown Copyright 2010 - 2019, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -1123,13 +1123,30 @@ def remove_cell_measure(self, cell_measure):

Args:

* cell_measure (CellMeasure)
The CellMeasure to remove from the cube.
* cell_measure (string or cell_measure)
The (name of the) cell measure to remove from the cube. As either

See also
:meth:`Cube.add_cell_measure()<iris.cube.Cube.add_cell_measure>`
(a) a :attr:`standard_name`, :attr:`long_name`, or
:attr:`var_name`. Defaults to value of `default`
(which itself defaults to `unknown`) as defined in
:class:`iris._cube_coord_common.CFVariableMixin`.
Copy link
Member

Choose a reason for hiding this comment

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

@alastair-gemmell A lovely piece of clarification, which explains that cell_measure can be an actual CellMeasure instance or an appropriate string name 😄


(b) a cell_measure instance with metadata equal to that of
the desired cell_measures.

.. note::

If the argument given does not represent a valid cell_measure on
the cube, an :class:`iris.exceptions.CellMeasureNotFoundError`
is raised.

.. seealso::

:meth:`Cube.add_cell_measure()<iris.cube.Cube.add_cell_measure>`

"""
cell_measure = self.cell_measure(cell_measure)

self._cell_measures_and_dims = [[cell_measure_, dim] for cell_measure_,
dim in self._cell_measures_and_dims
if cell_measure_ is not cell_measure]
Expand Down
11 changes: 10 additions & 1 deletion lib/iris/tests/unit/cube/test_Cube.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2013 - 2018, Met Office
# (C) British Crown Copyright 2013 - 2019, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -1648,6 +1648,15 @@ def test_remove_cell_measure(self):
self.assertEqual(self.cube._cell_measures_and_dims,
[[self.b_cell_measure, (0, 1)]])

def test_remove_cell_measure_by_name(self):
self.cube.remove_cell_measure('area')
self.assertEqual(self.cube._cell_measures_and_dims,
[[self.b_cell_measure, (0, 1)]])

def test_fail_remove_cell_measure_by_name(self):
with self.assertRaises(CellMeasureNotFoundError):
self.cube.remove_cell_measure('notarea')


class Test__getitem_CellMeasure(tests.IrisTest):
def setUp(self):
Expand Down