Skip to content

Commit 9aaa916

Browse files
authored
Add thickness tolerance to SensorConfig equality check
1 parent 1484726 commit 9aaa916

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/pyFAI/detectors/sensors.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import copy
4747
from math import exp
4848
from collections import namedtuple
49+
from typing import ClassVar
4950
from ..containers import dataclass, fields
5051
import numpy
5152
from ..resources import resource_filename
@@ -165,6 +166,8 @@ class SensorConfig:
165166
"class for configuration of a sensor"
166167
material: SensorMaterial|str
167168
thickness: float=None
169+
170+
THICKNESS_TOLERANCE: ClassVar[float] = 1e-6
168171

169172
def __repr__(self):
170173
return json.dumps(self.as_dict(), indent=4)
@@ -183,8 +186,11 @@ def __eq__(self, other):
183186
"""Check for equality, especially for the thickness within 1µm"""
184187
if isinstance(other, self.__class__):
185188
if (self.material == other.material):
186-
if self.thickness and other.thickness and abs(self.thickness - other.thickness)<1e-6:
187-
return True
189+
if (self.thickness and
190+
other.thickness and
191+
numpy.isclose(self.thickness, other.thickness, abs_tol=self.THICKNESS_TOLERANCE)):
192+
193+
return True
188194
else:
189195
return self.thickness == other.thickness
190196
return False

0 commit comments

Comments
 (0)