Skip to content

openpiv.gpu.validation.Validation._mean_validation uses median_tol instead of mean_tol #33

Description

@DumbledoreCalrissian

Summary

In openpiv/gpu/validation.py, scalar mean validation appears to use the wrong tolerance parameter. The _mean_validation() method computes the local mean residual, but passes self.median_tol to _neighbour_validation() instead of self.mean_tol.

Current behaviour

Current code in Validation._mean_validation():

def _mean_validation(self):
    for k in range(self._num_fields):
        f_mean_residual = _gpu_residual(
            self._mean[k],
            self._neighbours[k],
            self._neighbours_present,
            "mean_residual",
        )
        self.val_locations = _neighbour_validation(
            self._f[k],
            self._mean[k],
            f_mean_residual,
            self.median_tol,
            self.val_locations,
        )

Expected Behaviour

Scalar mean validation should use self.mean_tol:

self.val_locations = _neighbour_validation(
    self._f[k],
    self._mean[k],
    f_mean_residual,
    self.mean_tol,
    self.val_locations,
)

Why this looks like a bug

  • Validation.__init__ exposes separate median_tol and mean_tol parameters.
  • _median_validation() correctly uses self.median_tol.
  • _mean_validation_vec2d() correctly uses self.mean_tol.
  • _rms_validation() correctly uses self.rms_tol.
  • The scalar _mean_validation() path is the only path using another validation method's tolerance.

Impact

Users who configure mean_tol separately from median_tol get unexpected validation masks.

For example:

validation_method = "mean_velocity"
median_tol = 2
mean_tol = 5

The scalar validation still uses 2, not 5, making mean validation stricter than requested.

Suggested fix

Change this line in _mean_validation():

self.median_tol

to:

self.mean_tol

Suggested test

Add a test where median_tol and mean_tol differ, then assert scalar mean validation matches a direct _neighbour_validation(..., tol=mean_tol) reference.

Current tests use default equal values (MEDIAN_TOL == MEAN_TOL == 2) in the direct mean-validation test, so the bug is masked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions