match_to_catalog_sky should raise a nicer error when the match or catalog coordinates have nan values
See original GitHub issueI believe this is related to this SO question filed a few months ago.
Basically, match_to_catalog_sky()
is throwing an IndexError
and I can’t figure out why. I’m using Python 3.7.3
and astropy 3.1.2
.
Here’s the code to reproduce it (data files):
from astropy.io import ascii
from astropy.coordinates import SkyCoord
from astropy import units as u
d1 = ascii.read('c1.dat')
ra_obs, dec_obs = d1['ra'], d1['dec']
d2 = ascii.read('c2.dat')
ra_qry, dec_qry = d2['ra'], d2['dec']
c1 = SkyCoord(ra_obs, dec_obs, unit=(u.degree, u.degree))
c2 = SkyCoord(ra_qry, dec_qry, unit=(u.degree, u.degree))
idx, d2d, d3d = c1.match_to_catalog_sky(c2)
The full traceback is:
$ python test.py
/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/coordinates/angles.py:642: RuntimeWarning: invalid value encountered in less
if np.any(self_angle < wrap_angle_floor) or np.any(self_angle >= wrap_angle):
/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/coordinates/angles.py:642: RuntimeWarning: invalid value encountered in greater_equal
if np.any(self_angle < wrap_angle_floor) or np.any(self_angle >= wrap_angle):
/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/coordinates/angles.py:529: RuntimeWarning: invalid value encountered in less
if np.any(angles.value < lower) or np.any(angles.value > upper):
/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/coordinates/angles.py:529: RuntimeWarning: invalid value encountered in greater
if np.any(angles.value < lower) or np.any(angles.value > upper):
Traceback (most recent call last):
File "test.py", line 15, in <module>
idx, d2d, d3d = c1.match_to_catalog_sky(c2)
File "/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/coordinates/sky_coordinate.py", line 1045, in match_to_catalog_sky
storekdtree='_kdtree_sky')
File "/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/coordinates/matching.py", line 154, in match_coordinates_sky
idx, sep2d, sep3d = match_coordinates_3d(newmatch_u, newcat_u, nthneighbor, storekdtree)
File "/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/coordinates/matching.py", line 83, in match_coordinates_3d
sep2d = catalogcoord[idx].separation(matchcoord)
File "/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/utils/misc.py", line 940, in __getitem__
return self._apply('__getitem__', item)
File "/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/coordinates/baseframe.py", line 1476, in _apply
new._data = apply_method(self.data)
File "/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/coordinates/baseframe.py", line 1447, in apply_method
return value._apply(method, *args, **kwargs)
File "/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/coordinates/representation.py", line 780, in _apply
rep = super()._apply(method, *args, **kwargs)
File "/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/coordinates/representation.py", line 263, in _apply
apply_method(getattr(self, component)))
File "/home/gabriel/miniconda3/envs/py3/lib/python3.7/site-packages/astropy/units/quantity.py", line 1035, in __getitem__
out = super().__getitem__(key)
IndexError: index 22670 is out of bounds for axis 0 with size 22670
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Catalog Matching Using Astropy.Coordinates - ADocLib
I'm using Python 3.7.3 and astropy 3.1.2.should raise a nicer error when the match or catalog coordinates have nan values #8985. matchtocatalogsky ...
Read more >SkyCoord — Astropy v5.2
High-level object providing a flexible interface for celestial coordinate representation, manipulation, and transformation between systems. The SkyCoord class ...
Read more >1. A short course in PyVO 2. Prerequisites 3. What's the VO
This course will introduce you to the primary concepts of PyVO, an astropy-affiliated package for accessing Virtual Observatory services from Python.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think it’s because you have nan entries in c2. Not sure if this was also the cause for the SO question but it seems to work fine once you clean nans in c2.
The nan entries seems to completely mess up KDTree built from them making it return dist=inf and idx=(lenth of catalogcoord) for any query. Not sure if this was handled in previous versions of astropy.
(Oops, just saw @adrn mentioned
_3d
methods already)