# [AstroPy] calculate a new coordinate on sky given RA and Dec offsets and midpoint coordinate between two targets on sky

Eric Jensen ejensen1 at swarthmore.edu
Wed Mar 30 21:26:21 EDT 2016

```Hi Frank,

For #1, here’s a way you can do it:

from astropy.coordinates import Angle, SkyCoord
from astropy import units as u

# Define our initial coordinate position:
old_pos = SkyCoord('00h42m30s', '+61d12m00s', frame='icrs')

# Define the offsets:
ra_offset = Angle(15, unit=u.arcsec)
dec_offset = Angle(-4.5, unit=u.arcsec)

# Add the offsets to create a new coordinate position:
new_pos = SkyCoord(old_pos.ra + ra_offset, old_pos.dec + dec_offset, frame='icrs')

print(old_pos.to_string('hmsdms'))
print(new_pos.to_string('hmsdms'))

00h42m30s +61d12m00s
00h42m31s +61d11m55.5s

One thing to watch out for if you do it this way: notice that the RA offset is 15 arcseconds *of RA*, not 15 arcseconds *on the sky*.   At a dec of 61 degrees, 15 arcseconds of angle on the sky would be more like 30 arcseconds of RA (or in HMS, about 2 seconds of time rather than 1).

If you want to specify the RA offset in real angle on the sky and convert it to the appropriate RA offset to add to the initial coords, you could change the above to do something like

import numpy as np
ra_offset = Angle(15, unit=u.arcsec) / np.cos(old_pos.dec.to('radian'))

and then proceeding as before, you would get output:

00h42m30s +61d12m00s
00h42m32.0757s +61d11m55.5s

For your question number 2, you should be able to just do the arithmetic with subtracting the two RA values to find the RA separation, then halve it and add it to t1’s RA, then similarly with Dec, following the example above, to get the midpoint coordinates.

Both of the above answers probably break down at some level if you have large angular separations, but for small separations they should be reasonably good.   I also don’t know how these coordinate object handle edge cases, like crossing over RA = 0 or Dec = 90, but you could test it out.

Eric

On Mar 30, 2016, at 8:22 PM, Pistacho Datil <datilp at gmail.com> wrote:

> Hi,
>
> First of all apologies if these two questions are too simplistic.
>
> 1) I wonder if there is a way in astropy, given a target and an offset in RA and Dec to calculate a new target on sky.
>
> 2) Given two targets t1 and t2, is there a way using astropy of calculating the midpoint coordinate also on sky?
>
> Many thanks in advance,
>
> Frank
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20160330/b8b29f53/attachment.html>
```

More information about the AstroPy mailing list