Skip to content

Commit 6b8e3b2

Browse files
fix(linthresh): use dtype tiny instead of sqrt(eps) as zero threshold (Kitware#63)
Co-authored-by: Patrick O'Leary <olearypatrick@gmail.com>
1 parent 535bc9c commit 6b8e3b2

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/e3sm_quickview/utils/math.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
def calculate_linthresh(data):
1313
"""Calculate the linear threshold for symlog scaling.
1414
15-
Excludes machine-error zeros (values within ±sqrt(eps) of the data dtype),
15+
Excludes true zeros (values within ±tiny of the data dtype),
1616
then returns min(abs(valid)).
1717
1818
Operates on the original array without copies.
@@ -21,10 +21,9 @@ def calculate_linthresh(data):
2121
data: numpy array of data values
2222
2323
Returns:
24-
linthresh value (float), clamped to at least 1.0
24+
linthresh value (float), floored at dtype tiny to avoid zero
2525
"""
26-
eps = np.finfo(data.dtype).eps
27-
threshold = np.sqrt(eps)
26+
threshold = np.finfo(data.dtype).tiny
2827

2928
# Find min |x| > threshold without allocating a copy.
3029
# Using where= runs as a tight vectorized C loop, roughly 2-3 orders
@@ -37,7 +36,7 @@ def calculate_linthresh(data):
3736
if min_abs == np.inf:
3837
linthresh = 1.0
3938
else:
40-
linthresh = max(float(min_abs), 1.0)
39+
linthresh = max(float(min_abs), float(np.finfo(data.dtype).tiny))
4140

4241
return linthresh
4342

0 commit comments

Comments
 (0)