Suggest new method for SkyCoord: spherical_offset_by()
See original GitHub issueDescription
I’ve been searching for a SkyCoord method, given a SkyCoord object sk, will calculate the position that is an offset away, for example, an offset of 10" N and 5" E. It should use spherical math on general principles, even though this example would be safe to use a small-angle approximation.
I believe what I’m asking for is the opposite of this SkyCoord method: sc.spherical_offsets_to.
I believe it’s currently possible to do this math using the method sk.directional_offset_by(). However, it’s super-clunky (calling the method twice), and not how an observer thinks, since it uses a position angle and a total distance as the input, rather than the offsets in RA, DEC. Here’s the wrapper function I wrote:
def offset_coords(sk, delta_RA=0, delta_DEC=0) :
''' From Astropy SkyCoords position sk, compute new coordinates after offsets (in arcsec). Positive offsets move N and E
This should be a method in astropy SkyCoord, but I can't find it.'''
# Input coords should be in Astropy format, for example sk = SkyCoord(RA, DEC, unit='deg')
newsk = sk.directional_offset_by(0. *u.deg, delta_DEC * u.arcsec).directional_offset_by(90. *u.deg, delta_RA * u.arcsec)
return(newsk)
I was shocked that AstroPy doesn’t have a method to do something so simple as “Go 10 arcsec S, go 15 arcsec W.”) Am I missing something? I’m still learning AstroPy, so it’s totally possible that I am just not aware of an existing solution. If so please tell me! But I do suspect this may be a case where because AstroPy has over-generalized (to all kinds of coordinate systems), it’s lacking the tool the astronomer actually wants at the telescope, or while staring at an image.
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Personally I vote for a short and sweet convenience method
spherical_offsets_by
which is roughly the one-liner that @adrn wrote. That particular incantation usingSkyOffsetFrame
is not going to be discoverable by any means but the narrative docs, and even when reading it I had to think for a second.Adding this “feature” is not really creep in my mind because it does not increase code complexity or maintenance burden. It is just syntactic sugar to do something very common.
Thanks @janerigby for raising this! It sounds like it would be useful to either add this functionality to
directional_offset_by()
, or add a new method as suggested. On the plus side, I think this would improve discoverability for something that does sound like it would be useful for observational users. On the negative, we are always trying to balance “feature creep.”@janerigby : Another way to do what you want is to use the
SkyOffsetFrame
class like:Would this solution be good enough for you if we had documented it better, or added an example demonstrating this? Fine to say no, just curious!