Improved bound_range utility function
@@ -1212,11 +1212,16 @@ def is_nan(x):
return False
-def bound_range(vals, density, TOL=10e-8):
+def bound_range(vals, density, TOL=10e-9):
+ """
+ Computes a bounding range from a number of evenly spaced samples.
+ Will raise an error if samples are not evenly spaced within
+ tolerance.
+ """
low, high = vals.min(), vals.max()
if not density:
diff = np.diff(vals)
- unit = np.unique(np.floor(diff/TOL).astype(int))*TOL
+ unit = np.unique(np.round(diff/TOL).astype(int))*TOL
if len(unit) > 1:
raise ValueError('Data is not sampled on a grid.')
density = 1./unit[0]
