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

WCSAxes fails to draw grid along separable coordinate after slicing #9367

Open
Cadair opened this issue Oct 15, 2019 · 3 comments
Open

WCSAxes fails to draw grid along separable coordinate after slicing #9367

Cadair opened this issue Oct 15, 2019 · 3 comments

Comments

@Cadair
Copy link
Member

Cadair commented Oct 15, 2019

Running the following code:

from astropy.io import fits
from astropy.wcs import WCS
import matplotlib.pyplot as plt
import numpy as np



header = """
WCSAXES =                    3 / Number of coordinate axes
CRPIX1  =                  1.0 / Pixel coordinate of reference point
CRPIX2  =                386.5 / Pixel coordinate of reference point
CRPIX3  =                 32.0 / Pixel coordinate of reference point
PC2_2   =       0.999988496304 / Coordinate transformation matrix element
PC2_3   =       -0.13517896595 / Coordinate transformation matrix element
PC3_2   =    0.000939457726278 / Coordinate transformation matrix element
PC3_3   =       0.999988496304 / Coordinate transformation matrix element
CDELT1  =    1.29800001159E-12 / [m] Coordinate increment at reference point
CDELT2  =  4.6208333333333E-05 / [deg] Coordinate increment at reference point
CDELT3  =  0.00055428900205556 / [deg] Coordinate increment at reference point
CUNIT1  = 'm'                  / Units of coordinate increment and value
CUNIT2  = 'deg'                / Units of coordinate increment and value
CUNIT3  = 'deg'                / Units of coordinate increment and value
CTYPE1  = 'WAVE'               / Vacuum wavelength (linear)
CTYPE2  = 'HPLT-TAN'           / Coordinate type codegnomonic projection
CTYPE3  = 'HPLN-TAN'           / Coordinate type codegnomonic projection
CRVAL1  =    1.33168328015E-07 / [m] Coordinate value at reference point
CRVAL2  =   -0.029883055555556 / [deg] Coordinate value at reference point
CRVAL3  =     0.22718416666667 / [deg] Coordinate value at reference point
LONPOLE =                180.0 / [deg] Native longitude of celestial pole
LATPOLE =   -0.029883055555556 / [deg] Native latitude of celestial pole
"""


wcs = WCS(header=header)
data = np.random.random((64, 772, 2055))


ax = plt.subplot(projection=wcs, slices=('x', 0, 'y'))
ax.imshow(data[:,0,:])
ax.coords[0].grid()

plt.show()

results in this error:

Traceback (most recent call last):
  File "/home/stuart/.virtualenvs/sunpy-dev/lib/python3.7/site-packages/matplotlib/backends/backend_qt5.py", line 505, in _draw_idle
    self.draw()
  File "/home/stuart/.virtualenvs/sunpy-dev/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "/home/stuart/.virtualenvs/sunpy-dev/lib/python3.7/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/stuart/.virtualenvs/sunpy-dev/lib/python3.7/site-packages/matplotlib/figure.py", line 1709, in draw
    renderer, self, artists, self.suppressComposite)
  File "/home/stuart/.virtualenvs/sunpy-dev/lib/python3.7/site-packages/matplotlib/image.py", line 135, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/stuart/Git/astropy/astropy/visualization/wcsaxes/core.py", line 454, in draw
    super().draw(renderer, inframe=inframe)
  File "/home/stuart/.virtualenvs/sunpy-dev/lib/python3.7/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/stuart/.virtualenvs/sunpy-dev/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 2647, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/home/stuart/.virtualenvs/sunpy-dev/lib/python3.7/site-packages/matplotlib/image.py", line 135, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/stuart/Git/astropy/astropy/visualization/wcsaxes/core.py", line 43, in draw
    self.axes.draw_wcsaxes(renderer)
  File "/home/stuart/Git/astropy/astropy/visualization/wcsaxes/core.py", line 411, in draw_wcsaxes
    coord._draw_grid(renderer)
  File "/home/stuart/Git/astropy/astropy/visualization/wcsaxes/coordinate_helpers.py", line 533, in _draw_grid
    self._update_grid_lines()
  File "/home/stuart/Git/astropy/astropy/visualization/wcsaxes/coordinate_helpers.py", line 868, in _update_grid_lines
    pixel = self.transform.inverted().transform(xy_world)
  File "/home/stuart/Git/astropy/astropy/visualization/wcsaxes/wcsapi.py", line 231, in transform
    raise ValueError(f"Expected {self.wcs.world_n_dim} world coordinates, got {len(world)} ")
ValueError: Expected 3 world coordinates, got 2 

without the grid call it's fine.

cc @astrofrog

@pllim
Copy link
Member

pllim commented Oct 15, 2019

@Cadair , you are not using the template that we stole from you. 😝

What are the versions?

@Cadair
Copy link
Member Author

Cadair commented Oct 15, 2019

This is master, should have specified.

I am in the habit of ignoring that template already 😉

@dstansby
Copy link
Contributor

dstansby commented Dec 9, 2022

I think the coordinate isn't separable? Printing the transformation gives the below, with correlations between pixel dim 0 and world dims {1, 2}.

SlicedLowLevelWCS Transformation

This transformation has 2 pixel and 3 world dimensions

Array shape (Numpy order): None

Pixel Dim  Axis Name  Data size  Bounds
        0  None            None  None
        1  None            None  None

World Dim  Axis Name  Physical Type                   Units
        0  None       em.wl                           m
        1  None       custom:pos.helioprojective.lat  deg
        2  None       custom:pos.helioprojective.lon  deg

Correlation between pixel and world axes:

           Pixel Dim
World Dim    0    1
        0  yes   no
        1   no  yes
        2   no  yes

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