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
Freeze while passing NaN to unwrap_phase #3831
Comments
@ldes89150 thanks for the report! The code should never freeze, that's definitely a bug. However, to indicate masked values, you should use a NumPy masked array. The second part of the gallery example shows how to use this: http://scikit-image.org/docs/dev/auto_examples/filters/plot_phase_unwrap.html @scikit-image/core longer term, perhaps we should add a |
@ldes89150 bug confirmed. |
Quickly looking at the code, it seems there are some floating point comparisons that aren't NaN safe in the C code. Not sure the best way to deal with this that won't completely kill performance. |
On Thu, 11 Apr 2019 16:42:53 -0700, Mark Harfouche wrote:
Not sure the best way to deal with this that won't completely kill
performance.
It's okay to have weird results after NaNs are introduced; it just
shouldn't freeze.
|
Agreed. I think it is the floating point comparison that is tripping off the algorithm https://github.com/scikit-image/scikit-image/blob/master/skimage/restoration/unwrap_2d_ljmu.c#L100 |
typedef enum {
yes,
no
} yes_no;
yes_no find_pivot(EDGE *left, EDGE *right, double *pivot_ptr) { Really, bools were not sufficiently expressive here? 🤦♂️ @hmaarrfk a hang suggests a while loop is involved rather than a for-loop. I notice two whiles later on in that function... @stefanv perhaps |
We should look at how other NaN safe functions are implemented |
@jni Thanks for the suggestion of using masked arrays! |
Masking arrays unfortunately does not work for me. I have a 3000 x 3000 float array with NaNs masked out using MaskedArrays. Testing numpy.isnan(arr).any() returns False. |
@plu2k are you able to share your masked array with us for testing? |
This is strange. Although using masked arrays works in some cases, when trying to corner the problem I found this minimal example: import numpy as np
from skimage.restoration import unwrap_phase
wrapped = np.empty((100, 100), dtype=np.float64)
wrapped[:] = np.linspace(0, 4*np.pi, 100) % (2*np.pi)
wrapped[10, 10] = np.nan # <-- comment out to get working code
masked = np.ma.masked_array(wrapped, mask=np.isnan(wrapped))
print(np.isnan(masked).any())
unwrapped = unwrap_phase(masked) which causes a freeze (skimage 0.15.0, numpy 1.16.2). |
Thanks, @plu2k, I can confirm that this is still the case on v0.19.2 |
See #7176 for an attempted fix. |
Description
I found in some situation the program will freeze after passing the array contains NaN values. Here is the minimum example I found that can reproduce the error. I'd like to know if there is a way to deal with missing data.
Thanks!
Way to reproduce
Version information
The text was updated successfully, but these errors were encountered: