I have two different catalogues (data_in and data_out) with x,y coordinates of many points. As shown below I need to find all data_in points that are near to data_out points, in particular all data_in points within a circle of radius r_search, centered on every data_out points.
This little script works fine, but it is very slow. There is a way to speed up the process?
import numpy as np
data_in = np.genfromtxt(file_in)
x_in = np.array(data_in[:,1])
y_in = np.array(data_in[:,2])
data_out = np.genfromtxt(file_out)
x_out = np.array(data_out[:,1])
y_out = np.array(data_out[:,2])
r_search = 5
a=0
for i in range(len(x_out)):
for j in range(len(x_in)):
delta_x = abs(x_in[j] - x_out[i])
delta_y = abs(y_in[j] - y_out[i])
r_tmp = np.sqrt(np.power(delta_x,2) + np.power(delta_y,2))
if (r_tmp <= r_search):
a=a+1
X = np.zeros(a)
Y = np.zeros(a)
a=0
for i in range(len(x_out)):
for j in range(len(x_in)):
delta_x = abs(x_in[j] - x_out[i])
delta_y = abs(y_in[j] - y_out[i])
r_tmp = np.sqrt(np.power(delta_x,2) + np.power(delta_y,2))
if (r_tmp <= r_search):
X[a] = x_in[j]
Y[a] = y_in[j]
a=a+1