# How to calculate distance from object to point on celestial sphere

I'd like to calculate the distance (in arcsec) from the object nearest to ra='08h55m10s' dec='-7d14m42s' to that point on the celestial sphere.

I am actually having trouble identifying the object. I have python code to run a cone search:

from astropy.coordinates import SkyCoord
from astroquery.irsa import Irsa
import astropy.units as u

loc = SkyCoord('08h55m10s',' -7d14m42s','icrs')
table = Irsa.query_region(coordinates=loc,catalog="wise_allsky_4band_p3as_psd", radius= 1 * u.arcminute)
print(table)

This prints:

designation        ra     dec   ...       angle         id
deg     deg   ...        deg
------------------- ------- ------- ... ------------------ ---
J085507.72-071428.4 133.782  -7.241 ... 291.84348499999999   0
J085511.22-071522.2 133.797  -7.256 ... 155.64652000000001   1
J085508.65-071354.0 133.786  -7.232 ... 337.39116000000001   2
J085509.94-071534.8 133.791  -7.260 ... 180.87171799999999   3
J085511.28-071528.1 133.797  -7.258 ... 157.48249000000001   4
J085509.47-071502.9 133.789  -7.251 ...         200.548395   5
J085513.60-071440.0 133.807  -7.244 ... 87.949470000000005   6
J085510.83-071442.5 133.795  -7.245 ... 92.439341999999996   7
J085511.39-071427.5 133.797  -7.241 ...          55.110833   8
J085513.30-071420.4 133.805  -7.239 ... 66.332006000000007   9

And this is where I am stumped. Which of these objects is nearest to the point? (I assume it must be the object in the zero index). And why? And how can I calculate the distance from the object to that point on the celestial sphere?

• Re I assume it must be the object in the zero index. That's a bad assumption. The object closest to your coordinates is the eight one (index=7) on your list, J085510.83-071442.5. That tool is doing a SQL query and the results are unsorted. – David Hammen Jan 17 '15 at 21:56
• Could you explain how you identified the object closest to the coordinates? – user5341 Jan 17 '15 at 22:49
• see the formula in Rob Jeffries answer. It is the correct formula. – David Hammen Jan 17 '15 at 22:56
• Ok this clears my misunderstanding. Just to clarify, the smallest angular distance returned by the function is $55.110833^{\circ}=198 398.999"$, is this correct? – user5341 Jan 18 '15 at 2:21
• No! Think about it. Your query asked for objects within 1 arc minute (60 arc seconds) of your given coordinates. The search found ten objects. – David Hammen Jan 18 '15 at 8:06

You can use SkyCoord.separation to compute the separation between coordinates:

c1 = SkyCoord('08h55m10s',' -7d14m42s', frame='icrs')  # your coords
c2 = SkyCoord(133.782, -7.241, unit='deg', frame='icrs')  # first object in table
sep = c1.separation(c2)

print c1
<SkyCoord (ICRS): ra=133.791666667 deg, dec=-7.245 deg>
print c2
<SkyCoord (ICRS): ra=133.782208333 deg, dec=-7.24123611111 deg>
print sep
0d00m36.3947s

The table you printed is truncated in between. If you enlarge your terminal emulator, you will be able to see a column called dist, which is the distance between your input coordinates and the corresponding object in arcsecs:

print table['dist']
dist
------------------
36.420772999999997
44.138542000000001
51.987606999999997
52.838003
49.937266999999999
22.372699000000001
53.621690000000001
12.375482
25.27176
53.707365000000003

Then the nearest object is the one whose separation is:

print table['dist'].min()
12.375482

Or equivalently, the one whose index is:

print table['dist'].argmin()
7

The separation is calculated using the equation that @Rob Jeffries pointed out.

The shortest angular distance between two points on the celestial sphere is measured along a great circle that passes through both of them.

The equation your program is using is $$\cos \theta = \sin \delta_1 \sin \delta_2 + \cos \delta_1 \cos \delta_2 \cos (\alpha_1 - \alpha_2),$$ where $(\alpha_1, \delta_1)$ and $(\alpha_2, \delta_2)$ are the right ascension and declination of the two points on the sky (expressed in degrees, then converted to radians).

In terms of output from your program its harder to help, especially as you have not given the full output. The first three columns should be self explanatory - columns 2 and 3 are just the coordinates expressed in degrees. I am guessing that the third column from last, that you haven't shown, gives the separation between your object and the catalogue objects and that the penultimate column is the angle that the great circle between the points makes on the sky. That looks right because the fourth object in the list has almost the same RA as your input object but is 67 arcseconds due south (i.e. at 180 degrees).