WCS.world_to_array_index_values ignores units of inputs
- Dominant language
- Python
- Stars
- 5.3k
- Forks
- 2.2k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 75
Description
### Description
When equivalent inputs are given to `WCS.world_to_array_index_values` but in different units, different array indices are returned. Presumably this is because the unit information is being ignored and it is being assumed that the inputs are in the same unit as stored in the WCS.
### Expected behavior
Equivalent inputs in different units produce same output.
### Actual behavior
### Steps to Reproduce
```python
>>> import astropy.units as u
>>> import numpy as np
>>> from astropy.wcs import WCS
>>> wcs = WCS()
>>> wcs.wcs.ctype = 'HPLN-TAN', 'HPLT-TAN'
>>> wcs.wcs.crval = 0.00089530541880571, 0.00038493926472938695
>>> wcs.wcs.crpix = 512.5, 512.5
>>> wcs.wcs.pc = np.array([[ 0.99999706, 0.00242302], [-0.00242302, 0.99999706]])
>>> wcs.wcs.cdelt = 0.0006674422222222221, 0.0006674422222222221
>>> wcs.wcs.cunit = ['deg', 'deg']
>>> # Define inputs
>>> a = [-900., -900.] * u.arcsec
>>> b = [0., -200.] *u.arcsec
>>> # The following two commands should return the same result, but don't.
>>> wcs.world_to_array_index_values(a.to(u.deg), b.to(u.deg))
(array([511, 428]), array([136, 136]))
>>> wcs.world_to_array_index_values(a.to(u.arcsec), b.to(u.arcsec))
(array([-9223372036854775808, 31755]),
array([-9223372036854775808, 510]))
```
### System Details
Contributor guide
Research direction
Start with the WCS.world_to_array_index_values entry point and run the provided Python reproduction using equivalent degree and arcsecond inputs. Trace how input units are handled relative to wcs.wcs.cunit, then add or update a regression test showing equivalent inputs return the same array indices.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100