Skip to content

Commit a98cc3b

Browse files
committed
BUG: fix heuristic for detecting uniformly spaced grid axes
1 parent ee32b46 commit a98cc3b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/gpgi/_data_types.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ def collect_exceptions(cls, data: Grid[FloatT]) -> list[Exception]:
112112
)
113113

114114

115+
def is_uniformly_spaced(arr: np.ndarray[tuple[int], np.dtype[FloatT]]) -> bool:
116+
dbase = np.diff(arr)
117+
return bool(dbase.std() / dbase.max() / dbase.size < 5 * np.finfo(arr.dtype).eps)
118+
119+
115120
@final
116121
class Grid(Generic[FloatT]):
117122
def __init__(
@@ -149,7 +154,7 @@ def __init__(
149154
(3,), -1, dtype=self.coordinates[self.axes[0]].dtype
150155
)
151156
for i, ax in enumerate(self.axes):
152-
if self.size == 1 or np.diff(self.coordinates[ax]).std() < 1e-16:
157+
if self.size == 1 or is_uniformly_spaced(self.coordinates[ax]):
153158
# got a constant step in this direction, store it
154159
self._dx[i] = self.coordinates[ax][1] - self.coordinates[ax][0]
155160

0 commit comments

Comments
 (0)