You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does astropy support calculation of the PA or position angle between two points on the
celestial sphere. I am using astropy.coordinates.angles.AngularSeparation to compute the angular separation.
Something like what slalib SLA_BEAR is what I am looking for:
@richardgmcmahon This is not implemented yet, but I think would be great to have!
Do you think you could implement this in Astropy in the coming weeks if we give pointers?
that takes two astropy.coordinates as input, converts other_coordinate to the same coordinate system as reference_coordinate if needed and then executes the appropriate formula (see e.g. here or here) is easy (and would already be useful).
But sometimes one needs to convert position angles from one coordinate system (say ICRS) to another (say Galactic) and for that I'm not sure what a good API would be. Off the top of my head one option would be an attribute on the coordinates base class that is None by default, but gets transformed if present:
But this might very well be a bad idea ... @eteq will know.
A while ago I had to do this transformation of position angles and came up with this bad algorithm of creating a second point eps away from the reference point ... there must be some way to do this with cartesian unit 3D vectors and rotation matrices, but I don't know any code that implements this.
In any case the NED coordinate calculator can transform position angles and can be used to generate reference results for unit tests.
To answer your actual question: to compute an angular separation use SphericalCoordinatesBase.separation, i.e. take an astropy coordinates as input for your function and then call the separation method on it.
If you're not familiar with Astropy coding much, the hardest part for this PR is probably not implementing the formula for the position angle, but finding out how to add and run unit tests. There's quite a bit of documentation for this here, but you should also be able to copy & paste & edit existing tests.
Just so that you don't waste time, I think it makes sense to agree on the desired API before you implement this. After looking a bit at how that current implementation, I think you should follow the example of the SphericalCoordinatesBase.separation method calling an angular_separation function, i.e. you should implement a method and a function in this format:
So I'm 👍 to this, in the form @cdeil mentioned in his last message: a method in the same way separation is implemented, called position_angle.
Also, note that there's currently a major re-write of the coordinates framework happening, which will lead to these methods being moved to a different class in the next astropy version. But It's fine to implement this now as you're planning, @richardgmcmahon , and one of us developers will take care of moving it to the right place down the road.
@astrofrog - I took a look at this and it's actually really trivial in SOFA/ERFA - three lines of C code. Probably better to just implement it in python as a method of SkyCoord.
Activity
cdeil commentedon Apr 13, 2014
@richardgmcmahon This is not implemented yet, but I think would be great to have!
Do you think you could implement this in Astropy in the coming weeks if we give pointers?
Implementing a function
that takes two astropy.coordinates as input, converts
other_coordinateto the same coordinate system asreference_coordinateif needed and then executes the appropriate formula (see e.g. here or here) is easy (and would already be useful).But sometimes one needs to convert position angles from one coordinate system (say
ICRS) to another (sayGalactic) and for that I'm not sure what a good API would be. Off the top of my head one option would be an attribute on the coordinates base class that isNoneby default, but gets transformed if present:But this might very well be a bad idea ... @eteq will know.
A while ago I had to do this transformation of position angles and came up with this bad algorithm of creating a second point
epsaway from the reference point ... there must be some way to do this with cartesian unit 3D vectors and rotation matrices, but I don't know any code that implements this.In any case the NED coordinate calculator can transform position angles and can be used to generate reference results for unit tests.
richardgmcmahon commentedon Apr 13, 2014
OK, I have forked astropy and think that I can create a function angular_bearing based on astropy angular_separation and slalib sla_bear.f
richardgmcmahon commentedon Apr 14, 2014
Now, I am a bit confused since astropy 0.2x has an AngularSeparation class in angles.py which is not present in 0.3x
https://github.com/astropy/astropy/blob/v0.2.x/astropy/coordinates/angles.py
all = ['Angle', 'RA', 'Dec', 'AngularSeparation']
https://github.com/astropy/astropy/blob/v0.3.x/astropy/coordinates/angles.py
all = ['Angle', 'Latitude', 'Longitude']
the angular separation is in angles_utilities
https://github.com/astropy/astropy/blob/v0.3.x/astropy/coordinates/angle_utilities.py
def angular_separation(lon1, lat1, lon2, lat2):
I am easily confused and planned to implement an PositionAngle function based on AngularSeparation.
Comments appreciated.
cdeil commentedon Apr 14, 2014
@richardgmcmahon GitHub has a great full-text search for issues, pull requests and code.
In this case if you search for
AngularSeparationyou will find #1007 which shows you when it was removed and the dicsussion why:https://github.com/astropy/astropy/search?q=angularseparation&ref=cmdform&type=Issues
(I'm not saying you have to read that ... I'm just mentioning it as an example how you can find out such things quickly.)
To answer your actual question: to compute an angular separation use SphericalCoordinatesBase.separation, i.e. take an astropy coordinates as input for your function and then call the
separationmethod on it.richardgmcmahon commentedon Apr 14, 2014
Thanks, that is very helpful. I will look at this on a weeks timescale.
cdeil commentedon Apr 14, 2014
@richardgmcmahon Thanks for doing this!
If you're not familiar with Astropy coding much, the hardest part for this PR is probably not implementing the formula for the position angle, but finding out how to add and run unit tests. There's quite a bit of documentation for this here, but you should also be able to copy & paste & edit existing tests.
Just so that you don't waste time, I think it makes sense to agree on the desired API before you implement this. After looking a bit at how that current implementation, I think you should follow the example of the
SphericalCoordinatesBase.separationmethod calling anangular_separationfunction, i.e. you should implement a method and a function in this format:@eteq Agreed?
eteq commentedon Apr 14, 2014
@cdeil @richardgmcmahon - Note that this has been on the "todo" list since #1012 .
So I'm 👍 to this, in the form @cdeil mentioned in his last message: a method in the same way
separationis implemented, calledposition_angle.Also, note that there's currently a major re-write of the coordinates framework happening, which will lead to these methods being moved to a different class in the next astropy version. But It's fine to implement this now as you're planning, @richardgmcmahon , and one of us developers will take care of moving it to the right place down the road.
Thanks for your interest in doing this, @richardgmcmahon !
richardgmcmahon commentedon May 7, 2014
The SOFA fortran is here
http://www.iausofa.org/2013_1202_F/sofa/pas.html
Slalib is here:
https://github.com/richardgmcmahon/starlink/blob/master/libraries/sla/bear.f
astrofrog commentedon May 7, 2014
Oh, if it's in SOFA then it must be in ERFA (which we include in Astropy), so maybe we then just need a wrapper to it?
eteq commentedon May 14, 2014
@astrofrog - I took a look at this and it's actually really trivial in SOFA/ERFA - three lines of C code. Probably better to just implement it in python as a method of
SkyCoord.