Skip to content

Commit d3c7295

Browse files
committed
Fix regression: fit model was accepted too early
This was leading to incomplete, suboptimal fits.
1 parent 41f4170 commit d3c7295

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

mitcom/peak_detection.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ def _process_protein_impl(
341341
model, params = build_model(profile, peaks)
342342
result = model.fit(profile, params, x=x, weights=weights)
343343

344+
latest_result = result
345+
latest_peaks = peaks
346+
344347
# add more peaks if needed
345348
while len(peaks) < 12:
346349
# area above 'best fit' line
@@ -390,15 +393,16 @@ def _process_protein_impl(
390393

391394
# add additional peak
392395
# print("Adding additional peak at", best_new_peak_index)
393-
new_peaks = np.append(peaks, best_new_peak_index)
396+
peaks = np.append(peaks, best_new_peak_index)
394397
model, params = build_model(profile, peaks)
395-
new_result = model.fit(profile, params, x=x, weights=weights)
398+
result = model.fit(profile, params, x=x, weights=weights)
396399

397-
if not new_result.success:
398-
break
400+
if result.success:
401+
latest_result = result
402+
latest_peaks = peaks
399403

400-
result = new_result
401-
peaks = new_peaks
404+
result = latest_result
405+
peaks = latest_peaks
402406

403407
if not result.success:
404408
raise ValueError(f"Fit aborted: {result.message}")

0 commit comments

Comments
 (0)