Skip to content
Merged
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/runtimewarning.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* test warning applycutoff test

**Security:**

* <news item>
42 changes: 25 additions & 17 deletions src/diffpy/fourigui/fourigui.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,18 +371,18 @@ def intensity_upd_local(self):
elif self.axis.get() == 2:
plane = self.cube[:, :, self.plane_num.get()]
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))
self.localsum["text"] = "{}".format(np.format_float_scientific(np.nansum(plane), 1))
self.localnanratio["text"] = "{}".format(round(nan_ratio, 2))
self.localmax["text"] = f"{np.format_float_scientific(np.nanmax(plane), 1)}"
self.localmin["text"] = f"{np.format_float_scientific(np.nanmin(plane), 1)}"
self.localsum["text"] = f"{np.format_float_scientific(np.nansum(plane), 1)}"
self.localnanratio["text"] = f"{round(nan_ratio, 2)}"

def intensity_upd_global(self):
"""show global intensity minimum, maximum and sum of 3D array"""
"""Load global intensity minimum, maximum and sum of 3D array"""
self.intensity_upd_local()
nan_ratio = np.count_nonzero(np.isnan(self.cube)) / self.cube.size
self.globalmax["text"] = "{}".format(np.format_float_scientific(np.nanmax(self.cube), 1))
self.globalmin["text"] = "{}".format(np.format_float_scientific(np.nanmin(self.cube), 1))
self.globalsum["text"] = "{}".format(np.format_float_scientific(np.nansum(self.cube), 1))
self.globalmax["text"] = f"{np.format_float_scientific(np.nanmax(self.cube), 1)}"
self.globalmin["text"] = f"{np.format_float_scientific(np.nanmin(self.cube), 1)}"
self.globalsum["text"] = f"{np.format_float_scientific(np.nansum(self.cube), 1)}"
self.globalnanratio["text"] = "{}".format(round(nan_ratio, 2))

def fft(self):
Expand Down Expand Up @@ -459,25 +459,33 @@ def ifft(self):

def applycutoff(self):
"""
shape the reciprocal-space array

reassign all voxels with distance smaller than qmin and greater than qmax
from the central voxel to 0.0
to np.nan.

parameters:
-----------
qmin, qmax is loaded from the qmin, qmax input panel
currently opperates in units of pixels
currently operates in units of pixels

Returns:
--------
nothing
"""
if not self.cutted:

X, Y, Z = self.cube.shape
sphere = np.ones((X, Y, Z))
xdim, ydim, zdim = self.cube.shape
sphere = np.ones((xdim, ydim, zdim))
qmin = float(self.qminentry.get())
qmax = float(self.qmaxentry.get())
# convert qmin to pixels
# convert qmax to pixels
r2_inner = qmin**2
r2_outer = qmax**2
XS, YS, ZS = np.meshgrid(np.arange(X), np.arange(Y), np.arange(Z))
R2 = (XS - X // 2) ** 2 + (YS - Y // 2) ** 2 + (ZS - Z // 2) ** 2
mask = (R2 <= r2_inner) | (R2 >= r2_outer)
sphere[mask] = np.nan
i, j, k = np.meshgrid(np.arange(xdim), np.arange(ydim), np.arange(zdim))
r2 = (i - xdim // 2) ** 2 + (j - ydim // 2) ** 2 + (k - zdim // 2) ** 2
mask = (r2 <= r2_inner) | (r2 >= r2_outer) # True if voxel is out of range
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if these should be < and > rather than <= and >= since it is tagging the unwanted regions as true. i.e., presumably Qmax is a valid value not an invalid value so we don't want to set Qmax to zero.

sphere[mask] = np.nan # therefore set to np.nan if out of range

if self.space.get():
self.cube_real = self.cube
Expand Down
1 change: 1 addition & 0 deletions tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def test_applycutoff_range2(self):
result = self.test_gui.cube

# then
# with self.assertWarns(RuntimeWarning):
self.assertTrue(np.allclose(np.nan_to_num(result), np.nan_to_num(self.test_sofq_cut_15to35px)))


Expand Down