astro/
match_sph.pro
top source match_sph
Astro
result = match_sph(ra1, dec1, ra2, dec2, sphrad, mindist=mindist, one_to_one=one_to_one)
For each angular point in one vector, determines the closest angular match from another vector. Method is to take the list returned by MATCHALL_SPH and narrow it down to the closest match.
Return value
The function returns an array with one entry for each Ra1, Dec1 element containing the index in Ra2, Dec2 that is closest, or -1 if there are none within Sphrad.
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. Matches outside of this radius are ignored.
Keywords
- mindist in
Optional output containing an array of the actual distance to the closest match for each element of Ra1, Dec1.
- one_to_one in
Enforces one-to-one matching. By default, matching can be many-to-one, i.e. one entry in Ra2,Dec2 can be the closest match to several entries in Ra1,Dec1. If /ONE_TO_ONE is given, then each multiple entry in Ra2,Dec2 is first assigned to its closest point in Ra1,Dec1. Then any entries in Ra1,Dec1 that have lost their match are assigned the next closest point within Sphrad. This process is iterated until all points in Ra1,Dec1 are matched to a unique point in Ra2,Dec2 or there are no more points within Sphrad
Examples
n1 = 25
n2 = 10
seed = 43L
ra1 = randomn(seed, n1)
dec1 = randomn(seed, n1)
ra2 = randomn(seed, n2)
dec2 = randomn(seed, n2)
result1 = match_sph(ra1, dec1, ra2, dec2, 1.)
result2 = match_sph(ra1, dec1, ra2, dec2, 1., /one_to_one)
!p.multi=[0,2,1]
plot, psym=1, ra1, dec1, xrange=[-3,3], yrange=[-3,3], title='Default'
oplot, psym=4, ra2, dec2
for i=0l,n1-1 do if result1[i] ne -1 then oplot, [ra1[i],ra2[result1[i]]], $
[dec1[i],dec2[result1[i]]]
plot, psym=1, ra1, dec1, xrange=[-3,3], yrange=[-3,3], title='/ONE_TO_ONE'
oplot, psym=4, ra2, dec2
for i=0l,n1-1 do if result2[i] ne -1 then oplot, [ra1[i],ra2[result2[i]]], $
[dec1[i],dec2[result2[i]]]
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 23 August 2010 Modified to only return closest match as WITHINSPHRAD_CLOSEST (importing some stuff back from MATCH_2D) 8 Sept 2010 Renamed MATCH_SPH. Added /ONE_TO_ONE option, and modified to explicitly call MATCHALL_SPH and then cull. 13 April 2011 Fixed to work around cumulative total 1-element array bug.
File attributes
| Modification date: | Tue Aug 9 10:50:41 2011 |
| Lines: | 174 |
![[attach.png]](../idldoc-resources/attach.png)