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.

    Could you explain how you identified the object closest to the coordinates?

    see the formula in Rob Jeffries answer. It is the correct formula.

    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?

    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.

  • skytux

    skytux Correct answer

    7 years ago

    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.


License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM