File: geometry.tex

package info (click to toggle)
pyfai 0.20.0%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 78,460 kB
  • sloc: python: 49,743; lisp: 7,059; sh: 225; ansic: 165; makefile: 119
file content (317 lines) | stat: -rw-r--r-- 10,283 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
\documentclass[12pt]{article}

\usepackage{amsmath}

\begin{document}

\section{Geometry definition of \texttt{pyFAI}}

All dimentions are in meter and all rotation are in radians.

\texttt{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. In
the simplest case this is a pixel size.  

\texttt{pyFAI} uses a coordinate system where the first axis (1)  is 
vertically up (or $y$), the second axis (2) is horizontal ($x$) towards the ring
center (starboard), and the third axis (3) along the beam $z$. Note that
in this order (1,2,3) is a right-handed coordinate system, which makes
$xyz$ in the usual order a left-handed coordinate system!

The PONI parameters are: a distance $L$, the $y$ and $x$ coordinates
of the point of normal incidence in meters, $\mathrm{poni}_{1,2}$, and
3 detector rotations, $\theta_{1,2,3}$ about the $y$, $x$ and $z$
axes. The inversion of the $x$ and $y$ axes is due to the arrangement
of the detector data, with $x$-rows being the ``slow'' axis and
$y$-columns the ``fast'' axis. Extra care has to be taken with the
signs of the rotations when converting form this coordinate system to
another.

The detector rotations are taken about the origin of the coordinate
system (sample position). They are represented by the rotation
matrices:

\begin{align}
  \mathrm{R}_1(\theta_1)
  & =
  \begin{bmatrix}
    1 & 0 & 0 \\
    0 & \cos(\theta_1) & \sin(\theta_1) \\
    0 & -\sin(\theta_1) & \cos(\theta_1)
  \end{bmatrix}
  \\
  \mathrm{R}_2(\theta_2)
  & =
  \begin{bmatrix}
    \cos(\theta_2) & 0 & -\sin(\theta_2) \\
    0 & 1 & 0 \\
    \sin(\theta_2) & 0 & \cos(\theta_2)
  \end{bmatrix}
  \\
  \mathrm{R}_3(\theta_3)
  & =
  \begin{bmatrix}
    \cos(\theta_3) & -\sin(\theta_3) & 0\\
    \sin(\theta_3) & \cos(\theta_3) & 0\\
    0 & 0 & 1  
  \end{bmatrix}
  \\
  R(\theta_1, \theta_2, \theta_3)
  & =
  R_3(\theta_3) \cdot R_2(\theta_2) \cdot R_1(\theta_1)
\end{align}

Let $P$ be a point on the detector at pixel coordinates $(d_1, d_2)$
in units $\mathrm{px}$. In the most simple case (in the absence of
distortions) these are converted into coordinates in units of meters
by multiplication with a scaling factor ``pixel size''
($\mathrm{pxsize}_{1,2}$m in units of $\mathrm{m}/\mathrm{px}$) and
subsequent subtraction of an offset ($\mathrm{poni}_{1,2}$, in units of
meters and yielding the coordinates $(p_1, p_2)$ in meters.

\begin{align}
  p_1 & = \mathrm{pxsize}_1 d_1 - \mathrm{poni}_1 \\
  p_2 & = \mathrm{pxsize}_2 d_2 - \mathrm{poni}_2
\end{align}

Let $L$ be the distance from the
origin/sample/diffractometer center of rotation. In the absence of any
detector rotations, $L$ is taken along $z$, $p_1$ along the $x$-axis
(horizontal) and $p_2$ along the $y$ axis (vertical). Then, in the
``detector coordinate system''

\begin{align}
  P & = \begin{bmatrix} p_1 \\ p_2 \\ L \end{bmatrix}
\end{align}

The coordinates in the laboratory system are obtained by
multiplication with the rotation matrix $R$

\begin{align}
  \begin{bmatrix} t_1 \\ t_2 \\ t_3 \end{bmatrix}
  = &
  R_{\mathtt{pyFAI}}(\theta_1, \theta_2, \theta_3) \cdot P
  \\
  = &
  R_3(\theta_3) \cdot R_2(\theta_2) \cdot R_1(\theta_1) \cdot
  \begin{bmatrix}
    \mathrm{pxsize}_1 d_1 - \mathrm{poni}_1 \\
    \mathrm{pxsize}_2 d_2 - \mathrm{poni}_2 \\
    L
  \end{bmatrix}
  \\
  = &
  R_3(\theta_3) \cdot R_2(\theta_2) \cdot R_1(\theta_1)
  \nonumber \\ &
  \cdot
  \left(
  \begin{bmatrix}
    \mathrm{pxsize}_1 & 0 & 0 \\
    0 & \mathrm{pxsize}_2 & 0 \\
    0 & 0 & 1
  \end{bmatrix}
  \cdot
  \begin{bmatrix}
    d_1 \\
    d_2 \\
    0
  \end{bmatrix}
  +
  \begin{bmatrix}
    - \mathrm{poni}_1 \\
    - \mathrm{poni}_2 \\
    L
  \end{bmatrix}
  \right)
  \label{eq-tpyFAI}
\end{align}

The inversion is straight-forward:

\begin{align}
  R_1(-\theta_1)\cdot R_2(-\theta_2) \cdot R_3(-\theta_3) \cdot
  \begin{bmatrix} t_1 \\ t_2 \\ t_3
  \end{bmatrix}
  & =
  \begin{bmatrix} p_1 \\ p_2 \\ L \end{bmatrix}
  \label{eq-find-alpha}
  \\
  \begin{bmatrix}
    t_1 \\ t_2 \\ t_3
  \end{bmatrix}
  & =
  \begin{bmatrix}
    A_1  \\ A_2 \\ A_3 
  \end{bmatrix}
  + \alpha
  \begin{bmatrix}
    k_1 \\ k_2 \\ k_3
  \end{bmatrix},
\end{align}
where $A_{1,2,3}$ are the coordinates, in the laboratory system, of
the scattering center (grain, sub-grain or voxel), and $k_{1,2,3}$ is
the direction of the scattered beam. The third line ($\ldots = L$) of
eq.~\ref{eq-find-alpha} is then used to determine the free parameter
$\alpha$, which in turn is used in the first and second lines to find
$p_{1,2}$ and thus $d_{1,2}$.

As the most trivial example we consider the case of no rotations,
$\theta_1 = \theta_2 = \theta_3 = 0$. Then

\begin{align}
  A_3 + \alpha k_3 & = L \\
  \alpha & = \frac{L-A_3}{k_3} \\
  p_1 & = A_1 + (L-A_3) \frac{k_1}{k_3} \\
  p_2 & = A_2 + (L-A_3) \frac{k_2}{k_3}.
\end{align}

We see also that when all rotations are zero, $(\mathrm{poni}_1,
\mathrm{poni_2})$ are the real space coordinates of the direct beam
($A_{1,2,3}=k_{1,2}=0$) .

\section{Geometry definition of \texttt{ImageD11}}

For maximum convenience, \texttt{ImageD11} defines almost everything
differently than \texttt{pyFAI}.

Coordinate system: \texttt{ImageD11} uses the ID06 coordinate system
with $x$ along the beam, $y$ to port (away from the ring center), and
$z$ up.

Units: As the system is somewhat scale-invariant, \texttt{ImageD11}
allows a free choice of the unit of length, which we will call $X$
here. The same unit has to be used for all translations, and for the
pixel size of the detector. The default used in the code appears to be
$X = 1\,\mathrm{\mu m}$, but it might as well be Planck lengths,
millimeters, inches, meters, tlalcuahuitl, furlongs, nautical miles,
light years, kparsec, or whatever else floats your boat. The only
requirement is that you can actually measure and express the detector
pixel size and COR-to-detector distance in your units of choice.

Parameters: \texttt{ImageD11} defines the detector geometry via the
following parameters:

\begin{itemize}
\item Beam center $y_{\mathrm{center}}$ and $z_{\mathrm{center}}$:
  Position of the direct beam on the detector, in $\mathrm{px}$.
\item Pixel size $y_{\mathrm{size}}$ and $z_{\mathrm{size}}$ in
  ${X}/{\mathrm{px}}$.
\item Detector tilts $t_x$, $t_y$, and $t_z$, in $\mathrm{rad}$. The
  center of rotation is the point where the direct beam intersects the
  detector.
\item Distance $D$, in units $X$, between the origin to the point
  where the direct beam intersects the detector.
\item Detector flip matrix $O = \begin{bmatrix} o_{11} & o_{12}
  \\ o_{21} & o_{22} \end{bmatrix}$. This matrix takes care of
  correcting typical problems with the way pixel coordinates are
  arranged on the detector. If, e.g., the detector is rotated by
  $90^{\circ}$, then $O=\begin{bmatrix} 0 & 1 \\ -1 &
  0\end{bmatrix}$. If left and right (or up and down) are inverted on the
  detector, then $o_{22} = -1$ ($o_{11}=-1$). 
\end{itemize}

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.

The implementation in the code \texttt{transform.py} is using the
following equations:

\begin{align}
  R_{\mathtt{ImageD11}}(\theta_x, \theta_y, \theta_z)
  & =
  R_1(\theta_x) \cdot R_2(\theta_y) \cdot R_3(\theta_z)
  \\
  \begin{bmatrix}
    p_z \\ p_y
  \end{bmatrix}
  & =
  \begin{bmatrix}
    o_{11} & o_{12}
    \\ o_{21} & o_{22}
  \end{bmatrix}
  \cdot
  \begin{bmatrix}
    (d_z - z_{\mathrm{center}}) z_{\mathrm{size}} \\
    (d_y - y_{\mathrm{center}}) y_{\mathrm{size}}
  \end{bmatrix}
  \label{eq-p}
  \\
  \begin{bmatrix}
    t_x \\ t_y \\ t_z
  \end{bmatrix}
  & =
  R_{\mathtt{ImageD11}}(\theta_x, \theta_y, \theta_z)
  \cdot
  \begin{bmatrix}
    0 \\ p_y \\ p_z
  \end{bmatrix}
  +
  \begin{bmatrix}
    D \\ 0 \\ 0
  \end{bmatrix}
  \label{eq-t}
\end{align}
Note that the order of $y$ and $z$ is not the same in eqs.~\ref{eq-p} and \ref{eq-t}.

The same could be achieved more easily by

\begin{align}
  \begin{bmatrix}
    t_x \\ t_y \\ t_z
  \end{bmatrix}
  & =
  R_{\mathtt{ImageD11}}(\theta_x, \theta_y, \theta_z)
  \cdot
  \begin{bmatrix}
    1 & 0 & 0 \\
    0 & y_{\mathrm{size}} o_{22} & z_{\mathrm{size}} o_{21} \\
    0 & y_{\mathrm{size}} o_{12} & z_{\mathrm{size}} o_{11}
  \end{bmatrix}
  \cdot
  \begin{bmatrix}
    D \\ p_y - y_{\mathrm{center}} \\ p_z - z_{\mathrm{center}}
  \end{bmatrix}.
  \label{eq-tImageD11}
\end{align}

\section{Conversion}

The transformation between the different coordinate systems is
achieved by
\begin{align}
  t_{\mathtt{ImageD11}}
  =
  \begin{bmatrix}
    0 & 0 & 1 \\ 0 & -1 & 0 \\ 1 & 0 & 0
  \end{bmatrix}
  t_{\mathtt{pyFAI}},
  \label{eq-coordconv}
\end{align}
where $t_{\mathtt{ImageD11}}$ is given by eq.~\ref{eq-tImageD11}, and
$t_{\mathtt{pyFAI}}$ is given by eq.~\ref{eq-tpyFAI}. Substituting
these equations into eq.~\ref{eq-coordconv}, one can them attempt to
convert \texttt{pyFAI} parameters into \texttt{ImageD11} parameters
and vice versa. As \texttt{pyFAI} does not allow for detector
flipping, $o_{11}=o_{22}=1$ and $o_{12}=o_{21}=0$. Furthermore,
$\mathrm{pxsize}_1 = z_{\mathrm{size}}$ and $\mathrm{pxsize}_2 =
y_{\mathrm{size}}$. Because we assume that both equations describe the
same pixel, twice in detector coordinates and twice in real-space
coordinates, $p_y = p_2$ and $p_z = p_1$.

CHECK IF $p_y = p_2$ or $p_y = - p_2$/$o_{22}=-1$ DUE TO
\texttt{pyFAI} LEFT HANDED COORDINATE SYSTEM!!!

For the translations, the equivalence is tractable by setting $p_1 =
p_2 = p_y = p_z = 0$. One obtains 3 equations that are coupled via the
rotation matrices --- as the center of rotations are different, there
should be a noticeable influence of the distance on the offsets. In
general, $D \geq L$ with $D=L$ only for $\theta_1=\theta_2=0$
($\theta_y = \theta_z = 0$. Because the rotations are applied in
different order one can not assume, \emph{a priori}, that the angles
are the same! (If at least two tilt angles are small, this may be a
good approximation)

\end{document}