8000 Raise ValueError if NaN found in phase_cross_correlation result by GenevieveBuckley · Pull Request #4886 · scikit-image/scikit-image · GitHub
[go: up one dir, main page]

Skip to content

Raise ValueError if NaN found in phase_cross_correlation result #4886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

GenevieveBuckley
Copy link
Contributor

Description

Closes #4763

As requested by @emmanuelle in #4767 (comment)

This PR raises a ValueError if a NaN value is found in the error or phase_diff, indicating that there were unexpected NaN values in the input data.

Note: this check only occurs if the keyword argument return_error=True, which is the default value for this kwarg in phase_cross_correlation. If return_error=False then there is no check, and it's possible to get a garbage shift result of zero back if the input data accidentally contained NaNs. This is because it's computationally expensive to check a large array for NaN values, which is what we'd have to do if return_error=False. Still, it seems helpful if we can catch at least some of these mistakes and redirect the user to the masked cross correlation functionality instead.

Checklist

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.

@pep8speaks
Copy link
pep8speaks commented Aug 5, 2020

Hello @GenevieveBuckley! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-08-05 07:47:10 UTC

Copy link
Member
@emmanuelle emmanuelle left a comment

Choose a reason for hiding this comment

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

Thanks @GenevieveBuckley the PR is a clear improvement over the existing situation, and I think it's a reasonable trade-off with respect to performance and validity of results.

@emmanuelle
Copy link
Member

A possibility would be to add a note in the docstring mentioning that if don't return the error you are supposed to check that there are no nans (or to use a mask).

@GenevieveBuckley
Copy link
Contributor Author

A possibility would be to add a note in the docstring mentioning that if don't return the error you are supposed to check that there are no nans (or to use a mask).

The docstring already has info about the reference_mask and moving_mask keyword arguments, so I don't think there's much extra benefit to adding this (although I do appreciate your suggestion). I think that catching some of the errors some of the time, is as you say, a clear improvement over the existing situation so it'll be fine.

Copy link
Contributor
@grlee77 grlee77 left a comment

Choose a reason for hiding this comment

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

Thanks. This should make the function more user friendly

@grlee77 grlee77 merged commit 66f78a4 into scikit-image:master Aug 8, 2020
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.

phase_cross_correlation with NaN pixels returns an invalid result
4 participants
0