Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/NaNhandling.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* When a slice of all `NaN`s is encountered, the `NaN`s are now set to zero.

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
4 changes: 4 additions & 0 deletions src/diffpy/fourigui/fourigui.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ def intensity_upd_local(self):
plane = self.cube[:, self.plane_num.get(), :]
elif self.axis.get() == 2:
plane = self.cube[:, :, self.plane_num.get()]

if np.all(np.isnan(plane)):
plane = np.zeros_like(plane)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

condition setting all NaNs to zero

Copy link
Contributor

Choose a reason for hiding this comment

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

If we do that, that means we are simply converting nan values to all 0s. but only for [nan, nan, ... , nan] but not when [nan, 0.1, 0.2, nan, ...]

so doesn't feel like a good solution to me - when we call np.nanmax, I think it will pick up 0 instead of nan and this might not be good since your code has a section where it calculates nan_ratio.

I am not sure why we use nan in the first place. Why nan instead of 0? Having nan around for an array where it should have the same type for the particular array normally, it feels quite odd.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not the preferred behavior. Setting NaN's to 0 falls under the umbrella of "magic". Especially as scientists we want to avoid updating people's data.

Caden said "The goal of the test is to verify that the applycutoff method is working as expected for a given qmin and qmax." which of course is a tautology. That is what a test does. But the question is what do "we expect" that function to do. In other words, what is our desired behavior?

nan_ratio = np.count_nonzero(np.isnan(plane)) / plane.size
self.localmax["text"] = "{}".format(np.format_float_scientific(np.nanmax(plane), 1))
self.localmin["text"] = "{}".format(np.format_float_scientific(np.nanmin(plane), 1))
Expand Down