Skip to content

Improve the exception when attempting to partially collapse a multidimensional coordinate #291

@pelson

Description

@pelson

Example:

import iris.tests.stock as stock

c = stock.simple_4d_with_hybrid_height()
print c

print c.collapsed('grid_latitude', iris.analysis.MEAN)

Output:

air_temperature                     (time: 3; model_level_number: 4; grid_latitude: 5; grid_longitude: 6)
     Dimension coordinates:
          time                           x                      -                 -                  -
          model_level_number             -                      x                 -                  -
          grid_latitude                  -                      -                 x                  -
          grid_longitude                 -                      -                 -                  x
     Auxiliary coordinates:
          level_height                   -                      x                 -                  -
          sigma                          -                      x                 -                  -
          surface_altitude               -                      -                 x                  x
     Derived coordinates:
          altitude                       -                      x                 x                  x
iris/coords.py:673: UserWarning: Collapsing a non-contiguous coordinate. Metadata may not be fully descriptive for "grid_latitude".
  'not be fully descriptive for "%s".' % self.name())
Traceback (most recent call last):
  File "example.py", line 26, in <module>
    print c.collapsed('grid_latitude', iris.analysis.MEAN)
  File "iris/cube.py", line 1849, in collapsed
    collapsed_cube.replace_coord(coord.collapsed(local_dims))
  File "iris/coords.py", line 665, in collapsed
    raise ValueError('Cannot partially collapse a coordinate (%s).' % self.name())
ValueError: Cannot partially collapse a coordinate (surface_altitude).

Consider being explicit about removing the coordinate (and an example?) in the actual exception.

This issue is a direct result of a question I was asked offline by a frequent user of Iris.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions