question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggest new method for SkyCoord: spherical_offset_by()

See original GitHub issue

Description

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:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
taldcroftcommented, Jan 1, 2021

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 using SkyOffsetFrame 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.

1reaction
adrncommented, Dec 31, 2020

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:

c = coord.SkyCoord(ra=152.234*u.deg,
                   dec=-17.4329*u.deg)
delta_RA = 17.3 * u.arcsec
delta_Dec = 3.5 * u.arcsec

coord.SkyOffsetFrame(delta_RA, delta_Dec, 
                     origin=c).transform_to(coord.ICRS())

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

SkyCoord — Astropy v5.2
A convenience method to create and return a new SkyCoord from the data in an astropy Table. Insert coordinate values before the given...
Read more >
Using the SkyCoord High-Level Class — Astropy v5.2
This requires that the new values be set from an another SkyCoord object that is equivalent in all ways except for the actual...
Read more >
Separations, Offsets, Catalog Matching, and Related ... - Astropy
SkyCoord.separation() methods, which computes the great-circle distance (not the ... To do the inverse operation — determining the new “destination” ...
Read more >
Astronomical Coordinate Systems (astropy.coordinates)
The best way to start using coordinates is to use the SkyCoord class. SkyCoord objects are instantiated by passing in positions (and optional...
Read more >
Usage Tips/Suggestions for Methods That Access Remote ...
The first is the SkyCoord from_name() method, which uses Sesame to ... the accuracy of coordinates might improve, and new observatories may be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found