Astropy can't go back and forth between coordinates

Viewed 139

I have icrs coordinates(SkyCoord) of two sources. Using astropy directional_offset_by() method I have found position angle and separation between them. So when I add this position angle and separation to the first Skycoord I should get the second SkyCoord, and I did. But when I try to get the first SkyCoord from the second source, I get different results.
Separation should be the same, but the position angle should be rotated by 180 deg, right?
I am missing something obvious but can't see what.
I put below minimum working example.

Alpheratz = SkyCoord.from_name('Alpheratz') 
Peg = SkyCoord.from_name("Psi Pegasi") 
Pos_ang = Alpheratz.position_angle(Peg)
Sep = Alpheratz.separation(Peg)
print("Pos_ang:",Pos_ang,"Sep:", Sep)
Peg_from_A = Alpheratz.directional_offset_by(position_angle = Pos_ang, separation = Sep)
Alphe_back_from_Peg = Peg_from_A.directional_offset_by(position_angle = Pos_ang - 180*u.deg, separation = Sep)
print("Peg from name:",Peg,"\nPeg from A:", Peg_from_A)
print("Alphe from Name:", Alpheratz, "\nAlphe back from P from A", Alphe_back_from_Peg)
1 Answers

As I understand the question, I don’t think the inverse angle should be 180 degrees from the the first due to these positions being on a sphere, and the position angle from one point to another is defined by a great circle path between the 2 points.

I find this easiest to picture near the poles. Imagine two points, p1 at (0, 89) and p2 and (45, 89), both at the same declination near the pole but 45 degrees apart in RA.

The pos angle from p1 to p2 is about 67 degree, but the pos angle from p2 to p1 is about 292 degrees, which is not close to 180 degrees different. This makes sense to me when picturing the sphere with these points near the pole.

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

p1 = SkyCoord(0, 89, unit='deg')
p2 = SkyCoord(45, 89, unit='deg')
Pos_ang = p1.position_angle(p2)
Sep = p1.separation(p2)
print("Pos_ang p1 to p2:",Pos_ang, f"({Pos_ang.degree} deg) ", "Sep:", Sep)

pos_ang_p2_to_p1 = p2.position_angle(p1)
print("Pos_ang p2 to p1:",pos_ang_p2_to_p1, f"({pos_ang_p2_to_p1.degree} deg) ", "Sep:", Sep)

p2_from_p1 = p1.directional_offset_by(position_angle = Pos_ang, separation = Sep)

p1_back_from_p2 = p2_from_p1.directional_offset_by(position_angle = Pos_ang - 180*u.deg, separation = Sep)

print("\n\np2 pos:",p2,"\np2 from p1:", p2_from_p1)
print("p1 pos:", p1, "\np1 back from p2", p1_back_from_p2)
Related