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

iris plot bug when certain aux and dim coords present #448

Closed
cpelley opened this issue Apr 11, 2013 · 3 comments
Closed

iris plot bug when certain aux and dim coords present #448

cpelley opened this issue Apr 11, 2013 · 3 comments

Comments

@cpelley
Copy link

cpelley commented Apr 11, 2013

import numpy as np

import iris
import iris.analysis.cartography as icart

import matplotlib.pyplot as plt
import iris.plot as iplt

cube = iris.load_cube(iris.sample_data_path('rotated_pole.nc'))

glon = cube.coord('grid_longitude')
rotated_lons = glon.points
glat = cube.coord('grid_latitude')
rotated_lats = glat.points
pole_lat = glat.coord_system.grid_north_pole_latitude
pole_lon = glat.coord_system.grid_north_pole_longitude

rotated_lats, rotated_lons = np.meshgrid(rotated_lons, rotated_lats)

lons, lats = icart.unrotate_pole(rotated_lons, rotated_lats, pole_lon, pole_lat)

lat = iris.coords.AuxCoord(lons, standard_name='longitude', units='degree_north')
lon = iris.coords.AuxCoord(lats, standard_name='latitude', units='degree_east')

cube.add_aux_coord(lat, [0, 1])
cube.add_aux_coord(lon, [0, 1])

iplt.contourf(cube)
plt.show()

Producing the following error:

Traceback (most recent call last):
  File "/net/home/h05/cpelley/Remedy/GITHUB/no_pass_coords.py", line 28, in <module>
    iplt.contourf(cube)
  File "/home/h05/cpelley/git/iris/lib/iris/plot.py", line 464, in contourf
    result = _draw_2d_from_points('contourf', None, cube, *args, **kwargs)
  File "/home/h05/cpelley/git/iris/lib/iris/plot.py", line 261, in _draw_2d_from_points
    *args, **kwargs)
  File "/home/h05/cpelley/git/iris/lib/iris/plot.py", line 373, in _map_common
    x, y = cartography.get_xy_grids(cube)
  File "/home/h05/cpelley/git/iris/lib/iris/analysis/cartography.py", line 190, in get_xy_grids
    x_coord, y_coord = cube.coord(axis="X"), cube.coord(axis="Y")
  File "/home/h05/cpelley/git/iris/lib/iris/cube.py", line 1041, in coord
    raise iris.exceptions.CoordinateNotFoundError(msg)
iris.exceptions.CoordinateNotFoundError: u'Expected to find exactly 1 coordinate, but found 2. They were: grid_longitude, longitude.'

Current workaround is to simply delete the dim coords or delete the aux coords.

@pelson
Copy link
Member

pelson commented Apr 11, 2013

How about:

iplt.contourf(cube, coords=['grid_longitude', 'grid_latitude'])

?

@cpelley
Copy link
Author

cpelley commented Apr 16, 2013

No I'm afraid I already tried this, in fact there is a bug with the coords keyword argument not being passed through in some situations (which I was going to raise, once I clarify better the specific problem). That along with coords not being an argument but a keyword argument (contrary to documentation).

I'll raise the coords bug sometime today if I can and link from here.
(In any case I would have expected iris to have defaulted to use the dimension coordinates)

@esc24
Copy link
Member

esc24 commented Apr 16, 2013

iplt.contourf(cube, coords=['grid_longitude', 'grid_latitude'])

Interestingly iplt.contourf(cube, coords=['grid_latitude', 'grid_longitude']) works (albeit not as a map type plot).

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

3 participants