MATCHALL_SPH
Name
MATCHALL_SPH
Purpose
Determines which of a set of angular coordinates on the sky (or on a
sphere) are within a given angular distance from each of a vector of
points. New optimized version that uses histograms based on 3D
locations on the unit sphere and borrows heavily from JD's MATCH_2D.
Category
Astro
Calling Sequence
Result = MATCHALL_SPH(Ra1, Dec1, Ra2, Dec2, Sphrad, Nwithin)
Inputs
Ra1: Vector of longitude coordinates, in degrees.
Dec1: Vector of latitude coordinates, in degrees.
Ra2: Vector of longitude coordinates, in degrees.
Dec2: Vector of latitude coordinates, in degrees.
Sphrad: Maximum angular distance, in degrees.
Outputs
The function returns the list of indices of Ra2, Dec2 that lie within
Sphrad of each point Ra1,Dec1. The format of the returned array is
similar to the REVERSE_INDICES array from HISTOGRAM: the indices
into Ra2,Dec2 that are close enough to element i of Ra1,Dec1 are
contained in Result[Result[i]:Result[i+1]-1] (note, however, that
these indices are not guaranteed to be sorted). If there are no matches,
then Result[i] eq Result[i+1].
Optional Outputs
Nwithin: A vector containing the number of matches for each of Ra1,Dec1.
Keyword Parameters
DISTANCE: Optional output containing the distances between each pair.
The distances are stored in the same order as the Result
array but starting at 0, i.e. if j is match number k to
element i then
j = Result[Result[i]+k]
and the distance between points i and j is
DISTANCE[Result[i]+k-Result[0]]
Example
Note that the routine is similar to finding
WHERE(SPHDIST(Ra1,Dec1,Ra2,Dec2,/DEGREE) LE Sphrad, Nwithin)
for each element of Ra1 and Dec1, but is much more efficient.
Shows which random points are within 10 degrees of various coordinates:
seed=43
nrandcoords = 5000l
ra_randcoords = 360. * RANDOMU(seed, nrandcoords)
dec_randcoords = ASIN( 2*RANDOMU(seed, nrandcoords)-1 ) * !RADEG
ra_centers = 60. * FINDGEN(5)
dec_centers = [0., 45., 0., -45., 90.]
matches = MATCHALL_SPH(ra_centers, dec_centers, ra_randcoords, $
dec_randcoords, 10., nmatches)
plot, /iso, psym=3, ra_randcoords, dec_randcoords
oplot, psym=1, color=fsc_color('blue'), ra_centers, dec_centers
oplot, psym=3, color=fsc_color('red'), ra_randcoords[matches[6:*]], $
dec_randcoords[matches[6:*]]
Modification History
Written by: Jeremy Bailin
10 June 2008 Public release in JBIU as WITHINSPHRAD
24 April 2009 Vectorized as WITHINSPHRAD_VEC
25 April 2009 Polished to improve memory use
9 May 2009 Radical efficiency re-write as WITHINSPHRAD_VEC3D borrowing
heavily from JD Smith's MATCH_2D
13 May 2009 Removed * from LHS index in final remapping for speed
8 Sept 2010 Renamed MATCHALL_SPH and added DISTANCE keyword
9 Aug 2011 Bug fix: incorrect bin size caused occasional matches
to be missed (thanks to J. Donley for reporting)