Last active
September 27, 2015 06:38
-
-
Save taldcroft/1227280 to your computer and use it in GitHub Desktop.
Find quasar pairs using KDTree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scipy.spatial | |
from astropy.table import Table | |
dat = Table.read('sources_ra_dec_z.fits') | |
ok = ((dat['z'] > 0) | |
& (dat['ra'] > 150.0) & (dat['ra'] < 151.0) | |
& (dat['dec'] > 2.0) & (dat['dec'] < 3.0)) | |
datok = dat[ok] | |
# hist(dat['z'][ok], bins=50) | |
x = np.array([datok['ra'], datok['dec']]).transpose() | |
kdt = scipy.spatial.KDTree(x) | |
print 'running query_pairs' | |
radec_pairs = kdt.query_pairs(dist) | |
pairs = [] | |
zs = datok['z'] | |
for i1, i2 in radec_pairs: | |
if np.abs(zs[i1] - zs[i2]) < 0.2: | |
pairs.append((i1, i2)) | |
print len(pairs) # 104192 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh nice, I didn't even know about
scipy.spatial.KDTree
. Laughing now at all the horrible hacks I've seen various people write to do this kind of search (I knew there were better ways but I didn't know of any specific implementations that were convenient to use in Python).