|
2 | 2 | import pickle |
3 | 3 | from scipy.spatial import distance_matrix |
4 | 4 | from numba import njit |
| 5 | +from numpy.linalg import LinAlgError |
5 | 6 |
|
6 | 7 | from astrohack.utils.algorithms import least_squares, create_2d_array_reconstruction_array, create_coordinate_images, regrid_data_onto_2d_grid |
| 8 | +from astrohack.visualization.plot_tools import * |
7 | 9 |
|
8 | 10 | nanvec3d = np.array([np.nan, np.nan, np.nan]) |
9 | 11 | return_line = "\033[F" |
10 | 12 |
|
| 13 | + |
11 | 14 | def generalized_dot(vec_map_a, vec_map_b): |
12 | 15 | return np.sum(vec_map_a * vec_map_b, axis=-1) |
13 | 16 |
|
@@ -73,7 +76,11 @@ def np_qps_fitting(pcd): |
73 | 76 | sys_matrix[npnt:, :npnt] = 1.0 |
74 | 77 |
|
75 | 78 | sys_vector[:npnt] = pcd[:, 2] |
76 | | - qps_coeffs, _, _ = least_squares(sys_matrix, sys_vector) |
| 79 | + try: |
| 80 | + qps_coeffs, _, _ = least_squares(sys_matrix, sys_vector) |
| 81 | + except LinAlgError: |
| 82 | + print(sys_matrix, sys_vector) |
| 83 | + raise LinAlgError |
77 | 84 | return qps_coeffs |
78 | 85 |
|
79 | 86 |
|
@@ -143,13 +150,15 @@ def qps_image_jit(global_pcd, local_qps_coeffs, local_pcds, points): |
143 | 150 | npnt = points.shape[0] |
144 | 151 | new_zval = np.empty(npnt, dtype=np.float64) |
145 | 152 | new_norm = np.empty((npnt, 3), dtype=np.float64) |
| 153 | + print() |
146 | 154 | for ipnt in range(npnt): |
| 155 | + print(return_line, 100*ipnt/npnt, '% done ') |
147 | 156 | dist = np.sum((global_pcd[:, 0:2]-points[ipnt])**2, axis=-1) |
148 | 157 | i_closest = np.argmin(dist) |
149 | 158 | pnt, norm = qps_compute_point_and_normal_jit(points[ipnt], local_qps_coeffs[i_closest], local_pcds[i_closest]) |
150 | 159 | new_zval[ipnt] = pnt[2] |
151 | 160 | new_norm[ipnt] = norm |
152 | | - |
| 161 | + print('Done') |
153 | 162 | return new_zval, new_norm |
154 | 163 |
|
155 | 164 |
|
@@ -177,14 +186,14 @@ def __init__(self): |
177 | 186 | self.high_res_v_axis = None |
178 | 187 |
|
179 | 188 | @classmethod |
180 | | - def from_pcd(cls, pcd_data, local_qps_n_pnt=20, displacement=(0,0,0)): |
| 189 | + def from_pcd(cls, pcd_data, local_qps_n_pnt=20, displacement=(0, 0, 0)): |
181 | 190 | new_obj = cls() |
182 | 191 | new_obj._init_from_pcd(pcd_data, local_qps_n_pnt, displacement) |
183 | 192 | return new_obj |
184 | 193 |
|
185 | 194 | def _init_from_pcd(self, pcd_data, local_qps_n_pnt, displacement): |
186 | 195 | self.global_pcd = pcd_data |
187 | | - self.global_pcd -= np.array(displacement) |
| 196 | + self.global_pcd[:, ] -= np.array(displacement) |
188 | 197 | self.npnt = self.global_pcd.shape[0] |
189 | 198 | self.local_qps_n_pnt = local_qps_n_pnt |
190 | 199 | self.local_pcds = np.empty([self.npnt, self.local_qps_n_pnt, 3]) |
@@ -261,10 +270,17 @@ def execute_selection(pcd_selection, point_sel): |
261 | 270 |
|
262 | 271 | return z_val, z_norm |
263 | 272 |
|
264 | | - def plot_z_val_and_z_cos(self, colormap, zlim, dpi, display): |
| 273 | + def plot_z_val_and_z_cos(self, colormap='viridis', zlim=None, dpi=300, display=False): |
| 274 | + fig, ax = create_figure_and_axes(None, [1, 2]) |
| 275 | + simple_imshow_map_plot(ax[0], fig, self.current_u_axis, self.current_v_axis, self.current_z_val, |
| 276 | + 'Z value', colormap, zlim, z_label='Z value [m]', transpose=True) |
| 277 | + simple_imshow_map_plot(ax[1], fig, self.current_u_axis, self.current_v_axis, self.current_z_cos, |
| 278 | + 'Z Cosine', colormap, zlim, z_label='Z cosine []', transpose=True) |
| 279 | + close_figure(fig, 'Gridded surface and cosine of surface angle to Z axis', 'zval_zcos.png', |
| 280 | + dpi, display) |
265 | 281 | return |
266 | 282 |
|
267 | | - def compute_gridded_z_val_and_z_cos(self, u_axis, v_axis, mask, gridding_engine='2D regrid', light=(0,0,-1), |
| 283 | + def compute_gridded_z_val_and_z_cos(self, u_axis, v_axis, mask, gridding_engine='2D regrid', light=(0, 0, -1), |
268 | 284 | vectorized=True): |
269 | 285 | light = np.array(light) |
270 | 286 |
|
|
0 commit comments