これがあなたが意図したことをしているかどうかを確認してください。効率的な組み込み/ numpy/scipy関数を使用すると、多くの計算時間を節約できます。たとえばm=(q<1) & (q>0)
はabs(q) < 1
に置き換えることができます(また、すべてのオブジェクトを1度以内で検索する場合は、m=(q<1) & (q>0)
はm=(q<1) & (q>-1)
)。
球の極座標でオブジェクトを正しく検索するには、大きな円の距離を見つける必要があります。そうでないと、極と周回境界(つまり(0.1,10.2)と(359.9,10.1) )。
2つの巨大なカタログ(たとえば両方とも10^9行)をクロスマッチさせたい場合は、非効率的なコードのために行く方法ではありません。しかし、あなたのカタログのうちの1つが〜700行しかない場合、効率的な検索機能の開発時間はおそらく検索自体よりもはるかに長くなるでしょう。
import numpy as np
# Set arbitrary size for a reference catalogue and a RR Lyrae cataloge
cat_size = 1000000
lyrae_size = 1000
# Draw sample randomly in a cartesian plane for the catalogue
# (1) RA, (2) Dec and (3) unique ID
ra_cat = np.random.random(cat_size) * 360.
dec_cat = np.random.random(cat_size) * 180. - 90.
id_cat = np.arange(cat_size)
# Draw sample randomly in a cartesian plane for the RR Lyrae catalogue
ra_lyrae = np.random.random(lyrae_size) * 360.
dec_lyrae = np.random.random(lyrae_size) * 180. - 90.
id_lyrae = np.arange(lyrae_size)
def great_circle_distance(ra1, dec1, ra_list, dec_list):
'''
Finding the great circle distance between given points and the list of
points given in equatorial coordinates. Note: this from cosine rule, which
is not the most accurate way to find the great circle distance.
Input:
ra1, dec1 - the reference point in degrees
ra_list, dec_list - is the list of object positions in degrees
Output:
list of distances between the reference point and the list of objects
in units of degrees.
'''
ra1 = np.radians(ra1)
dec1 = np.radians(dec1)
ra2 = np.radians(ra_list)
dec2 = np.radians(dec_list)
# Great circle distance in radians
dist = (np.arccos(np.sin(dec1) * np.sin(dec2) +
np.cos(dec1) * np.cos(dec2) * np.cos(ra1 - ra2)))
return np.degrees(dist)
# Loop through the RR Lyrae catalogue
for i, position in enumerate(zip(ra_lyrae, dec_lyrae)):
# Get the (RA, Dec) from zipped position
ra, dec = position
# Consider only objects within a 2x2 degree box
mask_candidate = (np.abs(ra_cat - ra) < 1.) | (np.abs(dec_cat - dec) < 1.)
# Get the distance between the RR Lyrae star to the objects in the box
distance = great_circle_distance(
ra, dec, ra_cat[mask_candidate], dec_cat[mask_candidate]
)
# Select all objects within 1 degree radius
mask_final = (distance < 1.)
# Get the unique ID of the catalogue objects
id_cat_matched = id_cat[mask_candidate][mask_final]
# print/save/further analysis with the list of matched objects
print 'lyrae id: ' + str(i+1) + ' matched with catalogue id: ' + str(id_cat_matched)
「lyrae」の大きさはどれくらいですか?いくつかのサンプルデータを提供できますか? –
今は700種類の星ですが、それほど問題にならないようにしようとしています。すぐにデータのサイズが大きくなります。 –
最初のいくつかの要素を表示して、データの構造について考えてみてください。 –