Faster alternative to SkyCoord.seperation?

I am using SkyCoord.separation to find the pixels around a given coordinate from an array. I have noticed the separation function takes too long. I have to repeat the calculation on a huge data set and using this function does not seem practical. Is there a faster alternative to SkyCoord.separation which handles arrays? The other similar functions do not seem to take array inputs and can only calculate separation between two sets of coordinates.

For example:
I have longitude and latitude arrays (size 50,331,648). I need to find the separation of each row with the rest of the array. So I run a loop 50,331,648 times.

Any suggestions would be of great help!
Thank you.

Hey @Axya,

If I understand correctly: You have an array of ~50 million sky coordinates (longitude and latitude), and you would like to compute the sky separation between all pairs of coordinates? Or am I misunderstanding? That operation by itself is going to be slow because naïvely you will have to do ~(50 million)^2 operations to compute those separations! Can you say more about your goal (i.e. unpack your first sentence a bit more), because it’s possible there is a faster workaround. For example, if you have an array of sky positions, and an array of pixel sky positions, and you want to find the nearest N sky positions to each pixel, you can use the “matching catalogs” functionality in astropy.coordinates as described here. This will work if you want to find the nearest N sky positions, or if you want to find all matching sky positions up to some search radius (see the match_coordinates_sky() and search_around_sky() methods. These methods will be much faster than trying to compute all pairwise separations. But let me know if I misunderstood your question!

1 Like

Thank you for the response! I am trying to find all the pixels within a certain radius around each coordinate. This is for an all-sky map and not a catalog search.
I am dealing with a HEALPix map and found healpy.query_disc after I posted the question. The speed for my loop reduced from 3seconds to 0.4 microseconds! This is more useful for my application as I am trying to extract certain regions around each pixel. I will check these functions you mentioned and see if they perform better.