HansSnah
HansSnah

Reputation: 2250

Astropy: Asymmetric catalog matching results

I am doing some catalog matching for a project and found that the results I get are different when using astropy compared to other software packages for coordinate matching (e.g. Topcat). In particular, I do not understand why the following code produces asymmetric results

import numpy as np
from astropy.coordinates import match_coordinates_sky, SkyCoord

# Get some random coordinates
ra1, ra2 = np.random.uniform(80, 90, size=1E6), np.random.uniform(80, 90, size=1E6)
dec1, dec2 = np.random.uniform(20, 30, size=1E6), np.random.uniform(20, 30, size=1E6)

# Define SkyCoord instances
c1 = SkyCoord(ra1, dec1, frame="icrs", unit="deg")
c2 = SkyCoord(ra2, dec2, frame="icrs", unit="deg")

# Do matching
idx1, dis1, _ = match_coordinates_sky(c1, c2, nthneighbor=1)
idx1 = idx1[dis1.arcsec < 2]
idx2, dis2, _ = match_coordinates_sky(c2, c1, nthneighbor=1)
idx2 = idx2[dis2.arcsec < 2]

# Print results
print(len(idx1), len(idx2))

This prints: 10547 10553

Here I just reverse the catalog order and get different results. In particular, for my project the differences are much greater and I am not sure what the problem is.

thanks!

Upvotes: 0

Views: 909

Answers (1)

Tom Aldcroft
Tom Aldcroft

Reputation: 2542

The match_coordinates routine as you are using it is not symmetric. For example:

In [2]: c1 = SkyCoord(ra=[0], dec=[0], unit='deg')

In [3]: c2 = SkyCoord(ra=[0, 0], dec=[1./3600, 2./3600], unit='deg')

In [4]: from astropy.coordinates import match_coordinates_sky

In [5]: idx1, idis1, _ = match_coordinates_sky(c1, c2, nthneighbor=1)

In [6]: idx1
Out[6]: array([0])

In [7]: idis1
Out[7]: <Angle [ 0.00027778] deg>

In [8]: idx2, idis2, _ = match_coordinates_sky(c2, c1, nthneighbor=1)

In [9]: idis2
Out[9]: <Angle [ 0.00027778, 0.00055556] deg>

In [10]: idx2
Out[10]: array([0, 0])

Upvotes: 2

Related Questions