Skip to content

Commit 13a41a5

Browse files
authored
Merge pull request #45 from sbillinge/runtimewarning
working on RunTimeWarning in tests
2 parents 24f611c + 7327e24 commit 13a41a5

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

news/runtimewarning.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* test warning applycutoff test
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/fourigui/fourigui.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -371,18 +371,18 @@ def intensity_upd_local(self):
371371
elif self.axis.get() == 2:
372372
plane = self.cube[:, :, self.plane_num.get()]
373373
nan_ratio = np.count_nonzero(np.isnan(plane)) / plane.size
374-
self.localmax["text"] = "{}".format(np.format_float_scientific(np.nanmax(plane), 1))
375-
self.localmin["text"] = "{}".format(np.format_float_scientific(np.nanmin(plane), 1))
376-
self.localsum["text"] = "{}".format(np.format_float_scientific(np.nansum(plane), 1))
377-
self.localnanratio["text"] = "{}".format(round(nan_ratio, 2))
374+
self.localmax["text"] = f"{np.format_float_scientific(np.nanmax(plane), 1)}"
375+
self.localmin["text"] = f"{np.format_float_scientific(np.nanmin(plane), 1)}"
376+
self.localsum["text"] = f"{np.format_float_scientific(np.nansum(plane), 1)}"
377+
self.localnanratio["text"] = f"{round(nan_ratio, 2)}"
378378

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

388388
def fft(self):
@@ -459,25 +459,33 @@ def ifft(self):
459459

460460
def applycutoff(self):
461461
"""
462+
shape the reciprocal-space array
463+
462464
reassign all voxels with distance smaller than qmin and greater than qmax
463-
from the central voxel to 0.0
465+
to np.nan.
466+
467+
parameters:
468+
-----------
464469
qmin, qmax is loaded from the qmin, qmax input panel
465-
currently opperates in units of pixels
470+
currently operates in units of pixels
471+
472+
Returns:
473+
--------
474+
nothing
466475
"""
467476
if not self.cutted:
468-
469-
X, Y, Z = self.cube.shape
470-
sphere = np.ones((X, Y, Z))
477+
xdim, ydim, zdim = self.cube.shape
478+
sphere = np.ones((xdim, ydim, zdim))
471479
qmin = float(self.qminentry.get())
472480
qmax = float(self.qmaxentry.get())
473481
# convert qmin to pixels
474482
# convert qmax to pixels
475483
r2_inner = qmin**2
476484
r2_outer = qmax**2
477-
XS, YS, ZS = np.meshgrid(np.arange(X), np.arange(Y), np.arange(Z))
478-
R2 = (XS - X // 2) ** 2 + (YS - Y // 2) ** 2 + (ZS - Z // 2) ** 2
479-
mask = (R2 <= r2_inner) | (R2 >= r2_outer)
480-
sphere[mask] = np.nan
485+
i, j, k = np.meshgrid(np.arange(xdim), np.arange(ydim), np.arange(zdim))
486+
r2 = (i - xdim // 2) ** 2 + (j - ydim // 2) ** 2 + (k - zdim // 2) ** 2
487+
mask = (r2 <= r2_inner) | (r2 >= r2_outer) # True if voxel is out of range
488+
sphere[mask] = np.nan # therefore set to np.nan if out of range
481489

482490
if self.space.get():
483491
self.cube_real = self.cube

tests/integration_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def test_applycutoff_range2(self):
123123
result = self.test_gui.cube
124124

125125
# then
126+
# with self.assertWarns(RuntimeWarning):
126127
self.assertTrue(np.allclose(np.nan_to_num(result), np.nan_to_num(self.test_sofq_cut_15to35px)))
127128

128129

0 commit comments

Comments
 (0)