HEXRD / hexrd

A cross-platform, open-source library for the analysis of X-ray diffraction data.
Other
56 stars 25 forks source link

C-API version gvec_to_xy fails to return `nan`s in certain cases. #704

Open donald-e-boyce opened 1 month ago

donald-e-boyce commented 1 month ago

The C-API transforms version of gvec_to_xy does not return nans under the same conditions as the numpy version.

The numpy version uses two conditions to return an nan.

  1. For diffraction to occur, the g-vector needs to make an acute angle with the negative beam direction. If that condition is not met, then nans are returned.
  2. If the direction of the diffracted beam points away from the detector (dot product of diffracted beam direction and detector normal is nonnegative), then again the nans are returned.

The relevant section of code is: https://github.com/HEXRD/hexrd/blob/32009f305d6e28905785e499e17d58eb38663333/hexrd/transforms/xf.py#L180-L207

The C-API version seems to check the same conditions (although in a slightly different way), but somehow they are ignored. The relevant code is: https://github.com/HEXRD/hexrd/blob/32009f305d6e28905785e499e17d58eb38663333/hexrd/transforms/transforms_CFUNC.c#L461-L493

Note that the diffracted beam direction in the C version (dvec_l) is the negative of the diffracted beam direction in numpy (also dvec_l), but the C version checks for denom > 0 while the numpy version checks for denom < -ztol, so they are the same except for the case that the diffracted beam is (very near) parallel to the detector plane.

So I don't understand how the C-version fails to return nans in so many cases.