Skip to content

Commit 8783b1c

Browse files
committed
added full np version, it is marginally faster than the jit version, however it is less precise
1 parent 2eeb921 commit 8783b1c

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

src/astrohack/utils/ray_tracing_general.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
2-
from astrohack.utils.algorithms import least_squares_jit
2+
from astrohack.utils.algorithms import least_squares_jit, least_squares
33
from numba import njit
4+
from scipy.spatial.distance import cdist
45

56

67
def generalized_dot(vec_map_a, vec_map_b):
@@ -19,6 +20,7 @@ def normalize_vector_map(vector_map):
1920
def reflect_light(light, normals):
2021
return light - 2 * generalized_dot(light, normals)[..., np.newaxis] * normals
2122

23+
2224
@njit(cache=True, nogil=True)
2325
def compute_quintic_pseudo_spline_coefficients(point_cloud):
2426
# QPS definition from Bergman et al. 1994, IEEE Transactions on Antennas and propagation
@@ -58,7 +60,35 @@ def dist_2d(pnt_a, pnt_b):
5860
matrix[irow, 0:npnt] = 1
5961

6062
qps_coeffs, _, _, _ = least_squares_jit(matrix, vector)
61-
return qps_coeffs
63+
return qps_coeffs, matrix, vector
64+
65+
66+
def compute_qps_full_np(point_cloud):
67+
n_extra_coeffs = 6
68+
pcd_xy = point_cloud[:, 0:2]
69+
pcd_z = point_cloud[:, 2]
70+
71+
npnt = pcd_xy.shape[0]
72+
n_var = npnt + n_extra_coeffs
73+
matrix_shape = (n_var, n_var)
74+
75+
matrix = np.empty(matrix_shape)
76+
vector = np.zeros(n_var)
77+
78+
matrix[0:npnt, 0:npnt] = cdist(pcd_xy, pcd_xy)**5
79+
matrix[0:npnt, npnt+0] = pcd_xy[:, 0] ** 2
80+
matrix[0:npnt, npnt+1] = pcd_xy[:, 0] * pcd_xy[:, 1]
81+
matrix[0:npnt, npnt+2] = pcd_xy[:, 1] ** 2
82+
matrix[0:npnt, npnt+3] = pcd_xy[:, 0]
83+
matrix[0:npnt, npnt+4] = pcd_xy[:, 1]
84+
matrix[0:npnt, npnt+5] = 1
85+
matrix[npnt:n_var, 0:npnt] = 1
86+
matrix[npnt:n_var, npnt:n_var] = 0
87+
vector[0:npnt] = pcd_z
88+
89+
qps_coeffs, _, _ = least_squares(matrix, vector)
90+
return qps_coeffs, matrix, vector
91+
6292

6393
def compute_qps_value(pnt, qps_coeffs, point_cloud):
6494
# QPS definition from Bergman et al. 1994, IEEE Transactions on Antennas and propagation
@@ -73,6 +103,7 @@ def compute_qps_value(pnt, qps_coeffs, point_cloud):
73103

74104
return z_val
75105

106+
76107
def qps_pcd_fitting(point_cloud_filename, output_coeff_filename, max_rows=None):
77108

78109
pcd_data = np.loadtxt(point_cloud_filename, max_rows=max_rows)

0 commit comments

Comments
 (0)