Skip to content

Commit 3f30ab5

Browse files
committed
ENH: Set w2_thresh to positive values for clarity, update doc to indicate 3*eps
1 parent 0ecaa8e commit 3f30ab5

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

nibabel/nifti1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ class Nifti1Header(SpmAnalyzeHeader):
688688
single_magic = b'n+1'
689689

690690
# Quaternion threshold near 0, based on float32 precision
691-
quaternion_threshold = -np.finfo(np.float32).eps * 3
691+
quaternion_threshold = np.finfo(np.float32).eps * 3
692692

693693
def __init__(self, binaryblock=None, endianness=None, check=True, extensions=()):
694694
"""Initialize header from binary data block and extensions"""

nibabel/quaternions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def fillpositive(xyz, w2_thresh=None):
4444
w2_thresh : None or float, optional
4545
threshold to determine if w squared is non-zero.
4646
If None (default) then w2_thresh set equal to
47-
``-np.finfo(xyz.dtype).eps``, if possible, otherwise
48-
``-np.finfo(np.float64).eps``
47+
3 * ``np.finfo(xyz.dtype).eps``, if possible, otherwise
48+
3 * ``np.finfo(np.float64).eps``
4949
5050
Returns
5151
-------
@@ -89,9 +89,9 @@ def fillpositive(xyz, w2_thresh=None):
8989
# If necessary, guess precision of input
9090
if w2_thresh is None:
9191
try: # trap errors for non-array, integer array
92-
w2_thresh = -np.finfo(xyz.dtype).eps * 3
92+
w2_thresh = np.finfo(xyz.dtype).eps * 3
9393
except (AttributeError, ValueError):
94-
w2_thresh = -FLOAT_EPS * 3
94+
w2_thresh = FLOAT_EPS * 3
9595
# Use maximum precision
9696
xyz = np.asarray(xyz, dtype=MAX_FLOAT)
9797
# Calculate w

nibabel/tests/test_quaternions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_fillpositive_simulated_error(dtype):
108108
# as xyz with small error, and we want to recover the w of 0
109109

110110
# Permit 1 epsilon per value (default, but make explicit here)
111-
w2_thresh = 3 * -np.finfo(dtype).eps
111+
w2_thresh = 3 * np.finfo(dtype).eps
112112

113113
pos_error = neg_error = False
114114
for _ in range(50):

0 commit comments

Comments
 (0)