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.

SkyCoord.separation is slow due to unneeded frame transform

See original GitHub issue

SkyCoord.separation() takes 22 milliseconds, compared to 4.5 milliseconds for Skycoord.position_angle(). This is the timing for two points in the same coordinate system.

The difference in speed is due to the fact that position_angle() checks whether the coordinate systems are the same, while separation() always does a transformation. Since the most common use-case is to have all of the points be in the same coordinate system, this is extremely wasteful.

The code at sky_coordinate.py:1060:position_angle() and sky_coordinate.py:677:separation() should be identical, since they both serve the same function.

(Neither is fast, largely due #5698 . separation() calls FRAME_ATTR_NAMES_SET() 22 times causing 2717 getattr() calls).

Other comments: I don’t know why the various methods have their own import statements, e.g. sky_coordinate.py:392. It probably is a minimal speed-up to put them all at the top, but it may be a stylistic convention in this project.

The following are possible enhancements (Should they go in a separate issue? Do they already exist in some other library?): I would also like to suggest a single function that returns both separation and posang (because that is something commonly desired).

Also useful would be a function that takes a separation and posang to produce a new point. (My particular use is triangulation from the InterPlanetary Network (IPN) that does timing-base localization of gamma ray bursts. Other uses include drawing field-of-view circles and finding the midpoint between two points.)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
taldcroftcommented, Jan 15, 2017

Since the issue of performance for separation is coming up again, there were similar discussions previously and I argued that we should support a very fast cythonized version that accepts only floats. I still believe this. See https://github.com/astropy/astropy/issues/3908#issuecomment-176782129.

0reactions
eteqcommented, Oct 28, 2018

#5727 #5723 are in now so I think this is set to be closed. Can be reopened if there’s still some thread I missed though, as this spawned a lot of discussion. Thanks @dmopalmer !

(Also, @hamogu, note that #5727 may now have the solution to you problem from https://github.com/astropy/astropy/issues/5702#issuecomment-274378485 … sure, maybe 1.5 yrs after, but better late than never? ⏲ 😉)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Separations, Offsets, Catalog Matching, and Related ... - Astropy
SkyCoord.separation() methods, which computes the great-circle distance ... Also note that the two input coordinates were not in the same frame — one...
Read more >
Source code for astropy.coordinates.baseframe
Licensed under a 3-clause BSD style license - see LICENSE.rst """ Framework and base classes for coordinate frames/"low-level" coordinate classes.
Read more >
SkyCoord — Astropy v5.2
Computes on-sky separation between this coordinate and another. Note. If the other coordinate object is in a different frame, it is first transformed...
Read more >
Using the SkyCoord High-Level Class — Astropy v5.2
At present, SkyCoord objects can use only coordinate frames that have transformations defined in the astropy.coordinates.frame_transform_graph transform graph ...
Read more >
astropy.coordinates.baseframe — gala v1.3
As originally created, this is only used in the SkyCoord initializer, ... frame object or SkyCoord object The frame to transform this coordinate...
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