astro/
matchall_sph.pro
Routines
result = wsrad_map(ngrid, a0, a1, a2, map, usemap)result = matchall_sph(ra1, dec1, ra2, dec2, sphrad [, nwithin], distance=distance)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.
Routine details
top source wsrad_map
result = wsrad_map(ngrid, a0, a1, a2, map, usemap)
Parameters
- ngrid
- a0
- a1
- a2
- map
- usemap
top source matchall_sph
Astro
result = matchall_sph(ra1, dec1, ra2, dec2, sphrad [, nwithin], distance=distance)
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.
Return value
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].
Parameters
- ra1 in
Vector of longitude coordinates, in degrees.
- dec1 in
Vector of latitude coordinates, in degrees.
- ra2 in
Vector of longitude coordinates, in degrees.
- dec2 in
Vector of latitude coordinates, in degrees.
- sphrad in
Maximum angular distance, in degrees.
- nwithin optional
A vector containing the number of matches for each of Ra1,Dec1.
Keywords
- distance in
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]]
Examples
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:*]]
Author information
- 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)
File attributes
| Modification date: | Tue Aug 9 11:53:25 2011 |
| Lines: | 207 |
![[attach.png]](../idldoc-resources/attach.png)