# [AstroPy] AstroPy Digest, Vol 114, Issue 12

Pistacho Datil datilp at gmail.com
Thu Mar 31 18:54:20 EDT 2016

```thanks Eric

For the midpoint I went for

def midpoint(coord1, coord2):
ra1 = coord1.ra
dec1 = coord1.dec
ra2 = coord2.ra
dec2 = coord2.dec

delta_ra = ra2 - ra1
bx = np.cos(dec2) * np.cos(delta_ra)
by = np.cos(dec2) * np.sin(delta_ra)
dec_term1 = np.sin(dec1) + np.sin(dec2)
dec_term2 = np.sqrt(np.power((np.cos(dec1) + bx), 2) + np.power(by, 2))
decMid = np.arctan2(dec_term1, dec_term2)
raMid = ra1 + np.arctan2(by, np.cos(dec1) + bx)

return SkyCoord(raMid, decMid, frame='fk5')

not my code but it calculates the midpoint on sky.

Thanks again,

Frank

On Thu, Mar 31, 2016 at 5:00 AM, <astropy-request at scipy.org> wrote:

> Send AstroPy mailing list submissions to
>         astropy at scipy.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.scipy.org/mailman/listinfo/astropy
> or, via email, send a message with subject or body 'help' to
>         astropy-request at scipy.org
>
> You can reach the person managing the list at
>         astropy-owner at scipy.org
>
> than "Re: Contents of AstroPy digest..."
>
>
> Today's Topics:
>
>    1. calculate a new coordinate on sky given RA and Dec offsets
>       and midpoint coordinate between two targets on sky (Pistacho Datil)
>    2. Re: calculate a new coordinate on sky given RA and Dec
>       offsets and midpoint coordinate between two targets on sky
>       (Eric Jensen)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 30 Mar 2016 17:22:23 -0700
> From: Pistacho Datil <datilp at gmail.com>
> To: astropy at scipy.org
> Subject: [AstroPy] calculate a new coordinate on sky given RA and Dec
>         offsets and midpoint coordinate between two targets on sky
> Message-ID:
>         <
> CABH4OQKtS1s7js1s5823_EO4xJgOj8j19c1scTgTVeNK-jJFvA at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> 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?
>
>
> Frank
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> https://mail.scipy.org/pipermail/astropy/attachments/20160330/0e20a58b/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 2
> Date: Wed, 30 Mar 2016 21:26:21 -0400
> From: Eric Jensen <ejensen1 at swarthmore.edu>
> To: Astronomical Python mailing list <astropy at scipy.org>
> Subject: Re: [AstroPy] calculate a new coordinate on sky given RA and
>         Dec     offsets and midpoint coordinate between two targets on sky
> Content-Type: text/plain; charset="windows-1252"
>
> 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: <
> https://mail.scipy.org/pipermail/astropy/attachments/20160330/b8b29f53/attachment-0001.html
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy
>
>
> ------------------------------
>
> End of AstroPy Digest, Vol 114, Issue 12
> ****************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20160331/4426a1e4/attachment.html>
```