Skip to content

fix: apply apodization when delay is zero in scan_line#743

Merged
waltsims merged 1 commit into
waltsims:masterfrom
wangwangbobo:fix/scan_line_apodization_delay_zero
May 18, 2026
Merged

fix: apply apodization when delay is zero in scan_line#743
waltsims merged 1 commit into
waltsims:masterfrom
wangwangbobo:fix/scan_line_apodization_delay_zero

Conversation

@wangwangbobo
Copy link
Copy Markdown
Contributor

@wangwangbobo wangwangbobo commented May 18, 2026

Fixes #627

The scan_line method in NotATransducer only applied apodization weights when delay != 0, silently skipping elements with delay == 0. This meant those elements contributed to the summed line without their receive apodization weight.

Added an else branch to apply apodization for all active elements regardless of delay value.

# Before: elements with delay==0 skipped apodization entirely
if delays[element_index] > 0:
    ...
elif delays[element_index] < 0:
    ...
# delay == 0 → no apodization applied ❌

# After:
else:
    # No delay — still apply apodization weight
    sensor_data[element_index, :] *= apodization[element_index]

Greptile Summary

This PR fixes a silent beamforming bug in NotATransducer.scan_line where elements whose delay rounded to exactly zero were summed into the output line without having their receive apodization weight applied. The fix is a minimal, correct else branch that mirrors the apodization multiply already present in the > 0 and < 0 branches.

  • The impact is most pronounced when steering_angle == 0 and focus_distance == inf, where every element's delay is zero — meaning the old code applied no apodization at all for that common B-mode configuration.
  • The single-line change is tightly scoped and does not affect any other code path.

Confidence Score: 5/5

Safe to merge — the change closes a well-defined gap where zero-delay elements skipped apodization entirely.

The three-line addition completes a pattern that is already correct in the adjacent branches, and the failure scenario (unweighted elements contributing to the summed line) is clearly reproduced whenever all delays are zero, which is the default no-steering/no-focus case.

No files require special attention.

Important Files Changed

Filename Overview
kwave/ktransducer.py Adds else branch to scan_line so apodization is applied to elements whose beamforming delay rounds to zero, fixing a silent bug where those elements contributed unweighted signal to the summed line.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[scan_line called] --> B[get_receive_apodization]
    B --> C[delays = -beamforming_delays]
    C --> D{for each element_index}
    D --> E{delays value?}
    E -- "> 0" --> F[Pad right, shift forward\n× apodization]
    E -- "< 0" --> G[Pad left, shift backward\n× apodization]
    E -- "== 0\n(NEW: else branch)" --> H[No shift\n× apodization]
    E -- "== 0\n(OLD: no branch)" --> I[❌ No apodization applied]
    F --> J[np.sum across elements]
    G --> J
    H --> J
    J --> K[Return scan line]
Loading

Reviews (1): Last reviewed commit: "fix: apply apodization when delay is zer..." | Re-trigger Greptile

The scan_line method only applied apodization weights when delay was
non-zero, silently skipping elements with delay==0. Added else branch
to apply apodization for all active elements regardless of delay.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 75.54%. Comparing base (0ba7876) to head (c4db03a).

Files with missing lines Patch % Lines
kwave/ktransducer.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #743      +/-   ##
==========================================
- Coverage   75.55%   75.54%   -0.01%     
==========================================
  Files          57       57              
  Lines        8187     8188       +1     
  Branches     1598     1598              
==========================================
  Hits         6186     6186              
- Misses       1380     1381       +1     
  Partials      621      621              
Flag Coverage Δ
3.10 75.51% <0.00%> (-0.01%) ⬇️
3.11 75.51% <0.00%> (-0.01%) ⬇️
3.12 75.51% <0.00%> (-0.01%) ⬇️
3.13 75.51% <0.00%> (-0.01%) ⬇️
macos-latest 75.45% <0.00%> (-0.01%) ⬇️
ubuntu-latest 75.45% <0.00%> (-0.01%) ⬇️
windows-latest 75.29% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Owner

@waltsims waltsims left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

A passing test case would have made the test coverage pass.

thanks!

@waltsims waltsims merged commit 4177811 into waltsims:master May 18, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] NotATransducer.scan_line use apodization only for delay != 0

2 participants