pycroscopy / sidpy

Python utilities for storing, processing, and visualizing spectroscopic and imaging data
https://pycroscopy.github.io/sidpy/
MIT License
11 stars 14 forks source link

Correct fail case for get_exponent with NaN? #124

Closed rajgiriUW closed 3 years ago

rajgiriUW commented 3 years ago

Where there are NaN values, I saw that get_exponent will return an error as you can't cast a NaN as int. I'm wondering what should be the correct use case here?

Specifically get_exponent in num_utils. This situation comes up if using plot_map and there are NaNs in the image, as often happens in cases where you miss a pixel, or if you happen to have a sparsely-sampled image in certain processing methods.

Suggestion 1 is return np.NaN in num_utils (add a check for if the source vector contains a NaN or not) Suggestion 2 is have to change plot_map to check the correct range (i.e. find the max of only non-NaN pixels in the image).

I will suggest and make a PR with something like fix 2 this afternoon and maybe have get_exponent throw an error with a message if the source vector contains a NaN (so it's more obvious what the error is).

ramav87 commented 3 years ago

I agree that np.nan failures are not necessarily wanted, especially when plotting because it is how we specify 'dead' pixels that should not be plotted. Thanks for the PR.

rajgiriUW commented 3 years ago

Thanks Rama. Addressed in #125 , closing