Skip to content

Commit e9f1aa4

Browse files
author
Brandon Kirkland
committed
Fix out-of-grid fallback speed and degenerate GMM guard (#150)
Use the simulation's reference sound speed (not the default c0) for geometric fallback on elements outside the grid. Add a guard for near-constant parenchyma intensity that would cause the GMM to degenerate.
1 parent c3b4c9e commit e9f1aa4

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/openlifu/bf/delay_methods/simulation_corrected.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def fortran_linear_index(idx, shape):
248248
if el_i in out_of_grid:
249249
# Element is outside the simulation grid; use geometric fallback
250250
dist = np.linalg.norm(element_positions_m[el_i] - target.get_position(units="m"))
251-
arrival_times[el_i] = dist / self.c0
251+
arrival_times[el_i] = dist / sound_speed_ref
252252
continue
253253

254254
row = voxel_to_row[sensor_idx]

src/openlifu/seg/seg_methods/threshold_mri.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,12 @@ def _classify_brain_gmm(
909909
# Extract parenchyma intensities for the initial fit.
910910
parenchyma_vals = classify_data[parenchyma_mask]
911911

912+
# Guard against near-constant intensity distributions where a
913+
# 3-component GMM would be degenerate (all components collapse
914+
# to the same mean, posteriors tie, argmax assigns class 0).
915+
if float(np.ptp(parenchyma_vals)) < 1e-6:
916+
raise ValueError("Parenchyma intensity range is near-zero; GMM cannot fit")
917+
912918
# Initial GMM fit on raw parenchyma intensities.
913919
means, stds, weights = self._fit_gmm_1d(
914920
parenchyma_vals, n_components=n_components

0 commit comments

Comments
 (0)