Skip to content

Commit f9d8b06

Browse files
committed
Passing test
1 parent f03356c commit f9d8b06

1 file changed

Lines changed: 13 additions & 32 deletions

File tree

kwave/utils/interp.py

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -262,44 +262,25 @@ def interp_cart_data(kgrid, cart_sensor_data, cart_sensor_mask, binary_sensor_ma
262262
binary_sensor_data[point_index, :] = cart_sensor_data[dist_min_index, :]
263263

264264
elif interp == "linear":
265-
# raise NotImplementedError
266-
# append the distance information onto the data set
267-
cart_sensor_data_ro = cart_sensor_data
268-
np.append(cart_sensor_data_ro, dist[:, None], axis=1)
269-
new_col_pos = -1
265+
# Find the two closest points
266+
dist_min_indices = np.argsort(dist)[:2]
270267

271-
# reorder the data set based on distance information
272-
cart_sensor_data_ro = sort_rows(cart_sensor_data_ro, new_col_pos)
268+
# Get distances to the two closest points
269+
dist1, dist2 = dist[dist_min_indices]
273270

274-
# linearly interpolate between the two closest points
275-
perc = cart_sensor_data_ro[2, new_col_pos] / (cart_sensor_data_ro[1, new_col_pos] + cart_sensor_data_ro[2, new_col_pos])
276-
binary_sensor_data[point_index, :] = perc * cart_sensor_data_ro[1, :] + (1 - perc) * cart_sensor_data_ro[2, :]
271+
# Calculate interpolation weights based on distances
272+
total_dist = dist1 + dist2
273+
w1 = dist2 / total_dist
274+
w2 = dist1 / total_dist
275+
276+
# Interpolate the time series data
277+
binary_sensor_data[point_index, :] = (
278+
w1 * cart_sensor_data[dist_min_indices[0], :] + w2 * cart_sensor_data[dist_min_indices[1], :]
279+
)
277280

278281
else:
279282
raise ValueError("Unknown interpolation option.")
280283

281-
# elif interp == 'linear':
282-
#
283-
# # dist = np.sqrt((cart_bsm[0, point_index] - cart_sensor_mask[0, :])**2 +
284-
# (cart_bsm[1, point_index] - cart_sensor_mask[1, :])**2)
285-
# # dist = np.linalg.norm(cart_bsm[:, point_index] - cart_sensor_mask.T, axis=1)
286-
# # append the distance information onto the data set
287-
# new_col_pos = len(cart_sensor_data[1, :]) -1
288-
# cart_sensor_data_ro = cart_sensor_data
289-
# cart_sensor_data_ro[:, new_col_pos] = dist
290-
#
291-
# # reorder the data set based on distance information
292-
# cart_sensor_data_ro = sort_rows(cart_sensor_data_ro, new_col_pos)
293-
#
294-
# # linearly interpolate between the two closest points
295-
# perc = cart_sensor_data_ro[1, new_col_pos] /
296-
# (cart_sensor_data_ro[0, new_col_pos] + cart_sensor_data_ro[1, new_col_pos] )
297-
# binary_sensor_data[point_index, :] = perc * cart_sensor_data_ro[1, :new_col_pos - 1] +
298-
# (1 - perc) * cart_sensor_data_ro[1, :new_col_pos - 1]
299-
#
300-
# else:
301-
# raise ValueError('Unknown interpolation option.')
302-
303284
# update command line status
304285
logging.log(logging.INFO, f" computation completed in {scale_time(timer.toc())}")
305286
return binary_sensor_data

0 commit comments

Comments
 (0)