TomographicImaging / CIL

A versatile python framework for tomographic imaging
https://tomographicimaging.github.io/CIL/
Apache License 2.0
95 stars 41 forks source link

numpy.isclose too restrictive when creating AcquisitionGeometry #1804

Open effepivi opened 4 months ago

effepivi commented 4 months ago

Description

epsilon may be too small in File ~\AppData\Local\miniconda3\envs\dXCT2024\lib\site-packages\cil\framework\framework.py:657, in Detector2D.set_direction(self,

    655 dot_product = x.dot(y)
    656 if not numpy.isclose(dot_product, 0):
--> 657     raise ValueError("vectors detector.direction_x and detector.direction_y must be orthogonal")

with some experimental data. I got the position of the centre of the imager, its top and right.

Centre Top Right
imager_centre imager_top imager_right
-2.82322, -190.014, -459.137 -3.44796, -46.6199, -458.012 140.575 , -189.388, -459.257

We can compute the detector_direction_x and detector_direction_y vectors as follows:

    detector_direction_x = imager_right - imager_centre
    detector_half_width = np.linalg.norm(detector_direction_x)
    detector_direction_x /= detector_half_width

    detector_direction_y = imager_top - imager_centre
    detector_half_height = np.linalg.norm(detector_direction_y)
    detector_direction_y /= detector_half_height

The dot product between these two perpendicular vectors must be close to 0.0.

    dot_product = np.dot(detector_direction_x, detector_direction_y)

It is 2.0960759873050085e-06, which is relatively close to zero.

We can compute the angle between these two vectors as follows:

math.acos(dot_product) * 180.0 / math.pi

The angle is 89.99987990369239. One might argue that it is 90 degrees once we account for numerical inaccuracies. However, it raises an error as numpy.isclose(dot_product, 0) returns False.

It would be great if the user could overwrite the tolerance parameters.

Environment

23.1.0 -1 3.10.13 | packaged by conda-forge | (main, Dec 23 2023, 15:27:34) [MSC v.1937 64 bit (AMD64)] win32