The purpose of this note is to compare how pyFAI
and ImageD11
treat the detector position. In particular, we derive how “PONI”
detector parameters refined with pyFAI
can be transformed into
ImageD11
parameters.
In both packages, the transformation from pixel space to 3D laboratory coordinates is carried out in 4 steps:
Transformation from “pixel space” to the “detector coordinate system”. The detector coordinate system is a 3D coordinate system centered on the (0,0) pixel of the detector.
Correction for linear offsets, i.e. the position of the (0,0) pixel relative to the beam axis.
Correction for the origin/diffractometer-to-detector distance. The sample and diffractometer center of rotation are assumed to be located at the origin.
A series of rotations for the detector coordinate system relative to the laboratory coordinates.
Unfortunately, the conventions chosen by pyFAI
and ImageD11
differ. For example, pyFAI
applies the origin-to-detector distance
correction before rotations, whereas ImageD11
applies it after
rotations. Furthermore, they employ different coordinate systems.
Detector
We consider a pixelated 2D imaging detector. In “pixel space”, the
position of a given pixel is given by the horizontal and vertical pixel
numbers,
The pixel numbers
This function will account for the detector’s pixel size and the orientation and direction of pixel rows and columns relative to the detector coordinate system. Furthermore it may apply a distortion correction. This, however, is beyond the scope of this note.
Limiting ourselves to linear functions, pyFAI
and ImageD11
. We assume that the
pixels have a constant horizontal and vertical size,
pyFAI
specifically defines the unit of
length as meter, we will therefore use pixel sizes in units of
The position and orientation of this detector relative to the laboratory coordinates are described below.
Geometry definition of pyFAI
Coordinates
pyFAI
uses a coordinate system where the first axis (1) is
vertically up (
Units
All dimensions in pyFAI
are in meter and all rotation are in
radians.
Parameters
pyFAI
describes the position and orientation of the detector by six
variables, collectively called the PONI, for point of normal incidence.
In addition, a detector calibration is provided in the PONI-file to
convert pixel coordinates into real-space coordinates. Here we limit our
discussion to the simplest case, i.e. a pixel size as discussed above.
- Rotations:
, and describe the detector’s orientation relative to the laboratory coordinate system.- Offsets:
and describe the offsets of pixel (0,0) relative to the “point of normal incidence”. In the absence of rotations the point of normal incidence is defined by the intersection of the direct beam beam axis with the detector.- Distance:
describes the distance from the origin of the laboratory system to the point of normal incidence.
Detector
The transformation from pixel space to pyFAI
detector coordinates is
given by
Offsets
The PONI parameters are: a distance
pyFAI
applies both the offset correction and the origin-to-detector
distance after the transformation from pixel space to the detector
system, but before rotations,
Let
Rotations
The detector rotations are taken about the origin of the coordinate system (sample position). We define the following right-handed rotation matrices:
The rotations 1 and 2 in pyFAI
are left handed, i.e. the sign of
The combined pyFAI
rotation matrix is then
which yields the final laboratory coordinates after rotation
Inversion: Finding where a scattered beam hits the detector
For a 3DXRD-type simulation, we have to determine the pixel where a
scattered ray intercepts the detector. Let
The inversion eq. [eq-tpyFAI] is straight-forward:
The third line (
As the most trivial example we consider the case of no rotations,
We see also that when all rotations are zero,
Geometry definition of ImageD11
For maximum convenience, ImageD11
defines almost everything
differently than pyFAI
.
Coordinates
ImageD11
uses the ID06 coordinate system with
Units
As the problem is somewhat scale-invariant, ImageD11
allows a free
choice of the unit of length, which we will call pyFAI
, we choose
Rotations are given in radians.
Parameters
ImageD11
defines the detector geometry via the following parameters:
- Beam center:
and define the position of the direct beam on the detector. Contrary topyFAI
, the beam center is given in pixel space, in units of .- Pixel size:
The horizontal and vertical pixel size are defined by
and in . With the right choice of the unit of length , these corresponds directly to the pixel sizes and defined above.- Detector flip matrix:
. This matrix takes care ofcorrecting typical problems with the way pixel coordinates are arranged on the detector. If, e.g., the detector is rotated by , then . If left and right (or up and down) are inverted on the detector, then ( ).- Rotations:
Detector tilts
, , and , in . The center of rotation is the point where the direct beam intersects the detector.- Distance:
, in units , is the distance between the origin to the point where the direct beam intersects the detector. Note that this is again different from the definition ofpyFAI
.
It appears that these conventions where defined under the assumption that the detector is more or less centered in the direct beam, and that the detector tilts are small.
Transformation
The implementation in the code transform.py
is using the following
equations:
Note that the order of
By combining the detector flip matrix
Conversion
Assume that the same detector geometry is described by the two notations. How can the parameters be converted from one to the other?
Detector -matrix
The pixel size is the same in both notations,
As pyFAI
does not allow for detector flipping, ImageD11
and pyFAI
) and
Coordinates
Both notations use the same sign for the vertical and beam axes. The sign of the horizontal transverse axis, however, is inverted.
The transformation between the different coordinate systems is then achieved by:
where
Substituting these equations into eq. [eq-coordconv], one can them
attempt to convert pyFAI
parameters into ImageD11
parameters and
vice versa.
Rotations
Take an arbitrary vector pyFAI
coordinate system by multiplication with pyFAI
coordinates, ImageD11
coordinates,
Comparing the last two lines, we find that with
the transformation is applicable for each and any vector
Applying this to the rotations matrices defined in
eqs. [eq-rot1]–[eq-rot3] shows, unsurprisingly, that this coordinate
transformation is an exchange of rotation axes
Applying this transformation to the pyFAI
rotation matrix can
comparing to the ImageD11
rotation matrix, we see
We find that, by divine intervention [1] and despite all the efforts to
choose incompatible conventions, the effective order of rotations is
actually the same between ``ImageD11`` and ``pyFAI``. Consequently,
there is a direct correspondence with only a change of sign between
Translations and offsets
Inserting eqs. [eq-thetax]–[eq-thetaz] into [eq-transformation], we find
With a little help from our friend Mathematica, we find for the
conversion from pyFAI
to ImageD11
and for the conversion from ImageD11
to pyFAI