Skip to content

Use the depth axis to exclude the first 3D correlation peak - #379

Open
antonsoo wants to merge 1 commit into
OpenPIV:masterfrom
antonsoo:fix/3d-second-peak-depth
Open

antonsoo wants to merge 1 commit into
OpenPIV:masterfrom
antonsoo:fix/3d-second-peak-depth

Conversation

@antonsoo

@antonsoo antonsoo commented Oct 20, 2026 •

Copy link
Copy Markdown

Fixes #152.

find_second_peak_3D clips the depth of its exclusion region to corr.shape[1]. For a correlation volume deeper than its width, this can leave the first peak unmasked and return it as the second peak. The resulting peak-to-peak signal-to-noise ratio is one, so subsequent validation rejects the vector.

Use corr.shape[2] for that bound. For example, a (7, 8, 20) volume with peaks of 10 at (3, 4, 15) and 4 at (3, 4, 5) now selects the second location and returns a ratio of 2.5, rather than selecting the first location again.

The tests cover supplied/inferred first peaks, exclusion widths, rectangular and cubic volumes, depth-edge clipping and unchanged inputs. Ten cases fail before the fix; eight existing-behavior controls also pass. Separate synthetic 3D particle-volume runs restore 192 falsely rejected vectors across 24 pipelines, while 24 complete volume controls and all velocity fields remain unchanged. Recorded 2D image workflows, saved/reloaded fields and the original tutorial retain identical results on Python 3.10/3.12.

Full suites: 272 passed with the Rust extension on Python 3.12; 237 passed and 4 optional skips without Rust on Python 3.10. All original test outcomes are retained. Full Ruff has 561 existing findings versus 562 on unchanged master; this change adds none. The 3D function uses the SciPy path; the Rust sources are unchanged.

Summary by Sourcery

Fix 3D peak selection to use the depth dimension when excluding the primary correlation peak.

Bug Fixes:

  • Correct the 3D second-peak exclusion bounds so correlation volumes deeper than their width no longer return the primary peak as the secondary peak.

Tests:

  • Add coverage for inferred and explicit first peaks across rectangular and cubic volumes, exclusion widths, depth-edge clipping, signal-to-noise results, and input immutability.

Clamp the z exclusion interval to the depth of a correlation volume. Rectangular volumes otherwise retain the first peak and report a peak-to-peak signal-to-noise ratio of one.

Fixes OpenPIV#152.
@sourcery-ai

sourcery-ai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Fixes 3D second-peak exclusion by clipping the masked depth region against corr.shape[2] instead of the width axis, preventing the first peak from being selected again in deeper-than-wide volumes. Adds parametrized regression tests covering peak inference, dimensions, widths, edge clipping, input immutability, and the resulting signal-to-noise ratio.

Flow diagram for 3D second-peak exclusion

flowchart TD
    A[3D correlation volume] --> B[find_second_peak_3D]
    B --> C[Infer or use first peak]
    C --> D[Build exclusion region]
    D --> E["Clip depth bound to corr.shape[2]"]
    E --> F[Mask first peak region]
    F --> G[find_first_peak on masked volume]
    G --> H[Return second peak and peak-to-peak ratio]
Loading

File-Level Changes

Change Details Files
Correct the depth-axis boundary used when masking the first correlation peak.
  • Bound the exclusion region with the correlation volume’s depth dimension.
  • Preserve existing peak-search behavior for other axes and input arrays.
openpiv/pyprocess3D.py
Add focused regression coverage for second-peak selection and signal-to-noise behavior.
  • Test explicit and inferred first peaks across rectangular and cubic volumes.
  • Cover zero and nonzero exclusion widths, depth-edge clipping, and unchanged inputs.
  • Verify deep-volume peak-to-peak ratios no longer reuse the first peak.
openpiv/test/test_pyprocess3D.py

Assessment against linked issues

Issue Objective Addressed Explanation
#152 In find_second_peak_3D, bound the peak-exclusion region along the depth axis using the correlation volume’s depth dimension, so the first peak is excluded even when depth exceeds width. ✅
#152 Add regression coverage showing second-peak selection and peak-to-peak signal-to-noise behavior work for deep, rectangular, and other 3D correlation volumes without modifying the input. ✅

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
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.

seems to be a bug

1 participant