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

CASA images may have bad WCS #57

Open
keflavich opened this issue Nov 22, 2021 · 8 comments
Open

CASA images may have bad WCS #57

keflavich opened this issue Nov 22, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@keflavich
Copy link
Contributor

I loaded a CASA .image in glue and tried to do a PV cut. I got the following traceback:

Traceback (most recent call last):
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/plugins/tools/pv_slicer/qt/pv_slicer.py", line 237, in _slice_from_path
    result = extract_pv_slice(cube, path=p, wcs=cube_wcs, order=0)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/external/pvextractor/pvextractor.py", line 76, in extract_pv_slice
    wcs = sanitize_wcs(wcs)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/external/pvextractor/utils/wcs_utils.py", line 39, in sanitize_wcs
    pc = np.matrix(mywcs.wcs.get_pc())
AttributeError: 'astropy.wcs.Wcsprm' object has no attribute 'wcs'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/adamginsburg/.local/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 270, in process
    func(*args, **kwargs)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/viewers/matplotlib/toolbar_mode.py", line 207, in key
    self._finish_roi(self._last_event)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/viewers/matplotlib/toolbar_mode.py", line 101, in _finish_roi
    self._roi_callback(self)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/plugins/tools/pv_slicer/qt/pv_slicer.py", line 41, in _extract_callback
    self._build_from_vertices(vx, vy)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/plugins/tools/pv_slicer/qt/pv_slicer.py", line 44, in _build_from_vertices
    pv_slice, x, y, wcs = _slice_from_path(vx, vy, self.viewer.state.reference_data,
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/plugins/tools/pv_slicer/qt/pv_slicer.py", line 240, in _slice_from_path
    result = extract_pv_slice(cube, path=p, wcs=None, order=0)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/external/pvextractor/pvextractor.py", line 79, in extract_pv_slice
    scale = get_spatial_scale(wcs)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/external/pvextractor/utils/wcs_utils.py", line 10, in get_spatial_scale
    wcs = wcs.sub([WCSSUB_CELESTIAL])
AttributeError: 'NoneType' object has no attribute 'sub'

I'm not certain, but I think this implies that mywcs is already the wcs object that should be getting used....

...looking closer, maybe this is a pvextractor problem? I'll try to track it down further but I want to post.

@keflavich keflavich added the bug Something isn't working label Nov 22, 2021
@keflavich
Copy link
Contributor Author

I think this line is the problem: https://github.com/glue-viz/glue/blob/ed71979f8e0e41f993a2363b3b5a8f8c3167a130/glue/plugins/tools/pv_slicer/qt/pv_slicer.py#L210
because data.coords is itself the wcs object

@keflavich
Copy link
Contributor Author

Hm, simply replacing the WCS gives:
NotImplementedError: Don't yet support nd fancy indexing

@astrofrog
Copy link
Member

Could you post the full traceback? I think this is likely to be an issue with pvextractor not working well with dask arrays, but I'd need to see the traceback to know for sure. I can try and investigate this on Thursday.

@keflavich
Copy link
Contributor Author

I think that is the full traceback? I was able to reproduce it this morning though so I'll try to get you a more complete MWE. But, just try doing a PV extraction on any CASA .image, maybe?

@astrofrog
Copy link
Member

Sorry I meant the lack of traceback in #57 (comment) - but I will try myself on Thursday with a cube I have.

@keflavich
Copy link
Contributor Author

Oh right, sorry. I'll see if I can get that.

@keflavich
Copy link
Contributor Author

Traceback (most recent call last):
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/plugins/tools/pv_slicer/qt/pv_slicer.py", line 240, in _slice_from_path
    result = extract_pv_slice(cube, path=p, wcs=cube_wcs, order=0)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/external/pvextractor/pvextractor.py", line 97, in extract_pv_slice
    pv_slice = extract_slice(cube, path, wcs=wcs, spacing=pixel_spacing,
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/external/pvextractor/geometry/slices.py", line 42, in extract_slice
    slice = extract_line_slice(cube, x, y, order=order)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/external/pvextractor/geometry/line_slices.py", line 43, in extract_line_slice
    total_slice[:,ok] = cube[:, y[ok].astype(int), x[ok].astype(int)]
  File "/orange/adamginsburg/miniconda3/envs/python39/lib/python3.9/site-packages/dask/array/core.py", line 1754, in __getitem__
    dsk, chunks = slice_array(out, self.name, self.chunks, index2, self.itemsize)
  File "/orange/adamginsburg/miniconda3/envs/python39/lib/python3.9/site-packages/dask/array/slicing.py", line 174, in slice_array
    dsk_out, bd_out = slice_with_newaxes(out_name, in_name, blockdims, index, itemsize)
  File "/orange/adamginsburg/miniconda3/envs/python39/lib/python3.9/site-packages/dask/array/slicing.py", line 196, in slice_with_newaxes
    dsk, blockdims2 = slice_wrap_lists(out_name, in_name, blockdims, index2, itemsize)
  File "/orange/adamginsburg/miniconda3/envs/python39/lib/python3.9/site-packages/dask/array/slicing.py", line 242, in slice_wrap_lists
    raise NotImplementedError("Don't yet support nd fancy indexing")
NotImplementedError: Don't yet support nd fancy indexing

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/adamginsburg/.local/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 270, in process
    func(*args, **kwargs)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/viewers/matplotlib/toolbar_mode.py", line 207, in key
    self._finish_roi(self._last_event)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/viewers/matplotlib/toolbar_mode.py", line 101, in _finish_roi
    self._roi_callback(self)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/plugins/tools/pv_slicer/qt/pv_slicer.py", line 41, in _extract_callback
    self._build_from_vertices(vx, vy)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/plugins/tools/pv_slicer/qt/pv_slicer.py", line 44, in _build_from_vertices
    pv_slice, x, y, wcs = _slice_from_path(vx, vy, self.viewer.state.reference_data,
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/plugins/tools/pv_slicer/qt/pv_slicer.py", line 243, in _slice_from_path
    result = extract_pv_slice(cube, path=p, wcs=None, order=0)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/external/pvextractor/pvextractor.py", line 79, in extract_pv_slice
    scale = get_spatial_scale(wcs)
  File "/blue/adamginsburg/adamginsburg/repos/glue/glue/external/pvextractor/utils/wcs_utils.py", line 10, in get_spatial_scale
    wcs = wcs.sub([WCSSUB_CELESTIAL])
AttributeError: 'NoneType' object has no attribute 'sub'

@keflavich
Copy link
Contributor Author

I added these lines:

    if isinstance(cube_wcs, wcs.Wcsprm):
        cube_wcs = data.coords

after line 210 (also had to import wcs from astropy)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants