Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial collapse of multidimensional auxcoords with bounds #3298

Closed
rcomer opened this issue Mar 28, 2019 · 1 comment
Closed

Partial collapse of multidimensional auxcoords with bounds #3298

rcomer opened this issue Mar 28, 2019 · 1 comment
Assignees
Milestone

Comments

@rcomer
Copy link
Member

rcomer commented Mar 28, 2019

Since #3028, we can partially collapse a multidimesional auxcoord, which is great. However, it goes wrong if that auxcoord has bounds. Example:

import iris
import numpy as np

print(iris.__version__)

cube = iris.cube.Cube(np.zeros((2, 3)))

coord1 = iris.coords.DimCoord(range(2), long_name='foo')
coord2 = iris.coords.DimCoord(range(3), long_name='bar')

spanning_bounds = np.stack([np.arange(6), np.arange(1, 7)], axis=-1)
spanning_points = np.mean(spanning_bounds, axis=-1)
spanning_coord = iris.coords.AuxCoord(
    spanning_points.reshape(2, 3), bounds=spanning_bounds.reshape(2, 3, 2),
    long_name='spanning')

for i, coord in enumerate([coord1, coord2]):
    cube.add_dim_coord(coord, i)

cube.add_aux_coord(spanning_coord, (0, 1))

print(cube.collapsed('foo', iris.analysis.MEAN))

Output:

2.2.0
[warnings about metadata]
Traceback (most recent call last):
  File "2d_coord_issue.py", line 24, in <module>
    print(cube.collapsed('foo', iris.analysis.MEAN))
  File "[site-packages-path]/iris/cube.py", line 3217, in collapsed
    collapsed_cube.replace_coord(coord.collapsed(local_dims))
  File "[site-packages-path]/iris/cube.py", line 1149, in replace_coord
    self.add_aux_coord(new_coord, dims)
  File "[site-packages-path]/iris/cube.py", line 949, in add_aux_coord
    self._add_unique_aux_coord(coord, data_dims)
  File "[site-packages-path]/iris/cube.py", line 981, in _add_unique_aux_coord
    data_dims = self._check_multi_dim_metadata(coord, data_dims)
  File "[site-packages-path]/iris/cube.py", line 973, in _check_multi_dim_metadata
    metadata.shape[i]))
ValueError: Unequal lengths. Cube dimension 0 => 3; metadata 'spanning' dimension 0 => 2.
@rcomer
Copy link
Member Author

rcomer commented Aug 24, 2019

Fixed at #3302.

@rcomer rcomer closed this as completed Aug 24, 2019
@QuLogic QuLogic added this to the v2.3.0 milestone Aug 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants